Disable Grant Button for 1 seconds after popup display

This commit is contained in:
Fox2Code 2020-02-12 05:45:10 +00:00 committed by GitHub
parent 36897ceb19
commit 10eb159e1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -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<ComparableRvItem<*>> { 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() {

View File

@ -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" />
</LinearLayout>