mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-23 18:15:30 +00:00
Maintain separate flash screen state
This commit is contained in:
parent
e0d5d90267
commit
aabc36f86b
@ -35,13 +35,16 @@ class FlashFragment : BaseFragment<FragmentFlashMd2Binding>() {
|
||||
setHasOptionsMenu(true)
|
||||
activity?.setTitle(R.string.flash_screen_title)
|
||||
|
||||
viewModel.subtitle.observe(this) {
|
||||
activity?.supportActionBar?.setSubtitle(it)
|
||||
}
|
||||
|
||||
viewModel.flashResult.observe(this) { success ->
|
||||
binding.restartBtn.apply {
|
||||
if (success && viewModel.showReboot) {
|
||||
viewModel.flashState.observe(this) {
|
||||
activity?.supportActionBar?.setSubtitle(
|
||||
when (it) {
|
||||
FlashViewModel.State.FLASHING -> R.string.flashing
|
||||
FlashViewModel.State.SUCCESS -> R.string.done
|
||||
FlashViewModel.State.FAILED -> R.string.failure
|
||||
}
|
||||
)
|
||||
if (it == FlashViewModel.State.SUCCESS && viewModel.showReboot) {
|
||||
binding.restartBtn.apply {
|
||||
if (!this.isVisible) this.show()
|
||||
if (!this.isFocused) this.requestFocus()
|
||||
}
|
||||
@ -84,7 +87,8 @@ class FlashFragment : BaseFragment<FragmentFlashMd2Binding>() {
|
||||
}
|
||||
|
||||
override fun onBackPressed(): Boolean {
|
||||
if (viewModel.loading) return true
|
||||
if (viewModel.flashing.value == true)
|
||||
return true
|
||||
return super.onBackPressed()
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import android.view.MenuItem
|
||||
import androidx.databinding.Bindable
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.Transformations
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.topjohnwu.magisk.BR
|
||||
import com.topjohnwu.magisk.R
|
||||
@ -27,17 +28,18 @@ import kotlinx.coroutines.launch
|
||||
|
||||
class FlashViewModel : BaseViewModel() {
|
||||
|
||||
enum class State {
|
||||
FLASHING, SUCCESS, FAILED
|
||||
}
|
||||
|
||||
private val _flashState = MutableLiveData(State.FLASHING)
|
||||
val flashState: LiveData<State> get() = _flashState
|
||||
val flashing = Transformations.map(flashState) { it == State.FLASHING }
|
||||
|
||||
@get:Bindable
|
||||
var showReboot = Info.isRooted
|
||||
set(value) = set(value, field, { field = it }, BR.showReboot)
|
||||
|
||||
private val _subtitle = MutableLiveData(R.string.flashing)
|
||||
val subtitle get() = _subtitle as LiveData<Int>
|
||||
|
||||
private val _flashResult = MutableLiveData<Boolean>()
|
||||
val flashResult: LiveData<Boolean>
|
||||
get() = _flashResult
|
||||
|
||||
val items = diffListOf<ConsoleItem>()
|
||||
lateinit var args: FlashFragmentArgs
|
||||
|
||||
@ -87,12 +89,7 @@ class FlashViewModel : BaseViewModel() {
|
||||
}
|
||||
|
||||
private fun onResult(success: Boolean) {
|
||||
state = if (success) State.LOADED else State.LOADING_FAILED
|
||||
when {
|
||||
success -> _subtitle.postValue(R.string.done)
|
||||
else -> _subtitle.postValue(R.string.failure)
|
||||
}
|
||||
_flashResult.value = success
|
||||
_flashState.value = if (success) State.SUCCESS else State.FAILED
|
||||
}
|
||||
|
||||
fun onMenuItemClicked(item: MenuItem): Boolean {
|
||||
|
@ -39,14 +39,14 @@
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
android:id="@+id/restart_btn"
|
||||
gone="@{!viewModel.loaded || !viewModel.showReboot}"
|
||||
gone="@{viewModel.flashing || !viewModel.showReboot}"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/l1"
|
||||
android:layout_marginBottom="@dimen/l1"
|
||||
android:clickable="@{!viewModel.loaded}"
|
||||
android:enabled="@{viewModel.loaded}"
|
||||
android:clickable="@{!viewModel.flashing}"
|
||||
android:enabled="@{!viewModel.flashing}"
|
||||
android:focusable="true"
|
||||
android:onClick="@{() -> viewModel.restartPressed()}"
|
||||
android:text="@string/reboot"
|
||||
|
Loading…
Reference in New Issue
Block a user