feat(phase-1/m4.4d): shared settings sections to commonMain
AppearanceSection / BackupSection / AboutSection + the building-blocks helpers (SettingsSection, SettingsToggle, SettingsRow) lifted verbatim to commonMain as internal — desktop settings (M4.5) composes exactly these. SettingsScreen keeps the Android-only Security section, the PIN/biometric screens, the timeout dialog and all SAF wiring. Design decision (as planned): full commonization of the 1026-LOC screen buys nothing — SecuritySection is BiometricPrompt + PIN state machines and the export/import pickers are SAF; sharing the sections shares the UI, each platform keeps its plumbing. Two callbacks went nullable to HIDE platform-incapable rows (dynamic color on desktop, Carnet importer) — Android passes non-null so its pixels are unchanged. Verified: ./gradlew assembleDebug :desktopApp:build SUCCESSFUL + :composeApp:compileKotlinJvm :composeApp:compileDebugKotlinAndroid + :desktopApp:run --self-test (SELFTEST id=1 -> RENDER notes=1 selected=1).
This commit is contained in:
1 parent
6b5c24e1bc
commit
018db4819c
2 files changed
+239
-195
No files matched your search
@@ -667,55 +667,6 @@ private var pendingPassphraseMode: PassphraseDialogMode = PassphraseDialogMode.E
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@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
|
* v0.3.3.0: PIN and Biometric are mutually-exclusive toggles. When
|
||||||
* the master security switch is off, both are greyed. When one is
|
* 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
|
@Composable
|
||||||
private fun TimeoutDialog(
|
private fun TimeoutDialog(
|
||||||
|
|||||||
@@ -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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user