Fix crash when entering to "Protect access" screen.

This commit is contained in:
Benoit Marty 2023-05-09 13:46:49 +02:00
parent 79b451546d
commit 8b7601029b

View file

@ -16,9 +16,7 @@
package im.vector.app.features.settings
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.preference.Preference
import androidx.preference.SwitchPreference
import dagger.hilt.android.AndroidEntryPoint
@ -80,13 +78,13 @@ class VectorSettingsPinFragment :
override fun onResume() {
super.onResume()
updateBiometricPrefState(isPinCodeChecked = usePinCodePref.isChecked)
viewLifecycleOwner.lifecycleScope.launch {
refreshPinCodeStatus()
}
}
override fun bindPref() {
refreshPinCodeStatus()
usePinCodePref.setOnPreferenceChangeListener { _, value ->
val isChecked = (value as? Boolean).orFalse()
updateBiometricPrefState(isPinCodeChecked = isChecked)
@ -130,9 +128,7 @@ class VectorSettingsPinFragment :
.onFailure { Timber.e(it) }
}
private fun refreshPinCodeStatus() {
viewLifecycleOwner.lifecycleScope.launch {
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) {
private suspend fun refreshPinCodeStatus() {
val hasPinCode = pinCodeStore.hasEncodedPin()
usePinCodePref.isChecked = hasPinCode
usePinCodePref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
@ -162,14 +158,12 @@ class VectorSettingsPinFragment :
true
}
}
}
}
private fun showEnableBiometricErrorMessage() {
context?.toast(R.string.settings_security_pin_code_use_biometrics_error)
}
private val pinActivityResultLauncher = registerStartForActivityResult {
refreshPinCodeStatus()
// Nothing to do, refreshPinCodeStatus() will be called by `onResume`
}
}