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) {

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) {

View File

@ -24,13 +24,13 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/flash_content"
app:items="@{viewModel.items}"
scrollToLast="@{true}"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clipToPadding="false"
android:orientation="vertical"
app:fitsSystemWindowsInsets="start|end|bottom"
app:items="@{viewModel.items}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/item_console_md2" />
@ -38,26 +38,30 @@
</HorizontalScrollView>
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/restart_btn"
gone="@{!viewModel.loaded || !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:focusable="true"
android:onClick="@{() -> viewModel.restartPressed()}"
android:text="@string/reboot"
android:textAllCaps="false"
android:textColor="?colorOnPrimary"
android:textStyle="bold"
app:layout_fitsSystemWindowsInsets="bottom"
app:backgroundTint="?colorPrimary"
app:icon="@drawable/ic_restart"
app:iconTint="?colorOnPrimary" />
app:iconTint="?colorOnPrimary"
app:layout_fitsSystemWindowsInsets="bottom" />
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/snackbar_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/snackbar_container"
app:fitsSystemWindowsInsets="top|bottom" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>