Skip to content

Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.

feat: Extra Features can show the number of search results (#39)

Josh315a9c1d39ec
diff --git a/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/AppViewModel.kt b/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/AppViewModel.kt
index 822b3d2..58e6b74 100644
--- a/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/AppViewModel.kt
+++ b/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/AppViewModel.kt
@@ -853,6 +853,18 @@ class AppViewModel(app: Application, private val saved: SavedStateHandle) : Andr
appPrefs.edit().putBoolean("statusBarInDocuments", on).apply()
}
+ /**
+ * Extra Features ▸ the number of search results: Find shows which result is on screen and how
+ * many there are, "3 of 12" (#39; the reference's page view shows no count).
+ */
+ var searchCount by mutableStateOf(appPrefs.getBoolean("searchCount", false))
+ private set
+
+ fun updateSearchCount(on: Boolean) {
+ searchCount = on
+ appPrefs.edit().putBoolean("searchCount", on).apply()
+ }
+
// ---- Reading the document ---------------------------------------------------------------
suspend fun outline(doc: OpenDocument) = engine?.let { e -> runCatching { e.command { outline(doc.id) } }.getOrNull() }.orEmpty()
diff --git a/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/home/Tabs.kt b/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/home/Tabs.kt
index 02ff6d9..26a2bbe 100644
--- a/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/home/Tabs.kt
+++ b/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/home/Tabs.kt
@@ -391,6 +391,11 @@ private fun Preferences(vm: AppViewModel) {
PdfSwitch(vm.statusBarInDocuments, { vm.updateStatusBarInDocuments(it) })
}
Text(stringResource(R.string.home_status_bar_in_documents_body), color = c.textSecondary, fontSize = 13.sp, modifier = Modifier.padding(horizontal = 20.dp))
+ Spacer(Modifier.height(8.dp))
+ SheetRow(null, stringResource(R.string.home_search_count), { vm.updateSearchCount(!vm.searchCount) }) {
+ PdfSwitch(vm.searchCount, { vm.updateSearchCount(it) })
+ }
+ Text(stringResource(R.string.home_search_count_body), color = c.textSecondary, fontSize = 13.sp, modifier = Modifier.padding(horizontal = 20.dp))
Spacer(Modifier.height(24.dp))
if (authorDialog) {
var name by remember { mutableStateOf(vm.toolPrefs.author) }
diff --git a/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/viewer/ViewerBars.kt b/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/viewer/ViewerBars.kt
index 88fb97c..8f2cc7f 100644
--- a/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/viewer/ViewerBars.kt
+++ b/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/viewer/ViewerBars.kt
@@ -202,7 +202,8 @@ private fun ReadAloudSwitch(on: Boolean, onToggle: () -> Unit) {
/**
* Find in the top bar: collapse, the query field (searched on submit), then clear, Previous and
- * Next, greyed until they can be used. Like the reference, it shows no hit counter.
+ * Next, greyed until they can be used. Like the reference, it shows no hit counter, unless Extra
+ * Features asks for one: [count], "3 of 12", between the field and the buttons.
*/
@Composable
fun SearchBar(
@@ -214,6 +215,7 @@ fun SearchBar(
onClose: () -> Unit,
onPrev: () -> Unit,
onNext: () -> Unit,
+ count: String? = null,
) {
val c = pdfColors
val focus = remember { FocusRequester() }
@@ -254,6 +256,7 @@ fun SearchBar(
},
)
}
+ if (count != null) Text(count, color = c.textSecondary, fontSize = 15.sp, maxLines = 1, modifier = Modifier.padding(horizontal = 4.dp))
BarIcon(LucideIcons.X, stringResource(R.string.common_clear), onClear, size = 40.dp, enabled = query.isNotEmpty())
BarIcon(LucideIcons.ChevronLeft, stringResource(R.string.viewer_find_previous), onPrev, enabled = canStep, size = 40.dp)
BarIcon(LucideIcons.ChevronRight, stringResource(R.string.viewer_find_next), onNext, enabled = canStep, size = 40.dp)
diff --git a/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/viewer/ViewerScreen.kt b/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/viewer/ViewerScreen.kt
index b8af63a..7ede698 100644
--- a/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/viewer/ViewerScreen.kt
+++ b/apps/pdfcraft-android/android/app/src/main/java/io/github/artcraftandroid/pdfcraft/ui/viewer/ViewerScreen.kt
@@ -351,6 +351,11 @@ fun ViewerScreen(vm: AppViewModel, doc: OpenDocument) {
onClose = { closeSearch(doc) },
onPrev = { search.step(false)?.let { showHit(doc, it) } },
onNext = { search.step(true)?.let { showHit(doc, it) } },
+ // Extra Features: which result is on screen, of how many (still growing while
+ // the rest of a long document is searched)
+ count = if (vm.searchCount && search.hits.isNotEmpty()) {
+ stringResource(R.string.viewer_search_count, (search.current + 1).coerceAtLeast(1), search.hits.size)
+ } else null,
)
} else {
val fa = vm.fieldActions
diff --git a/apps/pdfcraft-android/android/app/src/main/res/values-es/strings.xml b/apps/pdfcraft-android/android/app/src/main/res/values-es/strings.xml
index 7763216..ceeb0ba 100644
--- a/apps/pdfcraft-android/android/app/src/main/res/values-es/strings.xml
+++ b/apps/pdfcraft-android/android/app/src/main/res/values-es/strings.xml
@@ -229,6 +229,8 @@
<string name="home_extra_body">Cambios opcionales en el aspecto y el funcionamiento de PdfCraft.</string>
<string name="home_status_bar_in_documents">Mostrar la barra de estado en los documentos</string>
<string name="home_status_bar_in_documents_body">La barra de estado se muestra con las barras de herramientas. Al tocar para ocultarlas, la página ocupa toda la pantalla, también alrededor de la cámara.</string>
+ <string name="home_search_count">Mostrar el número de resultados de búsqueda</string>
+ <string name="home_search_count_body">Buscar en un documento muestra en qué resultado estás y cuántos hay, por ejemplo 3 de 12.</string>
<!-- Settings: About PdfCraft -->
<string name="home_section_about">Acerca de</string>
@@ -447,6 +449,7 @@
<string name="viewer_edit_text">Editar texto</string>
<string name="viewer_zoom_in">Acercar</string>
<string name="viewer_zoom_out">Alejar</string>
+ <string name="viewer_search_count">%1$d de %2$d</string>
<string name="viewer_read_from_here">Leer desde aquí</string>
<string name="viewer_copy_text">Copiar texto</string>
<!-- Translator note: accessibility labels of the two handles at the ends of selected text. -->
diff --git a/apps/pdfcraft-android/android/app/src/main/res/values/strings.xml b/apps/pdfcraft-android/android/app/src/main/res/values/strings.xml
index c7a2fea..53bb465 100644
--- a/apps/pdfcraft-android/android/app/src/main/res/values/strings.xml
+++ b/apps/pdfcraft-android/android/app/src/main/res/values/strings.xml
@@ -230,6 +230,8 @@
<string name="home_extra_body">Optional changes to how PdfCraft looks and works.</string>
<string name="home_status_bar_in_documents">Show the status bar in documents</string>
<string name="home_status_bar_in_documents_body">The status bar shows with the toolbars. When you tap to hide them, the page uses the whole screen, around the camera too.</string>
+ <string name="home_search_count">Show the number of search results</string>
+ <string name="home_search_count_body">Find in a document shows which result you\'re on and how many there are, such as 3 of 12.</string>
<!-- Settings: About PdfCraft -->
<string name="home_section_about">About</string>
@@ -448,6 +450,7 @@
<string name="viewer_edit_text">Edit text</string>
<string name="viewer_zoom_in">Zoom in</string>
<string name="viewer_zoom_out">Zoom out</string>
+ <string name="viewer_search_count">%1$d of %2$d</string>
<string name="viewer_read_from_here">Read from here</string>
<string name="viewer_copy_text">Copy text</string>
<!-- Translator note: accessibility labels of the two handles at the ends of selected text. -->