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(ui): convert files menu to bottom GlassSheet with fluid rise animation, overhaul xlsx search bar with live search, 'Not found' alert, and clear button

chethan616f4d62217835b
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/FilesScreen.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/FilesScreen.kt
index 3c89e9e..652f0c3 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/FilesScreen.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/desk/FilesScreen.kt
@@ -55,6 +55,7 @@ import com.chethan616.clearpdf.ui.glass.GlassMenu
import com.chethan616.clearpdf.ui.glass.GlassMenuItem
import com.chethan616.clearpdf.ui.glass.GlassPill
import com.chethan616.clearpdf.ui.glass.GlassRow
+import com.chethan616.clearpdf.ui.glass.GlassSheet
import com.chethan616.clearpdf.ui.glass.GlassTab
import com.chethan616.clearpdf.ui.glass.GlassTabs
import com.chethan616.clearpdf.ui.glass.WashPanel
@@ -67,6 +68,8 @@ import com.chethan616.clearpdf.ui.theme.Candy
import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
import com.chethan616.clearpdf.ui.glass.Capsule
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.verticalScroll
import kotlinx.coroutines.delay
/** At most this many rows share one panel, so a long folder isn't one giant item. */
@@ -189,21 +192,105 @@ fun FilesScreen(vm: AppViewModel, onBrowse: () -> Unit) {
}
if (menuOpen) {
- val anchor = menuAnchor ?: Rect.Zero
- val items = buildList {
- add(GlassMenuItem(stringResource(if (sortByName) R.string.home_sort_by_date else R.string.home_sort_by_name), LucideIcons.ArrowUpDown) { sortByName = !sortByName })
- // show one kind of file: the one shown has a tick
- for (k in com.chethan616.clearpdf.engine.DocumentTypes.Kind.entries) {
- add(GlassMenuItem(stringResource(k.label), if (k == kind) LucideIcons.Check else k.icon) { kind = k })
- }
- if (tab == 0 && vm.recentList.isNotEmpty()) add(GlassMenuItem(stringResource(R.string.home_clear_recent), LucideIcons.BrushCleaning) { confirmClear = true })
- if (tab == 2) {
- add(GlassMenuItem(stringResource(R.string.home_refresh), LucideIcons.RotateCw) { vm.scanLocal(force = true) })
- add(GlassMenuItem(stringResource(R.string.home_add_folder), LucideIcons.FolderPlus) { vm.requestFileAccess() })
- for ((tree, name) in vm.localFolders()) add(GlassMenuItem(stringResource(R.string.home_stop_listing, name), LucideIcons.FolderOpen) { vm.removeLocalFolder(tree) })
+ GlassSheet(
+ onDismiss = { menuOpen = false },
+ title = stringResource(R.string.home_tab_files),
+ subtitle = pluralStringResource(R.plurals.files_count, rows.size, rows.size),
+ maxHeightFraction = 0.85f,
+ ) {
+ Column(
+ Modifier
+ .fillMaxWidth()
+ .verticalScroll(rememberScrollState()),
+ ) {
+ // Sort
+ GlassRow(
+ label = stringResource(if (sortByName) R.string.home_sort_by_date else R.string.home_sort_by_name),
+ onClick = {
+ sortByName = !sortByName
+ menuOpen = false
+ },
+ icon = LucideIcons.ArrowUpDown,
+ accent = Candy.Sky,
+ )
+
+ // Filter by Kind (All, PDFs, Word, Presentations, Spreadsheets, Text)
+ for (k in com.chethan616.clearpdf.engine.DocumentTypes.Kind.entries) {
+ val isSelected = k == kind
+ val accent = when (k) {
+ com.chethan616.clearpdf.engine.DocumentTypes.Kind.All -> Candy.Sky
+ com.chethan616.clearpdf.engine.DocumentTypes.Kind.Pdf -> Candy.Tomato
+ com.chethan616.clearpdf.engine.DocumentTypes.Kind.Word -> Candy.Cobalt
+ com.chethan616.clearpdf.engine.DocumentTypes.Kind.Slides -> Candy.Tangerine
+ com.chethan616.clearpdf.engine.DocumentTypes.Kind.Sheets -> Candy.Lime
+ com.chethan616.clearpdf.engine.DocumentTypes.Kind.Text -> Candy.Grape
+ }
+ GlassRow(
+ label = stringResource(k.label),
+ onClick = {
+ kind = k
+ menuOpen = false
+ },
+ icon = k.icon,
+ accent = accent,
+ trailing = if (isSelected) {
+ {
+ Icon(
+ LucideIcons.Check,
+ null,
+ tint = Candy.Sky,
+ modifier = Modifier.size(20.dp).padding(end = 4.dp),
+ )
+ }
+ } else null,
+ )
+ }
+
+ if (tab == 0 && vm.recentList.isNotEmpty()) {
+ GlassRow(
+ label = stringResource(R.string.home_clear_recent),
+ onClick = {
+ menuOpen = false
+ confirmClear = true
+ },
+ icon = LucideIcons.BrushCleaning,
+ destructive = true,
+ )
+ }
+
+ if (tab == 2) {
+ GlassRow(
+ label = stringResource(R.string.home_refresh),
+ onClick = {
+ menuOpen = false
+ vm.scanLocal(force = true)
+ },
+ icon = LucideIcons.RotateCw,
+ accent = Candy.Sky,
+ )
+ GlassRow(
+ label = stringResource(R.string.home_add_folder),
+ onClick = {
+ menuOpen = false
+ vm.requestFileAccess()
+ },
+ icon = LucideIcons.FolderPlus,
+ accent = Candy.Grape,
+ )
+ for ((tree, name) in vm.localFolders()) {
+ GlassRow(
+ label = stringResource(R.string.home_stop_listing, name),
+ onClick = {
+ menuOpen = false
+ vm.removeLocalFolder(tree)
+ },
+ icon = LucideIcons.FolderOpen,
+ destructive = true,
+ )
+ }
+ }
}
}
- GlassMenu(anchor, { menuOpen = false }, items)
}
if (confirmClear) {
GlassDialog(
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/sheets/SheetViewer.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/sheets/SheetViewer.kt
index 492ae2e..59df125 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/sheets/SheetViewer.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/sheets/SheetViewer.kt
@@ -66,8 +66,10 @@ import com.chethan616.clearpdf.ui.glass.GlassIcon
import com.chethan616.clearpdf.ui.glass.GlassLoader
import com.chethan616.clearpdf.ui.glass.LocalBackdrop
import com.chethan616.clearpdf.ui.glass.glassBar
+import com.chethan616.clearpdf.ui.glass.ChromeCapsule
import com.chethan616.clearpdf.ui.theme.ClearType
import com.chethan616.clearpdf.ui.theme.clear
+import kotlinx.coroutines.delay
import com.kyant.backdrop.backdrops.layerBackdrop
import com.kyant.backdrop.backdrops.rememberLayerBackdrop
import kotlinx.coroutines.flow.distinctUntilChanged
@@ -342,6 +344,20 @@ fun SheetViewer(vm: AppViewModel, doc: OpenDocument) {
val s = grid.selected ?: return@LaunchedEffect
input = runCatching { eng.command { sheetInput(doc.id, grid.current.toUInt(), s.row0, s.col0) } }.getOrDefault("")
}
+ // live debounced search across the active sheet
+ LaunchedEffect(query, grid.current, searching) {
+ if (!searching || query.isBlank()) {
+ grid.hits = emptyList()
+ grid.hit = 0
+ } else {
+ delay(180)
+ val q = query.trim()
+ if (q.isNotEmpty()) {
+ grid.hits = runCatching { eng.command { sheetFind(doc.id, grid.current.toUInt(), q, false, 1000u) } }.getOrDefault(emptyList())
+ grid.hit = 0
+ }
+ }
+ }
fun after() {
grid.changed()
scope.launch { vm.refresh(doc) }
@@ -390,7 +406,19 @@ fun SheetViewer(vm: AppViewModel, doc: OpenDocument) {
grid.sheets.getOrNull(grid.current)?.let { Text(it.name + if (doc.info.dirty) " · " + stringResource(R.string.sheet_edited) else "", style = ClearType.Caption, color = c.inkSoft, maxLines = 1) }
}
Spacer(Modifier.size(10.dp))
- GlassCircle(onClick = { searching = !searching; if (!searching) grid.hits = emptyList() }, label = stringResource(R.string.viewer_find_in_document)) { GlassIcon(LucideIcons.Search, null, Modifier.size(20.dp)) }
+ GlassCircle(
+ onClick = {
+ searching = !searching
+ if (!searching) {
+ grid.hits = emptyList()
+ query = ""
+ }
+ },
+ label = stringResource(R.string.viewer_find_in_document),
+ surface = if (searching) Candy.Sky.copy(alpha = 0.22f) else Color.Unspecified,
+ ) {
+ GlassIcon(if (searching) LucideIcons.X else LucideIcons.Search, null, Modifier.size(20.dp), tint = if (searching) Candy.Sky else c.ink)
+ }
Spacer(Modifier.size(10.dp))
var moreRect by remember { mutableStateOf(androidx.compose.ui.geometry.Rect.Zero) }
GlassCircle(
@@ -398,27 +426,126 @@ fun SheetViewer(vm: AppViewModel, doc: OpenDocument) {
modifier = Modifier.onGloballyPositioned { moreRect = it.boundsInWindow() },
) { GlassIcon(LucideIcons.MoreHorizontal, null, Modifier.size(20.dp)) }
}
- if (searching) Row(Modifier.fillMaxWidth().padding(horizontal = 12.dp), verticalAlignment = Alignment.CenterVertically) {
- Row(Modifier.weight(1f).height(48.dp).background(c.frost, com.chethan616.clearpdf.ui.glass.Capsule).padding(horizontal = 16.dp), verticalAlignment = Alignment.CenterVertically) {
- GlassTextField(
- query, { query = it }, stringResource(R.string.viewer_find_in_document), Modifier.weight(1f),
- keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
- keyboardActions = KeyboardActions(onSearch = {
- val q = query.trim()
- scope.launch {
- grid.hits = if (q.isEmpty()) emptyList() else runCatching { eng.command { sheetFind(doc.id, grid.current.toUInt(), q, false, 1000u) } }.getOrDefault(emptyList())
- grid.hit = 0
- if (q.isNotEmpty() && grid.hits.isEmpty()) vm.tell(com.chethan616.clearpdf.text(R.string.msg_search_no_matches, q))
+ if (searching) {
+ val searchFocus = remember { androidx.compose.ui.focus.FocusRequester() }
+ LaunchedEffect(Unit) { searchFocus.requestFocus() }
+ val qTrim = query.trim()
+ val notFound = qTrim.isNotEmpty() && grid.hits.isEmpty()
+ Row(
+ Modifier
+ .fillMaxWidth()
+ .padding(horizontal = 12.dp)
+ .height(48.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(8.dp),
+ ) {
+ Row(
+ Modifier
+ .weight(1f)
+ .fillMaxHeight()
+ .glassBar(
+ shape = ChromeCapsule,
+ surface = if (notFound) Candy.Tomato.copy(alpha = 0.15f) else Color.Unspecified,
+ )
+ .padding(start = 14.dp, end = 8.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ ) {
+ androidx.compose.material3.Icon(
+ LucideIcons.Search,
+ null,
+ tint = if (notFound) Candy.Tomato else c.inkSoft,
+ modifier = Modifier.size(18.dp),
+ )
+ Spacer(Modifier.size(10.dp))
+ androidx.compose.foundation.text.BasicTextField(
+ value = query,
+ onValueChange = { query = it },
+ singleLine = true,
+ textStyle = ClearType.Body.copy(color = if (notFound) Candy.Tomato else c.ink),
+ cursorBrush = androidx.compose.ui.graphics.SolidColor(if (notFound) Candy.Tomato else Candy.Sky),
+ keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
+ keyboardActions = KeyboardActions(onSearch = {
+ val q = query.trim()
+ scope.launch {
+ grid.hits = if (q.isEmpty()) emptyList() else runCatching {
+ eng.command { sheetFind(doc.id, grid.current.toUInt(), q, false, 1000u) }
+ }.getOrDefault(emptyList())
+ grid.hit = 0
+ }
+ }),
+ modifier = Modifier
+ .weight(1f)
+ .androidx.compose.ui.focus.focusRequester(searchFocus)
+ .androidx.compose.ui.semantics.semantics {
+ androidx.compose.ui.semantics.contentDescription = stringResource(R.string.viewer_find_in_document)
+ },
+ decorationBox = { inner ->
+ Box(contentAlignment = Alignment.CenterStart) {
+ if (query.isEmpty()) {
+ Text(
+ stringResource(R.string.viewer_find_in_document),
+ style = ClearType.Body,
+ color = c.inkFaint,
+ maxLines = 1,
+ )
+ }
+ inner()
+ }
+ },
+ )
+ if (notFound) {
+ Text(
+ "Not found",
+ style = ClearType.Label.copy(fontWeight = FontWeight.Bold, fontSize = 12.sp),
+ color = Candy.Tomato,
+ maxLines = 1,
+ modifier = Modifier.padding(start = 6.dp, end = 4.dp),
+ )
+ } else if (grid.hits.isNotEmpty()) {
+ Text(
+ "${grid.hit + 1}/${grid.hits.size}",
+ style = ClearType.Label.copy(fontWeight = FontWeight.SemiBold, fontSize = 12.sp),
+ color = c.inkSoft,
+ maxLines = 1,
+ modifier = Modifier.padding(start = 6.dp, end = 4.dp),
+ )
+ }
+ if (query.isNotEmpty()) {
+ Box(
+ Modifier
+ .size(24.dp)
+ .androidx.compose.ui.draw.clip(androidx.compose.foundation.shape.CircleShape)
+ .androidx.compose.foundation.clickable {
+ query = ""
+ grid.hits = emptyList()
+ },
+ contentAlignment = Alignment.Center,
+ ) {
+ androidx.compose.material3.Icon(
+ LucideIcons.X,
+ stringResource(R.string.common_clear),
+ tint = if (notFound) Candy.Tomato else c.inkSoft,
+ modifier = Modifier.size(15.dp),
+ )
}
- }),
- )
- if (grid.hits.isNotEmpty()) Text("${grid.hit + 1}/${grid.hits.size}", style = ClearType.Caption, color = c.inkSoft)
- }
- if (grid.hits.size > 1) {
- Spacer(Modifier.size(8.dp))
- GlassCircle(onClick = { grid.hit = (grid.hit - 1 + grid.hits.size) % grid.hits.size }, size = 44.dp, label = stringResource(R.string.viewer_find_previous)) { GlassIcon(LucideIcons.ChevronUp, null, Modifier.size(18.dp)) }
- Spacer(Modifier.size(6.dp))
- GlassCircle(onClick = { grid.hit = (grid.hit + 1) % grid.hits.size }, size = 44.dp, label = stringResource(R.string.viewer_find_next)) { GlassIcon(LucideIcons.ChevronDown, null, Modifier.size(18.dp)) }
+ }
+ }
+ if (grid.hits.size > 1) {
+ GlassCircle(
+ onClick = { grid.hit = (grid.hit - 1 + grid.hits.size) % grid.hits.size },
+ size = 44.dp,
+ label = stringResource(R.string.viewer_find_previous),
+ ) {
+ GlassIcon(LucideIcons.ChevronUp, null, Modifier.size(18.dp))
+ }
+ GlassCircle(
+ onClick = { grid.hit = (grid.hit + 1) % grid.hits.size },
+ size = 44.dp,
+ label = stringResource(R.string.viewer_find_next),
+ ) {
+ GlassIcon(LucideIcons.ChevronDown, null, Modifier.size(18.dp))
+ }
+ }
}
}
if (searching) Spacer(Modifier.height(8.dp))