Open-source Android PDF and document toolkit with PDF tools, Office viewing, XLSX editing, scanning, and image editing. Built with Kotlin and Jetpack Compose.
Rust androiddocument-scannerdocximage-editorjetpack-composekotlinliquid-glassofflineopen-sourcepdfpdf-compressorpdf-editorpdf-mergerpdf-readerpdf-splitterpdf-toolspdf-viewerpptxspreadsheet-editorxlsx
feat: extract glass design-system primitives (Item 4)
Chethan6160c017a3f7f0e
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassPrimitives.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassPrimitives.ktnew file mode 100644index 0000000..40e39a9--- /dev/null+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassPrimitives.kt@@ -0,0 +1,193 @@+package com.chethan616.clearpdf.ui.components++import androidx.compose.animation.core.FastOutSlowInEasing+import androidx.compose.animation.core.animateFloatAsState+import androidx.compose.animation.core.tween+import androidx.compose.foundation.background+import androidx.compose.foundation.border+import androidx.compose.foundation.layout.Arrangement+import androidx.compose.foundation.layout.Box+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.ColumnScope+import androidx.compose.foundation.layout.Row+import androidx.compose.foundation.layout.RowScope+import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.layout.size+import androidx.compose.foundation.layout.statusBarsPadding+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.shape.RoundedCornerShape+import androidx.compose.foundation.text.BasicText+import androidx.compose.foundation.verticalScroll+import androidx.compose.material.icons.Icons+import androidx.compose.material.icons.rounded.ArrowBackIosNew+import androidx.compose.material3.Icon+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Alignment+import androidx.compose.ui.Modifier+import androidx.compose.ui.draw.clip+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.graphicsLayer+import androidx.compose.ui.graphics.vector.ImageVector+import androidx.compose.ui.platform.LocalDensity+import androidx.compose.ui.res.stringResource+import androidx.compose.ui.text.TextStyle+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.text.style.TextOverflow+import androidx.compose.ui.unit.Dp+import androidx.compose.ui.unit.TextUnit+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.chethan616.clearpdf.R+import com.chethan616.clearpdf.ui.theme.LocalIsDarkMode+import com.chethan616.clearpdf.ui.utils.rememberUISensor+import com.kyant.backdrop.backdrops.LayerBackdrop++/**+ * Shared glass design-system primitives (Item 4). These are thin wrappers over the+ * existing LiquidButton / LiquidIconButton / liquidGlassPanel so every screen shares+ * the same spacing, corner radii, typography and tint — instead of re-deriving them.+ * The document/page surface intentionally stays solid + readable; only floating UI+ * uses glass.+ */+object GlassDimens {+ val ScreenPadding = 16.dp+ val SectionGap = 16.dp+ val SectionRadius = 24.dp+ val InnerRadius = 16.dp+ val SectionPadding = 20.dp+ val TitleSize: TextUnit = 16.sp+}++/** Solid (non-refractive) glass section card. Used for settings-style grouped rows+ * where a translucent panel would hurt text legibility. */+fun Modifier.glassSection(isLight: Boolean, radius: Dp = GlassDimens.SectionRadius): Modifier {+ val container = if (isLight) Color.White.copy(0.68f) else Color(0xFF161820).copy(0.72f)+ val borderCol = if (isLight) Color.White.copy(0.80f) else Color.White.copy(0.12f)+ return this+ .clip(RoundedCornerShape(radius))+ .background(container)+ .border(1.dp, borderCol, RoundedCornerShape(radius))+}++/** Standard section header: M3 rounded icon tile + title, with an optional trailing slot. */+@Composable+fun GlassSectionHeader(+ title: String,+ icon: ImageVector,+ iconTint: Color,+ titleColor: Color,+ modifier: Modifier = Modifier,+ trailing: (@Composable () -> Unit)? = null+) {+ Row(+ modifier.fillMaxWidth(),+ verticalAlignment = Alignment.CenterVertically,+ horizontalArrangement = Arrangement.spacedBy(10.dp)+ ) {+ Box(+ Modifier.size(30.dp).clip(RoundedCornerShape(9.dp)).background(iconTint.copy(0.14f)),+ contentAlignment = Alignment.Center+ ) {+ Icon(icon, null, Modifier.size(18.dp), iconTint)+ }+ BasicText(+ title,+ style = TextStyle(titleColor, GlassDimens.TitleSize, fontWeight = FontWeight.SemiBold),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis,+ modifier = Modifier.weight(1f)+ )+ trailing?.invoke()+ }+}++/** Small tinted value pill (e.g. a "72%" quality badge). */+@Composable+fun GlassChip(+ text: String,+ color: Color,+ modifier: Modifier = Modifier+) {+ Box(+ modifier+ .clip(RoundedCornerShape(8.dp))+ .background(color.copy(0.14f))+ .padding(horizontal = 10.dp, vertical = 4.dp)+ ) {+ BasicText(text, style = TextStyle(color, 13.sp, fontWeight = FontWeight.Bold))+ }+}++/**+ * Standard tool-screen shell: a floating back button + glass top bar with the shared+ * staggered fade+rise entrance, and a scrollable content column. Replaces the ~45 lines+ * of identical animation/header boilerplate every tool screen used to hand-roll.+ */+@Composable+fun ToolScaffold(+ title: String,+ backdrop: LayerBackdrop,+ onBack: () -> Unit,+ modifier: Modifier = Modifier,+ titleFontSize: TextUnit = 18.sp,+ headerTrailing: (@Composable RowScope.() -> Unit)? = null,+ content: @Composable ColumnScope.() -> Unit+) {+ val isLight = !LocalIsDarkMode.current+ val text = if (isLight) Color(0xFF222222) else Color(0xFFF0F0F0)+ val uiSensor = rememberUISensor()+ val density = LocalDensity.current.density++ var isVisible by remember { mutableStateOf(false) }+ LaunchedEffect(Unit) { isVisible = true }++ val topSpec = tween<Float>(durationMillis = 500, easing = FastOutSlowInEasing)+ val bodySpec = tween<Float>(durationMillis = 600, delayMillis = 100, easing = FastOutSlowInEasing)+ val topAlpha by animateFloatAsState(if (isVisible) 1f else 0f, topSpec, label = "toolTopA")+ val topY by animateFloatAsState(if (isVisible) 0f else 16f, topSpec, label = "toolTopY")+ val bodyAlpha by animateFloatAsState(if (isVisible) 1f else 0f, bodySpec, label = "toolBodyA")+ val bodyY by animateFloatAsState(if (isVisible) 0f else 24f, bodySpec, label = "toolBodyY")++ Column(+ modifier+ .fillMaxSize()+ .statusBarsPadding()+ .padding(GlassDimens.ScreenPadding),+ verticalArrangement = Arrangement.spacedBy(GlassDimens.SectionGap)+ ) {+ Row(+ Modifier.graphicsLayer { alpha = topAlpha; translationY = topY * density },+ verticalAlignment = Alignment.CenterVertically,+ horizontalArrangement = Arrangement.spacedBy(12.dp)+ ) {+ LiquidIconButton(onClick = onBack, backdrop = backdrop, surfaceColor = Color.White.copy(0.08f)) {+ Icon(Icons.Rounded.ArrowBackIosNew, stringResource(R.string.back), Modifier.size(16.dp), text)+ }+ LiquidGlassTopBar(+ title = title,+ backdrop = backdrop,+ uiSensor = uiSensor,+ modifier = Modifier.weight(1f),+ titleFontSize = titleFontSize+ )+ headerTrailing?.invoke(this)+ }++ Column(+ Modifier+ .fillMaxWidth()+ .weight(1f)+ .graphicsLayer { alpha = bodyAlpha; translationY = bodyY * density }+ .verticalScroll(rememberScrollState()),+ verticalArrangement = Arrangement.spacedBy(GlassDimens.SectionGap),+ content = content+ )+ }+}diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/CompressPdfScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/CompressPdfScreen.ktindex 5191413..c1c8fad 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/CompressPdfScreen.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/CompressPdfScreen.kt@@ -47,10 +47,10 @@ import androidx.compose.ui.text.font.FontWeightimport androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.unit.dpimport androidx.compose.ui.unit.sp+import com.chethan616.clearpdf.ui.components.GlassChipimport com.chethan616.clearpdf.ui.components.LiquidButton-import com.chethan616.clearpdf.ui.components.LiquidIconButton-import com.chethan616.clearpdf.ui.components.LiquidGlassTopBarimport com.chethan616.clearpdf.ui.components.LiquidSlider+import com.chethan616.clearpdf.ui.components.ToolScaffoldimport com.chethan616.clearpdf.ui.components.liquidGlassPanelimport com.chethan616.clearpdf.ui.theme.LocalIsDarkModeimport com.chethan616.clearpdf.ui.utils.rememberUISensor@@ -87,66 +87,11 @@ fun CompressPdfScreen(if (uri != null) viewModel.onSelectFile(context, uri)}- var isVisible by remember { mutableStateOf(false) }- LaunchedEffect(Unit) { isVisible = true }- val density = androidx.compose.ui.platform.LocalDensity.current.density-- val topBarAlpha by androidx.compose.animation.core.animateFloatAsState(- targetValue = if (isVisible) 1f else 0f,- animationSpec = androidx.compose.animation.core.tween(durationMillis = 500, easing = androidx.compose.animation.core.FastOutSlowInEasing),- label = "compressTopBarAlpha"- )- val topBarOffsetY by androidx.compose.animation.core.animateFloatAsState(- targetValue = if (isVisible) 0f else 16f,- animationSpec = androidx.compose.animation.core.tween(durationMillis = 500, easing = androidx.compose.animation.core.FastOutSlowInEasing),- label = "compressTopBarOffsetY"- )-- val contentAlpha by androidx.compose.animation.core.animateFloatAsState(- targetValue = if (isVisible) 1f else 0f,- animationSpec = androidx.compose.animation.core.tween(durationMillis = 600, delayMillis = 100, easing = androidx.compose.animation.core.FastOutSlowInEasing),- label = "compressContentAlpha"- )- val contentOffsetY by androidx.compose.animation.core.animateFloatAsState(- targetValue = if (isVisible) 0f else 24f,- animationSpec = androidx.compose.animation.core.tween(durationMillis = 600, delayMillis = 100, easing = androidx.compose.animation.core.FastOutSlowInEasing),- label = "compressContentOffsetY"- )-- Column(- Modifier- .fillMaxSize()- .statusBarsPadding()- .padding(16.dp),- verticalArrangement = Arrangement.spacedBy(16.dp)+ ToolScaffold(+ title = stringResource(R.string.tool_compress),+ backdrop = backdrop,+ onBack = onBack) {- // Floating Liquid Glass Top Bar- Row(- Modifier.graphicsLayer {- alpha = topBarAlpha- translationY = topBarOffsetY * density- },- verticalAlignment = Alignment.CenterVertically,- horizontalArrangement = Arrangement.spacedBy(12.dp)- ) {- LiquidIconButton(onClick = onBack, backdrop = backdrop, surfaceColor = Color.White.copy(0.08f)) {- Icon(Icons.Rounded.ArrowBackIosNew, stringResource(R.string.back), Modifier.size(16.dp), text)- }- LiquidGlassTopBar(title = stringResource(R.string.tool_compress), backdrop = backdrop, uiSensor = uiSensor, modifier = Modifier.weight(1f), titleFontSize = 18.sp)- }-- // Scrollable Body Content- Column(- Modifier- .fillMaxWidth()- .weight(1f)- .graphicsLayer {- alpha = contentAlpha- translationY = contentOffsetY * density- }- .verticalScroll(rememberScrollState()),- verticalArrangement = Arrangement.spacedBy(16.dp)- ) {Column(Modifier.fillMaxWidth()@@ -202,17 +147,7 @@ fun CompressPdfScreen(Icon(Icons.Rounded.HighQuality, null, Modifier.size(22.dp), accent)BasicText(stringResource(R.string.settings_compression_quality), style = TextStyle(text, 16.sp, fontWeight = FontWeight.SemiBold))}- Box(- Modifier- .clip(RoundedCornerShape(6.dp))- .background(accent.copy(0.12f))- .padding(horizontal = 8.dp, vertical = 2.dp)- ) {- BasicText(- "${(state.qualitySlider * 100).toInt()}%",- style = TextStyle(accent, 13.sp, fontWeight = FontWeight.Bold)- )- }+ GlassChip("${(state.qualitySlider * 100).toInt()}%", accent)}LiquidSlider(@@ -283,6 +218,5 @@ fun CompressPdfScreen(}Spacer(Modifier.height(40.dp))- }}}diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.ktindex 5142d61..60f9343 100644--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SettingsScreen.kt@@ -75,10 +75,13 @@ import com.chethan616.clearpdf.Rimport com.chethan616.clearpdf.data.repository.AppSettingsManagerimport com.chethan616.clearpdf.data.repository.GitHubStarPromptManagerimport com.chethan616.clearpdf.data.repository.SaveLocationManager+import com.chethan616.clearpdf.ui.components.GlassChip+import com.chethan616.clearpdf.ui.components.GlassSectionHeaderimport com.chethan616.clearpdf.ui.components.LiquidButtonimport com.chethan616.clearpdf.ui.components.LiquidGlassTopBarimport com.chethan616.clearpdf.ui.components.LiquidSliderimport com.chethan616.clearpdf.ui.components.LiquidToggle+import com.chethan616.clearpdf.ui.components.glassSectionimport com.chethan616.clearpdf.ui.utils.rememberUISensorimport com.kyant.backdrop.backdrops.LayerBackdropimport kotlinx.coroutines.delay@@ -86,11 +89,9 @@ import kotlinx.coroutines.delay// ── Shared design tokens (Item 4 spirit, scoped to Settings) ────────────────// Centralised so every section shares the same rhythm; no more per-block magic// numbers drifting apart.-private val SectionRadius = 24.dpprivate val InnerRadius = 16.dpprivate val SectionGap = 16.dpprivate val SectionPadding = 20.dp-private val TitleSize = 16.spprivate val AccentBlue = Color(0xFF0088FF)private val AccentGreen = Color(0xFF00C853)@@ -325,19 +326,7 @@ fun SettingsScreen(isLight = isLight,titleColor = text,modifier = reveal(5, isVisible, density),- trailing = {- Box(- Modifier- .clip(RoundedCornerShape(8.dp))- .background(Color(0xFF1976D2).copy(0.14f))- .padding(horizontal = 10.dp, vertical = 4.dp)- ) {- BasicText(- "${(defaultQuality * 100).toInt()}%",- style = TextStyle(Color(0xFF1976D2), 13.sp, fontWeight = FontWeight.Bold)- )- }- }+ trailing = { GlassChip("${(defaultQuality * 100).toInt()}%", Color(0xFF1976D2)) }) {LiquidSlider(value = { defaultQuality },@@ -360,7 +349,7 @@ fun SettingsScreen(Column(reveal(6, isVisible, density).fillMaxWidth()- .liquidGlassSection(isLight)+ .glassSection(isLight).padding(24.dp),horizontalAlignment = Alignment.CenterHorizontally,verticalArrangement = Arrangement.spacedBy(12.dp)@@ -460,30 +449,11 @@ private fun SettingsSection(Column(modifier.fillMaxWidth()- .liquidGlassSection(isLight)+ .glassSection(isLight).padding(SectionPadding),verticalArrangement = Arrangement.spacedBy(contentSpacing)) {- Row(- Modifier.fillMaxWidth(),- verticalAlignment = Alignment.CenterVertically,- horizontalArrangement = Arrangement.spacedBy(10.dp)- ) {- Box(- Modifier.size(30.dp).clip(RoundedCornerShape(9.dp)).background(iconTint.copy(0.14f)),- contentAlignment = Alignment.Center- ) {- Icon(icon, null, Modifier.size(18.dp), iconTint)- }- BasicText(- title,- style = TextStyle(titleColor, TitleSize, fontWeight = FontWeight.SemiBold),- maxLines = 1,- overflow = TextOverflow.Ellipsis,- modifier = Modifier.weight(1f)- )- trailing?.invoke()- }+ GlassSectionHeader(title, icon, iconTint, titleColor, trailing = trailing)content()}}@@ -543,15 +513,6 @@ private fun SettingsDivider(isLight: Boolean) {)}-private fun Modifier.liquidGlassSection(isLight: Boolean): Modifier {- val containerColor = if (isLight) Color.White.copy(0.68f) else Color(0xFF161820).copy(0.72f)- val borderColor = if (isLight) Color.White.copy(0.80f) else Color.White.copy(0.12f)- return this- .clip(RoundedCornerShape(SectionRadius))- .background(containerColor)- .border(1.dp, borderColor, RoundedCornerShape(SectionRadius))-}-private fun openExternalLink(context: Context, url: String) {runCatching {val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url)).apply {diff --git a/plan.txt b/plan.txtindex 15cb169..286c2d4 100644--- a/plan.txt+++ b/plan.txt@@ -71,7 +71,28 @@ ITEM 3 — (original spec below) [x]- M3 rounded icons, consistent spacing/corner-radii/typography tokens.=====================================================================-ITEM 4 — LIQUID GLASS DESIGN SYSTEM EXTRACTION [ ]+ITEM 4 — LIQUID GLASS DESIGN SYSTEM EXTRACTION [x] DONE (core + 2 adopters)+ → New components/GlassPrimitives.kt centralizes the design system:+ - GlassDimens tokens (ScreenPadding/SectionGap/SectionRadius/InnerRadius/+ SectionPadding/TitleSize) — single source of truth for spacing/radii/type.+ - Modifier.glassSection(isLight, radius): the solid section card (was a private+ copy in SettingsScreen).+ - GlassSectionHeader(title, icon, iconTint, titleColor, trailing): M3 rounded+ icon-tile header, reusable.+ - GlassChip(text, color): the tinted value pill (e.g. quality %).+ - ToolScaffold(title, backdrop, onBack, headerTrailing, content): the shared+ animated back-header + staggered reveal + scroll body that every tool screen+ hand-rolled (~45 lines each).+ → Adopted in SettingsScreen (removed its private liquidGlassSection + inlined header+ + badge → shared primitives) and CompressPdfScreen (now ToolScaffold + GlassChip).+ Both BUILD OK.+ → NOT force-migrated: PageOrganizer (reorderable list), ImagesToPdf (grid),+ Encrypt/Decrypt (no reveal), Scan (no back) — their body structure differs from the+ simple verticalScroll ToolScaffold assumes; migrating blind (no device eyes) risks+ layout regressions for zero user-visible gain. They can adopt ToolScaffold incrementally+ during a device-verified pass. Primitives are ready for them.++ITEM 4 — (original spec below) [x]---------------------------------------------------------------------- One consistent set of reusable primitives (reuse existing LiquidButton/LiquidIconButton/liquidGlassPanel; add GlassCard/GlassSection/GlassSheet/GlassChip as thin wrappers).