diff --git a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt index 72bfb90..e2ec7a9 100644 --- a/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt +++ b/composeApp/src/androidMain/kotlin/org/incido/compose/ui/settings/SettingsScreen.kt @@ -667,55 +667,6 @@ private var pendingPassphraseMode: PassphraseDialogMode = PassphraseDialogMode.E // --------------------------------------------------------------------------- @OptIn(ExperimentalMaterial3Api::class) -@Composable -private fun AppearanceSection( - themeMode: ThemeMode, - dynamicColor: Boolean, - onThemeMode: (ThemeMode) -> Unit, - onDynamicColor: (Boolean) -> Unit, -) { - SettingsSection(title = "Appearance") { - Column(modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp)) { - Text("Theme", style = MaterialTheme.typography.labelLarge) - Spacer(Modifier.padding(top = 6.dp)) - SingleChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) { - ThemeMode.values().forEachIndexed { index, mode -> - SegmentedButton( - selected = themeMode == mode, - onClick = { onThemeMode(mode) }, - shape = SegmentedButtonDefaults.itemShape( - index = index, - count = ThemeMode.values().size, - ), - label = { - Text(when (mode) { - ThemeMode.SYSTEM -> "System" - ThemeMode.LIGHT -> "Light" - ThemeMode.DARK -> "Dark" - }) - }, - ) - } - } - Spacer(Modifier.padding(top = 12.dp)) - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - ) { - Column(modifier = Modifier.weight(1f)) { - Text("Dynamic color", style = MaterialTheme.typography.bodyMedium) - Text( - "Use the system Material You palette on Android 12+.", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } - Switch(checked = dynamicColor, onCheckedChange = onDynamicColor) - } - } - } -} - /** * v0.3.3.0: PIN and Biometric are mutually-exclusive toggles. When * the master security switch is off, both are greyed. When one is @@ -844,152 +795,6 @@ private fun SecuritySection( } } -@Composable -private fun BackupSection( - onExport: () -> Unit, - onImport: () -> Unit, - onImportCarnet: () -> Unit, -) { - SettingsSection(title = "Backup & Restore") { - Column( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 16.dp, vertical = 12.dp), - verticalArrangement = Arrangement.spacedBy(8.dp), - ) { - Text( - "Export your notes to a JSON file (with optional passphrase " + - "encryption) or import a backup. Imports are additive — " + - "they don't replace your existing notes.", - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - Button(onClick = onExport, modifier = Modifier.fillMaxWidth()) { - Text("Export to file…") - } - OutlinedButton(onClick = onImport, modifier = Modifier.fillMaxWidth()) { - Text("Import from file…") - } - OutlinedButton(onClick = onImportCarnet, modifier = Modifier.fillMaxWidth()) { - Text("Import 3rd Party Notes") - } - } - } -} - -@Composable -private fun AboutSection( - version: String, - onVersionClick: () -> Unit, -) { - SettingsSection(title = "About") { - Column(modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp)) { - Row( - modifier = Modifier - .fillMaxWidth() - .clickable(onClick = onVersionClick) - .padding(vertical = 6.dp), - verticalAlignment = Alignment.CenterVertically, - ) { - Column(modifier = Modifier.weight(1f)) { - Text("Incido", style = MaterialTheme.typography.titleMedium) - Text( - text = "Version $version", - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.primary, - ) - } - Text( - text = "Tap for release notes", - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.onSurfaceVariant, - ) - } - } - } -} - -// --------------------------------------------------------------------------- -// Building blocks -// --------------------------------------------------------------------------- - -@Composable -private fun SettingsSection(title: String, content: @Composable () -> Unit) { - Column { - Text( - text = title, - style = MaterialTheme.typography.labelLarge, - color = MaterialTheme.colorScheme.primary, - fontWeight = FontWeight.SemiBold, - modifier = Modifier.padding(start = 4.dp, top = 8.dp, bottom = 4.dp), - ) - Card(modifier = Modifier.fillMaxWidth()) { - content() - } - } -} - -/** v0.3.3.0: optionally renders a disabled (greyed) switch — used for - * the mutually-exclusive PIN / Biometric toggles. */ -@Composable -private fun SettingsToggle( - title: String, - subtitle: String, - checked: Boolean, - onCheckedChange: (Boolean) -> Unit, - enabled: Boolean = true, -) { - val color = if (enabled) { - MaterialTheme.colorScheme.onSurface - } else { - MaterialTheme.colorScheme.onSurfaceVariant - } - val subColor = if (enabled) { - MaterialTheme.colorScheme.onSurfaceVariant - } else { - MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f) - } - Row( - modifier = Modifier - .fillMaxWidth() - .padding(vertical = 4.dp), - verticalAlignment = Alignment.CenterVertically, - ) { - Column(modifier = Modifier.weight(1f)) { - Text(title, style = MaterialTheme.typography.bodyMedium, color = color) - Text( - subtitle, - style = MaterialTheme.typography.labelSmall, - color = subColor, - ) - } - Switch(checked = checked, onCheckedChange = onCheckedChange, enabled = enabled) - } -} - -@Composable -private fun SettingsRow( - title: String, - subtitle: String, - onClick: () -> Unit, -) { - Row( - modifier = Modifier - .fillMaxWidth() - .clickable(onClick = onClick) - .padding(vertical = 8.dp), - verticalAlignment = Alignment.CenterVertically, - ) { - Column(modifier = Modifier.weight(1f)) { - Text(title, style = MaterialTheme.typography.bodyMedium) - Text( - subtitle, - style = MaterialTheme.typography.labelSmall, - color = MaterialTheme.colorScheme.primary, - ) - } - } -} @Composable private fun TimeoutDialog( diff --git a/composeApp/src/commonMain/kotlin/org/incido/compose/ui/settings/SettingsSections.kt b/composeApp/src/commonMain/kotlin/org/incido/compose/ui/settings/SettingsSections.kt new file mode 100644 index 0000000..de2b87d --- /dev/null +++ b/composeApp/src/commonMain/kotlin/org/incido/compose/ui/settings/SettingsSections.kt @@ -0,0 +1,239 @@ +package org.incido.compose.ui.settings + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Button +import androidx.compose.material3.Card +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.OutlinedButton +import androidx.compose.material3.SegmentedButton +import androidx.compose.material3.SegmentedButtonDefaults +import androidx.compose.material3.SingleChoiceSegmentedButtonRow +import androidx.compose.material3.Switch +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import org.incido.compose.data.settings.ThemeMode + +// --------------------------------------------------------------------------- +// M4.4d — the platform-neutral settings sections, lifted verbatim from +// SettingsScreen.kt (which keeps the Android-only Security section, the +// SAF wiring, and the screen chrome). The desktop settings screen (M4.5) +// composes exactly these three. +// +// Two callbacks became nullable so a platform can HIDE a row it cannot +// serve (dynamic color is Android-12 Material You; the Carnet importer is +// Android-side) — Android passes non-null everywhere, so its rendering +// is pixel-identical to pre-M4. +// --------------------------------------------------------------------------- + +@Composable +internal fun AppearanceSection( + themeMode: ThemeMode, + dynamicColor: Boolean, + onThemeMode: (ThemeMode) -> Unit, + /** Null hides the Dynamic-color row (desktop has no Material You). */ + onDynamicColor: ((Boolean) -> Unit)?, +) { + SettingsSection(title = "Appearance") { + Column(modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp)) { + Text("Theme", style = MaterialTheme.typography.labelLarge) + Spacer(Modifier.padding(top = 6.dp)) + SingleChoiceSegmentedButtonRow(modifier = Modifier.fillMaxWidth()) { + ThemeMode.values().forEachIndexed { index, mode -> + SegmentedButton( + selected = themeMode == mode, + onClick = { onThemeMode(mode) }, + shape = SegmentedButtonDefaults.itemShape( + index = index, + count = ThemeMode.values().size, + ), + label = { + Text(when (mode) { + ThemeMode.SYSTEM -> "System" + ThemeMode.LIGHT -> "Light" + ThemeMode.DARK -> "Dark" + }) + }, + ) + } + } + if (onDynamicColor != null) { + Spacer(Modifier.padding(top = 12.dp)) + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + ) { + Column(modifier = Modifier.weight(1f)) { + Text("Dynamic color", style = MaterialTheme.typography.bodyMedium) + Text( + "Use the system Material You palette on Android 12+.", + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + Switch(checked = dynamicColor, onCheckedChange = onDynamicColor) + } + } + } + } +} + +@Composable +internal fun BackupSection( + onExport: () -> Unit, + onImport: () -> Unit, + /** Null hides the Carnet row — its importer lives in androidMain. */ + onImportCarnet: (() -> Unit)?, +) { + SettingsSection(title = "Backup & Restore") { + Column( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 16.dp, vertical = 12.dp), + verticalArrangement = Arrangement.spacedBy(8.dp), + ) { + Text( + "Export your notes to a JSON file (with optional passphrase " + + "encryption) or import a backup. Imports are additive — " + + "they don't replace your existing notes.", + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + Button(onClick = onExport, modifier = Modifier.fillMaxWidth()) { + Text("Export to file…") + } + OutlinedButton(onClick = onImport, modifier = Modifier.fillMaxWidth()) { + Text("Import from file…") + } + if (onImportCarnet != null) { + OutlinedButton(onClick = onImportCarnet, modifier = Modifier.fillMaxWidth()) { + Text("Import 3rd Party Notes") + } + } + } + } +} + +@Composable +internal fun AboutSection( + version: String, + onVersionClick: () -> Unit, +) { + SettingsSection(title = "About") { + Column(modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp)) { + Row( + modifier = Modifier + .fillMaxWidth() + .clickable(onClick = onVersionClick) + .padding(vertical = 6.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Column(modifier = Modifier.weight(1f)) { + Text("Incido", style = MaterialTheme.typography.titleMedium) + Text( + text = "Version $version", + style = MaterialTheme.typography.bodyMedium, + color = MaterialTheme.colorScheme.primary, + ) + } + Text( + text = "Tap for release notes", + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.onSurfaceVariant, + ) + } + } + } +} + +// --------------------------------------------------------------------------- +// Building blocks — M4.4d: internal so SettingsScreen (androidMain) and +// the desktop settings surface (commonMain) share one vocabulary. +// --------------------------------------------------------------------------- + +@Composable +internal fun SettingsSection(title: String, content: @Composable () -> Unit) { + Column { + Text( + text = title, + style = MaterialTheme.typography.labelLarge, + color = MaterialTheme.colorScheme.primary, + fontWeight = FontWeight.SemiBold, + modifier = Modifier.padding(start = 4.dp, top = 8.dp, bottom = 4.dp), + ) + Card(modifier = Modifier.fillMaxWidth()) { + content() + } + } +} + +/** v0.3.3.0: optionally renders a disabled (greyed) switch — used for + * the mutually-exclusive PIN / Biometric toggles. */ +@Composable +internal fun SettingsToggle( + title: String, + subtitle: String, + checked: Boolean, + onCheckedChange: (Boolean) -> Unit, + enabled: Boolean = true, +) { + val color = if (enabled) { + MaterialTheme.colorScheme.onSurface + } else { + MaterialTheme.colorScheme.onSurfaceVariant + } + val subColor = if (enabled) { + MaterialTheme.colorScheme.onSurfaceVariant + } else { + MaterialTheme.colorScheme.onSurfaceVariant.copy(alpha = 0.5f) + } + Row( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 4.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Column(modifier = Modifier.weight(1f)) { + Text(title, style = MaterialTheme.typography.bodyMedium, color = color) + Text( + subtitle, + style = MaterialTheme.typography.labelSmall, + color = subColor, + ) + } + Switch(checked = checked, onCheckedChange = onCheckedChange, enabled = enabled) + } +} + +@Composable +internal fun SettingsRow( + title: String, + subtitle: String, + onClick: () -> Unit, +) { + Row( + modifier = Modifier + .fillMaxWidth() + .clickable(onClick = onClick) + .padding(vertical = 8.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Column(modifier = Modifier.weight(1f)) { + Text(title, style = MaterialTheme.typography.bodyMedium) + Text( + subtitle, + style = MaterialTheme.typography.labelSmall, + color = MaterialTheme.colorScheme.primary, + ) + } + } +} \ No newline at end of file