From 10eb159e1b634b5730e2fc67cf8a0d9a4db0d889 Mon Sep 17 00:00:00 2001 From: Fox2Code <42963271+Fox2Code@users.noreply.github.com> Date: Wed, 12 Feb 2020 05:45:10 +0000 Subject: [PATCH] Disable Grant Button for 1 seconds after popup display --- .../magisk/legacy/surequest/SuRequestViewModel.kt | 7 ++++++- app/src/main/res/layout/activity_request.xml | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/legacy/surequest/SuRequestViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/legacy/surequest/SuRequestViewModel.kt index c9338f568..582750b9a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/legacy/surequest/SuRequestViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/legacy/surequest/SuRequestViewModel.kt @@ -39,6 +39,8 @@ class SuRequestViewModel( val selectedItemPosition = KObservableField(0) + val grantEnabled = KObservableField(false) + private val items = DiffObservableList(ComparableRvItem.callback) private val itemBinding = ItemBinding.of> { binding, _, item -> item.bind(binding) @@ -104,7 +106,10 @@ class SuRequestViewModel( val millis = SECONDS.toMillis(Config.suDefaultTimeout.toLong()) timer = object : CountDownTimer(millis, 1000) { override fun onTick(remains: Long) { - denyText.value = "${res.getString(R.string.deny)} (${remains / 1000})" + if (remains <= millis - 1000) { + grantEnabled.value = true + } + denyText.value = "${res.getString(R.string.deny)} (${(remains / 1000) + 1})" } override fun onFinish() { diff --git a/app/src/main/res/layout/activity_request.xml b/app/src/main/res/layout/activity_request.xml index 9f51c3b98..ff6f9b3be 100644 --- a/app/src/main/res/layout/activity_request.xml +++ b/app/src/main/res/layout/activity_request.xml @@ -141,6 +141,7 @@ android:layout_height="wrap_content" android:layout_weight="1" android:onClick="@{() -> viewModel.grantPressed()}" + android:enabled="@{viewModel.grantEnabled}" android:text="@string/grant" />