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.

fix(ui): revert files menu to top dropdown, fix icon contrast in word & photo editor, overhaul xlsx viewer smooth scrolling

chethan6169c25e9ceb8fe
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 5e67945..eebd056 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,7 +55,6 @@ 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
@@ -192,105 +191,21 @@ fun FilesScreen(vm: AppViewModel, onBrowse: () -> Unit) {
}
if (menuOpen) {
- 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.InkBlue
- 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,
- )
- }
- }
+ 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) })
}
}
+ GlassMenu(anchor = anchor, onDismiss = { menuOpen = false }, items = items)
}
if (confirmClear) {
GlassDialog(
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Buttons.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Buttons.kt
index 97c7fb5..6888b56 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Buttons.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/glass/Buttons.kt
@@ -281,7 +281,15 @@ val BackArrow: ImageVector by lazy {
@Composable
fun GlassBackButton(onBack: () -> Unit, modifier: Modifier = Modifier, label: String? = null, immediate: Boolean = false) {
val beat = rememberBeat(onBack)
- GlassCircle(onClick = if (immediate) onBack else beat, modifier = modifier, size = HeaderButtonSize, label = label ?: androidx.compose.ui.res.stringResource(com.chethan616.clearpdf.R.string.common_back), ink = clear.ink) {
+ val barSurface = if (clear.dark) Color(0xFF151828).copy(alpha = 0.65f) else Color.White.copy(alpha = 0.75f)
+ GlassCircle(
+ onClick = if (immediate) onBack else beat,
+ modifier = modifier,
+ size = HeaderButtonSize,
+ surface = barSurface,
+ label = label ?: androidx.compose.ui.res.stringResource(com.chethan616.clearpdf.R.string.common_back),
+ ink = clear.ink,
+ ) {
GlassIcon(BackArrow, null, Modifier.size(16.dp))
}
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/PhotoEditor.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/PhotoEditor.kt
index 6791660..5fcfbe3 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/PhotoEditor.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/notes/PhotoEditor.kt
@@ -451,15 +451,15 @@ private fun Dial(
onClick = onClick,
size = 50.dp,
label = stringResource(a.label),
- ink = if (chosen) Candy.Lemon else Color.White,
- tint = if (chosen) Candy.Lemon.copy(alpha = 0.28f) else Color.Unspecified,
- surface = if (chosen) Candy.Lemon.copy(alpha = 0.18f) else Color.White.copy(alpha = 0.10f),
+ ink = if (chosen) Color(0xFF141202) else Color.White,
+ tint = if (chosen) Candy.Lemon else Color.Unspecified,
+ surface = if (chosen) Candy.Lemon else Color.White.copy(alpha = 0.10f),
) {
GlassIcon(
a.icon,
null,
Modifier.size(22.dp),
- tint = if (chosen) Candy.Lemon else Color.White,
+ tint = if (chosen) Color(0xFF141202) else Color.White,
)
}
Spacer(Modifier.height(6.dp))
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 831615e..d928dbe 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
@@ -302,12 +302,14 @@ fun SheetGrid(
val m = l.merges.firstOrNull { row.toUInt() in it.row0..it.row1 && col.toUInt() in it.col0..it.col1 }
return m ?: CellSpan(row.toUInt(), col.toUInt(), row.toUInt(), col.toUInt())
}
+ val flinger = remember { arrayOfNulls<kotlinx.coroutines.Job>(1) }
Canvas(
Modifier
.fillMaxSize()
- .panZoomFling(state, l, px)
+ .panZoomFling(state, l, px, flinger)
.pointerInput(l, onCell, onDoubleTapCell) {
detectTapGestures(
+ onPress = { flinger[0]?.cancel() },
onTap = { p -> onCell?.invoke(cellAt(p)) },
onDoubleTap = { p ->
val cell = cellAt(p)
@@ -854,49 +856,94 @@ private fun DrawScope.drawSheet(
/**
* Pan and pinch-zoom the grid with a finger or two, and let it glide on when let go, slowing as a
- * list does (the platform's spline decay), held within the sheet.
+ * list does (the platform's spline decay), exactly matching the fluid physics of the PDF & doc viewers.
*/
-private fun Modifier.panZoomFling(state: SheetGridState, l: SheetLayout, px: Float): Modifier = pointerInput(l) {
- val decay = androidx.compose.animation.splineBasedDecay<Offset>(this)
+private fun Modifier.panZoomFling(
+ state: SheetGridState,
+ l: SheetLayout,
+ px: Float,
+ flinger: Array<kotlinx.coroutines.Job?>,
+): Modifier = pointerInput(l) {
+ val touchSlop = viewConfiguration.touchSlop
fun clamp(p: Offset, s: Float): Offset {
val k = px * s
- val maxX = (l.colX.last() * k - size.width / 2f).coerceAtLeast(0f)
- val maxY = (l.rowY.last() * k - size.height / 2f).coerceAtLeast(0f)
+ val maxX = (l.colX.last() * k - size.width + 120.dp.toPx()).coerceAtLeast(0f)
+ val maxY = (l.rowY.last() * k - size.height + 160.dp.toPx()).coerceAtLeast(0f)
return Offset(p.x.coerceIn(-maxX, 0f), p.y.coerceIn(-maxY, 0f))
}
+
kotlinx.coroutines.coroutineScope {
- var glide: kotlinx.coroutines.Job? = null
awaitEachGesture {
- awaitFirstDown(requireUnconsumed = false)
- glide?.cancel()
+ val down = awaitFirstDown(requireUnconsumed = false)
+ flinger[0]?.cancel()
val tracker = androidx.compose.ui.input.pointer.util.VelocityTracker()
+ tracker.addPosition(down.uptimeMillis, down.position)
+ var moved = Offset.Zero
+ var zoomed = 1f
+ var started = false
var pinched = false
- do {
+ var centroid = down.position
+
+ while (true) {
val event = awaitPointerEvent()
- val zoom = event.calculateZoom()
- val move = event.calculatePan()
- val centroid = event.calculateCentroid(useCurrent = true)
- if (zoom != 1f) pinched = true
- if (zoom != 1f || move != Offset.Zero) {
- val s = (state.scale * zoom).coerceIn(0.4f, 4f)
- val f = s / state.scale
- // zoom about the fingers, then follow them
- val origin = if (centroid.isSpecified) centroid else Offset.Zero
- state.pan = clamp((state.pan - origin) * f + origin + move, s)
- state.scale = s
- event.changes.forEach { if (it.positionChanged()) it.consume() }
+ val pressed = event.changes.filter { it.pressed }
+ if (pressed.isEmpty()) break
+ val zoomChange = event.calculateZoom()
+ val pan = event.calculatePan()
+
+ if (!started) {
+ moved += pan
+ zoomed *= zoomChange
+ if (moved.getDistance() > touchSlop || (pressed.size > 1 && kotlin.math.abs(1f - zoomed) * size.width / 2f > touchSlop)) {
+ started = true
+ }
}
- event.changes.firstOrNull()?.let { tracker.addPosition(it.uptimeMillis, it.position) }
- } while (event.changes.any { it.pressed })
- if (!pinched) {
- val v = tracker.calculateVelocity()
- glide = launch {
- androidx.compose.animation.core.AnimationState(Offset.VectorConverter, state.pan, Offset(v.x, v.y))
- .animateDecay(decay) {
- val next = clamp(value, state.scale)
- state.pan = next
- if (next != value) cancelAnimation()
+
+ if (started) {
+ if (pressed.size > 1) {
+ pinched = true
+ val c = event.calculateCentroid()
+ centroid = c
+ if (zoomChange != 1f) {
+ val newScale = (state.scale * zoomChange).coerceIn(0.4f, 4f)
+ val factor = newScale / state.scale
+ val origin = if (c.isSpecified) c else Offset.Zero
+ val target = (state.pan - origin) * factor + origin + pan
+ state.pan = clamp(target, newScale)
+ state.scale = newScale
+ }
+ } else {
+ if (pan != Offset.Zero) {
+ state.pan = clamp(state.pan + pan, state.scale)
}
+ }
+ event.changes.forEach { if (it.positionChanged()) it.consume() }
+ }
+
+ val lastChange = pressed.first()
+ tracker.addPosition(lastChange.uptimeMillis, lastChange.position)
+ }
+
+ if (!started) return@awaitEachGesture
+ val v = tracker.calculateVelocity()
+ val velocity = if (pinched) Offset.Zero else Offset(v.x, v.y)
+ if (velocity.getDistance() < 50f) return@awaitEachGesture
+
+ flinger[0] = launch {
+ val anim = androidx.compose.animation.core.Animatable(Offset.Zero, Offset.VectorConverter)
+ var last = Offset.Zero
+ val decay = androidx.compose.animation.splineBasedDecay<Offset>(androidx.compose.ui.unit.Density(density))
+ anim.animateDecay(velocity, decay) {
+ val delta = value - last
+ last = value
+ val target = state.pan + delta
+ val clamped = clamp(target, state.scale)
+ val consumed = clamped - state.pan
+ val left = delta - consumed
+ state.pan = clamped
+ if (kotlin.math.abs(left.x) > 0.5f && kotlin.math.abs(left.y) > 0.5f) {
+ throw kotlinx.coroutines.CancellationException("at the edge")
+ }
}
}
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt
index 1bc3c3d..1cfef16 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/ViewerBars.kt
@@ -131,7 +131,14 @@ fun ViewerTopBar(
} else {
com.chethan616.clearpdf.ui.glass.GlassBackButton(onBack)
}
- GlassPill(onClick = onTitle, modifier = Modifier.weight(1f), height = 48.dp, horizontalPadding = 16.dp) {
+ val barSurface = if (clear.dark) Color(0xFF151828).copy(alpha = 0.65f) else Color.White.copy(alpha = 0.75f)
+ GlassPill(
+ onClick = onTitle,
+ modifier = Modifier.weight(1f),
+ height = 48.dp,
+ horizontalPadding = 16.dp,
+ surface = barSurface,
+ ) {
if (toolTitle != null) Box(Modifier.size(9.dp).clip(CircleShape).background(Candy.Sky))
Column(Modifier.weight(1f)) {
Text(toolTitle ?: title, style = ClearType.Title.copy(fontSize = 15.5.sp, lineHeight = 19.sp), color = com.chethan616.clearpdf.ui.glass.LocalGlassInk.current, maxLines = 1, overflow = TextOverflow.Ellipsis)
@@ -197,8 +204,9 @@ fun GlassBars(visible: Boolean, fromTop: Boolean, content: @Composable () -> Uni
@Composable
private fun BarGroup(content: @Composable androidx.compose.foundation.layout.RowScope.() -> Unit) {
val probe = com.chethan616.clearpdf.ui.glass.rememberGlassInk(clear.ink)
+ val barSurface = if (clear.dark) Color(0xFF151828).copy(alpha = 0.65f) else Color.White.copy(alpha = 0.75f)
Row(
- Modifier.then(probe.modifier).height(48.dp).glassBar().padding(horizontal = 4.dp),
+ Modifier.then(probe.modifier).height(48.dp).glassBar(surface = barSurface).padding(horizontal = 4.dp),
verticalAlignment = Alignment.CenterVertically,
) { CompositionLocalProvider(com.chethan616.clearpdf.ui.glass.LocalGlassInk provides probe.color) { content() } }
}
diff --git a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/WordEdit.kt b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/WordEdit.kt
index 1cd613e..49e2ad7 100644
--- a/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/WordEdit.kt
+++ b/android/app/src/main/java/com/chethan616/clearpdf/ui/viewer/WordEdit.kt
@@ -132,7 +132,14 @@ fun WordEditDock(vm: AppViewModel, doc: OpenDocument) {
GlassIcon(LucideIcons.Check, null, Modifier.size(19.dp))
}
Row(
- Modifier.weight(1f).height(48.dp).glassBar().horizontalScroll(rememberScrollState()).padding(horizontal = 8.dp),
+ Modifier
+ .weight(1f)
+ .height(48.dp)
+ .glassBar(
+ surface = if (clear.dark) Color(0xFF1B1E2E).copy(alpha = 0.85f) else Color.White.copy(alpha = 0.90f)
+ )
+ .horizontalScroll(rememberScrollState())
+ .padding(horizontal = 8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(2.dp),
) {
@@ -155,13 +162,21 @@ fun WordEditDock(vm: AppViewModel, doc: OpenDocument) {
/** One glyph of the dock: in the glass's ink, lit by a soft accent while its formatting is on. */
@Composable
private fun EditKey(icon: ImageVector, label: String, enabled: Boolean = true, on: Boolean = false, onClick: () -> Unit) {
- val c = clear
+ val inkColor = if (on) Candy.Sky else if (clear.dark) Color(0xFFF0F4FC) else Color(0xFF1E222D)
Box(
- Modifier.size(40.dp).pressable({ if (enabled) onClick() }).then(
- if (on) Modifier.padding(4.dp).glassBar(surface = Candy.Sky.copy(alpha = 0.28f)) else Modifier,
- ),
+ Modifier
+ .size(40.dp)
+ .pressable({ if (enabled) onClick() })
+ .then(
+ if (on) Modifier.padding(4.dp).glassBar(surface = Candy.Sky.copy(alpha = 0.28f)) else Modifier,
+ ),
contentAlignment = Alignment.Center,
) {
- GlassIcon(icon, label, Modifier.size(21.dp).graphicsLayer { alpha = if (enabled) 1f else 0.35f }, tint = if (on) Candy.Sky else c.ink)
+ GlassIcon(
+ icon,
+ label,
+ Modifier.size(21.dp).graphicsLayer { alpha = if (enabled) 1f else 0.38f },
+ tint = inkColor,
+ )
}
}