fix restart button focus on flash result

This commit is contained in:
nikk gitanes
2022-06-08 04:47:14 +03:00
committed by John Wu
parent 482a5b991b
commit e0d5d90267
3 changed files with 27 additions and 7 deletions

View File

@@ -6,6 +6,7 @@ import android.content.pm.ActivityInfo
import android.net.Uri
import android.os.Bundle
import android.view.*
import androidx.core.view.isVisible
import androidx.navigation.NavDeepLinkBuilder
import com.topjohnwu.magisk.MainDirections
import com.topjohnwu.magisk.R
@@ -37,6 +38,15 @@ class FlashFragment : BaseFragment<FragmentFlashMd2Binding>() {
viewModel.subtitle.observe(this) {
activity?.supportActionBar?.setSubtitle(it)
}
viewModel.flashResult.observe(this) { success ->
binding.restartBtn.apply {
if (success && viewModel.showReboot) {
if (!this.isVisible) this.show()
if (!this.isFocused) this.requestFocus()
}
}
}
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
@@ -66,7 +76,7 @@ class FlashFragment : BaseFragment<FragmentFlashMd2Binding>() {
}
override fun onKeyEvent(event: KeyEvent): Boolean {
return when(event.keyCode) {
return when (event.keyCode) {
KeyEvent.KEYCODE_VOLUME_UP,
KeyEvent.KEYCODE_VOLUME_DOWN -> true
else -> false

View File

@@ -34,6 +34,10 @@ class FlashViewModel : BaseViewModel() {
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
@@ -88,6 +92,7 @@ class FlashViewModel : BaseViewModel() {
success -> _subtitle.postValue(R.string.done)
else -> _subtitle.postValue(R.string.failure)
}
_flashResult.value = success
}
fun onMenuItemClicked(item: MenuItem): Boolean {
@@ -100,7 +105,8 @@ class FlashViewModel : BaseViewModel() {
private fun savePressed() = withExternalRW {
viewModelScope.launch(Dispatchers.IO) {
val name = "magisk_install_log_%s.log".format(
System.currentTimeMillis().toTime(timeFormatStandard))
System.currentTimeMillis().toTime(timeFormatStandard)
)
val file = MediaStoreUtils.getFile(name, true)
file.uri.outputStream().bufferedWriter().use { writer ->
synchronized(logItems) {