Skip to content

Commit 2b88e6b

Browse files
committed
Use the current passcode length on unlock screen
1 parent 87d7ea5 commit 2b88e6b

6 files changed

Lines changed: 30 additions & 13 deletions

File tree

app/src/main/java/ua/com/radiokot/money/lock/AppLockModule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ val appLockModule = module {
6262

6363
viewModel {
6464
SetUpPasscodeScreenViewModel(
65+
passcodeLength = 4,
6566
enableAppLockUseCase = get(),
6667
)
6768
}

app/src/main/java/ua/com/radiokot/money/lock/logic/AppLock.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,37 @@ import kotlinx.coroutines.CoroutineScope
2525
import kotlinx.coroutines.Dispatchers
2626
import kotlinx.coroutines.SupervisorJob
2727
import kotlinx.coroutines.flow.StateFlow
28+
import ua.com.radiokot.money.MoneyAppActivity
2829
import ua.com.radiokot.money.lazyLogger
2930
import ua.com.radiokot.money.lock.data.AppLockPreferences
3031
import ua.com.radiokot.money.map
3132

33+
/**
34+
* A lock for app screens.
35+
* Locks if the passcode is set up and the app has been in background long enough.
36+
* It is purely visual, no encryption/decryption is happening under the hood.
37+
*
38+
* @see MoneyAppActivity.requiresUnlocking
39+
*/
3240
class AppLock(
3341
private val preferences: AppLockPreferences,
3442
) {
3543
private val log by lazyLogger("AppLock")
3644
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default)
3745
private var wentToBackgroundAtMs: Long = 0
3846

47+
/**
48+
* If [isEnabled], length of the current passcode,
49+
* 0 otherwise.
50+
*/
51+
val currentPasscodeLength: Int
52+
get() =
53+
preferences
54+
.appLockPasscode
55+
.value
56+
?.length
57+
?: 0
58+
3959
val isEnabled: StateFlow<Boolean> =
4060
preferences
4161
.appLockPasscode

app/src/main/java/ua/com/radiokot/money/lock/view/SetUpPasscodeScreenViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ import ua.com.radiokot.money.lazyLogger
3232
import ua.com.radiokot.money.lock.logic.EnableAppLockUseCase
3333

3434
class SetUpPasscodeScreenViewModel(
35+
val passcodeLength: Int,
3536
private val enableAppLockUseCase: EnableAppLockUseCase,
3637
) : ViewModel() {
3738

3839
private val log by lazyLogger("SetUpPasscodeScreenVM")
3940

40-
val passcodeLength = 4
4141
private val _isRepeating: MutableStateFlow<Boolean> = MutableStateFlow(false)
4242
val isRepeating = _isRepeating.asStateFlow()
4343
private val _passcode: MutableStateFlow<String> = MutableStateFlow("")

app/src/main/java/ua/com/radiokot/money/lock/view/UnlockActivity.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ class UnlockActivity : MoneyAppActivity(
100100
@Composable
101101
private fun Content() {
102102

103-
val passcode = rememberSaveable {
103+
val enteredPasscode = rememberSaveable {
104104
mutableStateOf("")
105105
}
106-
val length = 4
106+
val length = lock.currentPasscodeLength
107107

108108
BoxWithConstraints(
109109
contentAlignment = Alignment.Center,
@@ -140,17 +140,17 @@ class UnlockActivity : MoneyAppActivity(
140140

141141
PasscodeInput(
142142
length = length,
143-
passcode = passcode,
143+
passcode = enteredPasscode,
144144
onPasscodeChanged = { newValue: String ->
145145

146-
passcode.value = newValue
146+
enteredPasscode.value = newValue
147147

148148
if (newValue.length == length) {
149149
if (lock.unlock(newValue)) {
150150
setResult(RESULT_OK)
151151
finish()
152152
} else {
153-
passcode.value = ""
153+
enteredPasscode.value = ""
154154

155155
Toast
156156
.makeText(
@@ -163,7 +163,7 @@ class UnlockActivity : MoneyAppActivity(
163163
}
164164
},
165165
onBackspaceClicked = {
166-
passcode.value = passcode.value.dropLast(1)
166+
enteredPasscode.value = enteredPasscode.value.dropLast(1)
167167
},
168168
isBiometricsButtonShown = canUseBiometrics,
169169
onBiometricsClicked = ::showBiometricsPrompt,

fastlane/metadata/android/en-US/changelogs/35.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added:
2+
- Ability to lock the app with a passcode

0 commit comments

Comments
 (0)