File tree Expand file tree Collapse file tree
app/src/main/java/ua/com/radiokot/money/lock
fastlane/metadata/android/en-US/changelogs Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ val appLockModule = module {
6262
6363 viewModel {
6464 SetUpPasscodeScreenViewModel (
65+ passcodeLength = 4 ,
6566 enableAppLockUseCase = get(),
6667 )
6768 }
Original file line number Diff line number Diff line change @@ -25,17 +25,37 @@ import kotlinx.coroutines.CoroutineScope
2525import kotlinx.coroutines.Dispatchers
2626import kotlinx.coroutines.SupervisorJob
2727import kotlinx.coroutines.flow.StateFlow
28+ import ua.com.radiokot.money.MoneyAppActivity
2829import ua.com.radiokot.money.lazyLogger
2930import ua.com.radiokot.money.lock.data.AppLockPreferences
3031import 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+ */
3240class 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
Original file line number Diff line number Diff line change @@ -32,12 +32,12 @@ import ua.com.radiokot.money.lazyLogger
3232import ua.com.radiokot.money.lock.logic.EnableAppLockUseCase
3333
3434class 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 (" " )
Original file line number Diff line number Diff 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,
Load diff This file was deleted.
Original file line number Diff line number Diff line change 1+ Added:
2+ - Ability to lock the app with a passcode
You can’t perform that action at this time.
0 commit comments