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 RowLine(fg) {298 Name("Breach monitoring", fg)299 Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }300 }301302 SubLabel("MASTER PASSWORD", fg)303 ChangePasswordRow(fg, vm)304305 SubLabel("DURESS PASSWORD", fg)306 val duressIsPro by vm.isPro.collectAsState()307 if (!duressIsPro) {308 RowLine(fg) {309 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {310 Name("Duress password", fg); ProBadge(fg)311 }312 ValueText("off", fg)313 }314 Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)315 } else {316 DuressSection(fg, vm)317 }318}319320@Composable321private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {322 var open by remember { mutableStateOf(false) }323 var current by remember { mutableStateOf("") }324 var next by remember { mutableStateOf("") }325 var confirm by remember { mutableStateOf("") }326 var error by remember { mutableStateOf<String?>(null) }327 var done by remember { mutableStateOf(false) }328 val scope = rememberCoroutineScope()329330 RowLine(fg) {331 Name("Master password", fg)332 SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }333 }334 AnimatedVisibility(open) {335 Column(Modifier.fillMaxWidth().padding(top = 8.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {336 PwField("current password", current, fg) { current = it }337 PwField("new password (min 12 chars)", next, fg) { next = it }338 PwField("confirm new password", confirm, fg) { confirm = it }339 error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }340 if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)341 SubtleButton("save new password", fg) {342 error = when {343 current.isBlank() -> "enter your current password"344 next.length < 12 -> "new password must be at least 12 characters"345 next != confirm -> "new passwords do not match"346 next == current -> "new password must differ from current"347 else -> null348 }349 if (error == null) scope.launch {350 if (vm.changePassword(current, next)) {351 current = ""; next = ""; confirm = ""; open = false; done = true352 } else error = "incorrect current password"353 }354 }355 }356 }357}358359@Composable360private fun PwField(placeholder: String, value: String, fg: Color, onChange: (String) -> Unit) {361 Box(362 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))363 .background(Color(0x2E000000))364 .border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))365 .padding(horizontal = 10.dp, vertical = 10.dp),366 ) {367 if (value.isEmpty()) {368 Text(placeholder, color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Mono, fontSize = 12.sp)369 }370 BasicTextField(371 value = value,372 onValueChange = onChange,373 singleLine = true,374 textStyle = TextStyle(color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp),375 cursorBrush = SolidColor(fg),376 visualTransformation = PasswordVisualTransformation(),377 modifier = Modifier.fillMaxWidth(),378 )379 }380}381382383384@Composable385private fun VaultBody(386 fg: Color,387 vm: SettingsViewModel,388 s: VaultSettings,389 entriesCount: Int,390 onNavigate: (PeachNav) -> Unit,391) {392 val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")393 val current = s.trashRetentionDays ?: 0394 val isPro by vm.isPro.collectAsState()395 val dedupCount by vm.dedupCount.collectAsState()396 val dedupRunning by vm.dedupRunning.collectAsState()397 val dedupDone by vm.dedupDone.collectAsState()398 val history by vm.vaultHistory.collectAsState()399 val restoringSnapshotId by vm.restoringSnapshotId.collectAsState()400401 SubLabel("ENTRIES", fg, top = 0.dp)402 RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }403 RowLine(fg) {404 Name("Duplicates", fg)405 val done = dedupDone406 if (done != null) {407 ValueText(if (done == 0) "already clean" else "removed $done", com.peachpasswords.ui.theme.peachColors.SyncOk)408 } else {409 val count = dedupCount410 val label = when {411 dedupRunning -> "scanning..."412 count == null -> "scan"413 count == 0 -> "none found"414 else -> "$count found"415 }416 SubtleButton(label, fg) {417 if (count == null || count == 0) vm.scanDuplicates()418 }419 }420 }421 if ((dedupCount ?: 0) > 0 && dedupDone == null) {422 Column(423 Modifier.fillMaxWidth()424 .padding(top = 2.dp, bottom = 8.dp)425 .clip(RoundedCornerShape(8.dp))426 .background(fg.copy(alpha = 0.08f))427 .border(1.dp, fg.copy(alpha = 0.18f), RoundedCornerShape(8.dp))428 .padding(10.dp),429 verticalArrangement = Arrangement.spacedBy(8.dp),430 ) {431 val count = dedupCount ?: 0432 Text(433 "$count duplicate ${if (count == 1) "entry" else "entries"} found. The newest copy of each will be kept; older duplicates will be moved to trash.",434 color = fg.copy(alpha = 0.82f),435 fontFamily = PeachType.Body,436 fontSize = 11.sp,437 lineHeight = 16.sp,438 )439 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {440 SubtleButton("cancel", fg) { vm.cancelDuplicateRemoval() }441 SubtleButton(if (dedupRunning) "removing..." else "remove duplicates", fg) { vm.removeDuplicates() }442 }443 }444 }445446 SubLabel("MAINTENANCE", fg)447 RowLine(fg) {448 Name("Trash auto-delete", fg)449 val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)450 SubtleButton(trashOptions[idx].second, fg) {451 vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)452 }453 }454 RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }455 RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }456457 SubLabel("DATA", fg)458 RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }459 RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }460 RowLine(fg) {461 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }462 SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }463 }464 RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }465466 var historyShowAll by remember { mutableStateOf(false) }467 SubLabel("VAULT HISTORY", fg)468 if (history.isEmpty()) {469 Text(470 "No snapshots yet. Peach saves automatically before every change — saves, syncs, and imports.",471 color = fg.copy(alpha = 0.68f),472 fontFamily = PeachType.Body,473 fontSize = 11.sp,474 lineHeight = 16.sp,475 modifier = Modifier.padding(bottom = 6.dp),476 )477 } else {478 Text(479 "Restoring locks your vault. Unlock with the password that encrypted that snapshot to confirm.",480 color = fg.copy(alpha = 0.68f),481 fontFamily = PeachType.Body,482 fontSize = 11.sp,483 lineHeight = 16.sp,484 modifier = Modifier.padding(bottom = 4.dp),485 )486 history.take(if (historyShowAll) history.size else 3).forEach { snap ->487 RowLine(fg) {488 Column(Modifier.weight(1f)) {489 Text(snapshotTimeLabel(snap.savedAt), color = fg, fontFamily = PeachType.Body, fontSize = 12.sp)490 Text(snapshotSubLabel(snap), color = fg.copy(alpha = 0.62f), fontFamily = PeachType.Mono, fontSize = 10.sp)491 }492 SubtleButton(if (restoringSnapshotId == snap.id) "..." else "restore", fg) {493 vm.restoreVaultSnapshot(snap.id)494 }495 }496 }497 if (history.size > 3) {498 RowLine(fg) {499 Name(if (historyShowAll) "show less" else "${history.size - 3} older", fg)500 SubtleButton(if (historyShowAll) "hide" else "show", fg) { historyShowAll = !historyShowAll }501 }502 }503 Text(504 "${history.size} of 5 snapshots",505 color = fg.copy(alpha = 0.58f),506 fontFamily = PeachType.Mono,507 fontSize = 10.sp,508 modifier = Modifier.padding(top = 2.dp, bottom = 6.dp),509 )510 }511512 var advancedOpen by remember { mutableStateOf(false) }513 SubLabel("ADVANCED", fg)514 RowLine(fg) {515 Name("Advanced", fg)516 SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }517 }518 if (advancedOpen) {519 RowLine(fg) {520 Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)521 SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }522 }523 RowLine(fg) {524 Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)525 SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }526 }527 }528}529530private fun snapshotSubLabel(snapshot: VaultSnapshot): String {531 val count = snapshot.entryCount?.let { "up to $it ${if (it == 1) "entry" else "entries"}" }532 return listOfNotNull(count, snapshotReasonLabel(snapshot.reason)).joinToString(" · ")533}534535private fun snapshotReasonLabel(reason: String): String = when (reason) {536 "local_save" -> "saved"537 "sync_received" -> "synced"538 "import" -> "imported"539 "restore" -> "restored"540 else -> reason541}542543private fun snapshotTimeLabel(savedAt: Long): String {544 val diff = System.currentTimeMillis() - savedAt545 if (diff < 60_000) return "Just now"546 if (diff < 3_600_000) return "${diff / 60_000}m ago"547 val date = Date(savedAt)548 val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())549 val thenDay = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(date)550 val time = SimpleDateFormat("h:mm a", Locale.getDefault()).format(date)551 if (today == thenDay) return "Today $time"552 val yesterday = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date(System.currentTimeMillis() - 86_400_000))553 if (yesterday == thenDay) return "Yesterday $time"554 return SimpleDateFormat("MMM d h:mm a", Locale.getDefault()).format(date)555}556557558559@Composable560private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {561 val syncVm: SyncViewModel = hiltViewModel()562 val pairedDevices by syncVm.pairedDevices.collectAsState()563564 SubLabel("PAIRING", fg, top = 0.dp)565 RowLine(fg) {566 Column(Modifier.weight(1f)) {567 Row(verticalAlignment = Alignment.CenterVertically) {568 Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg)569 }570 Text(571 "Pair nearby devices by chirp and keep encrypted vault blobs in step without a central account.",572 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,573 modifier = Modifier.padding(top = 2.dp),574 )575 }576 }577 578 579 RowLine(fg, Modifier.clickable { onNavigate(PeachNav.ChirpPair) }) {580 Name("Sync hub", fg)581 Text("›", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 15.sp)582 }583 RowLine(fg) {584 Column(Modifier.weight(1f)) {585 Text("Pair new device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)586 Text(587 "Add a phone, another browser, or your desktop sync helper.",588 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,589 modifier = Modifier.padding(top = 2.dp),590 )591 }592 SubtleButton("pair", fg) { onNavigate(PeachNav.ChirpPair) }593 }594595 SubLabel("PAIRED DEVICES", fg)596 if (pairedDevices.isEmpty()) {597 Text(598 "No paired devices yet.",599 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 12.sp,600 modifier = Modifier.padding(top = 2.dp),601 )602 } else {603 pairedDevices.forEach { d ->604 RowLine(fg) {605 Name(d.deviceName ?: d.deviceId, fg)606 ValueText(if (d.lastSyncedAt != null) "synced" else "never", fg)607 }608 }609 RowLine(fg) { Name("Sync", fg); SubtleButton("sync now", fg) { syncVm.syncNow() } }610 }611612 Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg)613}614615616617@Composable618private fun ShortcutsBody(fg: Color) {619 val bindings = listOf(620 "Copy password" to "⌘C", "Copy username" to "⌘⇧C", "Open entry" to "↵",621 "Edit entry" to "E", "New entry" to "⌘N", "Search" to "/",622 )623 SubLabel("KEYBINDINGS", fg, top = 0.dp)624 Hint("Shortcuts apply when a hardware keyboard is attached. Defaults shown below.", fg)625 Spacer(Modifier.height(8.dp))626 bindings.forEach { (label, key) ->627 RowLine(fg) {628 Name(label, fg)629 Box(630 Modifier.clip(RoundedCornerShape(4.dp)).background(fg.copy(alpha = 0.06f))631 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(4.dp))632 .padding(horizontal = 7.dp, vertical = 2.dp),633 ) { Text(key, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) }634 }635 }636}637638639640@Composable641private fun ProBody(fg: Color, vm: SettingsViewModel) {642 val ctx = LocalContext.current643 val isPro by vm.isPro.collectAsState()644 if (isPro) {645 ProActiveBody(fg, vm)646 return647 }648 val features = listOf(649 "Peach Sync" to "Encrypted · peer-to-peer",650 "Peach Codex" to "Restore from paper",651 "Passkeys" to "Zero-knowledge WebAuthn",652 "Advanced Vault Health" to "Reuse · age · exposure",653 "Canary entries" to "Detects vault compromise",654 "Duress vault" to "Decoy under coercion",655 )656 Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)657 Text(658 "Everything, everywhere.",659 modifier = Modifier.padding(top = 8.dp),660 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,661 )662 Text(663 "One key unlocks every Pro feature — for the lifetime of the app.",664 modifier = Modifier.padding(top = 6.dp),665 color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,666 )667 Spacer(Modifier.height(12.dp))668 features.forEachIndexed { i, (name, desc) ->669 RowLine(fg) {670 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {671 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))672 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)673 }674 Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)675 }676 }677 Spacer(Modifier.height(14.dp))678 Text(679 "$39",680 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,681 )682 Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)683 Spacer(Modifier.height(10.dp))684 Box(685 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))686 .background(fg.copy(alpha = 0.16f))687 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))688 .clickable {689 runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }690 }691 .padding(vertical = 12.dp),692 contentAlignment = Alignment.Center,693 ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }694695 Spacer(Modifier.height(16.dp))696 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)697 var key by remember { mutableStateOf("") }698 val activating by vm.activating.collectAsState()699 val activationError by vm.activationError.collectAsState()700 Box(701 Modifier.fillMaxWidth().padding(top = 6.dp)702 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))703 .padding(horizontal = 12.dp, vertical = 10.dp),704 ) {705 BasicTextField(706 value = key,707 onValueChange = { key = it.uppercase(); vm.clearActivationError() },708 singleLine = true,709 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),710 cursorBrush = SolidColor(fg),711 modifier = Modifier.fillMaxWidth(),712 decorationBox = { inner ->713 if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)714 inner()715 },716 )717 }718 if (activationError != null) {719 Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))720 }721 Spacer(Modifier.height(8.dp))722 Box(723 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))724 .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))725 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))726 .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }727 .padding(vertical = 12.dp),728 contentAlignment = Alignment.Center,729 ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }730}731732@Composable733private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {734 val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")735 Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {736 com.peachpasswords.ui.components.PeachMark(size = 60.dp)737 }738 Text(739 "Peach Pro",740 modifier = Modifier.fillMaxWidth(),741 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,742 textAlign = androidx.compose.ui.text.style.TextAlign.Center,743 )744 Text(745 "active · yours forever",746 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),747 color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,748 textAlign = androidx.compose.ui.text.style.TextAlign.Center,749 )750 Spacer(Modifier.height(12.dp))751 features.forEachIndexed { i, name ->752 RowLine(fg) {753 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {754 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))755 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)756 }757 Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)758 }759 }760 Spacer(Modifier.height(12.dp))761 Box(762 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))763 .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))764 .clickable { vm.deactivate() }765 .padding(vertical = 12.dp),766 contentAlignment = Alignment.Center,767 ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }768}769770771772@OptIn(ExperimentalLayoutApi::class)773@Composable774private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {775 val categories = listOf("Bug report", "Feature request", "Question", "Other")776 var category by remember { mutableStateOf(categories[0]) }777 var message by remember { mutableStateOf("") }778 val state by vm.feedbackState.collectAsState()779780 781 DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }782783 if (state is FeedbackState.Sent) {784 Box(785 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))786 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),787 ) {788 Column {789 Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)790 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))791 }792 }793 return794 }795796 val sending = state is FeedbackState.Sending797798 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)799 SubLabel("TYPE", fg)800 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {801 categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }802 }803 SubLabel("MESSAGE", fg)804 Box(805 Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))806 .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))807 .padding(10.dp),808 ) {809 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)810 BasicTextField(811 value = message, onValueChange = { message = it },812 enabled = !sending,813 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),814 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),815 )816 }817 Spacer(Modifier.height(8.dp))818819 Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {820 val canSend = !sending && message.isNotBlank()821 Box(822 Modifier.clip(RoundedCornerShape(8.dp))823 .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))824 .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))825 .clickable(enabled = canSend) { vm.sendFeedback(category, message) }826 .padding(horizontal = 12.dp, vertical = 6.dp),827 ) {828 Text(829 if (state is FeedbackState.Error) "Retry" else "Send",830 color = fg.copy(alpha = if (canSend) 1f else 0.4f),831 fontFamily = PeachType.Mono, fontSize = 11.sp,832 )833 }834 if (sending) {835 CircularProgressIndicator(836 color = LocalPeachAccent.current,837 strokeWidth = 2.dp,838 modifier = Modifier.size(16.dp),839 )840 }841 }842843 (state as? FeedbackState.Error)?.let { err ->844 Text(845 err.message,846 modifier = Modifier.padding(top = 8.dp),847 color = peachColors.Breach,848 fontFamily = PeachType.Mono,849 fontSize = 11.sp,850 lineHeight = 15.sp,851 )852 }853854 Hint("Sent anonymously · no account required", fg)855}856857858859@Composable860internal fun DuressSection(fg: Color, vm: SettingsViewModel) {861 val configured by vm.duressConfigured.collectAsState()862 if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)863}864865@Composable866private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {867 Text(868 "Duress password is active",869 color = peachColors.HealthOk,870 fontFamily = PeachType.Mono,871 fontSize = 11.sp,872 modifier = Modifier.padding(top = 6.dp),873 )874 Spacer(Modifier.height(8.dp))875 DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }876 Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)877}878879@Composable880private fun DuressForm(fg: Color, vm: SettingsViewModel) {881 var enabled by remember { mutableStateOf(false) }882 var password by remember { mutableStateOf("") }883 var confirm by remember { mutableStateOf("") }884 var action by remember { mutableStateOf(DuressAction.DECOY) }885 var error by remember { mutableStateOf<String?>(null) }886 val scope = rememberCoroutineScope()887888 RowLine(fg) {889 Name("Duress password", fg)890 Toggle(enabled, fg) { on ->891 enabled = on892 if (!on) { password = ""; confirm = ""; error = null }893 }894 }895 Text(896 "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",897 color = fg.copy(alpha = 0.7f),898 fontFamily = PeachType.Mono,899 fontSize = 10.sp,900 modifier = Modifier.padding(top = 6.dp),901 )902903 AnimatedVisibility(enabled) {904 Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {905 PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }906 PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }907908 Text(909 "When your duress password is entered at the lock screen, Peach will:",910 color = fg.copy(alpha = 0.7f),911 fontFamily = PeachType.Mono,912 fontSize = 10.sp,913 modifier = Modifier.padding(top = 4.dp),914 )915916 DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }917 DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }918919 error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }920921 val canSave = password.isNotBlank() && confirm.isNotBlank()922 DuressSaveButton("Save duress password", fg, canSave) {923 error = when {924 password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"925 password != confirm -> "Passwords do not match"926 else -> null927 }928 if (error == null) scope.launch {929 if (vm.saveDuress(password, action)) {930 password = ""; confirm = ""; enabled = false931 } else {932 error = "Couldn't save — the duress passphrase must differ from your real password"933 }934 }935 }936 }937 }938}939940@Composable941private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {942 val accent = LocalPeachAccent.current943 Row(944 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),945 verticalAlignment = Alignment.CenterVertically,946 horizontalArrangement = Arrangement.spacedBy(10.dp),947 ) {948 Box(949 Modifier.size(16.dp).clip(CircleShape)950 .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),951 contentAlignment = Alignment.Center,952 ) {953 if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))954 }955 Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)956 }957}958959@Composable960private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {961 val accent = LocalPeachAccent.current962 val tint = if (enabled) accent else fg.copy(alpha = 0.3f)963 Box(964 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))965 .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))966 .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))967 .let { if (enabled) it.clickable(onClick = onClick) else it }968 .padding(vertical = 11.dp),969 contentAlignment = Alignment.Center,970 ) {971 Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)972 }973}974975@Composable976private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {977 Box(978 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))979 .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))980 .clickable(onClick = onClick)981 .padding(vertical = 11.dp),982 contentAlignment = Alignment.Center,983 ) {984 Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)985 }986}