diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2022-11-18 11:21:53 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2022-11-18 11:21:53 +0530 |
commit | 6fa8b188e6e53ec29f9a00eb0ee29afe5d66be21 (patch) | |
tree | 6a29e21398c2d2e69ec701b694f2e090a64d7814 /app/src/main | |
parent | 35a6e3b8ff0e4c4d8ab1936e442509294b606d41 (diff) |
feat: add a confirmation dialog for key deletion
Fixes #2257
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt | 32 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 2 |
2 files changed, 32 insertions, 2 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt index 8f46b8d5..c1b8047a 100644 --- a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt +++ b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt @@ -6,10 +6,16 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.material3.AlertDialog import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.Text +import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource @@ -36,6 +42,30 @@ private fun KeyItem( onItemClick: (identifier: GpgIdentifier) -> Unit, modifier: Modifier = Modifier, ) { + var isDeleting by remember { mutableStateOf(false) } + if (isDeleting) { + AlertDialog( + onDismissRequest = { isDeleting = false }, + title = { + Text(text = stringResource(R.string.pgp_key_manager_delete_confirmation_dialog_title)) + }, + confirmButton = { + TextButton( + onClick = { + onItemClick(identifier) + isDeleting = false + } + ) { + Text(text = stringResource(R.string.dialog_yes)) + } + }, + dismissButton = { + TextButton(onClick = { isDeleting = false }) { + Text(text = stringResource(R.string.dialog_no)) + } + }, + ) + } val label = when (identifier) { is GpgIdentifier.KeyId -> identifier.id.toString() @@ -47,7 +77,7 @@ private fun KeyItem( verticalAlignment = Alignment.CenterVertically, ) { Text(text = label) - IconButton(onClick = { onItemClick(identifier) }) { + IconButton(onClick = { isDeleting = true }) { Icon( painter = painterResource(R.drawable.ic_delete_24dp), stringResource(id = R.string.delete) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5a542b64..ad60e177 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -367,5 +367,5 @@ <string name="pwgen_some_error_occurred">Some error occurred</string> <string name="git_run_gc_job">Run garbage collection job</string> <string name="activity_label_pgp_key_manager">PGP Key Manager</string> - + <string name="pgp_key_manager_delete_confirmation_dialog_title">Delete key?</string> </resources> |