From 5eb9a2fa883e71dd7f52fbbf8821c93a9d4d6d35 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Nicolas <6371790+pynicolas@users.noreply.github.com> Date: Mon, 25 Aug 2025 12:06:21 +0200 Subject: [PATCH] New confirmation dialog when deleting a page --- .../org/fairscan/app/view/DocumentScreen.kt | 24 ++++++++++++++++--- app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/fairscan/app/view/DocumentScreen.kt b/app/src/main/java/org/fairscan/app/view/DocumentScreen.kt index a169ccc..545a529 100644 --- a/app/src/main/java/org/fairscan/app/view/DocumentScreen.kt +++ b/app/src/main/java/org/fairscan/app/view/DocumentScreen.kt @@ -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, title: String) { + ConfirmationDialog(title, stringResource(R.string.new_document_warning), showDialog, onConfirm) +} + +@Composable +private fun ConfirmationDialog( + title: String, + message: String, + showDialog: MutableState, + 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() }) { diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index eb22e92..5db3f35 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -10,6 +10,7 @@ Fermer le document Document en cours Supprimer la page + Voulez-vous supprimer cette page ? Document Erreur : %1$s Aucun document détecté diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 13b419a..163e47e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -11,6 +11,7 @@ Close document Current document Delete page + Do you want to delete this page? Document Error: %1$s No document detected