refactor: Remove PIN lock and consolidate with pattern lock
- Removed the separate PIN lock functionality. - Consolidated PIN lock related UI and logic into the pattern lock implementation. - Deleted and introduced . - Updated , , and to reflect these changes. - Added string resource.
This commit is contained in:
@@ -643,7 +643,9 @@ fun AppShell(
|
||||
var showSetRecipePasswordDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showSetListPasswordDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showSetPatternDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showSetPinDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showUnlockPatternDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var unlockPatternErrorMessage by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
var showUnlockPasswordDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showUnlockPinDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var unlockErrorMessage by rememberSaveable { mutableStateOf<String?>(null) }
|
||||
@@ -696,10 +698,10 @@ fun AppShell(
|
||||
itemToUnlockType = type
|
||||
showUnlockPasswordDialog = true
|
||||
}
|
||||
} else if (protectionType == 3) { // PIN protected
|
||||
} else if (protectionType == 3) { // Pattern protected
|
||||
itemToUnlockId = id
|
||||
itemToUnlockType = type
|
||||
showUnlockPinDialog = true
|
||||
showUnlockPatternDialog = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1183,11 +1185,11 @@ fun AppShell(
|
||||
itemToUnlockType = null
|
||||
}
|
||||
},
|
||||
showUnlockPinDialog = showUnlockPinDialog,
|
||||
onShowUnlockPinDialogChange = {
|
||||
showUnlockPinDialog = it
|
||||
showUnlockPatternDialog = showUnlockPatternDialog,
|
||||
onShowUnlockPatternDialogChange = {
|
||||
showUnlockPatternDialog = it
|
||||
if (!it) {
|
||||
unlockErrorMessage = null
|
||||
unlockPatternErrorMessage = null
|
||||
itemToUnlockId = null
|
||||
itemToUnlockType = null
|
||||
}
|
||||
@@ -1228,7 +1230,7 @@ fun AppShell(
|
||||
itemToUnlockId = null
|
||||
itemToUnlockType = null
|
||||
showUnlockPasswordDialog = false
|
||||
showUnlockPinDialog = false
|
||||
showUnlockPatternDialog = false
|
||||
} else {
|
||||
unlockErrorMessage = context.getString(R.string.incorrect_password)
|
||||
}
|
||||
@@ -1282,10 +1284,7 @@ fun AppShell(
|
||||
selectedListId = id
|
||||
showSetPatternDialog = true
|
||||
}
|
||||
LockMethod.PIN -> {
|
||||
selectedListId = id
|
||||
showSetPinDialog = true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
LockableItemType.NOTE -> {
|
||||
@@ -1301,10 +1300,7 @@ fun AppShell(
|
||||
selectedNoteId = id
|
||||
showSetPatternDialog = true
|
||||
}
|
||||
LockMethod.PIN -> {
|
||||
selectedNoteId = id
|
||||
showSetPinDialog = true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
LockableItemType.RECIPE -> {
|
||||
@@ -1320,10 +1316,7 @@ fun AppShell(
|
||||
selectedRecipeId = id
|
||||
showSetPatternDialog = true
|
||||
}
|
||||
LockMethod.PIN -> {
|
||||
selectedRecipeId = id
|
||||
showSetPinDialog = true
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1337,7 +1330,6 @@ fun AppShell(
|
||||
itemToLockType = itemToLockType,
|
||||
showSetPatternDialog = showSetPatternDialog,
|
||||
onShowSetPatternDialogChange = { showSetPatternDialog = it },
|
||||
showSetPinDialog = showSetPinDialog,
|
||||
onShowSetPinDialogChange = { showSetPinDialog = it }
|
||||
)
|
||||
|
||||
)
|
||||
}
|
||||
@@ -21,10 +21,9 @@ import androidx.compose.ui.unit.dp
|
||||
import de.lxtools.noteshop.R
|
||||
|
||||
enum class LockMethod {
|
||||
PASSWORD,
|
||||
BIOMETRIC,
|
||||
PATTERN,
|
||||
PIN
|
||||
PASSWORD
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -40,19 +39,6 @@ fun ChooseLockMethodDialog(
|
||||
title = { Text(text = stringResource(R.string.choose_lock_method)) },
|
||||
text = {
|
||||
Column {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { selectedMethod = LockMethod.PASSWORD }
|
||||
.padding(vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
RadioButton(
|
||||
selected = selectedMethod == LockMethod.PASSWORD,
|
||||
onClick = { selectedMethod = LockMethod.PASSWORD }
|
||||
)
|
||||
Text(text = stringResource(R.string.password), modifier = Modifier.padding(start = 8.dp))
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -83,15 +69,15 @@ fun ChooseLockMethodDialog(
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable { selectedMethod = LockMethod.PIN }
|
||||
.clickable { selectedMethod = LockMethod.PASSWORD }
|
||||
.padding(vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
RadioButton(
|
||||
selected = selectedMethod == LockMethod.PIN,
|
||||
onClick = { selectedMethod = LockMethod.PIN }
|
||||
selected = selectedMethod == LockMethod.PASSWORD,
|
||||
onClick = { selectedMethod = LockMethod.PASSWORD }
|
||||
)
|
||||
Text(text = stringResource(R.string.pin), modifier = Modifier.padding(start = 8.dp))
|
||||
Text(text = stringResource(R.string.password), modifier = Modifier.padding(start = 8.dp))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -70,63 +70,3 @@ fun UnlockPatternDialog(onDismiss: () -> Unit, onUnlock: (String) -> Unit, error
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun SetPinDialog(onDismiss: () -> Unit, onSetPin: (String) -> Unit) {
|
||||
var pin by remember { mutableStateOf("") }
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(text = stringResource(R.string.set_pin)) },
|
||||
text = {
|
||||
OutlinedTextField(
|
||||
value = pin,
|
||||
onValueChange = { pin = it },
|
||||
label = { Text(stringResource(R.string.enter_pin)) },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword)
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onSetPin(pin) }) {
|
||||
Text(text = stringResource(R.string.save))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(text = stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun UnlockPinDialog(onDismiss: () -> Unit, onUnlock: (String) -> Unit, errorMessage: String?) {
|
||||
var pin by remember { mutableStateOf("") }
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(text = stringResource(R.string.unlock_item)) },
|
||||
text = {
|
||||
Column {
|
||||
OutlinedTextField(
|
||||
value = pin,
|
||||
onValueChange = { pin = it },
|
||||
label = { Text(stringResource(R.string.enter_pin)) },
|
||||
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.NumberPassword),
|
||||
isError = errorMessage != null
|
||||
)
|
||||
if (errorMessage != null) {
|
||||
Text(text = errorMessage, color = MaterialTheme.colorScheme.error)
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = { onUnlock(pin) }) {
|
||||
Text(text = stringResource(R.string.unlock))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(text = stringResource(R.string.cancel))
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -79,10 +79,12 @@ fun AppDialogs(
|
||||
onShowSetListPasswordDialogChange: (Boolean) -> Unit,
|
||||
showUnlockPasswordDialog: Boolean,
|
||||
onShowUnlockPasswordDialogChange: (Boolean) -> Unit,
|
||||
showUnlockPinDialog: Boolean,
|
||||
onShowUnlockPinDialogChange: (Boolean) -> Unit,
|
||||
showUnlockPatternDialog: Boolean,
|
||||
onShowUnlockPatternDialogChange: (Boolean) -> Unit,
|
||||
onUnlock: (String) -> Unit,
|
||||
unlockErrorMessage: String?,
|
||||
|
||||
|
||||
showPasswordDialog: Boolean,
|
||||
onShowPasswordDialogChange: (Boolean) -> Unit,
|
||||
onHasEncryptionPasswordChange: (Boolean) -> Unit,
|
||||
@@ -103,8 +105,7 @@ fun AppDialogs(
|
||||
itemToLockType: de.lxtools.noteshop.ui.LockableItemType?,
|
||||
showSetPatternDialog: Boolean,
|
||||
onShowSetPatternDialogChange: (Boolean) -> Unit,
|
||||
showSetPinDialog: Boolean,
|
||||
onShowSetPinDialogChange: (Boolean) -> Unit
|
||||
|
||||
) {
|
||||
val scope = rememberCoroutineScope()
|
||||
val dynamicRecipeStrings = getDynamicRecipeStrings(recipesTitle)
|
||||
@@ -226,40 +227,11 @@ fun AppDialogs(
|
||||
)
|
||||
}
|
||||
|
||||
if (showSetPinDialog) {
|
||||
de.lxtools.noteshop.ui.SetPinDialog(
|
||||
onDismiss = { onShowSetPinDialogChange(false) },
|
||||
onSetPin = { pin ->
|
||||
when (itemToLockType) {
|
||||
LockableItemType.NOTE -> notesViewModel.setProtectionPin(pin)
|
||||
LockableItemType.RECIPE -> recipesViewModel.setProtectionPin(pin)
|
||||
LockableItemType.SHOPPING_LIST -> shoppingListsViewModel.setProtectionPin(pin)
|
||||
else -> {}
|
||||
}
|
||||
onShowSetPinDialogChange(false)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
if (showUnlockPasswordDialog) {
|
||||
UnlockPasswordDialog(
|
||||
onDismiss = {
|
||||
onShowUnlockPasswordDialogChange(false)
|
||||
},
|
||||
onUnlock = onUnlock,
|
||||
errorMessage = unlockErrorMessage
|
||||
)
|
||||
}
|
||||
|
||||
if (showUnlockPinDialog) {
|
||||
de.lxtools.noteshop.ui.UnlockPinDialog(
|
||||
onDismiss = {
|
||||
onShowUnlockPinDialogChange(false)
|
||||
},
|
||||
onUnlock = onUnlock,
|
||||
errorMessage = unlockErrorMessage
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (showPasswordDialog) {
|
||||
EncryptionPasswordDialog(
|
||||
@@ -317,6 +289,26 @@ fun AppDialogs(
|
||||
)
|
||||
}
|
||||
|
||||
if (showUnlockPasswordDialog) {
|
||||
UnlockPasswordDialog(
|
||||
onDismiss = {
|
||||
onShowUnlockPasswordDialogChange(false)
|
||||
},
|
||||
onUnlock = onUnlock,
|
||||
errorMessage = unlockErrorMessage
|
||||
)
|
||||
}
|
||||
|
||||
if (showUnlockPatternDialog) {
|
||||
de.lxtools.noteshop.ui.UnlockPatternDialog(
|
||||
onDismiss = {
|
||||
onShowUnlockPatternDialogChange(false)
|
||||
},
|
||||
onUnlock = onUnlock,
|
||||
errorMessage = unlockErrorMessage
|
||||
)
|
||||
}
|
||||
|
||||
if (showChooseLockMethodDialog) {
|
||||
ChooseLockMethodDialog(
|
||||
onDismiss = { onShowChooseLockMethodDialogChange(false) },
|
||||
|
||||
@@ -238,6 +238,7 @@
|
||||
<string name="unlock_item">Unlock Item</string>
|
||||
<string name="enter_password_to_unlock">Enter password to unlock this item.</string>
|
||||
<string name="incorrect_password">Incorrect password.</string>
|
||||
<string name="incorrect_pattern">Incorrect pattern.</string>
|
||||
|
||||
<string name="data_encryption">Data Encryption</string>
|
||||
<string name="set_encryption_password">Set Encryption Password</string>
|
||||
|
||||
Reference in New Issue
Block a user