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.

Liquid-glass dialog actions, live screen backdrop, reusable UnsavedChangesDialog; xlsx uses it

Chethan616b98794dc6aa3
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassDialog.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassDialog.kt
index cc6cf30..25ae506 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassDialog.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassDialog.kt
@@ -3,7 +3,6 @@ package com.chethan616.clearpdf.ui.components
import androidx.activity.compose.BackHandler
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.spring
-import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
@@ -21,6 +20,8 @@ import androidx.compose.foundation.layout.systemBarsPadding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.text.BasicText
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
@@ -28,13 +29,11 @@ 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.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
-import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.paneTitle
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.TextStyle
@@ -51,13 +50,25 @@ import com.kyant.backdrop.effects.colorControls
import com.kyant.backdrop.effects.lens
import com.kyant.backdrop.highlight.Highlight
import com.kyant.backdrop.shadow.Shadow
-import com.kyant.shapes.Capsule
import com.kyant.shapes.RoundedRectangle
+/** Backdrop the dialog panel samples, handed to [GlassDialogAction]s so the pills refract the same scene. */
+private val LocalDialogBackdrop = staticCompositionLocalOf<Backdrop?> { null }
+
+/** Blur of the dialog panel, so action pills frost the scene exactly like the sheet they sit on. */
+private val LocalDialogBlur = staticCompositionLocalOf { 16.dp }
+
+/** Panel surface wash, reused by neutral action pills so they read as the same glass. */
+private val LocalDialogSurface = staticCompositionLocalOf { Color.Unspecified }
+
/**
* Liquid-glass alert dialog (catalog DialogContent recipe) rendered **in-hierarchy** so it can
- * refract [backdrop]. Place it as the last child of a full-screen Box whose content records into
- * [backdrop] (a platform Dialog window could not sample the app's backdrop layer).
+ * refract [backdrop]. Place it as the last child of a full-screen Box, OUTSIDE the layer that records
+ * into [backdrop] (a platform Dialog window could not sample the app's backdrop layer).
+ *
+ * Pass the screen's LIVE backdrop — [ScreenBackdrop.glass] for a [GlassScreenScaffold] screen, the
+ * viewer's `contentBackdrop` for the PDF viewer / image editor. With the wallpaper off by default a
+ * wallpaper-only backdrop has nothing to bend and the panel reads as a flat card.
*
* Entrance: scrim fades in, panel scales 0.88 -> 1 with a spring while the lens strength ramps with
* the same progress (ControlCenter-style progressive lens). Back press and scrim tap call [onDismiss].
@@ -90,8 +101,11 @@ fun GlassDialog(
BackHandler(enabled = visible) { onDismiss() }
val isLight = !LocalIsDarkMode.current
- val containerColor = if (isLight) Color(0xFFFAFAFA).copy(0.6f) else Color(0xFF121212).copy(0.4f)
- val dimColor = if (isLight) Color(0xFF29293A).copy(0.23f) else Color(0xFF121212).copy(0.56f)
+ // Lighter wash + scrim than the catalog so the live screen behind stays visible through the
+ // glass — a heavy scrim leaves the lens nothing to refract.
+ val containerColor = if (isLight) Color(0xFFFAFAFA).copy(0.5f) else Color(0xFF121212).copy(0.34f)
+ val dimColor = if (isLight) Color(0xFF29293A).copy(0.16f) else Color(0xFF000000).copy(0.32f)
+ val blurDp = if (isLight) 16.dp else 8.dp
val contentColor = LiquidGlassColors.text(!isLight)
Box(
@@ -132,7 +146,7 @@ fun GlassDialog(
brightness = if (isLight) 0.2f else 0f,
saturation = 1.5f
)
- blur(if (isLight) 16f.dp.toPx() else 8f.dp.toPx())
+ blur(blurDp.toPx())
lens(24f.dp.toPx() * p, 48f.dp.toPx() * p, depthEffect = true, chromaticAberration = true)
},
highlight = { Highlight.Plain },
@@ -159,21 +173,28 @@ fun GlassDialog(
Column(Modifier.fillMaxWidth().padding(horizontal = 24f.dp, vertical = 8f.dp)) {
content()
}
- Row(
- Modifier
- .padding(24f.dp, 12f.dp, 24f.dp, 24f.dp)
- .fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(12f.dp),
- verticalAlignment = Alignment.CenterVertically,
- content = actions
- )
+ CompositionLocalProvider(
+ LocalDialogBackdrop provides backdrop,
+ LocalDialogBlur provides blurDp,
+ LocalDialogSurface provides containerColor
+ ) {
+ Row(
+ Modifier
+ .padding(24f.dp, 12f.dp, 24f.dp, 24f.dp)
+ .fillMaxWidth(),
+ horizontalArrangement = Arrangement.spacedBy(12f.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ content = actions
+ )
+ }
}
}
}
/**
- * Capsule action for [GlassDialog]'s `actions` slot (catalog style): secondary = faint glass fill,
- * primary = solid accent, destructive = red text.
+ * Liquid-glass capsule action for [GlassDialog]'s `actions` slot, in the vivid "Get it"
+ * [LiquidButton] style: primary = [tint] (screen accent), destructive = Red, neutral = clear glass
+ * frosted like the panel. Each pill refracts the same live backdrop as the dialog.
*/
@Composable
fun RowScope.GlassDialogAction(
@@ -182,36 +203,37 @@ fun RowScope.GlassDialogAction(
modifier: Modifier = Modifier,
primary: Boolean = false,
destructive: Boolean = false,
- enabled: Boolean = true
+ enabled: Boolean = true,
+ tint: Color = LiquidGlassColors.Blue
) {
val isDark = LocalIsDarkMode.current
val haptics = LocalHapticFeedback.current
- val accent = if (destructive) LiquidGlassColors.Red else LiquidGlassColors.Blue
- val bg = when {
- primary -> accent
- isDark -> Color.White.copy(0.10f)
- else -> Color.Black.copy(0.06f)
- }
- val fg = when {
- primary -> Color.White
+ val backdrop = LocalDialogBackdrop.current ?: error("GlassDialogAction must be used inside GlassDialog")
+ val pillTint = when {
destructive -> LiquidGlassColors.Red
- else -> LiquidGlassColors.text(isDark)
+ primary -> tint
+ else -> Color.Unspecified
}
- Row(
- modifier
- .weight(1f)
- .height(48.dp)
- .clip(Capsule)
- .background(bg)
- .clickable(enabled = enabled, role = Role.Button) {
- haptics.performHapticFeedback(HapticFeedbackType.ContextClick)
+ val fg = if (pillTint != Color.Unspecified) Color.White else LiquidGlassColors.text(isDark)
+ LiquidButton(
+ onClick = {
+ if (enabled) {
+ haptics.performHapticFeedback(if (destructive) HapticFeedbackType.LongPress else HapticFeedbackType.ContextClick)
onClick()
}
- .graphicsLayer { alpha = if (enabled) 1f else 0.4f }
- .padding(horizontal = 16.dp),
- horizontalArrangement = Arrangement.Center,
- verticalAlignment = Alignment.CenterVertically
+ },
+ backdrop = backdrop,
+ modifier = modifier
+ .weight(1f)
+ .graphicsLayer { alpha = if (enabled) 1f else 0.4f },
+ tint = pillTint,
+ surfaceColor = if (pillTint == Color.Unspecified) LocalDialogSurface.current else Color.Unspecified,
+ blurRadius = LocalDialogBlur.current
) {
- BasicText(text, style = TextStyle(fg, 16.sp, if (primary) FontWeight.SemiBold else FontWeight.Medium), maxLines = 1)
+ BasicText(
+ text,
+ style = TextStyle(fg, 16.sp, if (primary || destructive) FontWeight.SemiBold else FontWeight.Medium),
+ maxLines = 1
+ )
}
}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassScreenHeader.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassScreenHeader.kt
index 849433e..244f636 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassScreenHeader.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/GlassScreenHeader.kt
@@ -21,6 +21,8 @@ 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.Stable
+import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
@@ -32,6 +34,7 @@ import com.chethan616.clearpdf.R
import com.chethan616.clearpdf.ui.theme.LiquidGlassColors
import com.chethan616.clearpdf.ui.theme.LocalIsDarkMode
import com.kyant.backdrop.Backdrop
+import com.kyant.backdrop.backdrops.LayerBackdrop
import com.kyant.backdrop.backdrops.layerBackdrop
import com.kyant.backdrop.backdrops.rememberCombinedBackdrop
import com.kyant.backdrop.backdrops.rememberLayerBackdrop
@@ -61,10 +64,28 @@ private val DefaultHeaderGap = 12.dp
* navigation bar — feed it straight into a `LazyColumn`'s `contentPadding`, or into
* `Modifier.padding(...)` for a `verticalScroll` body.
*/
+/**
+ * The two backdrops a [GlassScreenScaffold] screen samples: [content] is the captured body layer,
+ * [glass] is `wallpaper + live content` — what anything floating OUTSIDE the body (header, dialogs,
+ * sheets) should refract. Hoist it with [rememberScreenBackdrop] when a sibling of the scaffold
+ * (a [GlassDialog], a bottom sheet) must see the real screen, not just the wallpaper — with the
+ * wallpaper off by default, sampling only the wallpaper reads as a flat card.
+ */
+@Stable
+class ScreenBackdrop internal constructor(val content: LayerBackdrop, val glass: Backdrop)
+
+@Composable
+fun rememberScreenBackdrop(wallpaper: Backdrop): ScreenBackdrop {
+ val content = rememberLayerBackdrop()
+ val glass = rememberCombinedBackdrop(wallpaper, content)
+ return remember(content, glass) { ScreenBackdrop(content, glass) }
+}
+
@Composable
fun GlassScreenScaffold(
backdrop: Backdrop,
modifier: Modifier = Modifier,
+ screenBackdrop: ScreenBackdrop = rememberScreenBackdrop(backdrop),
contentHorizontalPadding: Dp = GlassDimens.ScreenPadding,
contentBottomPadding: Dp = 0.dp,
headerHorizontalPadding: Dp = GlassDimens.ScreenPadding,
@@ -72,10 +93,10 @@ fun GlassScreenScaffold(
header: @Composable (headerBackdrop: Backdrop) -> Unit,
content: @Composable BoxScope.(contentPadding: PaddingValues) -> Unit
) {
- val contentBackdrop = rememberLayerBackdrop()
+ val contentBackdrop = screenBackdrop.content
// Wallpaper first, live content composited over it — the content layer is transparent wherever
// no card is drawn, so the header still refracts the wallpaper in the gaps.
- val headerBackdrop = rememberCombinedBackdrop(backdrop, contentBackdrop)
+ val headerBackdrop = screenBackdrop.glass
val statusTop = WindowInsets.statusBars.asPaddingValues().calculateTopPadding()
val navBottom = WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding()
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidButton.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidButton.kt
index 2b52e1a..9c97f2a 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidButton.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/LiquidButton.kt
@@ -16,6 +16,7 @@ import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.isSpecified
import androidx.compose.ui.semantics.Role
+import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.util.fastCoerceAtMost
import androidx.compose.ui.util.lerp
@@ -72,6 +73,10 @@ fun LiquidButton(
isInteractive: Boolean = true,
tint: Color = Color.Unspecified,
surfaceColor: Color = Color.Unspecified,
+ // Frost behind the pill. 2 dp is the catalog look over the wallpaper; a button that sits on
+ // top of another glass panel (dialog actions) passes that panel's blur so it reads as the same
+ // frosted sheet with a lensed rim instead of a sharp window punched through it.
+ blurRadius: Dp = 2.dp,
content: @Composable RowScope.() -> Unit
) {
val animationScope = rememberCoroutineScope()
@@ -86,7 +91,7 @@ fun LiquidButton(
shape = { Capsule },
effects = {
vibrancy()
- blur(2f.dp.toPx())
+ blur(blurRadius.toPx())
lens(12f.dp.toPx(), 24f.dp.toPx())
},
layerBlock = if (isInteractive) {
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/components/UnsavedChangesDialog.kt b/app/src/main/java/com/chethan616/clearpdf/ui/components/UnsavedChangesDialog.kt
new file mode 100644
index 0000000..a03020c
--- /dev/null
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/components/UnsavedChangesDialog.kt
@@ -0,0 +1,49 @@
+package com.chethan616.clearpdf.ui.components
+
+import androidx.compose.foundation.text.BasicText
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.res.stringResource
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.unit.sp
+import com.chethan616.clearpdf.R
+import com.chethan616.clearpdf.ui.theme.LiquidGlassColors
+import com.chethan616.clearpdf.ui.theme.LocalIsDarkMode
+import com.kyant.backdrop.Backdrop
+
+/**
+ * The one "Save changes?" card for every screen that can lose edits (xlsx, PDF / Office viewer,
+ * image editor). Layout is the spreadsheet's original: title, one line of body, then
+ * Discard (red) · Cancel (clear glass) · Save (accent) liquid pills.
+ *
+ * [backdrop] must be the screen's LIVE backdrop ([ScreenBackdrop.glass] or a viewer's
+ * `contentBackdrop`) so the card refracts what is actually behind it. [onSave] must perform the
+ * screen's real save and leave once it succeeds; [onCancel] also handles back / scrim tap.
+ */
+@Composable
+fun UnsavedChangesDialog(
+ visible: Boolean,
+ onDiscard: () -> Unit,
+ onCancel: () -> Unit,
+ onSave: () -> Unit,
+ backdrop: Backdrop,
+ title: String = stringResource(R.string.unsaved_title),
+ body: String = stringResource(R.string.unsaved_body),
+ saveLabel: String = stringResource(R.string.save),
+ accent: Color = LiquidGlassColors.Blue
+) {
+ val isDark = LocalIsDarkMode.current
+ GlassDialog(
+ visible = visible,
+ onDismiss = onCancel,
+ backdrop = backdrop,
+ title = title,
+ actions = {
+ GlassDialogAction(stringResource(R.string.unsaved_discard), onClick = onDiscard, destructive = true)
+ GlassDialogAction(stringResource(R.string.cancel), onClick = onCancel)
+ GlassDialogAction(saveLabel, onClick = onSave, primary = true, tint = accent)
+ }
+ ) {
+ BasicText(body, style = TextStyle(LiquidGlassColors.secondary(isDark), 15.sp))
+ }
+}
diff --git a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.kt b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.kt
index 25e4fe5..9928a86 100644
--- a/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.kt
+++ b/app/src/main/java/com/chethan616/clearpdf/ui/screen/SpreadsheetViewerScreen.kt
@@ -5,6 +5,10 @@ import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.animation.AnimatedVisibility
+import androidx.compose.animation.core.RepeatMode
+import androidx.compose.animation.core.animateFloat
+import androidx.compose.animation.core.infiniteRepeatable
+import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
@@ -121,8 +125,8 @@ import androidx.compose.ui.unit.sp
import com.chethan616.clearpdf.R
import com.chethan616.clearpdf.ui.components.GlassBottomSheet
import com.chethan616.clearpdf.ui.components.GlassColorPicker
-import com.chethan616.clearpdf.ui.components.GlassDialog
-import com.chethan616.clearpdf.ui.components.GlassDialogAction
+import com.chethan616.clearpdf.ui.components.UnsavedChangesDialog
+import com.chethan616.clearpdf.ui.components.rememberScreenBackdrop
import com.chethan616.clearpdf.ui.components.GlassMotion
import com.chethan616.clearpdf.ui.components.GlassScreenScaffold
import com.chethan616.clearpdf.ui.components.GlassSegmentedControl
@@ -405,9 +409,13 @@ fun SpreadsheetViewerScreen(
viewModel.applyStyle(idx, sel.range, patch)
}
+ // Hoisted so the unsaved-changes card and the format sheet (siblings of the scaffold, outside its
+ // captured layer) refract the live grid instead of only the — usually disabled — wallpaper.
+ val screenBackdrop = rememberScreenBackdrop(backdrop)
Box(Modifier.fillMaxSize()) {
GlassScreenScaffold(
backdrop = backdrop,
+ screenBackdrop = screenBackdrop,
contentHorizontalPadding = 12.dp,
headerHorizontalPadding = 12.dp,
header = { headerBackdrop ->
@@ -426,9 +434,17 @@ fun SpreadsheetViewerScreen(
)
}
if (state.dirty && state.editable) {
- LiquidIconButton(onClick = { save(false) }, backdrop = headerBackdrop, surfaceColor = accent.copy(0.85f)) {
- if (state.saving) CircularProgressIndicator(Modifier.size(16.dp), color = Color.White, strokeWidth = 2.dp)
- else Icon(Icons.Rounded.Check, stringResource(R.string.sheet_save), Modifier.size(20.dp), Color.White)
+ // Clear glass like the other header circles; only the tick carries the accent.
+ // While saving it breathes instead of swapping in a Material spinner.
+ val savePulse = if (state.saving) {
+ val t = rememberInfiniteTransition(label = "savePulse")
+ t.animateFloat(1f, 0.35f, infiniteRepeatable(tween(520), RepeatMode.Reverse), label = "savePulseA").value
+ } else 1f
+ LiquidIconButton(onClick = { if (!state.saving) save(false) }, backdrop = headerBackdrop) {
+ Icon(
+ Icons.Rounded.Check, stringResource(R.string.sheet_save),
+ Modifier.size(22.dp).graphicsLayer { alpha = savePulse }, accent
+ )
}
}
if (!editMode) {
@@ -701,7 +717,7 @@ fun SpreadsheetViewerScreen(
GlassBottomSheet(
visible = sheetPanel,
onDismiss = { panel = Panel.NONE },
- backdrop = backdrop
+ backdrop = screenBackdrop.glass
) {
val sel = selection
when (lastSheetPanel) {
@@ -740,19 +756,17 @@ fun SpreadsheetViewerScreen(
}
// Unsaved changes.
- GlassDialog(
+ UnsavedChangesDialog(
visible = confirmExit,
- onDismiss = { confirmExit = false },
- backdrop = backdrop,
+ onDiscard = { confirmExit = false; onBack() },
+ onCancel = { confirmExit = false },
+ onSave = { confirmExit = false; exitAfterSave = true; save(false) },
+ backdrop = screenBackdrop.glass,
title = stringResource(R.string.sheet_unsaved_title),
- actions = {
- GlassDialogAction(stringResource(R.string.sheet_discard), onClick = { confirmExit = false; onBack() }, destructive = true)
- GlassDialogAction(stringResource(R.string.cancel), onClick = { confirmExit = false })
- GlassDialogAction(stringResource(R.string.sheet_save), onClick = { confirmExit = false; exitAfterSave = true; save(false) }, primary = true)
- }
- ) {
- BasicText(stringResource(R.string.sheet_unsaved_body), style = TextStyle(sub, 15.sp))
- }
+ body = stringResource(R.string.sheet_unsaved_body),
+ saveLabel = stringResource(R.string.sheet_save),
+ accent = accent
+ )
}
}
@@ -808,10 +822,9 @@ private fun FormulaBar(
)
}
if (editing) {
- Box(
- Modifier.size(32.dp).clip(CircleShape).background(accent).clickable { onCommit() },
- contentAlignment = Alignment.Center
- ) { Icon(Icons.Rounded.Check, stringResource(R.string.save), Modifier.size(18.dp), Color.White) }
+ LiquidIconButton(onClick = onCommit, backdrop = backdrop, modifier = Modifier.size(34.dp), tint = accent) {
+ Icon(Icons.Rounded.Check, stringResource(R.string.save), Modifier.size(18.dp), Color.White)
+ }
}
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b480d5a..81ba433 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -639,6 +639,11 @@
<string name="ie_discard_body">Your changes to this image have not been saved.</string>
<string name="ie_discard">Discard</string>
<string name="ie_keep_editing">Keep editing</string>
+ <!-- Unsaved-changes card (every editor) -->
+ <string name="unsaved_title">Save changes?</string>
+ <string name="unsaved_body">Your edits to this document haven\'t been saved.</string>
+ <string name="unsaved_body_image">Your changes to this image haven\'t been saved.</string>
+ <string name="unsaved_discard">Discard</string>
<!-- Spreadsheet editor -->
<string name="sheet_edit">Edit</string>
<string name="sheet_done">Done</string>