New confirmation dialog when deleting a page

This commit is contained in:
Pierre-Yves Nicolas
2025-08-25 12:06:21 +02:00
parent 2eec4fe7ca
commit 5eb9a2fa88
3 changed files with 23 additions and 3 deletions

View File

@@ -75,6 +75,7 @@ fun DocumentScreen(
) {
// TODO Check how often images are loaded
val showNewDocDialog = rememberSaveable { mutableStateOf(false) }
val showDeletePageDialog = rememberSaveable { mutableStateOf(false) }
val showPdfDialog = rememberSaveable { mutableStateOf(false) }
val currentPageIndex = rememberSaveable { mutableIntStateOf(initialPage) }
if (currentPageIndex.intValue >= document.pageCount()) {
@@ -111,10 +112,17 @@ fun DocumentScreen(
)
},
) { modifier ->
DocumentPreview(document, currentPageIndex, onDeleteImage, modifier)
DocumentPreview(document, currentPageIndex, { showDeletePageDialog.value = true }, modifier)
if (showNewDocDialog.value) {
NewDocumentDialog(onConfirm = onStartNew, showNewDocDialog, stringResource(R.string.close_document))
}
if (showDeletePageDialog.value) {
ConfirmationDialog(
title = stringResource(R.string.delete_page),
message = stringResource(R.string.delete_page_warning),
showDialog = showDeletePageDialog
) { onDeleteImage(document.pageId(currentPageIndex.intValue)) }
}
if (showPdfDialog.value) {
PdfGenerationBottomSheetWrapper(
onDismiss = { showPdfDialog.value = false },
@@ -212,11 +220,21 @@ private fun BottomBar(
@Composable
fun NewDocumentDialog(onConfirm: () -> Unit, showDialog: MutableState<Boolean>, title: String) {
ConfirmationDialog(title, stringResource(R.string.new_document_warning), showDialog, onConfirm)
}
@Composable
private fun ConfirmationDialog(
title: String,
message: String,
showDialog: MutableState<Boolean>,
onConfirm: () -> Unit,
) {
AlertDialog(
title = { Text(title) },
text = { Text(stringResource(R.string.new_document_warning)) },
text = { Text(message) },
confirmButton = {
TextButton (onClick = {
TextButton(onClick = {
showDialog.value = false
onConfirm()
}) {

View File

@@ -10,6 +10,7 @@
<string name="close_document">Fermer le document</string>
<string name="current_document">Document en cours</string>
<string name="delete_page">Supprimer la page</string>
<string name="delete_page_warning">Voulez-vous supprimer cette page ?</string>
<string name="document">Document</string>
<string name="error">Erreur : %1$s</string>
<string name="error_no_document">Aucun document détecté</string>

View File

@@ -11,6 +11,7 @@
<string name="close_document">Close document</string>
<string name="current_document">Current document</string>
<string name="delete_page">Delete page</string>
<string name="delete_page_warning">Do you want to delete this page?</string>
<string name="document">Document</string>
<string name="error">Error: %1$s</string>
<string name="error_no_document">No document detected</string>