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.sync.SyncStatus33import com.peachpasswords.ui.theme.LocalPeachAccent34import com.peachpasswords.vault.DuressAction35import com.peachpasswords.ui.theme.peachColors36import androidx.compose.runtime.mutableStateOf37import androidx.compose.runtime.remember38import androidx.compose.runtime.rememberCoroutineScope39import androidx.compose.runtime.setValue40import androidx.compose.ui.Alignment41import androidx.compose.ui.Modifier42import androidx.compose.ui.draw.clip43import androidx.compose.ui.graphics.Color44import androidx.compose.ui.graphics.SolidColor45import androidx.compose.ui.platform.LocalContext46import androidx.compose.ui.text.TextStyle47import androidx.compose.ui.text.font.FontStyle48import androidx.compose.ui.text.input.PasswordVisualTransformation49import androidx.compose.ui.unit.Dp50import androidx.compose.ui.unit.dp51import androidx.compose.ui.unit.em52import androidx.compose.ui.unit.sp53import androidx.compose.material3.Text54import com.peachpasswords.ui.PeachNav55import com.peachpasswords.ui.sync.SyncViewModel56import com.peachpasswords.ui.theme.ACCENT_COLORS57import com.peachpasswords.ui.theme.PeachType58import androidx.hilt.navigation.compose.hiltViewModel59import com.peachpasswords.vault.VaultSettings60import com.peachpasswords.vault.VaultSnapshot61import kotlinx.coroutines.launch62import java.text.SimpleDateFormat63import java.util.Date64import java.util.Locale6566private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz"676869707172737475@Composable76fun CardBody(77 id: CardId,78 fg: Color,79 vm: SettingsViewModel,80 settings: VaultSettings,81 entriesCount: Int,82 onNavigate: (PeachNav) -> Unit,83) {84 when (id) {85 CardId.Appearance -> AppearanceBody(fg, vm, settings)86 CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)87 CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)88 CardId.Sync -> SyncBody(fg, onNavigate)89 CardId.Shortcuts -> ShortcutsBody(fg)90 CardId.Pro -> ProBody(fg, vm)91 CardId.Feedback -> FeedbackBody(fg, vm)92 }93}94959697@Composable98private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) {99 Text(100 text,101 modifier = Modifier.padding(top = top, bottom = 4.dp),102 color = fg.copy(alpha = 0.58f),103 fontFamily = PeachType.Mono,104 fontSize = 8.sp,105 letterSpacing = 0.22.em,106 )107}108109@Composable110private fun RowLine(fg: Color, modifier: Modifier = Modifier, content: @Composable RowScope.() -> Unit) {111 Row(112 Modifier.fillMaxWidth().then(modifier).padding(vertical = 9.dp),113 verticalAlignment = Alignment.CenterVertically,114 horizontalArrangement = Arrangement.SpaceBetween,115 content = content,116 )117 Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f)))118}119120@Composable121private fun RowScope.Name(text: String, fg: Color) {122 Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f))123}124125@Composable126private fun ValueText(text: String, fg: Color) {127 Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp)128}129130@Composable131private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) {132 Box(133 Modifier.clip(RoundedCornerShape(8.dp))134 .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp))135 .background(fg.copy(alpha = 0.08f))136 .clickable(onClick = onClick)137 .padding(horizontal = 12.dp, vertical = 6.dp),138 ) {139 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)140 }141}142143@Composable144private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) {145 val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob")146 Box(147 Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp))148 .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f))149 .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp))150 .clickable { onToggle(!on) },151 ) {152 Box(153 Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp)154 .padding(start = knob - 2.dp)155 .size(14.dp).clip(CircleShape)156 .background(if (on) fg else fg.copy(alpha = 0.58f)),157 )158 }159}160161@Composable162private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) {163 Box(164 Modifier.clip(RoundedCornerShape(999.dp))165 .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp))166 .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent)167 .clickable(onClick = onClick)168 .padding(horizontal = 12.dp, vertical = 5.dp),169 ) {170 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)171 }172}173174@Composable175private fun ProBadge(fg: Color) {176 Box(177 Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp))178 .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp),179 ) {180 Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp)181 }182}183184@Composable185private fun Hint(text: String, fg: Color) {186 Text(187 text,188 modifier = Modifier.padding(top = 6.dp),189 color = fg.copy(alpha = 0.6f),190 fontFamily = PeachType.Display,191 fontStyle = FontStyle.Italic,192 fontSize = 11.5.sp,193 lineHeight = 16.sp,194 )195}196197198199@OptIn(ExperimentalLayoutApi::class)200@Composable201private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {202 SubLabel("THEME", fg, top = 0.dp)203 RowLine(fg) {204 Name("Theme", fg)205 206 207 val (label, next) = when (s.theme) {208 "light" -> "Light" to "system"209 "system" -> "System" to "dark"210 else -> "Dark" to "light"211 }212 SubtleButton(label, fg) { vm.setTheme(next) }213 }214 SubLabel("ACCENT", fg)215 FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {216 ACCENT_COLORS.forEach { (name, color) ->217 Box(218 Modifier.size(22.dp).clip(CircleShape).background(color)219 .border(220 if (s.accentColor == name) 2.dp else 1.dp,221 if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),222 CircleShape,223 )224 .clickable { vm.setAccent(name) },225 )226 }227 }228 SubLabel("TEXT SIZE", fg)229 RowLine(fg) {230 Name("Size", fg)231 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {232 Pill("Default", s.textSize == "medium", fg) { vm.setTextSize("medium") }233 Pill("Large", s.textSize == "large", fg) { vm.setTextSize("large") }234 }235 }236 SubLabel("MOTION", fg)237 RowLine(fg) {238 Name("Reduce motion", fg)239 SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }240 }241}242243244245@Composable246private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {247 val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")248 val current = s.autoLockMinutes ?: 0249250 SubLabel("LOCKING", fg, top = 0.dp)251 RowLine(fg) {252 Name("Auto-lock after", fg)253 val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)254 SubtleButton(lockOptions[idx].second, fg) {255 val next = lockOptions[(idx + 1) % lockOptions.size].first256 vm.setAutoLockMinutes(if (next == 0) 0 else next)257 }258 }259 SubLabel("BIOMETRICS", fg)260 val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity261 RowLine(fg) {262 Name("Unlock with biometrics", fg)263 Toggle(s.biometricsEnabled, fg) { on ->264 if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()265 }266 }267 val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)268 if (bioError != null) {269 Text(270 bioError,271 color = com.peachpasswords.ui.theme.peachColors.Breach,272 fontFamily = PeachType.Mono, fontSize = 10.sp,273 modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),274 )275 }276 SubLabel("PASSKEYS", fg)277 RowLine(fg) {278 Column(Modifier.weight(1f)) {279 Text("Credential provider", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)280 Text(281 "Peach can handle passkey sign-in and creation through Android Credential Manager.",282 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,283 modifier = Modifier.padding(top = 2.dp),284 )285 }286 Toggle(s.passkeyProviderEnabled, fg) { vm.setPasskeyProviderEnabled(it) }287 }288 RowLine(fg) {289 Name("Status", fg)290 ValueText(if (s.passkeyProviderEnabled) "enabled" else "off", fg)291 }292 SubLabel("RECOVERY", fg)293 RowLine(fg) {294 Name("View recovery words", fg)295 SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) }296 }297 SubLabel("BREACH PROTECTION", fg)298 val checkingBreaches by vm.checkingBreaches.collectAsState()299 val breachResult by vm.breachResult.collectAsState()300 RowLine(fg) {301 Name("Breach monitoring", fg)302 Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }303 }304 RowLine(fg) {305 Name("Check all passwords", fg)306 SubtleButton(if (checkingBreaches) "checking..." else "run", fg) { vm.checkAllBreaches() }307 }308 breachResult?.let { result ->309 RowLine(fg) {310 Name("Last check", fg)311 ValueText(result, fg)312 }313 }314315 SubLabel("MASTER PASSWORD", fg)316 ChangePasswordRow(fg, vm)317318 SubLabel("DURESS PASSWORD", fg)319 val duressIsPro by vm.isPro.collectAsState()320 if (!duressIsPro) {321 RowLine(fg) {322 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {323 Name("Duress password", fg); ProBadge(fg)324 }325 ValueText("off", fg)326 }327 Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)328 } else {329 DuressSection(fg, vm)330 }331}332333@Composable334private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {335 var open by remember { mutableStateOf(false) }336 var current by remember { mutableStateOf("") }337 var next by remember { mutableStateOf("") }338 var confirm by remember { mutableStateOf("") }339 var error by remember { mutableStateOf<String?>(null) }340 var done by remember { mutableStateOf(false) }341 val scope = rememberCoroutineScope()342343 RowLine(fg) {344 Name("Master password", fg)345 SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }346 }347 AnimatedVisibility(open) {348 Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {349 PwField("current password", current, fg) { current = it }350 PwField("new password (min 12 chars)", next, fg) { next = it }351 PwField("confirm new password", confirm, fg) { confirm = it }352 error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }353 if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)354 SubtleButton("save new password", fg) {355 error = when {356 current.isBlank() -> "enter your current password"357 next.length < 12 -> "new password must be at least 12 characters"358 next != confirm -> "new passwords do not match"359 next == current -> "new password must differ from current"360 else -> null361 }362 if (error == null) scope.launch {363 if (vm.changePassword(current, next)) {364 current = ""; next = ""; confirm = ""; open = false; done = true365 } else error = "incorrect current password"366 }367 }368 }369 }370}371372@Composable373private fun PwField(placeholder: String, value: String, fg: Color, onChange: (String) -> Unit) {374 Box(375 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))376 .background(Color(0x2E000000))377 .border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))378 .padding(horizontal = 10.dp, vertical = 10.dp),379 ) {380 if (value.isEmpty()) {381 Text(placeholder, color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Mono, fontSize = 12.sp)382 }383 BasicTextField(384 value = value,385 onValueChange = onChange,386 singleLine = true,387 textStyle = TextStyle(color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp),388 cursorBrush = SolidColor(fg),389 visualTransformation = PasswordVisualTransformation(),390 modifier = Modifier.fillMaxWidth(),391 )392 }393}394395396397@Composable398private fun VaultBody(399 fg: Color,400 vm: SettingsViewModel,401 s: VaultSettings,402 entriesCount: Int,403 onNavigate: (PeachNav) -> Unit,404) {405 val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")406 val current = s.trashRetentionDays ?: 0407 val isPro by vm.isPro.collectAsState()408 val dedupCount by vm.dedupCount.collectAsState()409 val dedupRunning by vm.dedupRunning.collectAsState()410 val dedupDone by vm.dedupDone.collectAsState()411 val history by vm.vaultHistory.collectAsState()412 val restoringSnapshotId by vm.restoringSnapshotId.collectAsState()413414 SubLabel("ENTRIES", fg, top = 0.dp)415 RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }416 RowLine(fg) {417 Name("Duplicates", fg)418 val done = dedupDone419 if (done != null) {420 ValueText(if (done == 0) "already clean" else "removed $done", com.peachpasswords.ui.theme.peachColors.SyncOk)421 } else {422 val count = dedupCount423 val label = when {424 dedupRunning -> "scanning..."425 count == null -> "scan"426 count == 0 -> "none found"427 else -> "$count found"428 }429 SubtleButton(label, fg) {430 if (count == null || count == 0) vm.scanDuplicates()431 }432 }433 }434 if ((dedupCount ?: 0) > 0 && dedupDone == null) {435 Column(436 Modifier.fillMaxWidth()437 .padding(top = 2.dp, bottom = 8.dp)438 .clip(RoundedCornerShape(8.dp))439 .background(fg.copy(alpha = 0.08f))440 .border(1.dp, fg.copy(alpha = 0.18f), RoundedCornerShape(8.dp))441 .padding(10.dp),442 verticalArrangement = Arrangement.spacedBy(8.dp),443 ) {444 val count = dedupCount ?: 0445 Text(446 "$count duplicate ${if (count == 1) "entry" else "entries"} found. The newest copy of each will be kept; older duplicates will be moved to trash.",447 color = fg.copy(alpha = 0.82f),448 fontFamily = PeachType.Body,449 fontSize = 11.sp,450 lineHeight = 16.sp,451 )452 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {453 SubtleButton("cancel", fg) { vm.cancelDuplicateRemoval() }454 SubtleButton(if (dedupRunning) "removing..." else "remove duplicates", fg) { vm.removeDuplicates() }455 }456 }457 }458459 SubLabel("MAINTENANCE", fg)460 RowLine(fg) {461 Name("Trash auto-delete", fg)462 val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)463 SubtleButton(trashOptions[idx].second, fg) {464 vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)465 }466 }467 RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }468 RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }469470 SubLabel("DATA", fg)471 RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }472 RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }473 RowLine(fg) {474 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }475 SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }476 }477 RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }478479 var historyShowAll by remember { mutableStateOf(false) }480 SubLabel("VAULT HISTORY", fg)481 if (history.isEmpty()) {482 Text(483 "No snapshots yet. Peach saves automatically before every change — saves, syncs, and imports.",484 color = fg.copy(alpha = 0.68f),485 fontFamily = PeachType.Body,486 fontSize = 11.sp,487 lineHeight = 16.sp,488 modifier = Modifier.padding(bottom = 6.dp),489 )490 } else {491 Text(492 "Restoring locks your vault. Unlock with the password that encrypted that snapshot to confirm.",493 color = fg.copy(alpha = 0.68f),494 fontFamily = PeachType.Body,495 fontSize = 11.sp,496 lineHeight = 16.sp,497 modifier = Modifier.padding(bottom = 4.dp),498 )499 history.take(if (historyShowAll) history.size else 3).forEach { snap ->500 RowLine(fg) {501 Column(Modifier.weight(1f)) {502 Text(snapshotTimeLabel(snap.savedAt), color = fg, fontFamily = PeachType.Body, fontSize = 12.sp)503 Text(snapshotSubLabel(snap), color = fg.copy(alpha = 0.62f), fontFamily = PeachType.Mono, fontSize = 10.sp)504 }505 SubtleButton(if (restoringSnapshotId == snap.id) "..." else "restore", fg) {506 vm.restoreVaultSnapshot(snap.id)507 }508 }509 }510 if (history.size > 3) {511 RowLine(fg) {512 Name(if (historyShowAll) "show less" else "${history.size - 3} older", fg)513 SubtleButton(if (historyShowAll) "hide" else "show", fg) { historyShowAll = !historyShowAll }514 }515 }516 Text(517 "${history.size} of 5 snapshots",518 color = fg.copy(alpha = 0.58f),519 fontFamily = PeachType.Mono,520 fontSize = 10.sp,521 modifier = Modifier.padding(top = 2.dp, bottom = 6.dp),522 )523 }524525 var advancedOpen by remember { mutableStateOf(false) }526 SubLabel("ADVANCED", fg)527 RowLine(fg) {528 Name("Advanced", fg)529 SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }530 }531 if (advancedOpen) {532 RowLine(fg) {533 Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)534 SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }535 }536 RowLine(fg) {537 Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)538 SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }539 }540 }541}542543private fun snapshotSubLabel(snapshot: VaultSnapshot): String {544 val count = snapshot.entryCount?.let { "up to $it ${if (it == 1) "entry" else "entries"}" }545 return listOfNotNull(count, snapshotReasonLabel(snapshot.reason)).joinToString(" · ")546}547548private fun snapshotReasonLabel(reason: String): String = when (reason) {549 "local_save" -> "saved"550 "sync_received" -> "synced"551 "import" -> "imported"552 "restore" -> "restored"553 else -> reason554}555556private fun snapshotTimeLabel(savedAt: Long): String {557 val diff = System.currentTimeMillis() - savedAt558 if (diff < 60_000) return "Just now"559 if (diff < 3_600_000) return "${diff / 60_000}m ago"560 val date = Date(savedAt)561 val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())562 val thenDay = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(date)563 val time = SimpleDateFormat("h:mm a", Locale.getDefault()).format(date)564 if (today == thenDay) return "Today $time"565 val yesterday = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date(System.currentTimeMillis() - 86_400_000))566 if (yesterday == thenDay) return "Yesterday $time"567 return SimpleDateFormat("MMM d h:mm a", Locale.getDefault()).format(date)568}569570571572@Composable573private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {574 val syncVm: SyncViewModel = hiltViewModel()575 val pairedDevices by syncVm.pairedDevices.collectAsState()576 val syncStatus by syncVm.status.collectAsState()577 val scope = rememberCoroutineScope()578 var confirmUnpair by remember { mutableStateOf<String?>(null) }579 var rotateConfirmOpen by remember { mutableStateOf(false) }580 var rotating by remember { mutableStateOf(false) }581 var rotateError by remember { mutableStateOf<String?>(null) }582583 SubLabel("PAIRING", fg, top = 0.dp)584 RowLine(fg) {585 Column(Modifier.weight(1f)) {586 Row(verticalAlignment = Alignment.CenterVertically) {587 Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg)588 }589 Text(590 "Pair nearby devices by chirp and keep encrypted vault blobs in step without a central account.",591 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,592 modifier = Modifier.padding(top = 2.dp),593 )594 }595 }596 597 598 RowLine(fg, Modifier.clickable { onNavigate(PeachNav.ChirpPair) }) {599 Name("Sync hub", fg)600 Text("›", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 15.sp)601 }602 RowLine(fg) {603 Column(Modifier.weight(1f)) {604 Text("Pair new device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)605 Text(606 "Add a phone, another browser, or your desktop sync helper.",607 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,608 modifier = Modifier.padding(top = 2.dp),609 )610 }611 SubtleButton("pair", fg) { onNavigate(PeachNav.ChirpPair) }612 }613614 SubLabel("PAIRED DEVICES", fg)615 if (pairedDevices.isEmpty()) {616 Text(617 "No paired devices yet.",618 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp,619 modifier = Modifier.padding(top = 2.dp),620 )621 } else {622 pairedDevices.forEach { d ->623 RowLine(fg) {624 Column(Modifier.weight(1f)) {625 Text(d.deviceName ?: d.deviceId, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)626 Text(627 "${deviceTypeLabel(d.deviceType)} · ${syncTimeLabel(d.lastSyncedAt)}${if (isSyncStale(d.lastSyncedAt)) " · not seen recently" else ""}",628 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,629 modifier = Modifier.padding(top = 2.dp),630 )631 }632 if (confirmUnpair == d.deviceId) {633 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {634 SubtleButton("cancel", fg) { confirmUnpair = null }635 SubtleButton("remove", peachColors.Breach) { syncVm.unpairDevice(d.deviceId); confirmUnpair = null }636 }637 } else {638 SubtleButton("remove", fg) { confirmUnpair = d.deviceId }639 }640 }641 }642 RowLine(fg) {643 ValueText(syncFlashLabel(syncStatus), fg)644 SubtleButton(if (syncStatus == SyncStatus.Syncing) "syncing..." else "sync now", fg) {645 if (syncStatus != SyncStatus.Syncing) syncVm.syncNow()646 }647 }648 }649650 SubLabel("RECOVERY", fg)651 if (rotateConfirmOpen) {652 Hint("This will disconnect all paired devices and your 12 recovery words will change. You'll be shown the new words next.", peachColors.Breach)653 rotateError?.let {654 Text(it, color = peachColors.Breach, fontFamily = PeachType.Body, fontSize = 11.sp, modifier = Modifier.padding(top = 6.dp))655 }656 Row(Modifier.padding(top = 10.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {657 SubtleButton("cancel", fg) { if (!rotating) rotateConfirmOpen = false }658 SubtleButton(if (rotating) "rotating..." else "Rotate sync identity", peachColors.Breach) {659 if (rotating) return@SubtleButton660 rotating = true661 rotateError = null662 scope.launch {663 val ok = syncVm.rotateSyncIdentity()664 rotating = false665 if (ok) {666 rotateConfirmOpen = false667 onNavigate(PeachNav.RecoverySetup)668 } else {669 rotateError = "Rotation failed. Unlock your real vault and try again."670 }671 }672 }673 }674 } else {675 RowLine(fg) {676 Column(Modifier.weight(1f)) {677 Text("Rotate sync identity", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)678 Text(679 "Use this if a paired device was lost or stolen. Re-keys the vault so the old device's key is useless.",680 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,681 modifier = Modifier.padding(top = 2.dp),682 )683 }684 SubtleButton("rotate", peachColors.Breach) { rotateError = null; rotateConfirmOpen = true }685 }686 }687688 Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg)689}690691private fun deviceTypeLabel(type: String?): String = when (type) {692 "android" -> "Android"693 "phone" -> "Phone"694 "tablet" -> "Tablet"695 "desktop" -> "Desktop"696 "browser" -> "Browser"697 else -> "Device"698}699700private fun syncTimeLabel(lastSyncedAt: Long?): String {701 if (lastSyncedAt == null) return "never synced"702 val diff = System.currentTimeMillis() - lastSyncedAt703 if (diff < 60_000) return "just now"704 if (diff < 3_600_000) return "${diff / 60_000}m ago"705 if (diff < 86_400_000) return "${diff / 3_600_000}h ago"706 return "${diff / 86_400_000}d ago"707}708709private fun isSyncStale(lastSyncedAt: Long?): Boolean =710 lastSyncedAt != null && System.currentTimeMillis() - lastSyncedAt > 7L * 24L * 60L * 60L * 1000L711712private fun syncFlashLabel(status: SyncStatus): String = when (status) {713 SyncStatus.Idle -> ""714 SyncStatus.Syncing -> "syncing..."715 SyncStatus.Offline -> "offline"716 is SyncStatus.Error -> status.message717 is SyncStatus.LastSynced -> "synced ${syncTimeLabel(status.timestamp)}"718}719720721722@Composable723private fun ShortcutsBody(fg: Color) {724 val bindings = listOf(725 "Copy password" to "⌘C", "Copy username" to "⌘⇧C", "Open entry" to "↵",726 "Edit entry" to "E", "New entry" to "⌘N", "Search" to "/",727 )728 SubLabel("KEYBINDINGS", fg, top = 0.dp)729 Hint("Shortcuts apply when a hardware keyboard is attached. Defaults shown below.", fg)730 Spacer(Modifier.height(8.dp))731 bindings.forEach { (label, key) ->732 RowLine(fg) {733 Name(label, fg)734 Box(735 Modifier.clip(RoundedCornerShape(4.dp)).background(fg.copy(alpha = 0.06f))736 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(4.dp))737 .padding(horizontal = 7.dp, vertical = 2.dp),738 ) { Text(key, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) }739 }740 }741}742743744745@Composable746private fun ProBody(fg: Color, vm: SettingsViewModel) {747 val ctx = LocalContext.current748 val isPro by vm.isPro.collectAsState()749 if (isPro) {750 ProActiveBody(fg, vm)751 return752 }753 val features = listOf(754 "Peach Sync" to "Encrypted · peer-to-peer",755 "Peach Codex" to "Restore from paper",756 "Passkeys" to "Zero-knowledge WebAuthn",757 "Advanced Vault Health" to "Reuse · age · exposure",758 "Canary entries" to "Detects vault compromise",759 "Duress vault" to "Decoy under coercion",760 )761 Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)762 Text(763 "Everything, everywhere.",764 modifier = Modifier.padding(top = 8.dp),765 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,766 )767 Text(768 "One key unlocks every Pro feature — for the lifetime of the app.",769 modifier = Modifier.padding(top = 6.dp),770 color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,771 )772 Spacer(Modifier.height(12.dp))773 features.forEachIndexed { i, (name, desc) ->774 RowLine(fg) {775 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {776 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))777 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)778 }779 Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)780 }781 }782 Spacer(Modifier.height(14.dp))783 Text(784 "$39",785 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,786 )787 Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)788 Spacer(Modifier.height(10.dp))789 Box(790 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))791 .background(fg.copy(alpha = 0.16f))792 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))793 .clickable {794 runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }795 }796 .padding(vertical = 12.dp),797 contentAlignment = Alignment.Center,798 ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }799800 Spacer(Modifier.height(16.dp))801 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)802 var key by remember { mutableStateOf("") }803 val activating by vm.activating.collectAsState()804 val activationError by vm.activationError.collectAsState()805 Box(806 Modifier.fillMaxWidth().padding(top = 6.dp)807 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))808 .padding(horizontal = 12.dp, vertical = 10.dp),809 ) {810 BasicTextField(811 value = key,812 onValueChange = { key = it.uppercase(); vm.clearActivationError() },813 singleLine = true,814 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),815 cursorBrush = SolidColor(fg),816 modifier = Modifier.fillMaxWidth(),817 decorationBox = { inner ->818 if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)819 inner()820 },821 )822 }823 if (activationError != null) {824 Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))825 }826 Spacer(Modifier.height(8.dp))827 Box(828 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))829 .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))830 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))831 .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }832 .padding(vertical = 12.dp),833 contentAlignment = Alignment.Center,834 ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }835}836837@Composable838private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {839 val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")840 Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {841 com.peachpasswords.ui.components.PeachMark(size = 60.dp)842 }843 Text(844 "Peach Pro",845 modifier = Modifier.fillMaxWidth(),846 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,847 textAlign = androidx.compose.ui.text.style.TextAlign.Center,848 )849 Text(850 "active · yours forever",851 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),852 color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,853 textAlign = androidx.compose.ui.text.style.TextAlign.Center,854 )855 Spacer(Modifier.height(12.dp))856 features.forEachIndexed { i, name ->857 RowLine(fg) {858 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {859 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))860 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)861 }862 Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)863 }864 }865 Spacer(Modifier.height(12.dp))866 Box(867 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))868 .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))869 .clickable { vm.deactivate() }870 .padding(vertical = 12.dp),871 contentAlignment = Alignment.Center,872 ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }873}874875876877@OptIn(ExperimentalLayoutApi::class)878@Composable879private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {880 val categories = listOf("Bug report", "Feature request", "Question", "Other")881 var category by remember { mutableStateOf(categories[0]) }882 var message by remember { mutableStateOf("") }883 val state by vm.feedbackState.collectAsState()884885 886 DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }887888 if (state is FeedbackState.Sent) {889 Box(890 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))891 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),892 ) {893 Column {894 Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)895 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))896 }897 }898 return899 }900901 val sending = state is FeedbackState.Sending902903 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)904 SubLabel("TYPE", fg)905 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {906 categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }907 }908 SubLabel("MESSAGE", fg)909 Box(910 Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))911 .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))912 .padding(10.dp),913 ) {914 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)915 BasicTextField(916 value = message, onValueChange = { message = it },917 enabled = !sending,918 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),919 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),920 )921 }922 Spacer(Modifier.height(8.dp))923924 Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {925 val canSend = !sending && message.isNotBlank()926 Box(927 Modifier.clip(RoundedCornerShape(8.dp))928 .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))929 .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))930 .clickable(enabled = canSend) { vm.sendFeedback(category, message) }931 .padding(horizontal = 12.dp, vertical = 6.dp),932 ) {933 Text(934 if (state is FeedbackState.Error) "Retry" else "Send",935 color = fg.copy(alpha = if (canSend) 1f else 0.4f),936 fontFamily = PeachType.Mono, fontSize = 11.sp,937 )938 }939 if (sending) {940 CircularProgressIndicator(941 color = LocalPeachAccent.current,942 strokeWidth = 2.dp,943 modifier = Modifier.size(16.dp),944 )945 }946 }947948 (state as? FeedbackState.Error)?.let { err ->949 Text(950 err.message,951 modifier = Modifier.padding(top = 8.dp),952 color = peachColors.Breach,953 fontFamily = PeachType.Mono,954 fontSize = 11.sp,955 lineHeight = 15.sp,956 )957 }958959 Hint("Sent anonymously · no account required", fg)960}961962963964@Composable965internal fun DuressSection(fg: Color, vm: SettingsViewModel) {966 val configured by vm.duressConfigured.collectAsState()967 if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)968}969970@Composable971private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {972 Text(973 "Duress password is active",974 color = peachColors.HealthOk,975 fontFamily = PeachType.Mono,976 fontSize = 11.sp,977 modifier = Modifier.padding(top = 6.dp),978 )979 Spacer(Modifier.height(8.dp))980 DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }981 Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)982}983984@Composable985private fun DuressForm(fg: Color, vm: SettingsViewModel) {986 var enabled by remember { mutableStateOf(false) }987 var password by remember { mutableStateOf("") }988 var confirm by remember { mutableStateOf("") }989 var action by remember { mutableStateOf(DuressAction.DECOY) }990 var error by remember { mutableStateOf<String?>(null) }991 val scope = rememberCoroutineScope()992993 RowLine(fg) {994 Name("Duress password", fg)995 Toggle(enabled, fg) { on ->996 enabled = on997 if (!on) { password = ""; confirm = ""; error = null }998 }999 }1000 Text(1001 "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",1002 color = fg.copy(alpha = 0.7f),1003 fontFamily = PeachType.Mono,1004 fontSize = 10.sp,1005 modifier = Modifier.padding(top = 6.dp),1006 )10071008 AnimatedVisibility(enabled) {1009 Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1010 PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }1011 PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }10121013 Text(1014 "When your duress password is entered at the lock screen, Peach will:",1015 color = fg.copy(alpha = 0.7f),1016 fontFamily = PeachType.Mono,1017 fontSize = 10.sp,1018 modifier = Modifier.padding(top = 4.dp),1019 )10201021 DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }1022 DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }10231024 error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }10251026 val canSave = password.isNotBlank() && confirm.isNotBlank()1027 DuressSaveButton("Save duress password", fg, canSave) {1028 error = when {1029 password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"1030 password != confirm -> "Passwords do not match"1031 else -> null1032 }1033 if (error == null) scope.launch {1034 if (vm.saveDuress(password, action)) {1035 password = ""; confirm = ""; enabled = false1036 } else {1037 error = "Couldn't save — the duress passphrase must differ from your real password"1038 }1039 }1040 }1041 }1042 }1043}10441045@Composable1046private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {1047 val accent = LocalPeachAccent.current1048 Row(1049 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),1050 verticalAlignment = Alignment.CenterVertically,1051 horizontalArrangement = Arrangement.spacedBy(10.dp),1052 ) {1053 Box(1054 Modifier.size(16.dp).clip(CircleShape)1055 .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),1056 contentAlignment = Alignment.Center,1057 ) {1058 if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))1059 }1060 Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)1061 }1062}10631064@Composable1065private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {1066 val accent = LocalPeachAccent.current1067 val tint = if (enabled) accent else fg.copy(alpha = 0.3f)1068 Box(1069 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1070 .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))1071 .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))1072 .let { if (enabled) it.clickable(onClick = onClick) else it }1073 .padding(vertical = 11.dp),1074 contentAlignment = Alignment.Center,1075 ) {1076 Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)1077 }1078}10791080@Composable1081private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {1082 Box(1083 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1084 .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))1085 .clickable(onClick = onClick)1086 .padding(vertical = 11.dp),1087 contentAlignment = Alignment.Center,1088 ) {1089 Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)1090 }1091}