From efef66217aee71d4a8baa170057d1ab58c81fa80 Mon Sep 17 00:00:00 2001
From: Pierre-Yves Nicolas <6371790+pynicolas@users.noreply.github.com>
Date: Wed, 9 Jul 2025 13:49:47 +0200
Subject: [PATCH] Use strings.xml to manage plural for pageCount
---
.../org/mydomain/myscan/view/CameraScreen.kt | 2 +-
.../myscan/view/PdfGenerationBottomSheet.kt | 4 +--
.../java/org/mydomain/myscan/view/Strings.kt | 25 +++++++++++++++++++
app/src/main/res/values/strings.xml | 6 ++++-
4 files changed, 33 insertions(+), 4 deletions(-)
create mode 100644 app/src/main/java/org/mydomain/myscan/view/Strings.kt
diff --git a/app/src/main/java/org/mydomain/myscan/view/CameraScreen.kt b/app/src/main/java/org/mydomain/myscan/view/CameraScreen.kt
index 3a13e1c..5d7a658 100644
--- a/app/src/main/java/org/mydomain/myscan/view/CameraScreen.kt
+++ b/app/src/main/java/org/mydomain/myscan/view/CameraScreen.kt
@@ -414,7 +414,7 @@ fun CameraScreenFooter(
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
- text = "$pageCount pages",
+ text = pageCountText(pageCount),
style = MaterialTheme.typography.bodyMedium,
modifier = Modifier.clickable(onClick = onPageCountClick)
)
diff --git a/app/src/main/java/org/mydomain/myscan/view/PdfGenerationBottomSheet.kt b/app/src/main/java/org/mydomain/myscan/view/PdfGenerationBottomSheet.kt
index 9c874e0..e77112a 100644
--- a/app/src/main/java/org/mydomain/myscan/view/PdfGenerationBottomSheet.kt
+++ b/app/src/main/java/org/mydomain/myscan/view/PdfGenerationBottomSheet.kt
@@ -145,7 +145,7 @@ fun PdfGenerationBottomSheet(
val context = LocalContext.current
val formattedFileSize = formatFileSize(pdf.sizeInBytes, context)
Text(
- text = "${pdf.pageCount} pages · $formattedFileSize",
+ text = "${pageCountText(pdf.pageCount)} · $formattedFileSize",
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
)
@@ -267,7 +267,7 @@ fun PreviewPdfGenerationDialogDuringGeneration() {
fun PreviewPdfGenerationDialogAfterGeneration() {
PreviewToCustomize(
uiState = PdfGenerationUiState(
- generatedPdf = GeneratedPdf("file://fake.pdf".toUri(), 442897L, 3)
+ generatedPdf = GeneratedPdf("file://fake.pdf".toUri(), 442897L, 1)
)
)
}
diff --git a/app/src/main/java/org/mydomain/myscan/view/Strings.kt b/app/src/main/java/org/mydomain/myscan/view/Strings.kt
new file mode 100644
index 0000000..5be9978
--- /dev/null
+++ b/app/src/main/java/org/mydomain/myscan/view/Strings.kt
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2025 Pierre-Yves Nicolas
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see .
+ */
+package org.mydomain.myscan.view
+
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.platform.LocalContext
+import org.mydomain.myscan.R
+
+@Composable
+fun pageCountText(quantity: Int): String {
+ val context = LocalContext.current
+ return context.resources.getQuantityString(R.plurals.page_count, quantity, quantity)
+}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index f3c0d09..705697b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,3 +1,7 @@
MyScan
-
\ No newline at end of file
+
+ - %d page
+ - %d pages
+
+