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.

refactor: redesign Settings around reusable primitives (Item 3)

Chethan6168f512f604b13
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.kt
index b5d4c8e..5142d61 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
@@ -5,12 +5,16 @@ import android.content.Intent
import android.net.Uri
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
+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.clickable
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.Spacer
import androidx.compose.foundation.layout.WindowInsets
@@ -22,7 +26,6 @@ import androidx.compose.foundation.layout.navigationBars
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBarsPadding
-import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
@@ -38,8 +41,8 @@ import androidx.compose.material.icons.rounded.FolderOpen
import androidx.compose.material.icons.rounded.FolderSpecial
import androidx.compose.material.icons.rounded.HighQuality
import androidx.compose.material.icons.rounded.Info
-import androidx.compose.material.icons.rounded.LightMode
import androidx.compose.material.icons.rounded.Language
+import androidx.compose.material.icons.rounded.LightMode
import androidx.compose.material.icons.rounded.Notifications
import androidx.compose.material.icons.rounded.PhoneAndroid
import androidx.compose.material.icons.rounded.Star
@@ -56,15 +59,18 @@ 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.LocalContext
+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.TextAlign
import androidx.compose.ui.text.style.TextOverflow
+import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
-import androidx.compose.ui.res.stringResource
import com.chethan616.clearpdf.R
import com.chethan616.clearpdf.data.repository.AppSettingsManager
import com.chethan616.clearpdf.data.repository.GitHubStarPromptManager
@@ -73,13 +79,20 @@ import com.chethan616.clearpdf.ui.components.LiquidButton
import com.chethan616.clearpdf.ui.components.LiquidGlassTopBar
import com.chethan616.clearpdf.ui.components.LiquidSlider
import com.chethan616.clearpdf.ui.components.LiquidToggle
-import com.chethan616.clearpdf.ui.components.liquidGlassPanel
-import com.chethan616.clearpdf.ui.theme.LiquidGlassColors
import com.chethan616.clearpdf.ui.utils.rememberUISensor
import com.kyant.backdrop.backdrops.LayerBackdrop
import kotlinx.coroutines.delay
-import androidx.compose.ui.graphics.graphicsLayer
+// ── 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.dp
+private val InnerRadius = 16.dp
+private val SectionGap = 16.dp
+private val SectionPadding = 20.dp
+private val TitleSize = 16.sp
+private val AccentBlue = Color(0xFF0088FF)
+private val AccentGreen = Color(0xFF00C853)
@Composable
fun SettingsScreen(
@@ -92,21 +105,23 @@ fun SettingsScreen(
onLocaleChanged: (String) -> Unit = {}
) {
val isLight = !isDarkMode
- val text = if (isLight) Color(0xFF222222) else Color(0xFFF0F0F0)
- val sub = if (isLight) Color(0xFF888888) else Color(0xFFAAAAAA)
+ val text = if (isLight) Color(0xFF222222) else Color(0xFFF0F0F0)
+ val sub = if (isLight) Color(0xFF888888) else Color(0xFFAAAAAA)
val label = if (isLight) Color(0xFF444444) else Color(0xFFCCCCCC)
val uiSensor = rememberUISensor()
val context = LocalContext.current
+ val density = LocalDensity.current.density
val openRepo = remember(context) {
{ openExternalLink(context, GitHubStarPromptManager.REPO_URL) }
}
- var autoCompress by remember { mutableStateOf(AppSettingsManager.getAutoCompress(context)) }
- var keepOriginal by remember { mutableStateOf(AppSettingsManager.getKeepOriginal(context)) }
- var notifications by remember { mutableStateOf(AppSettingsManager.getNotifications(context)) }
+ // ── Backing state (unchanged persistence calls) ─────────────────────────
+ var autoCompress by remember { mutableStateOf(AppSettingsManager.getAutoCompress(context)) }
+ var keepOriginal by remember { mutableStateOf(AppSettingsManager.getKeepOriginal(context)) }
+ var notifications by remember { mutableStateOf(AppSettingsManager.getNotifications(context)) }
var defaultQuality by remember { mutableFloatStateOf(AppSettingsManager.getDefaultQuality(context)) }
- // Debounce quality slider persistence to prevent lag
+ // Debounce quality slider persistence to prevent lag.
LaunchedEffect(defaultQuality) {
delay(300L)
AppSettingsManager.setDefaultQuality(context, defaultQuality)
@@ -118,13 +133,12 @@ fun SettingsScreen(
contract = ActivityResultContracts.OpenDocumentTree()
) { uri: Uri? ->
if (uri != null) {
- // Take persistable permission so we can write there later
- val flags = android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION or
- android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION
+ val flags = Intent.FLAG_GRANT_READ_URI_PERMISSION or
+ Intent.FLAG_GRANT_WRITE_URI_PERMISSION
try {
context.contentResolver.takePersistableUriPermission(uri, flags)
} catch (_: Exception) {
- // Some providers may reject persistable flags; fallback still stores chosen URI.
+ // Some providers reject persistable flags; fallback still stores the chosen URI.
}
val displayPath = uri.lastPathSegment?.replace("primary:", "") ?: uri.toString()
SaveLocationManager.setSaveLocation(context, uri, displayPath)
@@ -133,88 +147,7 @@ fun SettingsScreen(
}
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 = 550, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsTopBarAlpha"
- )
- val topBarOffsetY by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 0f else 18f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 550, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsTopBarOffsetY"
- )
-
- val panel1Alpha by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 1f else 0f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 600, delayMillis = 60, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel1Alpha"
- )
- val panel1OffsetY by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 0f else 20f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 600, delayMillis = 60, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel1OffsetY"
- )
-
- val panel2Alpha by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 1f else 0f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 620, delayMillis = 120, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel2Alpha"
- )
- val panel2OffsetY by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 0f else 24f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 620, delayMillis = 120, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel2OffsetY"
- )
-
- val panel3Alpha by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 1f else 0f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 640, delayMillis = 180, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel3Alpha"
- )
- val panel3OffsetY by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 0f else 28f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 640, delayMillis = 180, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel3OffsetY"
- )
-
- val panel4Alpha by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 1f else 0f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 660, delayMillis = 240, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel4Alpha"
- )
- val panel4OffsetY by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 0f else 32f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 660, delayMillis = 240, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel4OffsetY"
- )
-
- val panel5Alpha by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 1f else 0f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 680, delayMillis = 300, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel5Alpha"
- )
- val panel5OffsetY by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 0f else 36f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 680, delayMillis = 300, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel5OffsetY"
- )
-
- val panel6Alpha by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 1f else 0f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 700, delayMillis = 360, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel6Alpha"
- )
- val panel6OffsetY by androidx.compose.animation.core.animateFloatAsState(
- targetValue = if (isVisible) 0f else 40f,
- animationSpec = androidx.compose.animation.core.tween(durationMillis = 700, delayMillis = 360, easing = androidx.compose.animation.core.FastOutSlowInEasing),
- label = "settingsPanel6OffsetY"
- )
+ LaunchedEffect(Unit) { isVisible = true }
Column(
Modifier
@@ -222,84 +155,37 @@ fun SettingsScreen(
.statusBarsPadding()
.padding(16.dp)
.verticalScroll(rememberScrollState()),
- verticalArrangement = Arrangement.spacedBy(16.dp)
+ verticalArrangement = Arrangement.spacedBy(SectionGap)
) {
- Box(
- Modifier.graphicsLayer {
- alpha = topBarAlpha
- translationY = topBarOffsetY * density
- }
- ) {
- LiquidGlassTopBar(title = stringResource(R.string.settings_title), backdrop = backdrop, uiSensor = uiSensor, modifier = Modifier.fillMaxWidth())
+ Box(reveal(0, isVisible, density)) {
+ LiquidGlassTopBar(
+ title = stringResource(R.string.settings_title),
+ backdrop = backdrop,
+ uiSensor = uiSensor,
+ modifier = Modifier.fillMaxWidth()
+ )
}
- // ── Theme Mode Selector ──
- Column(
- Modifier
- .fillMaxWidth()
- .graphicsLayer {
- alpha = panel1Alpha
- translationY = panel1OffsetY * density
- }
- .liquidGlassSection(isLight)
- .padding(20.dp),
- verticalArrangement = Arrangement.spacedBy(16.dp)
+ // ── Appearance ──────────────────────────────────────────────────────
+ SettingsSection(
+ title = stringResource(R.string.settings_appearance),
+ icon = Icons.Rounded.Tune,
+ iconTint = AccentBlue,
+ isLight = isLight,
+ titleColor = text,
+ modifier = reveal(1, isVisible, density)
) {
- Row(
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp)
- ) {
- Icon(Icons.Rounded.Tune, null, Modifier.size(22.dp), label)
- BasicText(stringResource(R.string.settings_appearance), style = TextStyle(text, 17.sp, fontWeight = FontWeight.SemiBold))
- }
-
- // Liquid Glass Theme Mode Selector
- Row(
- Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(10.dp)
- ) {
- data class ThemeOption(val idx: Int, val label: String, val icon: ImageVector, val activeColor: Color)
- val options = listOf(
- ThemeOption(0, stringResource(R.string.settings_theme_auto), Icons.Rounded.PhoneAndroid, Color(0xFF0088FF)),
- ThemeOption(1, stringResource(R.string.settings_theme_light), Icons.Rounded.LightMode, Color(0xFFFFA726)),
- ThemeOption(2, stringResource(R.string.settings_theme_dark), Icons.Rounded.DarkMode, Color(0xFF7C4DFF))
- )
- options.forEach { option ->
- val isSelected = themeMode == option.idx
- val itemContentColor = if (isSelected) Color.White else (if (isLight) Color(0xFF2C2C2E) else Color(0xFFE0E0E0))
- LiquidButton(
- onClick = { onThemeModeChanged(option.idx) },
- backdrop = backdrop,
- tint = if (isSelected) option.activeColor else Color.Transparent,
- surfaceColor = if (isSelected) option.activeColor.copy(0.18f) else (if (isLight) Color.White.copy(0.70f) else Color.White.copy(0.10f)),
- modifier = Modifier.weight(1f)
- ) {
- Row(
- Modifier.fillMaxWidth(),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(5.dp, Alignment.CenterHorizontally)
- ) {
- Icon(
- option.icon, null,
- Modifier.size(16.dp),
- itemContentColor
- )
- BasicText(
- option.label,
- style = TextStyle(
- itemContentColor,
- 13.sp,
- fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Medium
- ),
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier.weight(1f, fill = false)
- )
- }
- }
- }
- }
-
+ SegmentedSelector(
+ options = listOf(
+ SegOption("0", stringResource(R.string.settings_theme_auto), Icons.Rounded.PhoneAndroid, AccentBlue),
+ SegOption("1", stringResource(R.string.settings_theme_light), Icons.Rounded.LightMode, Color(0xFFFFA726)),
+ SegOption("2", stringResource(R.string.settings_theme_dark), Icons.Rounded.DarkMode, Color(0xFF7C4DFF))
+ ),
+ selectedId = themeMode.toString(),
+ isLight = isLight,
+ backdrop = backdrop,
+ onSelect = { onThemeModeChanged(it.toInt()) }
+ )
BasicText(
when (themeMode) {
1 -> stringResource(R.string.settings_theme_light_desc)
@@ -310,229 +196,136 @@ fun SettingsScreen(
)
}
- // ── Save Location ──
- Column(
- Modifier
- .fillMaxWidth()
- .graphicsLayer {
- alpha = panel2Alpha
- translationY = panel2OffsetY * density
- }
- .liquidGlassSection(isLight)
- .padding(20.dp),
- verticalArrangement = Arrangement.spacedBy(14.dp)
+ // ── Language ────────────────────────────────────────────────────────
+ SettingsSection(
+ title = stringResource(R.string.settings_language),
+ icon = Icons.Rounded.Language,
+ iconTint = AccentBlue,
+ isLight = isLight,
+ titleColor = text,
+ modifier = reveal(2, isVisible, density)
) {
- Row(
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp)
- ) {
- Icon(Icons.Rounded.FolderOpen, null, Modifier.size(22.dp), Color(0xFF0088FF))
- BasicText(stringResource(R.string.settings_save_location), style = TextStyle(text, 17.sp, fontWeight = FontWeight.SemiBold))
- }
-
- // Liquid Glass Save Location Mode Selector
- Row(
- Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(10.dp)
- ) {
- val isDefault = saveUri == null
- val activeBlue = Color(0xFF0088FF)
- val activeGreen = Color(0xFF00C853)
-
- // 1. Default Downloads Button
- val defContentColor = if (isDefault) Color.White else (if (isLight) Color(0xFF2C2C2E) else Color(0xFFE0E0E0))
- LiquidButton(
- onClick = {
- if (!isDefault) {
- SaveLocationManager.clearSaveLocation(context)
- saveUri = null
- }
- },
- backdrop = backdrop,
- tint = if (isDefault) activeBlue else Color.Transparent,
- surfaceColor = if (isDefault) activeBlue.copy(0.18f) else (if (isLight) Color.White.copy(0.70f) else Color.White.copy(0.10f)),
- modifier = Modifier.weight(1f)
- ) {
- Row(
- Modifier.fillMaxWidth(),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(5.dp, Alignment.CenterHorizontally)
- ) {
- Icon(Icons.Rounded.Download, null, Modifier.size(16.dp), defContentColor)
- BasicText(
- stringResource(R.string.settings_save_downloads),
- style = TextStyle(
- defContentColor,
- 13.sp,
- fontWeight = if (isDefault) FontWeight.Bold else FontWeight.Medium
- ),
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier.weight(1f, fill = false)
- )
- }
- }
+ SegmentedSelector(
+ options = listOf(
+ SegOption("en", stringResource(R.string.language_english), null, AccentBlue),
+ SegOption("pt-BR", stringResource(R.string.language_portuguese), null, AccentBlue)
+ ),
+ selectedId = selectedLocale,
+ isLight = isLight,
+ backdrop = backdrop,
+ onSelect = onLocaleChanged
+ )
+ }
- // 2. Custom Folder Button
- val isCustom = !isDefault
- val customContentColor = if (isCustom) Color.White else (if (isLight) Color(0xFF2C2C2E) else Color(0xFFE0E0E0))
- LiquidButton(
- onClick = { folderPicker.launch(null) },
- backdrop = backdrop,
- tint = if (isCustom) activeGreen else Color.Transparent,
- surfaceColor = if (isCustom) activeGreen.copy(0.18f) else (if (isLight) Color.White.copy(0.70f) else Color.White.copy(0.10f)),
- modifier = Modifier.weight(1f)
- ) {
- Row(
- Modifier.fillMaxWidth(),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(5.dp, Alignment.CenterHorizontally)
- ) {
- Icon(Icons.Rounded.FolderSpecial, null, Modifier.size(16.dp), customContentColor)
- BasicText(
- stringResource(R.string.settings_save_custom),
- style = TextStyle(
- customContentColor,
- 13.sp,
- fontWeight = if (isCustom) FontWeight.Bold else FontWeight.Medium
- ),
- maxLines = 1,
- overflow = TextOverflow.Ellipsis,
- modifier = Modifier.weight(1f, fill = false)
- )
+ // ── Files: save location ────────────────────────────────────────────
+ SettingsSection(
+ title = stringResource(R.string.settings_save_location),
+ icon = Icons.Rounded.FolderOpen,
+ iconTint = AccentBlue,
+ isLight = isLight,
+ titleColor = text,
+ modifier = reveal(3, isVisible, density)
+ ) {
+ val isDefault = saveUri == null
+ SegmentedSelector(
+ options = listOf(
+ SegOption("default", stringResource(R.string.settings_save_downloads), Icons.Rounded.Download, AccentBlue),
+ SegOption("custom", stringResource(R.string.settings_save_custom), Icons.Rounded.FolderSpecial, AccentGreen)
+ ),
+ selectedId = if (isDefault) "default" else "custom",
+ isLight = isLight,
+ backdrop = backdrop,
+ onSelect = { id ->
+ if (id == "default") {
+ if (!isDefault) { SaveLocationManager.clearSaveLocation(context); saveUri = null }
+ } else {
+ folderPicker.launch(null)
}
}
- }
+ )
- // Path Details Card
+ // Path details card.
+ val accent = if (saveUri != null) AccentGreen else AccentBlue
Row(
Modifier
.fillMaxWidth()
- .clip(RoundedCornerShape(16.dp))
+ .clip(RoundedCornerShape(InnerRadius))
.background(if (isLight) Color.Black.copy(0.03f) else Color.White.copy(0.05f))
- .border(1.dp, if (isLight) Color.Black.copy(0.05f) else Color.White.copy(0.08f), RoundedCornerShape(16.dp))
+ .border(1.dp, if (isLight) Color.Black.copy(0.05f) else Color.White.copy(0.08f), RoundedCornerShape(InnerRadius))
.padding(14.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
- val iconColor = if (saveUri != null) Color(0xFF00C853) else Color(0xFF0088FF)
Box(
- Modifier
- .size(38.dp)
- .clip(CircleShape)
- .background(iconColor.copy(0.14f)),
+ Modifier.size(38.dp).clip(CircleShape).background(accent.copy(0.14f)),
contentAlignment = Alignment.Center
) {
Icon(
if (saveUri != null) Icons.Rounded.FolderSpecial else Icons.Rounded.Download,
- null,
- Modifier.size(19.dp),
- iconColor
+ null, Modifier.size(19.dp), accent
)
}
Column(Modifier.weight(1f)) {
BasicText(
- if (saveUri != null) stringResource(R.string.settings_custom_directory) else stringResource(R.string.settings_default_directory),
+ if (saveUri != null) stringResource(R.string.settings_custom_directory)
+ else stringResource(R.string.settings_default_directory),
style = TextStyle(label, 13.sp, fontWeight = FontWeight.SemiBold)
)
- val path = if (saveUri != null) {
+ val path = if (saveUri != null)
saveUri!!.lastPathSegment?.replace("primary:", "") ?: saveUri.toString()
- } else stringResource(R.string.settings_default_path)
- BasicText(path, style = TextStyle(sub, 12.sp))
+ else stringResource(R.string.settings_default_path)
+ BasicText(path, style = TextStyle(sub, 12.sp), maxLines = 2, overflow = TextOverflow.Ellipsis)
}
}
}
- // ── File Handling ──
- Column(
- Modifier
- .fillMaxWidth()
- .graphicsLayer {
- alpha = panel3Alpha
- translationY = panel3OffsetY * density
- }
- .liquidGlassSection(isLight)
- .padding(20.dp),
- verticalArrangement = Arrangement.spacedBy(4.dp)
+ // ── Files: handling toggles ─────────────────────────────────────────
+ SettingsSection(
+ title = stringResource(R.string.settings_file_handling),
+ icon = Icons.Rounded.AutoFixHigh,
+ iconTint = Color(0xFF1976D2),
+ isLight = isLight,
+ titleColor = text,
+ contentSpacing = 2.dp,
+ modifier = reveal(4, isVisible, density)
) {
- Row(
- Modifier.padding(bottom = 8.dp),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp)
- ) {
- Icon(Icons.Rounded.AutoFixHigh, null, Modifier.size(22.dp), label)
- BasicText(stringResource(R.string.settings_file_handling), style = TextStyle(text, 17.sp, fontWeight = FontWeight.SemiBold))
- }
-
SettingsToggleRow(
icon = Icons.Rounded.AutoFixHigh,
title = stringResource(R.string.settings_auto_compress),
desc = stringResource(R.string.settings_auto_compress_desc),
checked = autoCompress,
onCheckedChange = { autoCompress = it; AppSettingsManager.setAutoCompress(context, it) },
- backdrop = backdrop,
- labelColor = label,
- subColor = sub
+ backdrop = backdrop, labelColor = label, subColor = sub
)
-
- // Separator
- Box(
- Modifier.fillMaxWidth().padding(vertical = 4.dp).height(1.dp)
- .background(if (isLight) Color.Black.copy(0.04f) else Color.White.copy(0.06f))
- )
-
+ SettingsDivider(isLight)
SettingsToggleRow(
icon = Icons.Rounded.FileCopy,
title = stringResource(R.string.settings_keep_original),
desc = stringResource(R.string.settings_keep_original_desc),
checked = keepOriginal,
onCheckedChange = { keepOriginal = it; AppSettingsManager.setKeepOriginal(context, it) },
- backdrop = backdrop,
- labelColor = label,
- subColor = sub
- )
-
- Box(
- Modifier.fillMaxWidth().padding(vertical = 4.dp).height(1.dp)
- .background(if (isLight) Color.Black.copy(0.04f) else Color.White.copy(0.06f))
+ backdrop = backdrop, labelColor = label, subColor = sub
)
-
+ SettingsDivider(isLight)
SettingsToggleRow(
icon = Icons.Rounded.Notifications,
title = stringResource(R.string.settings_notifications),
desc = stringResource(R.string.settings_notifications_desc),
checked = notifications,
onCheckedChange = { notifications = it; AppSettingsManager.setNotifications(context, it) },
- backdrop = backdrop,
- labelColor = label,
- subColor = sub
+ backdrop = backdrop, labelColor = label, subColor = sub
)
}
- // ── Default Quality ──
- Column(
- Modifier
- .fillMaxWidth()
- .graphicsLayer {
- alpha = panel4Alpha
- translationY = panel4OffsetY * density
- }
- .liquidGlassSection(isLight)
- .padding(20.dp),
- verticalArrangement = Arrangement.spacedBy(14.dp)
- ) {
- Row(
- Modifier.fillMaxWidth(),
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.SpaceBetween
- ) {
- Row(
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp)
- ) {
- Icon(Icons.Rounded.HighQuality, null, Modifier.size(22.dp), Color(0xFF1976D2))
- BasicText(stringResource(R.string.settings_compression_quality), style = TextStyle(text, 17.sp, fontWeight = FontWeight.SemiBold))
- }
+ // ── Files: compression quality ──────────────────────────────────────
+ SettingsSection(
+ title = stringResource(R.string.settings_compression_quality),
+ icon = Icons.Rounded.HighQuality,
+ iconTint = Color(0xFF1976D2),
+ isLight = isLight,
+ titleColor = text,
+ modifier = reveal(5, isVisible, density),
+ trailing = {
Box(
Modifier
.clip(RoundedCornerShape(8.dp))
@@ -545,110 +338,45 @@ fun SettingsScreen(
)
}
}
-
+ ) {
LiquidSlider(
value = { defaultQuality },
onValueChange = {
val snapped = ((it * 100f).toInt() / 100f).coerceIn(0f, 1f)
- if (snapped != defaultQuality) {
- defaultQuality = snapped
- }
+ if (snapped != defaultQuality) defaultQuality = snapped
},
valueRange = 0f..1f,
visibilityThreshold = 0.005f,
backdrop = backdrop,
modifier = Modifier.fillMaxWidth()
)
-
Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
- BasicText(stringResource(R.string.settings_smaller_size), style = TextStyle(sub.copy(0.7f), 11.sp))
+ BasicText(stringResource(R.string.settings_smaller_size), style = TextStyle(sub.copy(0.7f), 11.sp))
BasicText(stringResource(R.string.settings_higher_quality), style = TextStyle(sub.copy(0.7f), 11.sp))
}
}
- // ── Language Selection ──
+ // ── About ───────────────────────────────────────────────────────────
Column(
- Modifier
+ reveal(6, isVisible, density)
.fillMaxWidth()
- .graphicsLayer {
- alpha = panel4Alpha
- translationY = panel4OffsetY * density
- }
- .liquidGlassSection(isLight)
- .padding(20.dp),
- verticalArrangement = Arrangement.spacedBy(14.dp)
- ) {
- Row(
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp)
- ) {
- Icon(Icons.Rounded.Language, null, Modifier.size(22.dp), Color(0xFF0088FF))
- BasicText(stringResource(R.string.settings_language), style = TextStyle(text, 17.sp, fontWeight = FontWeight.SemiBold))
- }
-
- Row(
- Modifier.fillMaxWidth(),
- horizontalArrangement = Arrangement.spacedBy(10.dp)
- ) {
- val languages = listOf(
- Pair("en", stringResource(R.string.language_english)),
- Pair("pt-BR", stringResource(R.string.language_portuguese))
- )
- languages.forEach { (code, labelText) ->
- val isSelected = selectedLocale == code
- val activeColor = Color(0xFF0088FF)
- val contentColor = if (isSelected) Color.White else (if (isLight) Color(0xFF2C2C2E) else Color(0xFFE0E0E0))
- LiquidButton(
- onClick = { onLocaleChanged(code) },
- backdrop = backdrop,
- tint = if (isSelected) activeColor else Color.Transparent,
- surfaceColor = if (isSelected) activeColor.copy(0.18f) else (if (isLight) Color.White.copy(0.70f) else Color.White.copy(0.10f)),
- modifier = Modifier.weight(1f)
- ) {
- BasicText(
- labelText,
- style = TextStyle(
- contentColor,
- 13.sp,
- fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Medium
- ),
- modifier = Modifier.padding(vertical = 4.dp)
- )
- }
- }
- }
- }
-
- // ── About & Open Source ──
- Column(
- Modifier
- .fillMaxWidth()
- .graphicsLayer {
- alpha = panel5Alpha
- translationY = panel5OffsetY * density
- }
.liquidGlassSection(isLight)
.padding(24.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
Box(
- Modifier.size(56.dp).clip(CircleShape)
- .background(Color(0xFF0088FF).copy(0.12f)),
+ Modifier.size(56.dp).clip(CircleShape).background(AccentBlue.copy(0.12f)),
contentAlignment = Alignment.Center
) {
- Icon(Icons.Rounded.Info, null, Modifier.size(28.dp), Color(0xFF0088FF))
+ Icon(Icons.Rounded.Info, null, Modifier.size(28.dp), AccentBlue)
}
BasicText("ClearPDF", style = TextStyle(text, 20.sp, fontWeight = FontWeight.Bold))
BasicText(stringResource(R.string.settings_version), style = TextStyle(sub, 13.sp))
- BasicText(
- stringResource(R.string.settings_made_by),
- style = TextStyle(sub, 13.sp, textAlign = TextAlign.Center)
- )
+ BasicText(stringResource(R.string.settings_made_by), style = TextStyle(sub, 13.sp, textAlign = TextAlign.Center))
Spacer(Modifier.height(4.dp))
- // Star CTA
LiquidButton(
onClick = openRepo,
backdrop = backdrop,
@@ -663,78 +391,165 @@ fun SettingsScreen(
BasicText(stringResource(R.string.settings_star_github), style = TextStyle(Color.White, 14.sp, fontWeight = FontWeight.SemiBold))
}
}
-
BasicText(
stringResource(R.string.settings_open_source),
style = TextStyle(sub.copy(0.7f), 11.sp, textAlign = TextAlign.Center)
)
}
- // ── Licenses ──
- Column(
- Modifier
- .fillMaxWidth()
- .graphicsLayer {
- alpha = panel6Alpha
- translationY = panel6OffsetY * density
- }
- .liquidGlassSection(isLight)
- .padding(20.dp),
- verticalArrangement = Arrangement.spacedBy(12.dp)
+ // ── Licenses ────────────────────────────────────────────────────────
+ SettingsSection(
+ title = stringResource(R.string.settings_licenses),
+ icon = Icons.Rounded.Code,
+ iconTint = label,
+ isLight = isLight,
+ titleColor = text,
+ contentSpacing = 12.dp,
+ modifier = reveal(7, isVisible, density)
) {
- Row(
- verticalAlignment = Alignment.CenterVertically,
- horizontalArrangement = Arrangement.spacedBy(8.dp)
- ) {
- Icon(Icons.Rounded.Code, null, Modifier.size(22.dp), label)
- BasicText(stringResource(R.string.settings_licenses), style = TextStyle(text, 17.sp, fontWeight = FontWeight.SemiBold))
- }
-
LicenseItem(
- name = "AndroidLiquidGlass",
- author = "Kyant",
- license = "Apache License 2.0",
+ name = "AndroidLiquidGlass", author = "Kyant", license = "Apache License 2.0",
url = "https://github.com/Kyant0/AndroidLiquidGlass",
- labelColor = label,
- subColor = sub,
+ labelColor = label, subColor = sub,
onOpen = { openExternalLink(context, "https://github.com/Kyant0/AndroidLiquidGlass") }
)
-
LicenseItem(
- name = "Pdf_Tools",
- author = "Karna14314",
- license = "PDF viewer zoom/pan reference",
+ name = "Pdf_Tools", author = "Karna14314", license = "PDF viewer zoom/pan reference",
url = "https://github.com/Karna14314/Pdf_Tools",
- labelColor = label,
- subColor = sub,
+ labelColor = label, subColor = sub,
onOpen = { openExternalLink(context, "https://github.com/Karna14314/Pdf_Tools") }
)
-
- Box(
- Modifier.fillMaxWidth().height(1.dp)
- .background(if (isLight) Color.Black.copy(0.04f) else Color.White.copy(0.06f))
- )
-
+ SettingsDivider(isLight)
BasicText(
stringResource(R.string.settings_license_notice),
style = TextStyle(sub.copy(0.7f), 11.sp, lineHeight = 16.sp)
)
}
- // Dynamic bottom spacer: tab bar (64dp) + actual nav bar inset + breathing room
+ // Dynamic bottom spacer: tab bar + actual nav-bar inset + breathing room.
Spacer(Modifier.height(
WindowInsets.navigationBars.asPaddingValues().calculateBottomPadding() + 84.dp
))
}
}
+// ── Reusable primitives ─────────────────────────────────────────────────────
+
+/** Staggered fade + rise entrance, indexed so each section leads the next. */
+@Composable
+private fun reveal(index: Int, visible: Boolean, density: Float): Modifier {
+ val spec = tween<Float>(durationMillis = 560 + index * 22, delayMillis = index * 60, easing = FastOutSlowInEasing)
+ val alpha by animateFloatAsState(if (visible) 1f else 0f, spec, label = "revealA$index")
+ val dy by animateFloatAsState(if (visible) 0f else 18f + index * 4f, spec, label = "revealY$index")
+ return Modifier.graphicsLayer { this.alpha = alpha; translationY = dy * density }
+}
+
+/** A glass card with an M3 rounded-icon-tile header and an optional trailing slot. */
+@Composable
+private fun SettingsSection(
+ title: String,
+ icon: ImageVector,
+ iconTint: Color,
+ isLight: Boolean,
+ titleColor: Color,
+ modifier: Modifier = Modifier,
+ contentSpacing: Dp = 14.dp,
+ trailing: (@Composable () -> Unit)? = null,
+ content: @Composable ColumnScope.() -> Unit
+) {
+ Column(
+ modifier
+ .fillMaxWidth()
+ .liquidGlassSection(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()
+ }
+ content()
+ }
+}
+
+/** Equal-weight segmented control shared by theme / language / save-location. */
+private data class SegOption(val id: String, val label: String, val icon: ImageVector?, val activeColor: Color)
+
+@Composable
+private fun SegmentedSelector(
+ options: List<SegOption>,
+ selectedId: String,
+ isLight: Boolean,
+ backdrop: LayerBackdrop,
+ onSelect: (String) -> Unit
+) {
+ Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(10.dp)) {
+ options.forEach { option ->
+ val isSelected = selectedId == option.id
+ val contentColor = if (isSelected) Color.White else (if (isLight) Color(0xFF2C2C2E) else Color(0xFFE0E0E0))
+ LiquidButton(
+ onClick = { onSelect(option.id) },
+ backdrop = backdrop,
+ tint = if (isSelected) option.activeColor else Color.Transparent,
+ surfaceColor = if (isSelected) option.activeColor.copy(0.18f)
+ else (if (isLight) Color.White.copy(0.70f) else Color.White.copy(0.10f)),
+ modifier = Modifier.weight(1f)
+ ) {
+ Row(
+ Modifier.fillMaxWidth().padding(vertical = 4.dp),
+ verticalAlignment = Alignment.CenterVertically,
+ horizontalArrangement = Arrangement.spacedBy(5.dp, Alignment.CenterHorizontally)
+ ) {
+ if (option.icon != null) {
+ Icon(option.icon, null, Modifier.size(16.dp), contentColor)
+ }
+ BasicText(
+ option.label,
+ style = TextStyle(
+ contentColor, 13.sp,
+ fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Medium
+ ),
+ maxLines = 1,
+ overflow = TextOverflow.Ellipsis,
+ modifier = Modifier.weight(1f, fill = false)
+ )
+ }
+ }
+ }
+ }
+}
+
+@Composable
+private fun SettingsDivider(isLight: Boolean) {
+ Box(
+ Modifier.fillMaxWidth().padding(vertical = 4.dp).height(1.dp)
+ .background(if (isLight) Color.Black.copy(0.04f) else Color.White.copy(0.06f))
+ )
+}
+
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(24.dp))
+ .clip(RoundedCornerShape(SectionRadius))
.background(containerColor)
- .border(1.dp, borderColor, RoundedCornerShape(24.dp))
+ .border(1.dp, borderColor, RoundedCornerShape(SectionRadius))
}
private fun openExternalLink(context: Context, url: String) {
@@ -767,8 +582,7 @@ private fun SettingsToggleRow(
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
Box(
- Modifier.size(34.dp).clip(CircleShape)
- .background(labelColor.copy(0.08f)),
+ Modifier.size(34.dp).clip(CircleShape).background(labelColor.copy(0.08f)),
contentAlignment = Alignment.Center
) {
Icon(icon, null, Modifier.size(18.dp), labelColor)
@@ -777,11 +591,7 @@ private fun SettingsToggleRow(
BasicText(title, style = TextStyle(labelColor, 15.sp, fontWeight = FontWeight.Medium))
BasicText(desc, style = TextStyle(subColor, 12.sp))
}
- LiquidToggle(
- selected = { checked },
- onSelect = onCheckedChange,
- backdrop = backdrop
- )
+ LiquidToggle(selected = { checked }, onSelect = onCheckedChange, backdrop = backdrop)
}
}
@@ -811,6 +621,6 @@ private fun LicenseItem(
BasicText(stringResource(R.string.settings_license_author, author), style = TextStyle(subColor, 12.sp))
}
BasicText(license, style = TextStyle(subColor, 11.sp))
- BasicText(url, style = TextStyle(Color(0xFF0088FF), 11.sp))
+ BasicText(url, style = TextStyle(AccentBlue, 11.sp))
}
}
diff --git a/plan.txt b/plan.txt
index 9c649c3..15cb169 100644
--- a/plan.txt
+++ b/plan.txt
@@ -41,7 +41,24 @@ ITEM 2 — TEXT SELECTION + FIND OVERHAUL [x] DONE
- Feature-rich + quality-rich. Keep our OCR-block model; adapt Pdf_Tools ideas, don't copy code.
=====================================================================
-ITEM 3 — SETTINGS FULL REDESIGN [ ]
+ITEM 3 — SETTINGS FULL REDESIGN [x] DONE
+ → SettingsScreen.kt rewritten around 3 reusable primitives + centralized tokens:
+ - SettingsSection(title, icon, iconTint, titleColor, contentSpacing, trailing, content):
+ glass card + M3 rounded-icon TILE header (was a bare icon) + optional trailing slot
+ (used by the quality % badge). Replaces 7 hand-built headers.
+ - SegmentedSelector(options, selectedId, onSelect): one equal-weight glass segmented
+ control shared by Theme / Language / Save-location — replaces 3 copy-pasted blocks,
+ guarantees consistent overflow (maxLines=1 + ellipsis). SegOption carries optional icon.
+ - reveal(index, visible, density): one staggered fade+rise entrance modifier, replaces
+ 12 hand-written animateFloatAsState + graphicsLayer blocks AND fixes a real bug where
+ Quality + Language both reused panel4's animation. SettingsDivider extracted too.
+ - Tokens: SectionRadius/InnerRadius/SectionGap/SectionPadding/TitleSize/AccentBlue/Green.
+ - Overflow: section titles + save path now maxLines+ellipsis; dark-mode palette preserved.
+ → Preserved EVERY backing call (AppSettingsManager auto-compress/keep-original/notifications/
+ quality, SaveLocationManager + folder picker, onThemeModeChanged, onLocaleChanged, star CTA,
+ licenses). Function signature unchanged. No fake settings added (no privacy link target). BUILD OK.
+
+ITEM 3 — (original spec below) [x]
---------------------------------------------------------------------
- Rebuild hierarchy (only real settings, no fake ones):
Appearance: Theme, (Accent/Dynamic if they exist),