Pin : clean remaining pin code attempts
This commit is contained in:
parent
1d314e198a
commit
b135670196
1 changed files with 4 additions and 2 deletions
|
|
@ -45,13 +45,13 @@ class PreferencesPinCodeStore @Inject constructor(
|
||||||
|
|
||||||
override suspend fun getRemainingPinCodeAttemptsNumber(): Int {
|
override suspend fun getRemainingPinCodeAttemptsNumber(): Int {
|
||||||
return context.dataStore.data.map { preferences ->
|
return context.dataStore.data.map { preferences ->
|
||||||
preferences[remainingAttemptsKey] ?: 0
|
preferences.getRemainingPinCodeAttemptsNumber()
|
||||||
}.first()
|
}.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onWrongPin() {
|
override suspend fun onWrongPin() {
|
||||||
context.dataStore.edit { preferences ->
|
context.dataStore.edit { preferences ->
|
||||||
val current = preferences[remainingAttemptsKey] ?: 0
|
val current = preferences.getRemainingPinCodeAttemptsNumber()
|
||||||
val remaining = (current - 1).coerceAtLeast(0)
|
val remaining = (current - 1).coerceAtLeast(0)
|
||||||
preferences[remainingAttemptsKey] = remaining
|
preferences[remainingAttemptsKey] = remaining
|
||||||
}
|
}
|
||||||
|
|
@ -86,4 +86,6 @@ class PreferencesPinCodeStore @Inject constructor(
|
||||||
preferences[pinCodeKey] != null
|
preferences[pinCodeKey] != null
|
||||||
}.first()
|
}.first()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun Preferences.getRemainingPinCodeAttemptsNumber() = this[remainingAttemptsKey] ?: LockScreenConfig.MAX_PIN_CODE_ATTEMPTS_NUMBER_BEFORE_LOGOUT
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue