refactor: extract deletion confirmation dialog to its own method
This commit is contained in:
parent
6fa8b188e6
commit
10b502fb0a
1 changed files with 31 additions and 23 deletions
|
@ -43,29 +43,14 @@ private fun KeyItem(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
var isDeleting by remember { mutableStateOf(false) }
|
var isDeleting by remember { mutableStateOf(false) }
|
||||||
if (isDeleting) {
|
DeleteConfirmationDialog(
|
||||||
AlertDialog(
|
isDeleting = isDeleting,
|
||||||
onDismissRequest = { isDeleting = false },
|
onDismiss = { isDeleting = false },
|
||||||
title = {
|
onConfirm = {
|
||||||
Text(text = stringResource(R.string.pgp_key_manager_delete_confirmation_dialog_title))
|
onItemClick(identifier)
|
||||||
},
|
isDeleting = false
|
||||||
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 =
|
val label =
|
||||||
when (identifier) {
|
when (identifier) {
|
||||||
is GpgIdentifier.KeyId -> identifier.id.toString()
|
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
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
private fun KeyListPreview() {
|
private fun KeyListPreview() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue