mirror of
https://github.com/android-password-store/Android-Password-Store
synced 2025-08-29 13:27:46 +00:00
Refactor biometric preference handling (#1374)
Fixes #1371 Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
ae392beaeb
commit
e13a54f212
@ -58,49 +58,43 @@ class GeneralSettings(private val activity: FragmentActivity) : SettingsProvider
|
|||||||
defaultValue = false
|
defaultValue = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val canAuthenticate = BiometricAuthenticator.canAuthenticate(activity)
|
||||||
checkBox(PreferenceKeys.BIOMETRIC_AUTH) {
|
checkBox(PreferenceKeys.BIOMETRIC_AUTH) {
|
||||||
titleRes = R.string.pref_biometric_auth_title
|
titleRes = R.string.pref_biometric_auth_title
|
||||||
defaultValue = false
|
defaultValue = false
|
||||||
}
|
enabled = canAuthenticate
|
||||||
.apply {
|
summaryRes =
|
||||||
val canAuthenticate = BiometricAuthenticator.canAuthenticate(activity)
|
if (canAuthenticate) R.string.pref_biometric_auth_summary else R.string.pref_biometric_auth_summary_error
|
||||||
if (!canAuthenticate) {
|
onClick {
|
||||||
enabled = false
|
enabled = false
|
||||||
checked = false
|
val isChecked = checked
|
||||||
summaryRes = R.string.pref_biometric_auth_summary_error
|
activity.sharedPrefs.edit {
|
||||||
} else {
|
BiometricAuthenticator.authenticate(activity) { result ->
|
||||||
summaryRes = R.string.pref_biometric_auth_summary
|
when (result) {
|
||||||
onClick {
|
is BiometricAuthenticator.Result.Success -> {
|
||||||
enabled = false
|
// Apply the changes
|
||||||
val isChecked = checked
|
putBoolean(PreferenceKeys.BIOMETRIC_AUTH, checked)
|
||||||
activity.sharedPrefs.edit {
|
enabled = true
|
||||||
BiometricAuthenticator.authenticate(activity) { result ->
|
}
|
||||||
when (result) {
|
else -> {
|
||||||
is BiometricAuthenticator.Result.Success -> {
|
// If any error occurs, revert back to the previous
|
||||||
// Apply the changes
|
// state. This
|
||||||
putBoolean(PreferenceKeys.BIOMETRIC_AUTH, checked)
|
// catch-all clause includes the cancellation case.
|
||||||
enabled = true
|
putBoolean(PreferenceKeys.BIOMETRIC_AUTH, !checked)
|
||||||
}
|
checked = !isChecked
|
||||||
else -> {
|
enabled = true
|
||||||
// If any error occurs, revert back to the previous
|
|
||||||
// state. This
|
|
||||||
// catch-all clause includes the cancellation case.
|
|
||||||
putBoolean(PreferenceKeys.BIOMETRIC_AUTH, !checked)
|
|
||||||
checked = !isChecked
|
|
||||||
enabled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
|
||||||
activity.getSystemService<ShortcutManager>()?.apply {
|
|
||||||
removeDynamicShortcuts(dynamicShortcuts.map { it.id }.toMutableList())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||||
|
activity.getSystemService<ShortcutManager>()?.apply {
|
||||||
|
removeDynamicShortcuts(dynamicShortcuts.map { it.id }.toMutableList())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user