Skip to content

Commit efef662

Browse files
committed
Use strings.xml to manage plural for pageCount
1 parent d9bcf76 commit efef662

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

app/src/main/java/org/mydomain/myscan/view/CameraScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ fun CameraScreenFooter(
414414
horizontalArrangement = Arrangement.SpaceBetween
415415
) {
416416
Text(
417-
text = "$pageCount pages",
417+
text = pageCountText(pageCount),
418418
style = MaterialTheme.typography.bodyMedium,
419419
modifier = Modifier.clickable(onClick = onPageCountClick)
420420
)

app/src/main/java/org/mydomain/myscan/view/PdfGenerationBottomSheet.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fun PdfGenerationBottomSheet(
145145
val context = LocalContext.current
146146
val formattedFileSize = formatFileSize(pdf.sizeInBytes, context)
147147
Text(
148-
text = "${pdf.pageCount} pages · $formattedFileSize",
148+
text = "${pageCountText(pdf.pageCount)} · $formattedFileSize",
149149
style = MaterialTheme.typography.bodyMedium,
150150
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.6f)
151151
)
@@ -267,7 +267,7 @@ fun PreviewPdfGenerationDialogDuringGeneration() {
267267
fun PreviewPdfGenerationDialogAfterGeneration() {
268268
PreviewToCustomize(
269269
uiState = PdfGenerationUiState(
270-
generatedPdf = GeneratedPdf("file://fake.pdf".toUri(), 442897L, 3)
270+
generatedPdf = GeneratedPdf("file://fake.pdf".toUri(), 442897L, 1)
271271
)
272272
)
273273
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright 2025 Pierre-Yves Nicolas
3+
*
4+
* This program is free software: you can redistribute it and/or modify it
5+
* under the terms of the GNU General Public License as published by the Free
6+
* Software Foundation, either version 3 of the License, or (at your option)
7+
* any later version.
8+
* This program is distributed in the hope that it will be useful, but WITHOUT
9+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11+
* more details.
12+
* You should have received a copy of the GNU General Public License along with
13+
* this program. If not, see <https://www.gnu.org/licenses/>.
14+
*/
15+
package org.mydomain.myscan.view
16+
17+
import androidx.compose.runtime.Composable
18+
import androidx.compose.ui.platform.LocalContext
19+
import org.mydomain.myscan.R
20+
21+
@Composable
22+
fun pageCountText(quantity: Int): String {
23+
val context = LocalContext.current
24+
return context.resources.getQuantityString(R.plurals.page_count, quantity, quantity)
25+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
<resources>
22
<string name="app_name">MyScan</string>
3-
</resources>
3+
<plurals name="page_count">
4+
<item quantity="one">%d page</item>
5+
<item quantity="other">%d pages</item>
6+
</plurals>
7+
</resources>

0 commit comments

Comments
 (0)