Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 28 additions & 34 deletions app/src/main/java/dev/msfjarvis/aps/ui/settings/GeneralSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,49 +58,43 @@ class GeneralSettings(private val activity: FragmentActivity) : SettingsProvider
defaultValue = false
}

val canAuthenticate = BiometricAuthenticator.canAuthenticate(activity)
checkBox(PreferenceKeys.BIOMETRIC_AUTH) {
titleRes = R.string.pref_biometric_auth_title
defaultValue = false
}
.apply {
val canAuthenticate = BiometricAuthenticator.canAuthenticate(activity)
if (!canAuthenticate) {
enabled = false
checked = false
summaryRes = R.string.pref_biometric_auth_summary_error
} else {
summaryRes = R.string.pref_biometric_auth_summary
onClick {
enabled = false
val isChecked = checked
activity.sharedPrefs.edit {
BiometricAuthenticator.authenticate(activity) { result ->
when (result) {
is BiometricAuthenticator.Result.Success -> {
// Apply the changes
putBoolean(PreferenceKeys.BIOMETRIC_AUTH, checked)
enabled = true
}
else -> {
// 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
}
}
enabled = canAuthenticate
summaryRes =
if (canAuthenticate) R.string.pref_biometric_auth_summary else R.string.pref_biometric_auth_summary_error
onClick {
enabled = false
val isChecked = checked
activity.sharedPrefs.edit {
BiometricAuthenticator.authenticate(activity) { result ->
when (result) {
is BiometricAuthenticator.Result.Success -> {
// Apply the changes
putBoolean(PreferenceKeys.BIOMETRIC_AUTH, checked)
enabled = true
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
activity.getSystemService<ShortcutManager>()?.apply {
removeDynamicShortcuts(dynamicShortcuts.map { it.id }.toMutableList())
else -> {
// 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
}
}
false
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
activity.getSystemService<ShortcutManager>()?.apply {
removeDynamicShortcuts(dynamicShortcuts.map { it.id }.toMutableList())
}
}
false
}
}
}
}
}