aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-11-18 12:19:46 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-11-18 12:19:46 +0530
commit10b502fb0a9a028878720e75b38e6cfc17910c31 (patch)
treed84372423ce4b560e6a774824b287026a297ce98
parent6fa8b188e6e53ec29f9a00eb0ee29afe5d66be21 (diff)
refactor: extract deletion confirmation dialog to its own method
-rw-r--r--app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt54
1 files changed, 31 insertions, 23 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 c1b8047a..40d9223c 100644
--- a/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt
+++ b/app/src/main/java/app/passwordstore/ui/pgp/PGPKeyList.kt
@@ -43,29 +43,14 @@ private fun KeyItem(
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))
- }
- },
- )
- }
+ DeleteConfirmationDialog(
+ isDeleting = isDeleting,
+ onDismiss = { isDeleting = false },
+ onConfirm = {
+ onItemClick(identifier)
+ isDeleting = false
+ }
+ )
val label =
when (identifier) {
is GpgIdentifier.KeyId -> identifier.id.toString()
@@ -86,6 +71,29 @@ private fun KeyItem(
}
}
+@Suppress("NOTHING_TO_INLINE")
+@Composable
+private inline fun DeleteConfirmationDialog(
+ isDeleting: Boolean,
+ noinline onDismiss: () -> Unit,
+ noinline onConfirm: () -> Unit,
+) {
+ if (isDeleting) {
+ AlertDialog(
+ onDismissRequest = onDismiss,
+ title = {
+ Text(text = stringResource(R.string.pgp_key_manager_delete_confirmation_dialog_title))
+ },
+ confirmButton = {
+ TextButton(onClick = onConfirm) { Text(text = stringResource(R.string.dialog_yes)) }
+ },
+ dismissButton = {
+ TextButton(onClick = onDismiss) { Text(text = stringResource(R.string.dialog_no)) }
+ },
+ )
+ }
+}
+
@Preview
@Composable
private fun KeyListPreview() {