Fix NPE of SuRequestViewModel

countdown timer may have not initialized when backpressed
This commit is contained in:
LoveSy 2022-01-27 07:15:32 +08:00 committed by John Wu
parent 1893359142
commit 18de60f68c

View File

@ -73,7 +73,7 @@ class SuRequestViewModel(
val itemBinding = ItemBinding.of<String>(BR.item, R.layout.item_spinner) val itemBinding = ItemBinding.of<String>(BR.item, R.layout.item_spinner)
private val handler = SuRequestHandler(AppContext.packageManager, policyDB) private val handler = SuRequestHandler(AppContext.packageManager, policyDB)
private lateinit var timer: CountDownTimer private var timer: CountDownTimer? = null
fun grantPressed() { fun grantPressed() {
cancelTimer() cancelTimer()
@ -121,7 +121,7 @@ class SuRequestViewModel(
} }
private fun respond(action: Int) { private fun respond(action: Int) {
timer.cancel() timer?.cancel()
val pos = selectedItemPosition val pos = selectedItemPosition
timeoutPrefs.edit().putInt(handler.policy.packageName, pos).apply() timeoutPrefs.edit().putInt(handler.policy.packageName, pos).apply()
@ -132,7 +132,7 @@ class SuRequestViewModel(
} }
private fun cancelTimer() { private fun cancelTimer() {
timer.cancel() timer?.cancel()
denyText.seconds = 0 denyText.seconds = 0
} }