1package com.peachpasswords.ui.settings23import android.content.Intent4import android.net.Uri5import androidx.compose.animation.AnimatedVisibility6import androidx.compose.animation.core.animateDpAsState7import androidx.compose.foundation.background8import androidx.compose.foundation.border9import androidx.compose.foundation.clickable10import androidx.compose.foundation.layout.Arrangement11import androidx.compose.foundation.layout.Box12import androidx.compose.foundation.layout.Column13import androidx.compose.foundation.layout.FlowRow14import androidx.compose.foundation.layout.ExperimentalLayoutApi15import androidx.compose.foundation.layout.Row16import androidx.compose.foundation.layout.RowScope17import androidx.compose.foundation.layout.Spacer18import androidx.compose.foundation.layout.fillMaxWidth19import androidx.compose.foundation.layout.height20import androidx.compose.foundation.layout.padding21import androidx.compose.foundation.layout.size22import androidx.compose.foundation.layout.width23import androidx.compose.foundation.shape.CircleShape24import androidx.compose.foundation.shape.RoundedCornerShape25import androidx.compose.foundation.text.BasicTextField26import androidx.compose.runtime.Composable27import androidx.compose.material3.CircularProgressIndicator28import androidx.compose.runtime.DisposableEffect29import androidx.compose.runtime.collectAsState30import androidx.compose.runtime.getValue31import com.peachpasswords.feedback.FeedbackState32import com.peachpasswords.ui.theme.LocalPeachAccent33import com.peachpasswords.vault.DuressAction34import com.peachpasswords.ui.theme.peachColors35import androidx.compose.runtime.mutableStateOf36import androidx.compose.runtime.remember37import androidx.compose.runtime.rememberCoroutineScope38import androidx.compose.runtime.setValue39import androidx.compose.ui.Alignment40import androidx.compose.ui.Modifier41import androidx.compose.ui.draw.clip42import androidx.compose.ui.graphics.Color43import androidx.compose.ui.graphics.SolidColor44import androidx.compose.ui.platform.LocalContext45import androidx.compose.ui.text.TextStyle46import androidx.compose.ui.text.font.FontStyle47import androidx.compose.ui.text.input.PasswordVisualTransformation48import androidx.compose.ui.unit.Dp49import androidx.compose.ui.unit.dp50import androidx.compose.ui.unit.em51import androidx.compose.ui.unit.sp52import androidx.compose.material3.Text53import com.peachpasswords.ui.PeachNav54import com.peachpasswords.ui.sync.SyncViewModel55import com.peachpasswords.ui.theme.ACCENT_COLORS56import com.peachpasswords.ui.theme.PeachType57import androidx.hilt.navigation.compose.hiltViewModel58import com.peachpasswords.vault.VaultSettings59import com.peachpasswords.vault.VaultSnapshot60import kotlinx.coroutines.launch61import java.text.SimpleDateFormat62import java.util.Date63import java.util.Locale6465private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz"666768697071727374@Composable75fun CardBody(76 id: CardId,77 fg: Color,78 vm: SettingsViewModel,79 settings: VaultSettings,80 entriesCount: Int,81 onNavigate: (PeachNav) -> Unit,82) {83 when (id) {84 CardId.Appearance -> AppearanceBody(fg, vm, settings)85 CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)86 CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)87 CardId.Sync -> SyncBody(fg, onNavigate)88 CardId.Shortcuts -> ShortcutsBody(fg)89 CardId.Pro -> ProBody(fg, vm)90 CardId.Feedback -> FeedbackBody(fg, vm)91 }92}93949596@Composable97private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) {98 Text(99 text,100 modifier = Modifier.padding(top = top, bottom = 4.dp),101 color = fg.copy(alpha = 0.58f),102 fontFamily = PeachType.Mono,103 fontSize = 8.sp,104 letterSpacing = 0.22.em,105 )106}107108@Composable109private fun RowLine(fg: Color, modifier: Modifier = Modifier, content: @Composable RowScope.() -> Unit) {110 Row(111 Modifier.fillMaxWidth().then(modifier).padding(vertical = 9.dp),112 verticalAlignment = Alignment.CenterVertically,113 horizontalArrangement = Arrangement.SpaceBetween,114 content = content,115 )116 Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f)))117}118119@Composable120private fun RowScope.Name(text: String, fg: Color) {121 Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f))122}123124@Composable125private fun ValueText(text: String, fg: Color) {126 Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp)127}128129@Composable130private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) {131 Box(132 Modifier.clip(RoundedCornerShape(8.dp))133 .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp))134 .background(fg.copy(alpha = 0.08f))135 .clickable(onClick = onClick)136 .padding(horizontal = 12.dp, vertical = 6.dp),137 ) {138 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)139 }140}141142@Composable143private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) {144 val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob")145 Box(146 Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp))147 .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f))148 .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp))149 .clickable { onToggle(!on) },150 ) {151 Box(152 Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp)153 .padding(start = knob - 2.dp)154 .size(14.dp).clip(CircleShape)155 .background(if (on) fg else fg.copy(alpha = 0.58f)),156 )157 }158}159160@Composable161private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) {162 Box(163 Modifier.clip(RoundedCornerShape(999.dp))164 .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp))165 .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent)166 .clickable(onClick = onClick)167 .padding(horizontal = 12.dp, vertical = 5.dp),168 ) {169 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)170 }171}172173@Composable174private fun ProBadge(fg: Color) {175 Box(176 Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp))177 .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp),178 ) {179 Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp)180 }181}182183@Composable184private fun Hint(text: String, fg: Color) {185 Text(186 text,187 modifier = Modifier.padding(top = 6.dp),188 color = fg.copy(alpha = 0.6f),189 fontFamily = PeachType.Display,190 fontStyle = FontStyle.Italic,191 fontSize = 11.5.sp,192 lineHeight = 16.sp,193 )194}195196197198@OptIn(ExperimentalLayoutApi::class)199@Composable200private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {201 SubLabel("THEME", fg, top = 0.dp)202 RowLine(fg) {203 Name("Theme", fg)204 205 206 val (label, next) = when (s.theme) {207 "light" -> "Light" to "system"208 "system" -> "System" to "dark"209 else -> "Dark" to "light"210 }211 SubtleButton(label, fg) { vm.setTheme(next) }212 }213 SubLabel("ACCENT", fg)214 FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {215 ACCENT_COLORS.forEach { (name, color) ->216 Box(217 Modifier.size(22.dp).clip(CircleShape).background(color)218 .border(219 if (s.accentColor == name) 2.dp else 1.dp,220 if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),221 CircleShape,222 )223 .clickable { vm.setAccent(name) },224 )225 }226 }227 SubLabel("TEXT SIZE", fg)228 RowLine(fg) {229 Name("Size", fg)230 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {231 Pill("Default", s.textSize == "medium", fg) { vm.setTextSize("medium") }232 Pill("Large", s.textSize == "large", fg) { vm.setTextSize("large") }233 }234 }235 SubLabel("MOTION", fg)236 RowLine(fg) {237 Name("Reduce motion", fg)238 SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }239 }240}241242243244@Composable245private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {246 val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")247 val current = s.autoLockMinutes ?: 0248249 SubLabel("LOCKING", fg, top = 0.dp)250 RowLine(fg) {251 Name("Auto-lock after", fg)252 val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)253 SubtleButton(lockOptions[idx].second, fg) {254 val next = lockOptions[(idx + 1) % lockOptions.size].first255 vm.setAutoLockMinutes(if (next == 0) 0 else next)256 }257 }258 SubLabel("BIOMETRICS", fg)259 val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity260 RowLine(fg) {261 Name("Unlock with biometrics", fg)262 Toggle(s.biometricsEnabled, fg) { on ->263 if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()264 }265 }266 val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)267 if (bioError != null) {268 Text(269 bioError,270 color = com.peachpasswords.ui.theme.peachColors.Breach,271 fontFamily = PeachType.Mono, fontSize = 10.sp,272 modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),273 )274 }275 SubLabel("PASSKEYS", fg)276 RowLine(fg) {277 Column(Modifier.weight(1f)) {278 Text("Credential provider", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)279 Text(280 "Peach can handle passkey sign-in and creation through Android Credential Manager.",281 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,282 modifier = Modifier.padding(top = 2.dp),283 )284 }285 Toggle(s.passkeyProviderEnabled, fg) { vm.setPasskeyProviderEnabled(it) }286 }287 RowLine(fg) {288 Name("Status", fg)289 ValueText(if (s.passkeyProviderEnabled) "enabled" else "off", fg)290 }291 SubLabel("RECOVERY", fg)292 RowLine(fg) {293 Name("View recovery words", fg)294 SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) }295 }296 SubLabel("BREACH PROTECTION", fg)297 val checkingBreaches by vm.checkingBreaches.collectAsState()298 val breachResult by vm.breachResult.collectAsState()299 RowLine(fg) {300 Name("Breach monitoring", fg)301 Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }302 }303 RowLine(fg) {304 Name("Check all passwords", fg)305 SubtleButton(if (checkingBreaches) "checking..." else "run", fg) { vm.checkAllBreaches() }306 }307 breachResult?.let { result ->308 RowLine(fg) {309 Name("Last check", fg)310 ValueText(result, fg)311 }312 }313314 SubLabel("MASTER PASSWORD", fg)315 ChangePasswordRow(fg, vm)316317 SubLabel("DURESS PASSWORD", fg)318 val duressIsPro by vm.isPro.collectAsState()319 if (!duressIsPro) {320 RowLine(fg) {321 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {322 Name("Duress password", fg); ProBadge(fg)323 }324 ValueText("off", fg)325 }326 Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)327 } else {328 DuressSection(fg, vm)329 }330}331332@Composable333private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {334 var open by remember { mutableStateOf(false) }335 var current by remember { mutableStateOf("") }336 var next by remember { mutableStateOf("") }337 var confirm by remember { mutableStateOf("") }338 var error by remember { mutableStateOf<String?>(null) }339 var done by remember { mutableStateOf(false) }340 val scope = rememberCoroutineScope()341342 RowLine(fg) {343 Name("Master password", fg)344 SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }345 }346 AnimatedVisibility(open) {347 Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {348 PwField("current password", current, fg) { current = it }349 PwField("new password (min 12 chars)", next, fg) { next = it }350 PwField("confirm new password", confirm, fg) { confirm = it }351 error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }352 if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)353 SubtleButton("save new password", fg) {354 error = when {355 current.isBlank() -> "enter your current password"356 next.length < 12 -> "new password must be at least 12 characters"357 next != confirm -> "new passwords do not match"358 next == current -> "new password must differ from current"359 else -> null360 }361 if (error == null) scope.launch {362 if (vm.changePassword(current, next)) {363 current = ""; next = ""; confirm = ""; open = false; done = true364 } else error = "incorrect current password"365 }366 }367 }368 }369}370371@Composable372private fun PwField(placeholder: String, value: String, fg: Color, onChange: (String) -> Unit) {373 Box(374 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))375 .background(Color(0x2E000000))376 .border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))377 .padding(horizontal = 10.dp, vertical = 10.dp),378 ) {379 if (value.isEmpty()) {380 Text(placeholder, color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Mono, fontSize = 12.sp)381 }382 BasicTextField(383 value = value,384 onValueChange = onChange,385 singleLine = true,386 textStyle = TextStyle(color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp),387 cursorBrush = SolidColor(fg),388 visualTransformation = PasswordVisualTransformation(),389 modifier = Modifier.fillMaxWidth(),390 )391 }392}393394395396@Composable397private fun VaultBody(398 fg: Color,399 vm: SettingsViewModel,400 s: VaultSettings,401 entriesCount: Int,402 onNavigate: (PeachNav) -> Unit,403) {404 val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")405 val current = s.trashRetentionDays ?: 0406 val isPro by vm.isPro.collectAsState()407 val dedupCount by vm.dedupCount.collectAsState()408 val dedupRunning by vm.dedupRunning.collectAsState()409 val dedupDone by vm.dedupDone.collectAsState()410 val history by vm.vaultHistory.collectAsState()411 val restoringSnapshotId by vm.restoringSnapshotId.collectAsState()412413 SubLabel("ENTRIES", fg, top = 0.dp)414 RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }415 RowLine(fg) {416 Name("Duplicates", fg)417 val done = dedupDone418 if (done != null) {419 ValueText(if (done == 0) "already clean" else "removed $done", com.peachpasswords.ui.theme.peachColors.SyncOk)420 } else {421 val count = dedupCount422 val label = when {423 dedupRunning -> "scanning..."424 count == null -> "scan"425 count == 0 -> "none found"426 else -> "$count found"427 }428 SubtleButton(label, fg) {429 if (count == null || count == 0) vm.scanDuplicates()430 }431 }432 }433 if ((dedupCount ?: 0) > 0 && dedupDone == null) {434 Column(435 Modifier.fillMaxWidth()436 .padding(top = 2.dp, bottom = 8.dp)437 .clip(RoundedCornerShape(8.dp))438 .background(fg.copy(alpha = 0.08f))439 .border(1.dp, fg.copy(alpha = 0.18f), RoundedCornerShape(8.dp))440 .padding(10.dp),441 verticalArrangement = Arrangement.spacedBy(8.dp),442 ) {443 val count = dedupCount ?: 0444 Text(445 "$count duplicate ${if (count == 1) "entry" else "entries"} found. The newest copy of each will be kept; older duplicates will be moved to trash.",446 color = fg.copy(alpha = 0.82f),447 fontFamily = PeachType.Body,448 fontSize = 11.sp,449 lineHeight = 16.sp,450 )451 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {452 SubtleButton("cancel", fg) { vm.cancelDuplicateRemoval() }453 SubtleButton(if (dedupRunning) "removing..." else "remove duplicates", fg) { vm.removeDuplicates() }454 }455 }456 }457458 SubLabel("MAINTENANCE", fg)459 RowLine(fg) {460 Name("Trash auto-delete", fg)461 val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)462 SubtleButton(trashOptions[idx].second, fg) {463 vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)464 }465 }466 RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }467 RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }468469 SubLabel("DATA", fg)470 RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }471 RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }472 RowLine(fg) {473 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }474 SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }475 }476 RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }477478 var historyShowAll by remember { mutableStateOf(false) }479 SubLabel("VAULT HISTORY", fg)480 if (history.isEmpty()) {481 Text(482 "No snapshots yet. Peach saves automatically before every change — saves, syncs, and imports.",483 color = fg.copy(alpha = 0.68f),484 fontFamily = PeachType.Body,485 fontSize = 11.sp,486 lineHeight = 16.sp,487 modifier = Modifier.padding(bottom = 6.dp),488 )489 } else {490 Text(491 "Restoring locks your vault. Unlock with the password that encrypted that snapshot to confirm.",492 color = fg.copy(alpha = 0.68f),493 fontFamily = PeachType.Body,494 fontSize = 11.sp,495 lineHeight = 16.sp,496 modifier = Modifier.padding(bottom = 4.dp),497 )498 history.take(if (historyShowAll) history.size else 3).forEach { snap ->499 RowLine(fg) {500 Column(Modifier.weight(1f)) {501 Text(snapshotTimeLabel(snap.savedAt), color = fg, fontFamily = PeachType.Body, fontSize = 12.sp)502 Text(snapshotSubLabel(snap), color = fg.copy(alpha = 0.62f), fontFamily = PeachType.Mono, fontSize = 10.sp)503 }504 SubtleButton(if (restoringSnapshotId == snap.id) "..." else "restore", fg) {505 vm.restoreVaultSnapshot(snap.id)506 }507 }508 }509 if (history.size > 3) {510 RowLine(fg) {511 Name(if (historyShowAll) "show less" else "${history.size - 3} older", fg)512 SubtleButton(if (historyShowAll) "hide" else "show", fg) { historyShowAll = !historyShowAll }513 }514 }515 Text(516 "${history.size} of 5 snapshots",517 color = fg.copy(alpha = 0.58f),518 fontFamily = PeachType.Mono,519 fontSize = 10.sp,520 modifier = Modifier.padding(top = 2.dp, bottom = 6.dp),521 )522 }523524 var advancedOpen by remember { mutableStateOf(false) }525 SubLabel("ADVANCED", fg)526 RowLine(fg) {527 Name("Advanced", fg)528 SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }529 }530 if (advancedOpen) {531 RowLine(fg) {532 Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)533 SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }534 }535 RowLine(fg) {536 Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)537 SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }538 }539 }540}541542private fun snapshotSubLabel(snapshot: VaultSnapshot): String {543 val count = snapshot.entryCount?.let { "up to $it ${if (it == 1) "entry" else "entries"}" }544 return listOfNotNull(count, snapshotReasonLabel(snapshot.reason)).joinToString(" · ")545}546547private fun snapshotReasonLabel(reason: String): String = when (reason) {548 "local_save" -> "saved"549 "sync_received" -> "synced"550 "import" -> "imported"551 "restore" -> "restored"552 else -> reason553}554555private fun snapshotTimeLabel(savedAt: Long): String {556 val diff = System.currentTimeMillis() - savedAt557 if (diff < 60_000) return "Just now"558 if (diff < 3_600_000) return "${diff / 60_000}m ago"559 val date = Date(savedAt)560 val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())561 val thenDay = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(date)562 val time = SimpleDateFormat("h:mm a", Locale.getDefault()).format(date)563 if (today == thenDay) return "Today $time"564 val yesterday = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date(System.currentTimeMillis() - 86_400_000))565 if (yesterday == thenDay) return "Yesterday $time"566 return SimpleDateFormat("MMM d h:mm a", Locale.getDefault()).format(date)567}568569570571@Composable572private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {573 val syncVm: SyncViewModel = hiltViewModel()574 val pairedDevices by syncVm.pairedDevices.collectAsState()575576 SubLabel("PAIRING", fg, top = 0.dp)577 RowLine(fg) {578 Column(Modifier.weight(1f)) {579 Row(verticalAlignment = Alignment.CenterVertically) {580 Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg)581 }582 Text(583 "Pair nearby devices by chirp and keep encrypted vault blobs in step without a central account.",584 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,585 modifier = Modifier.padding(top = 2.dp),586 )587 }588 }589 590 591 RowLine(fg, Modifier.clickable { onNavigate(PeachNav.ChirpPair) }) {592 Name("Sync hub", fg)593 Text("›", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 15.sp)594 }595 RowLine(fg) {596 Column(Modifier.weight(1f)) {597 Text("Pair new device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)598 Text(599 "Add a phone, another browser, or your desktop sync helper.",600 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,601 modifier = Modifier.padding(top = 2.dp),602 )603 }604 SubtleButton("pair", fg) { onNavigate(PeachNav.ChirpPair) }605 }606607 SubLabel("PAIRED DEVICES", fg)608 if (pairedDevices.isEmpty()) {609 Text(610 "No paired devices yet.",611 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp,612 modifier = Modifier.padding(top = 2.dp),613 )614 } else {615 pairedDevices.forEach { d ->616 RowLine(fg) {617 Name(d.deviceName ?: d.deviceId, fg)618 ValueText(if (d.lastSyncedAt != null) "synced" else "never", fg)619 }620 }621 RowLine(fg) { Name("Sync", fg); SubtleButton("sync now", fg) { syncVm.syncNow() } }622 }623624 Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg)625}626627628629@Composable630private fun ShortcutsBody(fg: Color) {631 val bindings = listOf(632 "Copy password" to "⌘C", "Copy username" to "⌘⇧C", "Open entry" to "↵",633 "Edit entry" to "E", "New entry" to "⌘N", "Search" to "/",634 )635 SubLabel("KEYBINDINGS", fg, top = 0.dp)636 Hint("Shortcuts apply when a hardware keyboard is attached. Defaults shown below.", fg)637 Spacer(Modifier.height(8.dp))638 bindings.forEach { (label, key) ->639 RowLine(fg) {640 Name(label, fg)641 Box(642 Modifier.clip(RoundedCornerShape(4.dp)).background(fg.copy(alpha = 0.06f))643 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(4.dp))644 .padding(horizontal = 7.dp, vertical = 2.dp),645 ) { Text(key, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) }646 }647 }648}649650651652@Composable653private fun ProBody(fg: Color, vm: SettingsViewModel) {654 val ctx = LocalContext.current655 val isPro by vm.isPro.collectAsState()656 if (isPro) {657 ProActiveBody(fg, vm)658 return659 }660 val features = listOf(661 "Peach Sync" to "Encrypted · peer-to-peer",662 "Peach Codex" to "Restore from paper",663 "Passkeys" to "Zero-knowledge WebAuthn",664 "Advanced Vault Health" to "Reuse · age · exposure",665 "Canary entries" to "Detects vault compromise",666 "Duress vault" to "Decoy under coercion",667 )668 Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)669 Text(670 "Everything, everywhere.",671 modifier = Modifier.padding(top = 8.dp),672 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,673 )674 Text(675 "One key unlocks every Pro feature — for the lifetime of the app.",676 modifier = Modifier.padding(top = 6.dp),677 color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,678 )679 Spacer(Modifier.height(12.dp))680 features.forEachIndexed { i, (name, desc) ->681 RowLine(fg) {682 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {683 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))684 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)685 }686 Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)687 }688 }689 Spacer(Modifier.height(14.dp))690 Text(691 "$39",692 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,693 )694 Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)695 Spacer(Modifier.height(10.dp))696 Box(697 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))698 .background(fg.copy(alpha = 0.16f))699 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))700 .clickable {701 runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }702 }703 .padding(vertical = 12.dp),704 contentAlignment = Alignment.Center,705 ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }706707 Spacer(Modifier.height(16.dp))708 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)709 var key by remember { mutableStateOf("") }710 val activating by vm.activating.collectAsState()711 val activationError by vm.activationError.collectAsState()712 Box(713 Modifier.fillMaxWidth().padding(top = 6.dp)714 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))715 .padding(horizontal = 12.dp, vertical = 10.dp),716 ) {717 BasicTextField(718 value = key,719 onValueChange = { key = it.uppercase(); vm.clearActivationError() },720 singleLine = true,721 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),722 cursorBrush = SolidColor(fg),723 modifier = Modifier.fillMaxWidth(),724 decorationBox = { inner ->725 if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)726 inner()727 },728 )729 }730 if (activationError != null) {731 Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))732 }733 Spacer(Modifier.height(8.dp))734 Box(735 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))736 .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))737 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))738 .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }739 .padding(vertical = 12.dp),740 contentAlignment = Alignment.Center,741 ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }742}743744@Composable745private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {746 val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")747 Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {748 com.peachpasswords.ui.components.PeachMark(size = 60.dp)749 }750 Text(751 "Peach Pro",752 modifier = Modifier.fillMaxWidth(),753 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,754 textAlign = androidx.compose.ui.text.style.TextAlign.Center,755 )756 Text(757 "active · yours forever",758 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),759 color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,760 textAlign = androidx.compose.ui.text.style.TextAlign.Center,761 )762 Spacer(Modifier.height(12.dp))763 features.forEachIndexed { i, name ->764 RowLine(fg) {765 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {766 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))767 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)768 }769 Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)770 }771 }772 Spacer(Modifier.height(12.dp))773 Box(774 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))775 .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))776 .clickable { vm.deactivate() }777 .padding(vertical = 12.dp),778 contentAlignment = Alignment.Center,779 ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }780}781782783784@OptIn(ExperimentalLayoutApi::class)785@Composable786private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {787 val categories = listOf("Bug report", "Feature request", "Question", "Other")788 var category by remember { mutableStateOf(categories[0]) }789 var message by remember { mutableStateOf("") }790 val state by vm.feedbackState.collectAsState()791792 793 DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }794795 if (state is FeedbackState.Sent) {796 Box(797 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))798 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),799 ) {800 Column {801 Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)802 Text("Your note is in the queue. Someone will process it soon.", color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp, modifier = Modifier.padding(top = 4.dp))803 }804 }805 return806 }807808 val sending = state is FeedbackState.Sending809810 Text("Help us improve Peach. Every report goes directly to our inbox.", color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp)811 SubLabel("TYPE", fg)812 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {813 categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }814 }815 SubLabel("MESSAGE", fg)816 Box(817 Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))818 .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))819 .padding(10.dp),820 ) {821 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)822 BasicTextField(823 value = message, onValueChange = { message = it },824 enabled = !sending,825 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),826 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),827 )828 }829 Spacer(Modifier.height(8.dp))830831 Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {832 val canSend = !sending && message.isNotBlank()833 Box(834 Modifier.clip(RoundedCornerShape(8.dp))835 .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))836 .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))837 .clickable(enabled = canSend) { vm.sendFeedback(category, message) }838 .padding(horizontal = 12.dp, vertical = 6.dp),839 ) {840 Text(841 if (state is FeedbackState.Error) "Retry" else "Send",842 color = fg.copy(alpha = if (canSend) 1f else 0.4f),843 fontFamily = PeachType.Mono, fontSize = 11.sp,844 )845 }846 if (sending) {847 CircularProgressIndicator(848 color = LocalPeachAccent.current,849 strokeWidth = 2.dp,850 modifier = Modifier.size(16.dp),851 )852 }853 }854855 (state as? FeedbackState.Error)?.let { err ->856 Text(857 err.message,858 modifier = Modifier.padding(top = 8.dp),859 color = peachColors.Breach,860 fontFamily = PeachType.Mono,861 fontSize = 11.sp,862 lineHeight = 15.sp,863 )864 }865866 Hint("Sent anonymously · no account required", fg)867}868869870871@Composable872internal fun DuressSection(fg: Color, vm: SettingsViewModel) {873 val configured by vm.duressConfigured.collectAsState()874 if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)875}876877@Composable878private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {879 Text(880 "Duress password is active",881 color = peachColors.HealthOk,882 fontFamily = PeachType.Mono,883 fontSize = 11.sp,884 modifier = Modifier.padding(top = 6.dp),885 )886 Spacer(Modifier.height(8.dp))887 DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }888 Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)889}890891@Composable892private fun DuressForm(fg: Color, vm: SettingsViewModel) {893 var enabled by remember { mutableStateOf(false) }894 var password by remember { mutableStateOf("") }895 var confirm by remember { mutableStateOf("") }896 var action by remember { mutableStateOf(DuressAction.DECOY) }897 var error by remember { mutableStateOf<String?>(null) }898 val scope = rememberCoroutineScope()899900 RowLine(fg) {901 Name("Duress password", fg)902 Toggle(enabled, fg) { on ->903 enabled = on904 if (!on) { password = ""; confirm = ""; error = null }905 }906 }907 Text(908 "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",909 color = fg.copy(alpha = 0.7f),910 fontFamily = PeachType.Mono,911 fontSize = 10.sp,912 modifier = Modifier.padding(top = 6.dp),913 )914915 AnimatedVisibility(enabled) {916 Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {917 PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }918 PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }919920 Text(921 "When your duress password is entered at the lock screen, Peach will:",922 color = fg.copy(alpha = 0.7f),923 fontFamily = PeachType.Mono,924 fontSize = 10.sp,925 modifier = Modifier.padding(top = 4.dp),926 )927928 DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }929 DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }930931 error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }932933 val canSave = password.isNotBlank() && confirm.isNotBlank()934 DuressSaveButton("Save duress password", fg, canSave) {935 error = when {936 password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"937 password != confirm -> "Passwords do not match"938 else -> null939 }940 if (error == null) scope.launch {941 if (vm.saveDuress(password, action)) {942 password = ""; confirm = ""; enabled = false943 } else {944 error = "Couldn't save — the duress passphrase must differ from your real password"945 }946 }947 }948 }949 }950}951952@Composable953private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {954 val accent = LocalPeachAccent.current955 Row(956 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),957 verticalAlignment = Alignment.CenterVertically,958 horizontalArrangement = Arrangement.spacedBy(10.dp),959 ) {960 Box(961 Modifier.size(16.dp).clip(CircleShape)962 .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),963 contentAlignment = Alignment.Center,964 ) {965 if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))966 }967 Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)968 }969}970971@Composable972private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {973 val accent = LocalPeachAccent.current974 val tint = if (enabled) accent else fg.copy(alpha = 0.3f)975 Box(976 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))977 .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))978 .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))979 .let { if (enabled) it.clickable(onClick = onClick) else it }980 .padding(vertical = 11.dp),981 contentAlignment = Alignment.Center,982 ) {983 Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)984 }985}986987@Composable988private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {989 Box(990 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))991 .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))992 .clickable(onClick = onClick)993 .padding(vertical = 11.dp),994 contentAlignment = Alignment.Center,995 ) {996 Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)997 }998}