Skip to content

Commit c583301

Browse files
Add option to enable/disable login timeout option (#1081)
1 parent c48cf37 commit c583301

File tree

6 files changed

+83
-21
lines changed

6 files changed

+83
-21
lines changed

app/src/main/java/com/yogeshpaliyal/keypass/ui/auth/components/ButtonBar.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ fun ButtonBar(
5252

5353
if (userSettings.isBiometricEnable && state is AuthState.Login) {
5454
OutlinedButton(onClick = {
55+
5556
val currentTime = System.currentTimeMillis()
5657
val lastPasswordLoginTime = userSettings.lastPasswordLoginTime ?: -1
57-
if (lastPasswordLoginTime > 0 && (currentTime - lastPasswordLoginTime).toDuration(
58+
if (userSettings.biometricLoginTimeoutEnable != true || (lastPasswordLoginTime > 0 && (currentTime - lastPasswordLoginTime).toDuration(
5859
DurationUnit.MILLISECONDS
59-
).inWholeHours < 24
60+
).inWholeHours < 24)
6061
) {
6162
setBiometricEnable(true)
6263
} else {
@@ -97,7 +98,9 @@ fun ButtonBar(
9798
coroutineScope.launch {
9899
val savedPassword = userSettings.keyPassPassword
99100
if (savedPassword == password) {
100-
context.updateLastPasswordLoginTime(System.currentTimeMillis())
101+
if(userSettings.biometricLoginTimeoutEnable == true) {
102+
context.updateLastPasswordLoginTime(System.currentTimeMillis())
103+
}
101104
KeyPassRedux.getLastScreen()?.let {
102105
dispatchAction(GoBackAction)
103106
} ?: dispatchAction(NavigationAction(HomeState(), true))

app/src/main/java/com/yogeshpaliyal/keypass/ui/commonComponents/PreferenceItem.kt

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ import androidx.compose.ui.unit.dp
2323

2424
@Composable
2525
fun PreferenceItem(
26-
@StringRes title: Int? = null,
27-
@StringRes summary: Int? = null,
28-
summaryStr: String? = null,
26+
title: String? = null,
27+
summary: String? = null,
2928
icon: ImageVector? = null,
3029
painter: Painter? = null,
3130
isCategory: Boolean = false,
@@ -63,33 +62,49 @@ fun PreferenceItem(
6362
PreferenceItemTitle(title = title)
6463
}
6564
}
66-
if (summary != null || summaryStr != null) {
67-
val summaryText = if (summary != null) {
68-
stringResource(id = summary)
69-
} else {
70-
summaryStr
71-
}
72-
if (summaryText != null) {
73-
Text(text = summaryText, style = MaterialTheme.typography.bodyMedium)
74-
}
65+
if (summary != null) {
66+
Text(text = summary, style = MaterialTheme.typography.bodyMedium)
7567
}
7668
}
7769
}
7870
}
7971

72+
73+
@Composable
74+
fun PreferenceItem(
75+
@StringRes title: Int? = null,
76+
@StringRes summary: Int? = null,
77+
summaryStr: String? = null,
78+
icon: ImageVector? = null,
79+
painter: Painter? = null,
80+
isCategory: Boolean = false,
81+
removeIconSpace: Boolean = false,
82+
onClickItem: (() -> Unit)? = null
83+
) {
84+
PreferenceItem(
85+
title?.let { stringResource(it) },
86+
summary?.let { stringResource(summary) } ?: summaryStr,
87+
icon,
88+
painter,
89+
isCategory,
90+
removeIconSpace,
91+
onClickItem
92+
)
93+
}
94+
8095
@Composable
81-
private fun CategoryTitle(title: Int) {
96+
private fun CategoryTitle(title: String) {
8297
Text(
83-
text = stringResource(id = title),
98+
text = title,
8499
color = MaterialTheme.colorScheme.tertiary,
85100
style = MaterialTheme.typography.titleMedium
86101
)
87102
}
88103

89104
@Composable
90-
private fun PreferenceItemTitle(title: Int) {
105+
private fun PreferenceItemTitle(title: String) {
91106
Text(
92-
text = stringResource(id = title),
107+
text = title,
93108
style = MaterialTheme.typography.bodyLarge
94109
)
95110
}

app/src/main/java/com/yogeshpaliyal/keypass/ui/settings/MySettingsFragment.kt

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ import androidx.compose.material.icons.Icons
1919
import androidx.compose.material.icons.outlined.Info
2020
import androidx.compose.material.icons.rounded.Feedback
2121
import androidx.compose.material.icons.rounded.Fingerprint
22+
import androidx.compose.material.icons.rounded.LockReset
2223
import androidx.compose.material.icons.rounded.Password
2324
import androidx.compose.material.icons.rounded.Share
24-
import androidx.compose.material3.Divider
25+
import androidx.compose.material3.HorizontalDivider
2526
import androidx.compose.material3.MaterialTheme
2627
import androidx.compose.material3.Text
2728
import androidx.compose.runtime.Composable
@@ -35,9 +36,11 @@ import androidx.compose.ui.Alignment
3536
import androidx.compose.ui.Modifier
3637
import androidx.compose.ui.platform.LocalContext
3738
import androidx.compose.ui.res.painterResource
39+
import androidx.compose.ui.res.stringResource
3840
import androidx.compose.ui.unit.dp
3941
import com.yogeshpaliyal.common.utils.email
4042
import com.yogeshpaliyal.common.utils.setBiometricEnable
43+
import com.yogeshpaliyal.common.utils.setBiometricLoginTimeoutEnable
4144
import com.yogeshpaliyal.keypass.BuildConfig
4245
import com.yogeshpaliyal.keypass.R
4346
import com.yogeshpaliyal.keypass.ui.commonComponents.PreferenceItem
@@ -119,7 +122,9 @@ fun MySettingCompose() {
119122

120123
BiometricsOption()
121124

122-
Divider(
125+
AutoDisableBiometric()
126+
127+
HorizontalDivider(
123128
modifier = Modifier
124129
.fillMaxWidth(1f)
125130
.height(1.dp)
@@ -246,3 +251,33 @@ fun BiometricsOption() {
246251
}
247252
}
248253
}
254+
255+
256+
@Composable
257+
fun AutoDisableBiometric() {
258+
val context = LocalContext.current
259+
val userSettings = LocalUserSettings.current
260+
261+
val coroutineScope = rememberCoroutineScope()
262+
263+
264+
val enableDisableStr =
265+
if (userSettings.biometricLoginTimeoutEnable == true) {
266+
R.string.enabled
267+
} else {
268+
R.string.disabled
269+
}
270+
271+
PreferenceItem(
272+
title = R.string.biometric_login_timeout,
273+
summary = enableDisableStr,
274+
icon = Icons.Rounded.LockReset,
275+
onClickItem = if (userSettings.isBiometricEnable) {
276+
{
277+
coroutineScope.launch {
278+
context.setBiometricLoginTimeoutEnable(userSettings.biometricLoginTimeoutEnable != true)
279+
}
280+
}
281+
} else null
282+
)
283+
}

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
<string name="biometric_error_hw_unavailable">Biometric features are currently unavailable.</string>
110110
<string name="biometric_error_none_enrolled">Setup biometric on your device.</string>
111111
<string name="unlock_with_biometric">Unlock with biometric</string>
112+
<string name="biometric_login_timeout">Biometric Login Timeout (24 hrs)</string>
112113
<string name="password_set_from_settings">Please set password for your device first from phone settings</string>
113114
<string name="authentication_failed">Authentication Failed</string>
114115
<string name="authentication_error">Authentication Error %s</string>

common/src/main/java/com/yogeshpaliyal/common/data/UserSettings.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ data class UserSettings(
2222
val currentAppVersion: Int? = null,
2323
val passwordConfig: PasswordConfig = PasswordConfig.Initial,
2424
val passwordHint: String? = null,
25+
val biometricLoginTimeoutEnable: Boolean? = null,
2526
val lastPasswordLoginTime: Long? = null,
2627
val lastKeyPhraseEnterTime: Long? = null
2728
) {

common/src/main/java/com/yogeshpaliyal/common/utils/SharedPreferenceUtils.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ suspend fun Context.setBiometricEnable(isBiometricEnable: Boolean) {
6262
}
6363
}
6464

65+
suspend fun Context.setBiometricLoginTimeoutEnable(biometricLoginTimeoutEnable: Boolean) {
66+
getUserSettingsDataStore().updateData {
67+
it.copy(biometricLoginTimeoutEnable = biometricLoginTimeoutEnable)
68+
}
69+
}
70+
71+
6572
suspend fun Context.setBackupDirectory(backupDirectory: String) {
6673
getUserSettingsDataStore().updateData {
6774
it.copy(backupDirectory = backupDirectory)

0 commit comments

Comments
 (0)