From 60894e458ff7a61a093cf8757fddcdadf2859f05 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sun, 1 Sep 2024 23:37:56 +0800 Subject: [PATCH] Automatically close action fragment when action exits successfully --- .../magisk/ui/module/ActionFragment.kt | 28 +++++++++++++++---- app/core/src/main/res/values/strings.xml | 3 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ActionFragment.kt b/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ActionFragment.kt index 4117aba99..2c80954b1 100644 --- a/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ActionFragment.kt +++ b/app/apk/src/main/java/com/topjohnwu/magisk/ui/module/ActionFragment.kt @@ -8,11 +8,13 @@ import android.view.Menu import android.view.MenuInflater import android.view.MenuItem import android.view.View +import android.widget.Toast import androidx.core.view.MenuProvider import androidx.core.view.isVisible import com.topjohnwu.magisk.R import com.topjohnwu.magisk.arch.BaseFragment import com.topjohnwu.magisk.arch.viewModel +import com.topjohnwu.magisk.core.ktx.toast import com.topjohnwu.magisk.databinding.FragmentActionMd2Binding import com.topjohnwu.magisk.ui.flash.FlashViewModel import timber.log.Timber @@ -46,11 +48,27 @@ class ActionFragment : BaseFragment(), MenuProvider { ActionViewModel.State.FAILED -> CoreR.string.failure } ) - if (it != ActionViewModel.State.RUNNING) { - binding.closeBtn.apply { - if (!this.isVisible) this.show() - if (!this.isFocused) this.requestFocus() + when (it) { + ActionViewModel.State.SUCCESS -> { + activity?.apply { + toast( + getString( + com.topjohnwu.magisk.core.R.string.done_action, + this@ActionFragment.viewModel.args.name + ), Toast.LENGTH_LONG + ) + onBackPressed() + } } + + ActionViewModel.State.FAILED -> { + binding.closeBtn.apply { + if (!this.isVisible) this.show() + if (!this.isFocused) this.requestFocus() + } + } + + else -> {} } } } @@ -90,7 +108,7 @@ class ActionFragment : BaseFragment(), MenuProvider { } override fun onBackPressed(): Boolean { - if (!binding.closeBtn.isVisible) return true + if (viewModel.state.value == ActionViewModel.State.RUNNING) return true return super.onBackPressed() } diff --git a/app/core/src/main/res/values/strings.xml b/app/core/src/main/res/values/strings.xml index f5a25071d..f384e52bd 100644 --- a/app/core/src/main/res/values/strings.xml +++ b/app/core/src/main/res/values/strings.xml @@ -215,8 +215,9 @@ Close Release notes Flashing… - Running... + Running… Done! + Done running action of %1$s Failed! Hiding the Magisk app… No app found to open the link