diff --git a/app/src/main/java/com/topjohnwu/magisk/arch/BaseUIFragment.kt b/app/src/main/java/com/topjohnwu/magisk/arch/BaseUIFragment.kt index 318ab143f..ad339bd69 100644 --- a/app/src/main/java/com/topjohnwu/magisk/arch/BaseUIFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/arch/BaseUIFragment.kt @@ -41,6 +41,11 @@ abstract class BaseUIFragment : return binding.root } + override fun onStart() { + super.onStart() + activity.supportActionBar?.subtitle = null + } + override fun onEventDispatched(event: ViewEvent) = when(event) { is ContextExecutor -> event(requireContext()) is ActivityExecutor -> event(activity) diff --git a/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt b/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt index 181df636c..63214b228 100644 --- a/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt +++ b/app/src/main/java/com/topjohnwu/magisk/di/ViewModelsModule.kt @@ -29,6 +29,6 @@ val viewModelModules = module { viewModel { MainViewModel() } // Legacy - viewModel { (args: FlashFragmentArgs) -> FlashViewModel(args, get()) } + viewModel { (args: FlashFragmentArgs) -> FlashViewModel(args) } viewModel { SuRequestViewModel(get(), get(), get(SUTimeout), get()) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt index 90ec3c1d6..d57608b4c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashFragment.kt @@ -32,6 +32,10 @@ class FlashFragment : BaseUIFragment() super.onStart() setHasOptionsMenu(true) activity.setTitle(R.string.flash_screen_title) + + viewModel.subtitle.observe(this) { + activity.supportActionBar?.setSubtitle(it) + } } override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt index 92d89997d..35fd8a6a7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/flash/FlashViewModel.kt @@ -1,9 +1,10 @@ package com.topjohnwu.magisk.ui.flash -import android.content.res.Resources import android.net.Uri import android.view.MenuItem import androidx.databinding.Bindable +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope import com.topjohnwu.magisk.BR import com.topjohnwu.magisk.R @@ -26,17 +27,15 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch class FlashViewModel( - args: FlashFragmentArgs, - private val resources: Resources + args: FlashFragmentArgs ) : BaseViewModel() { @get:Bindable var showReboot = Shell.rootAccess() set(value) = set(value, field, { field = it }, BR.showReboot) - @get:Bindable - var behaviorText = resources.getString(R.string.flashing) - set(value) = set(value, field, { field = it }, BR.behaviorText) + private val _subtitle = MutableLiveData(R.string.flashing) + val subtitle get() = _subtitle as LiveData val adapter = RvBindingAdapter() val items = diffListOf() @@ -91,9 +90,9 @@ class FlashViewModel( private fun onResult(success: Boolean) { state = if (success) State.LOADED else State.LOADING_FAILED - behaviorText = when { - success -> resources.getString(R.string.done) - else -> resources.getString(R.string.failure) + when { + success -> _subtitle.postValue(R.string.done) + else -> _subtitle.postValue(R.string.failure) } } diff --git a/app/src/main/res/layout/fragment_flash_md2.xml b/app/src/main/res/layout/fragment_flash_md2.xml index d09e242fb..f28ed7f88 100644 --- a/app/src/main/res/layout/fragment_flash_md2.xml +++ b/app/src/main/res/layout/fragment_flash_md2.xml @@ -56,29 +56,6 @@ app:icon="@drawable/ic_restart" app:iconTint="?colorOnPrimary" /> - - - - - -