mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 02:15:46 +03:00
Fix crash when entering to "Protect access" screen.
This commit is contained in:
parent
79b451546d
commit
8b7601029b
1 changed files with 30 additions and 36 deletions
|
@ -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,38 +128,34 @@ class VectorSettingsPinFragment :
|
|||
.onFailure { Timber.e(it) }
|
||||
}
|
||||
|
||||
private fun refreshPinCodeStatus() {
|
||||
viewLifecycleOwner.lifecycleScope.launch {
|
||||
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) {
|
||||
val hasPinCode = pinCodeStore.hasEncodedPin()
|
||||
usePinCodePref.isChecked = hasPinCode
|
||||
usePinCodePref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
if (hasPinCode) {
|
||||
lifecycleScope.launch {
|
||||
pinCodeStore.deletePinCode()
|
||||
refreshPinCodeStatus()
|
||||
}
|
||||
} else {
|
||||
navigator.openPinCode(
|
||||
requireContext(),
|
||||
pinActivityResultLauncher,
|
||||
PinMode.CREATE
|
||||
)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
changePinCodePref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
if (hasPinCode) {
|
||||
navigator.openPinCode(
|
||||
requireContext(),
|
||||
pinActivityResultLauncher,
|
||||
PinMode.MODIFY
|
||||
)
|
||||
}
|
||||
true
|
||||
private suspend fun refreshPinCodeStatus() {
|
||||
val hasPinCode = pinCodeStore.hasEncodedPin()
|
||||
usePinCodePref.isChecked = hasPinCode
|
||||
usePinCodePref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
if (hasPinCode) {
|
||||
lifecycleScope.launch {
|
||||
pinCodeStore.deletePinCode()
|
||||
refreshPinCodeStatus()
|
||||
}
|
||||
} else {
|
||||
navigator.openPinCode(
|
||||
requireContext(),
|
||||
pinActivityResultLauncher,
|
||||
PinMode.CREATE
|
||||
)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
changePinCodePref.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
if (hasPinCode) {
|
||||
navigator.openPinCode(
|
||||
requireContext(),
|
||||
pinActivityResultLauncher,
|
||||
PinMode.MODIFY
|
||||
)
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,6 +164,6 @@ class VectorSettingsPinFragment :
|
|||
}
|
||||
|
||||
private val pinActivityResultLauncher = registerStartForActivityResult {
|
||||
refreshPinCodeStatus()
|
||||
// Nothing to do, refreshPinCodeStatus() will be called by `onResume`
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue