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.heightIn21import androidx.compose.foundation.layout.padding22import androidx.compose.foundation.layout.size23import androidx.compose.foundation.layout.width24import androidx.compose.foundation.shape.CircleShape25import androidx.compose.foundation.shape.RoundedCornerShape26import androidx.compose.foundation.text.BasicTextField27import androidx.compose.runtime.Composable28import androidx.compose.material3.CircularProgressIndicator29import androidx.compose.runtime.DisposableEffect30import androidx.compose.runtime.collectAsState31import androidx.compose.runtime.getValue32import com.peachpasswords.feedback.FeedbackState33import com.peachpasswords.shared.PeachClipboard34import com.peachpasswords.sync.SyncMode35import com.peachpasswords.sync.canShowBackgroundSyncNotification36import com.peachpasswords.sync.describeSyncOutcome37import com.peachpasswords.sync.privateRelayDraftOf38import com.peachpasswords.sync.syncIndicator39import com.peachpasswords.sync.syncIndicatorLabel40import com.peachpasswords.ui.components.SyncIndicatorDot41import com.peachpasswords.ui.theme.LocalPeachAccent42import com.peachpasswords.vault.DuressAction43import com.peachpasswords.ui.theme.peachColors44import androidx.compose.runtime.mutableStateOf45import androidx.compose.runtime.remember46import androidx.compose.runtime.rememberCoroutineScope47import androidx.compose.runtime.setValue48import androidx.compose.ui.Alignment49import androidx.compose.ui.Modifier50import androidx.compose.ui.draw.clip51import androidx.compose.ui.graphics.Color52import androidx.compose.ui.graphics.SolidColor53import androidx.compose.ui.platform.LocalContext54import androidx.compose.ui.text.TextStyle55import androidx.compose.ui.text.font.FontStyle56import androidx.compose.ui.text.input.PasswordVisualTransformation57import androidx.compose.ui.unit.Dp58import androidx.compose.ui.unit.dp59import androidx.compose.ui.unit.em60import androidx.compose.ui.unit.sp61import androidx.compose.material3.Text62import com.peachpasswords.BuildConfig63import com.peachpasswords.autofill.AutofillEnablement64import com.peachpasswords.ui.PeachNav65import com.peachpasswords.ui.components.PeachEmptyOrEndState66import com.peachpasswords.ui.components.PeachField67import com.peachpasswords.ui.pairing.BackgroundSyncDialog68import com.peachpasswords.ui.sync.SyncViewModel69import com.peachpasswords.ui.theme.ACCENT_COLORS70import com.peachpasswords.ui.theme.PeachSpacing71import com.peachpasswords.ui.theme.PeachType72import com.peachpasswords.ui.updates.ChangelogPhase73import com.peachpasswords.ui.updates.UpdatePhase74import com.peachpasswords.ui.updates.UpdateViewModel75import com.peachpasswords.updates.compareVersions76import androidx.hilt.navigation.compose.hiltViewModel77import com.peachpasswords.vault.VaultSettings78import com.peachpasswords.vault.VaultSnapshot79import kotlinx.coroutines.launch80import kotlinx.coroutines.delay81import java.text.SimpleDateFormat82import java.util.Date83import java.util.Locale8485private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz"868788899091929394@Composable95fun CardBody(96 id: CardId,97 fg: Color,98 vm: SettingsViewModel,99 settings: VaultSettings,100 entriesCount: Int,101 onNavigate: (PeachNav) -> Unit,102) {103 when (id) {104 CardId.Appearance -> AppearanceBody(fg, vm, settings)105 CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)106 CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)107 CardId.Sync -> SyncBody(fg, onNavigate)108 CardId.Pro -> ProBody(fg, vm)109 CardId.Feedback -> FeedbackBody(fg, vm)110 }111}112113114115@Composable116private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) {117 Text(118 text,119 modifier = Modifier.padding(top = top, bottom = 4.dp),120 color = fg.copy(alpha = 0.58f),121 fontFamily = PeachType.Mono,122 fontSize = 8.sp,123 letterSpacing = 0.22.em,124 )125}126127128129130131132@Composable133private fun SettingsGroup(134 label: String,135 fg: Color,136 initiallyOpen: Boolean = true,137 top: Dp = 14.dp,138 content: @Composable () -> Unit,139) {140 var open by remember { mutableStateOf(initiallyOpen) }141 Row(142 Modifier.fillMaxWidth()143 .clip(RoundedCornerShape(6.dp))144 .clickable { open = !open }145 .padding(top = top, bottom = 4.dp),146 verticalAlignment = Alignment.CenterVertically,147 ) {148 Text(149 label,150 modifier = Modifier.weight(1f),151 color = fg.copy(alpha = 0.58f),152 fontFamily = PeachType.Mono,153 fontSize = 8.sp,154 letterSpacing = 0.22.em,155 )156 Text(157 if (open) "–" else "+",158 color = fg.copy(alpha = 0.58f),159 fontFamily = PeachType.Mono,160 fontSize = 10.sp,161 )162 }163 164 165 AnimatedVisibility(visible = open) {166 Column(Modifier.fillMaxWidth()) { content() }167 }168}169170@Composable171private fun RowLine(172 fg: Color,173 modifier: Modifier = Modifier,174 verticalPadding: Dp = 9.dp,175 content: @Composable RowScope.() -> Unit,176) {177 Row(178 Modifier.fillMaxWidth().then(modifier).padding(vertical = verticalPadding),179 verticalAlignment = Alignment.CenterVertically,180 horizontalArrangement = Arrangement.SpaceBetween,181 content = content,182 )183 Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f)))184}185186@Composable187private fun RowScope.Name(text: String, fg: Color) {188 Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f))189}190191@Composable192private fun ValueText(text: String, fg: Color) {193 Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp)194}195196@Composable197private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) {198 Box(199 Modifier.clip(RoundedCornerShape(8.dp))200 .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp))201 .background(fg.copy(alpha = 0.08f))202 .clickable(onClick = onClick)203 .padding(horizontal = 12.dp, vertical = 6.dp),204 ) {205 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)206 }207}208209@Composable210private fun SyncDisclosure(211 title: String,212 summary: String,213 expanded: Boolean,214 fg: Color,215 onToggle: () -> Unit,216) {217 Row(218 modifier = Modifier219 .fillMaxWidth()220 .heightIn(min = 48.dp)221 .clip(RoundedCornerShape(8.dp))222 .clickable(onClick = onToggle)223 .padding(vertical = 8.dp),224 verticalAlignment = Alignment.CenterVertically,225 ) {226 Column(Modifier.weight(1f)) {227 Text(228 title.uppercase(),229 color = fg.copy(alpha = 0.58f),230 fontFamily = PeachType.Mono,231 fontSize = 8.sp,232 letterSpacing = 0.22.em,233 )234 Text(235 summary,236 color = fg.copy(alpha = 0.7f),237 fontFamily = PeachType.Body,238 fontSize = 11.sp,239 modifier = Modifier.padding(top = 3.dp),240 )241 }242 Text(243 if (expanded) "hide" else "show",244 color = fg,245 fontFamily = PeachType.Mono,246 fontSize = 10.sp,247 )248 }249}250251@Composable252private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) {253 val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob")254 Box(255 Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp))256 .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f))257 .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp))258 .clickable { onToggle(!on) },259 ) {260 Box(261 Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp)262 .padding(start = knob - 2.dp)263 .size(14.dp).clip(CircleShape)264 .background(if (on) fg else fg.copy(alpha = 0.58f)),265 )266 }267}268269@Composable270private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) {271 Box(272 Modifier.clip(RoundedCornerShape(999.dp))273 .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp))274 .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent)275 .clickable(onClick = onClick)276 .padding(horizontal = 12.dp, vertical = 5.dp),277 ) {278 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)279 }280}281282@Composable283private fun ProBadge(fg: Color) {284 Box(285 Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp))286 .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp),287 ) {288 Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp)289 }290}291292@Composable293private fun Hint(text: String, fg: Color) {294 Text(295 text,296 modifier = Modifier.padding(top = 6.dp),297 color = fg.copy(alpha = 0.6f),298 fontFamily = PeachType.Display,299 fontStyle = FontStyle.Italic,300 fontSize = 11.5.sp,301 lineHeight = 16.sp,302 )303}304305306307@OptIn(ExperimentalLayoutApi::class)308@Composable309private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {310 SubLabel("ACCENT", fg, top = 0.dp)311 FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {312 ACCENT_COLORS.forEach { (name, color) ->313 Box(314 Modifier.size(22.dp).clip(CircleShape).background(color)315 .border(316 if (s.accentColor == name) 2.dp else 1.dp,317 if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),318 CircleShape,319 )320 .clickable { vm.setAccent(name) },321 )322 }323 }324 SubLabel("TEXT SIZE", fg)325 RowLine(fg) {326 Name("Text size", fg)327 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {328 Pill("small", s.textSize == "small", fg) { vm.setTextSize("small") }329 Pill("medium", s.textSize == "medium", fg) { vm.setTextSize("medium") }330 Pill("large", s.textSize == "large", fg) { vm.setTextSize("large") }331 }332 }333 SubLabel("ICONS", fg)334 RowLine(fg) {335 Name("Site icons", fg)336 SubtleButton(if (s.faviconsEnabled) "On" else "Off", fg) { vm.setFaviconsEnabled(!s.faviconsEnabled) }337 }338 SubLabel("MOTION", fg)339 RowLine(fg) {340 Name("Reduce motion", fg)341 SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }342 }343}344345346347@Composable348private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {349 val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")350 val current = s.autoLockMinutes ?: 0351352 SubLabel("LOCKING", fg, top = 0.dp)353 RowLine(fg) {354 Name("Allow screenshots", fg)355 Toggle(s.allowScreenshots, fg) { vm.setAllowScreenshots(it) }356 }357 RowLine(fg) {358 Name("Auto-lock after", fg)359 val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)360 SubtleButton(lockOptions[idx].second, fg) {361 val next = lockOptions[(idx + 1) % lockOptions.size].first362 vm.setAutoLockMinutes(if (next == 0) 0 else next)363 }364 }365 SubLabel("BIOMETRICS", fg)366 val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity367 RowLine(fg) {368 Name("Unlock with biometrics", fg)369 Toggle(s.biometricsEnabled, fg) { on ->370 if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()371 }372 }373 val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)374 if (bioError != null) {375 Text(376 bioError,377 color = com.peachpasswords.ui.theme.peachColors.Breach,378 fontFamily = PeachType.Mono, fontSize = 10.sp,379 modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),380 )381 }382 SubLabel("AUTOFILL", fg)383 run {384 385 386 val ctx = LocalContext.current387 val enabled = AutofillEnablement.isEnabled(ctx)388 RowLine(fg) {389 Column(Modifier.weight(1f)) {390 Text("Fill passwords in other apps", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)391 Text(392 if (enabled) {393 "Peach is your autofill service."394 } else {395 "Android decides which app fills passwords. Turn Peach on in system settings."396 },397 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,398 modifier = Modifier.padding(top = 2.dp),399 )400 }401 if (!enabled) {402 SubtleButton("enable", fg) {403 404 405 406 runCatching { ctx.startActivity(AutofillEnablement.requestIntent(ctx)) }407 .onFailure { runCatching { ctx.startActivity(AutofillEnablement.fallbackIntent()) } }408 }409 } else {410 ValueText("on", fg)411 }412 }413 }414415 RowLine(fg) {416 Column(Modifier.weight(1f)) {417 Text("Hide autofill previews", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)418 Text(419 "Keyboard chips and suggestion rows show only Peach until tapped — no entry names or usernames over your shoulder.",420 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,421 modifier = Modifier.padding(top = 2.dp),422 )423 }424 Toggle(s.hideAutofillPreviews, fg) { vm.setHideAutofillPreviews(it) }425 }426427 SubLabel("PASSKEYS", fg)428 RowLine(fg) {429 Column(Modifier.weight(1f)) {430 Text("Credential provider", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)431 Text(432 "Peach can handle passkey sign-in and creation through Android Credential Manager.",433 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,434 modifier = Modifier.padding(top = 2.dp),435 )436 }437 Toggle(s.passkeyProviderEnabled, fg) { vm.setPasskeyProviderEnabled(it) }438 }439 RowLine(fg) {440 Name("Status", fg)441 ValueText(if (s.passkeyProviderEnabled) "enabled" else "off", fg)442 }443 SubLabel("RECOVERY", fg)444 RowLine(fg) {445 Column(Modifier.weight(1f)) {446 Text("View recovery words", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)447 Text(448 "Keep the paper copy current before rotating sync identity or replacing devices.",449 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,450 modifier = Modifier.padding(top = 2.dp),451 )452 }453 SubtleButton("view", fg) {454 if (bioActivity != null) {455 com.peachpasswords.ui.lock.Biometrics.authenticate(456 activity = bioActivity,457 title = "View recovery words",458 subtitle = "Confirm your identity to view your recovery words",459 onSuccess = { onNavigate(PeachNav.RecoveryView) },460 )461 } else onNavigate(PeachNav.RecoveryView)462 }463 }464 SubLabel("BREACH PROTECTION", fg)465 val checkingBreaches by vm.checkingBreaches.collectAsState()466 val breachResult by vm.breachResult.collectAsState()467 RowLine(fg) {468 Name("Breach monitoring", fg)469 Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }470 }471 RowLine(fg) {472 Name("Check all passwords", fg)473 SubtleButton(if (checkingBreaches) "checking..." else "run", fg) { vm.checkAllBreaches() }474 }475 breachResult?.let { result ->476 RowLine(fg) {477 Name("Last check", fg)478 ValueText(result, fg)479 }480 }481482 SubLabel("MASTER PASSWORD", fg)483 ChangePasswordRow(fg, vm)484485 SubLabel("DURESS PASSWORD", fg)486 val duressIsPro by vm.isPro.collectAsState()487 if (!duressIsPro) {488 RowLine(fg) {489 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {490 Name("Duress password", fg); ProBadge(fg)491 }492 ValueText("off", fg)493 }494 Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)495 } else {496 DuressSection(fg, vm)497 }498}499500@Composable501private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {502 var open by remember { mutableStateOf(false) }503 var current by remember { mutableStateOf("") }504 var next by remember { mutableStateOf("") }505 var confirm by remember { mutableStateOf("") }506 var error by remember { mutableStateOf<String?>(null) }507 var done by remember { mutableStateOf(false) }508 val scope = rememberCoroutineScope()509510 RowLine(fg) {511 Name("Master password", fg)512 SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }513 }514 AnimatedVisibility(open) {515 Column(Modifier.fillMaxWidth().padding(top = PeachSpacing.sm), verticalArrangement = Arrangement.spacedBy(PeachSpacing.sm)) {516 PwField("current password", current, fg) { current = it }517 PwField("new password (min 12 chars)", next, fg) { next = it }518 PwField("confirm new password", confirm, fg) { confirm = it }519 error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }520 if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)521 SubtleButton("save new password", fg) {522 error = when {523 current.isBlank() -> "enter your current password"524 next.length < 12 -> "new password must be at least 12 characters"525 next != confirm -> "new passwords do not match"526 next == current -> "new password must differ from current"527 else -> null528 }529 if (error == null) scope.launch {530 if (vm.changePassword(current, next)) {531 current = ""; next = ""; confirm = ""; open = false; done = true532 } else error = "incorrect current password"533 }534 }535 }536 }537}538539@Composable540private fun PwField(placeholder: String, value: String, @Suppress("UNUSED_PARAMETER") fg: Color, onChange: (String) -> Unit) {541 PeachField(542 label = placeholder,543 value = value,544 onValueChange = onChange,545 keyboardType = androidx.compose.ui.text.input.KeyboardType.Password,546 visualTransformation = PasswordVisualTransformation(),547 )548}549550551552@Composable553private fun UpdatesRows(fg: Color, onNavigate: (PeachNav) -> Unit) {554 val vm: UpdateViewModel = hiltViewModel()555 val available by vm.available.collectAsState()556 val state by vm.state.collectAsState()557 val changelog by vm.changelog.collectAsState()558 var changelogOpen by remember { mutableStateOf(false) }559560 RowLine(fg) {561 Name("Version", fg)562 ValueText(BuildConfig.VERSION_NAME, fg)563 }564 RowLine(fg) {565 Column(Modifier.weight(1f)) {566 Text("Updates", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)567 Text(568 when {569 available != null -> "v${available?.version} is available"570 state.phase == UpdatePhase.Checking -> "Checking…"571 state.phase == UpdatePhase.UpToDate -> "You're on the latest version"572 state.phase == UpdatePhase.Failed -> "Couldn't reach the update server"573 else -> "Peach checks once a day and tells you when there's a new version."574 },575 color = fg.copy(alpha = 0.7f),576 fontFamily = PeachType.Body,577 fontSize = 11.sp,578 lineHeight = 16.sp,579 modifier = Modifier.padding(top = 2.dp),580 )581 }582 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {583 SubtleButton("changelog", fg) {584 changelogOpen = !changelogOpen585 if (changelogOpen) vm.loadChangelog()586 }587 if (available != null) {588 SubtleButton("tap to install", fg) { onNavigate(PeachNav.Update) }589 } else {590 SubtleButton(if (state.phase == UpdatePhase.Checking) "checking" else "check for updates", fg) {591 vm.check()592 }593 }594 }595 }596 if (changelogOpen) {597 when (changelog.phase) {598 ChangelogPhase.Idle -> {}599 ChangelogPhase.Loading -> Text(600 "Loading changelog…",601 color = fg.copy(alpha = 0.68f),602 fontFamily = PeachType.Body,603 fontSize = 11.sp,604 modifier = Modifier.padding(vertical = 8.dp),605 )606 ChangelogPhase.Failed -> RowLine(fg) {607 Name("Couldn't reach the update server", fg)608 SubtleButton("retry", fg) { vm.loadChangelog() }609 }610 ChangelogPhase.Loaded -> Column(Modifier.fillMaxWidth()) {611 changelog.entries.forEachIndexed { index, entry ->612 Column(Modifier.fillMaxWidth().padding(vertical = 8.dp)) {613 Row(verticalAlignment = Alignment.CenterVertically) {614 Text("v${entry.version}", color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)615 if (compareVersions(entry.version, vm.currentVersion) == 0) {616 Text(" current", color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 9.sp)617 }618 }619 Text(620 entry.notes ?: "No notes for this release.",621 color = fg.copy(alpha = 0.72f),622 fontFamily = PeachType.Body,623 fontSize = 11.sp,624 lineHeight = 16.sp,625 modifier = Modifier.padding(top = 3.dp),626 )627 }628 if (index < changelog.entries.lastIndex) {629 Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.08f)))630 }631 }632 }633 }634 }635}636637@Composable638private fun VaultBody(639 fg: Color,640 vm: SettingsViewModel,641 s: VaultSettings,642 entriesCount: Int,643 onNavigate: (PeachNav) -> Unit,644) {645 val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")646 val current = s.trashRetentionDays ?: 0647 val isPro by vm.isPro.collectAsState()648 val dedupCount by vm.dedupCount.collectAsState()649 val dedupRunning by vm.dedupRunning.collectAsState()650 val dedupDone by vm.dedupDone.collectAsState()651 val history by vm.vaultHistory.collectAsState()652 val restoringSnapshotId by vm.restoringSnapshotId.collectAsState()653654 SettingsGroup("ENTRIES", fg, top = 0.dp) {655 RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }656 RowLine(fg) {657 Name("Duplicates", fg)658 val done = dedupDone659 if (done != null) {660 ValueText(if (done == 0) "already clean" else "removed $done", com.peachpasswords.ui.theme.peachColors.SyncOk)661 } else {662 val count = dedupCount663 val label = when {664 dedupRunning -> "scanning..."665 count == null -> "scan"666 count == 0 -> "none found"667 else -> "$count found"668 }669 SubtleButton(label, fg) {670 if (count == null || count == 0) vm.scanDuplicates()671 }672 }673 }674 if ((dedupCount ?: 0) > 0 && dedupDone == null) {675 Column(676 Modifier.fillMaxWidth()677 .padding(top = 2.dp, bottom = 8.dp)678 .clip(RoundedCornerShape(8.dp))679 .background(fg.copy(alpha = 0.08f))680 .border(1.dp, fg.copy(alpha = 0.18f), RoundedCornerShape(8.dp))681 .padding(10.dp),682 verticalArrangement = Arrangement.spacedBy(8.dp),683 ) {684 val count = dedupCount ?: 0685 Text(686 "$count duplicate ${if (count == 1) "entry" else "entries"} found. The newest copy of each will be kept; older duplicates will be moved to trash.",687 color = fg.copy(alpha = 0.82f),688 fontFamily = PeachType.Body,689 fontSize = 11.sp,690 lineHeight = 16.sp,691 )692 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {693 SubtleButton("cancel", fg) { vm.cancelDuplicateRemoval() }694 SubtleButton(if (dedupRunning) "removing..." else "remove duplicates", fg) { vm.removeDuplicates() }695 }696 }697 }698 }699700 SettingsGroup("MAINTENANCE", fg) {701 RowLine(fg) {702 Name("Trash auto-delete", fg)703 val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)704 SubtleButton(trashOptions[idx].second, fg) {705 vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)706 }707 }708 RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }709 RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }710 }711712 SettingsGroup("DATA", fg) {713 RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }714 RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }715 RowLine(fg) {716 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }717 SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }718 }719 RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }720 }721722 SettingsGroup("UPDATES", fg) {723 UpdatesRows(fg, onNavigate)724 }725726 SettingsGroup("VAULT HISTORY", fg, initiallyOpen = false) {727 var historyShowAll by remember { mutableStateOf(false) }728 if (history.isEmpty()) {729 Text(730 "No snapshots yet. Peach saves automatically before every change — saves, syncs, and imports.",731 color = fg.copy(alpha = 0.68f),732 fontFamily = PeachType.Body,733 fontSize = 11.sp,734 lineHeight = 16.sp,735 modifier = Modifier.padding(bottom = 6.dp),736 )737 } else {738 Text(739 "Restoring locks your vault. Unlock with the password that encrypted that snapshot to confirm.",740 color = fg.copy(alpha = 0.68f),741 fontFamily = PeachType.Body,742 fontSize = 11.sp,743 lineHeight = 16.sp,744 modifier = Modifier.padding(bottom = 4.dp),745 )746 history.take(if (historyShowAll) history.size else 3).forEach { snap ->747 RowLine(fg) {748 Column(Modifier.weight(1f)) {749 Text(snapshotTimeLabel(snap.savedAt), color = fg, fontFamily = PeachType.Body, fontSize = 12.sp)750 Text(snapshotSubLabel(snap), color = fg.copy(alpha = 0.62f), fontFamily = PeachType.Mono, fontSize = 10.sp)751 }752 SubtleButton(if (restoringSnapshotId == snap.id) "..." else "restore", fg) {753 vm.restoreVaultSnapshot(snap.id)754 }755 }756 }757 if (history.size > 3) {758 RowLine(fg) {759 Name(if (historyShowAll) "show less" else "${history.size - 3} older", fg)760 SubtleButton(if (historyShowAll) "hide" else "show", fg) { historyShowAll = !historyShowAll }761 }762 }763 Text(764 "${history.size} of 5 snapshots",765 color = fg.copy(alpha = 0.58f),766 fontFamily = PeachType.Mono,767 fontSize = 10.sp,768 modifier = Modifier.padding(top = 2.dp, bottom = 6.dp),769 )770 }771 }772773 SettingsGroup("ADVANCED", fg, initiallyOpen = false) {774 RowLine(fg) {775 Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)776 SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }777 }778 RowLine(fg) {779 Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)780 SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }781 }782 }783}784785private fun snapshotSubLabel(snapshot: VaultSnapshot): String {786 val count = snapshot.entryCount?.let { "up to $it ${if (it == 1) "entry" else "entries"}" }787 return listOfNotNull(count, snapshotReasonLabel(snapshot.reason)).joinToString(" · ")788}789790private fun snapshotReasonLabel(reason: String): String = when (reason) {791 "local_save" -> "saved"792 "sync_received" -> "synced"793 "import" -> "imported"794 "restore" -> "restored"795 else -> reason796}797798private fun snapshotTimeLabel(savedAt: Long): String {799 val diff = System.currentTimeMillis() - savedAt800 if (diff < 60_000) return "Just now"801 if (diff < 3_600_000) return "${diff / 60_000}m ago"802 val date = Date(savedAt)803 val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())804 val thenDay = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(date)805 val time = SimpleDateFormat("h:mm a", Locale.getDefault()).format(date)806 if (today == thenDay) return "Today $time"807 val yesterday = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date(System.currentTimeMillis() - 86_400_000))808 if (yesterday == thenDay) return "Yesterday $time"809 return SimpleDateFormat("MMM d h:mm a", Locale.getDefault()).format(date)810}811812813814@Composable815private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {816 val context = LocalContext.current817 val syncVm: SyncViewModel = hiltViewModel()818 val pairedDevices by syncVm.pairedDevices.collectAsState()819 val pendingVouched by syncVm.pendingVouched.collectAsState()820 val syncStatus by syncVm.status.collectAsState()821 val configuredRelayUrl by syncVm.privateRelayUrl.collectAsState()822 val syncMode by syncVm.syncMode.collectAsState()823 val backgroundSyncEnabled by syncVm.backgroundSyncEnabled.collectAsState()824 var notificationsAvailable by remember {825 mutableStateOf(canShowBackgroundSyncNotification(context))826 }827 var showBackgroundSyncPrompt by remember { mutableStateOf(false) }828 val scope = rememberCoroutineScope()829 var confirmUnpair by remember { mutableStateOf<String?>(null) }830 var rotateConfirmOpen by remember { mutableStateOf(false) }831 var rotating by remember { mutableStateOf(false) }832 var rotateError by remember { mutableStateOf<String?>(null) }833 var relayUrlDraft by remember(configuredRelayUrl) {834 mutableStateOf(privateRelayDraftOf(configuredRelayUrl))835 }836 var relayUrlStatus by remember { mutableStateOf<String?>(null) }837 var showConnection by remember { mutableStateOf(false) }838 var showRecovery by remember { mutableStateOf(false) }839840 SubLabel("ADD A DEVICE", fg, top = 0.dp)841 RowLine(fg) {842 Column(Modifier.weight(1f)) {843 Text("Pair a device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)844 Text(845 "Either scan a QR shown on the other device, or show this device's QR for the other one to scan.",846 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,847 modifier = Modifier.padding(top = 2.dp),848 )849 }850 851 852 853 854 SubtleButton("scan", fg) { onNavigate(PeachNav.AdoptVault) }855 Spacer(Modifier.width(PeachSpacing.xs))856 SubtleButton("show code", fg) { onNavigate(PeachNav.CodePair) }857 }858859 SubLabel("SYNC STATUS", fg)860 val indicator = syncIndicator(syncStatus, pairedDevices.size)861 RowLine(fg) {862 SyncIndicatorDot(863 indicator = indicator,864 label = syncIndicatorLabel(indicator, syncStatus),865 modifier = Modifier.padding(end = PeachSpacing.sm),866 size = 8.dp,867 )868 Text(869 describeSyncOutcome(syncStatus),870 color = fg.copy(alpha = 0.7f),871 fontFamily = PeachType.Body,872 fontSize = 11.sp,873 lineHeight = 16.sp,874 modifier = Modifier.weight(1f),875 )876 SubtleButton(if (syncStatus.syncing) "syncing..." else "sync now", fg) {877 if (!syncStatus.syncing) syncVm.syncNow()878 }879 }880881 SubLabel("PAIRED DEVICES", fg)882 if (pairedDevices.isEmpty()) {883 PeachEmptyOrEndState(884 message = "No paired devices yet.",885 detail = "Pair a nearby phone, tablet, or browser when you're ready to sync.",886 modifier = Modifier.padding(top = PeachSpacing.xs),887 )888 } else {889 pairedDevices.forEach { d ->890 RowLine(fg) {891 Column(Modifier.weight(1f)) {892 Text(d.deviceName ?: d.deviceId, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)893 Text(894 "${deviceTypeLabel(d.deviceType)} · ${syncTimeLabel(d.lastSyncedAt)}${if (isSyncStale(d.lastSyncedAt)) " · not seen recently" else ""}",895 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,896 modifier = Modifier.padding(top = 2.dp),897 )898 }899 if (confirmUnpair != d.deviceId) {900 SubtleButton("remove", fg) { confirmUnpair = d.deviceId }901 }902 }903 904 905 906 907 908 if (confirmUnpair == d.deviceId) {909 Column(Modifier.fillMaxWidth().padding(bottom = PeachSpacing.sm)) {910 Text(911 "Stops this device receiving future changes. It doesn't lock it " +912 "out of what it already has - if it's lost or stolen, also " +913 "change your master password and generate new recovery words.",914 color = fg.copy(alpha = 0.7f),915 fontFamily = PeachType.Body,916 fontSize = 11.sp,917 lineHeight = 16.sp,918 )919 Row(920 modifier = Modifier.fillMaxWidth().padding(top = PeachSpacing.sm),921 horizontalArrangement = Arrangement.End,922 ) {923 SubtleButton("cancel", fg) { confirmUnpair = null }924 Spacer(Modifier.width(PeachSpacing.sm))925 SubtleButton("remove", peachColors.Breach) { syncVm.unpairDevice(d.deviceId); confirmUnpair = null }926 }927 }928 }929 }930 }931932 SyncDisclosure(933 title = "Connection",934 summary = "Background sync, relay, and privacy choices",935 expanded = showConnection,936 fg = fg,937 onToggle = { showConnection = !showConnection },938 )939 if (showConnection) {940 RowLine(fg) {941 Column(Modifier.weight(1f)) {942 Text("Background sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)943 Text(944 when {945 backgroundSyncEnabled && !notificationsAvailable ->946 "Action needed — Android notifications are off, so background sync is not visible."947 backgroundSyncEnabled ->948 "On — keeps this phone reachable for paired devices."949 else ->950 "Off — Peach syncs only while you are using the app."951 },952 color = fg.copy(alpha = 0.7f),953 fontFamily = PeachType.Body,954 fontSize = 11.sp,955 lineHeight = 16.sp,956 modifier = Modifier.padding(top = 2.dp),957 )958 }959 SubtleButton(960 if (backgroundSyncEnabled && !notificationsAvailable) "allow" else "change",961 if (backgroundSyncEnabled && !notificationsAvailable) peachColors.Breach else fg,962 ) { showBackgroundSyncPrompt = true }963 }964 SyncModeRow(965 title = "Public relay",966 detail = "Works anywhere with nothing to set up. The relay cannot read your vault.",967 selected = syncMode == SyncMode.PUBLIC,968 fg = fg,969 ) { syncVm.setSyncMode(SyncMode.PUBLIC) }970 SyncModeRow(971 title = "Private relay",972 detail = "Use your own peach-relay on your own domain.",973 selected = syncMode == SyncMode.PRIVATE,974 fg = fg,975 ) { syncVm.setSyncMode(SyncMode.PRIVATE) }976977 if (syncMode == SyncMode.PRIVATE) {978 Text(979 "RELAY URL",980 color = fg.copy(alpha = 0.6f),981 fontFamily = PeachType.Mono,982 fontSize = 8.sp,983 letterSpacing = 0.22.em,984 modifier = Modifier.padding(top = 8.dp),985 )986 Box(987 Modifier.fillMaxWidth().padding(top = 6.dp)988 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))989 .padding(horizontal = 12.dp, vertical = 10.dp),990 ) {991 BasicTextField(992 value = relayUrlDraft,993 onValueChange = { relayUrlDraft = it; relayUrlStatus = null },994 singleLine = true,995 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 11.sp, color = fg),996 cursorBrush = SolidColor(fg),997 modifier = Modifier.fillMaxWidth(),998 )999 }1000 val needsRelayUrl = configuredRelayUrl.isEmpty()1001 RowLine(fg) {1002 val message = relayUrlStatus1003 ?: if (needsRelayUrl) {1004 "Sync is paused until you enter your relay URL."1005 } else {1006 "Only secure wss:// relays are accepted."1007 }1008 val warn = relayUrlStatus?.startsWith("Use") == true ||1009 (relayUrlStatus == null && needsRelayUrl)1010 ValueText(message, if (warn) peachColors.Breach else fg)1011 SubtleButton("save", fg) {1012 relayUrlStatus = if (syncVm.setRelayUrl(relayUrlDraft)) {1013 relayUrlDraft = privateRelayDraftOf(syncVm.privateRelayUrl.value)1014 "Saved"1015 } else {1016 "Use a valid wss:// relay URL"1017 }1018 }1019 }1020 }10211022 SyncModeRow(1023 title = "No sync",1024 detail = "Keep this device separate and move backups by hand.",1025 selected = syncMode == SyncMode.OFF,1026 fg = fg,1027 ) { syncVm.setSyncMode(SyncMode.OFF) }1028 Hint("Pairing authorizes a device, not a cloud account.", fg)1029 }10301031 if (pendingVouched.isNotEmpty()) {1032 SubLabel("PENDING DEVICES", fg)1033 pendingVouched.forEach { dev ->1034 RowLine(fg) {1035 Column(Modifier.weight(1f)) {1036 Text(dev.deviceName, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1037 Text(1038 "Was added by another device. Allow it to sync?",1039 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1040 modifier = Modifier.padding(top = 2.dp),1041 )1042 }1043 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {1044 SubtleButton("Allow", fg) { syncVm.confirmVouchedDevice(dev.deviceId) }1045 SubtleButton("Reject", fg) { syncVm.rejectVouchedDevice(dev.deviceId) }1046 }1047 }1048 }1049 }10501051 SyncDisclosure(1052 title = "Recovery & security",1053 summary = "For a lost or stolen device",1054 expanded = showRecovery,1055 fg = fg,1056 onToggle = { showRecovery = !showRecovery },1057 )1058 if (showRecovery) {1059 RowLine(fg) {1060 Column(Modifier.weight(1f)) {1061 Text("Re-pair this device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1062 Text(1063 "Scan only when this populated vault previously trusted the source device.",1064 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1065 modifier = Modifier.padding(top = 2.dp),1066 )1067 }1068 SubtleButton("scan", fg) { onNavigate(PeachNav.AdoptVault) }1069 }1070 if (rotateConfirmOpen) {1071 Hint("This disconnects every paired device and changes your 12 recovery words. You'll be shown the new words next.", peachColors.Breach)1072 rotateError?.let {1073 Text(it, color = peachColors.Breach, fontFamily = PeachType.Body, fontSize = 11.sp, modifier = Modifier.padding(top = 6.dp))1074 }1075 Row(Modifier.padding(top = 10.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {1076 SubtleButton("cancel", fg) { if (!rotating) rotateConfirmOpen = false }1077 SubtleButton(if (rotating) "rotating..." else "Rotate sync identity", peachColors.Breach) {1078 if (rotating) return@SubtleButton1079 rotating = true1080 rotateError = null1081 scope.launch {1082 val ok = syncVm.rotateSyncIdentity()1083 rotating = false1084 if (ok) {1085 rotateConfirmOpen = false1086 onNavigate(PeachNav.RecoverySetup)1087 } else {1088 rotateError = "Rotation failed. Unlock your real vault and try again."1089 }1090 }1091 }1092 }1093 } else {1094 RowLine(fg) {1095 Column(Modifier.weight(1f)) {1096 Text("Rotate sync identity", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1097 Text(1098 "Disconnects every device and replaces the keys used for sync.",1099 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1100 modifier = Modifier.padding(top = 2.dp),1101 )1102 }1103 SubtleButton("rotate", peachColors.Breach) { rotateError = null; rotateConfirmOpen = true }1104 }1105 }1106 }11071108 if (showBackgroundSyncPrompt) {1109 BackgroundSyncDialog { enabled ->1110 showBackgroundSyncPrompt = false1111 notificationsAvailable = canShowBackgroundSyncNotification(context)1112 syncVm.setBackgroundSyncEnabled(enabled)1113 }1114 }1115}11161117private fun deviceTypeLabel(type: String?): String = when (type) {1118 "android" -> "Android"1119 "phone" -> "Phone"1120 "tablet" -> "Tablet"1121 "browser" -> "Browser"1122 else -> "Device"1123}11241125private fun syncTimeLabel(lastSyncedAt: Long?): String {1126 if (lastSyncedAt == null) return "never synced"1127 val diff = System.currentTimeMillis() - lastSyncedAt1128 if (diff < 60_000) return "just now"1129 if (diff < 3_600_000) return "${diff / 60_000}m ago"1130 if (diff < 86_400_000) return "${diff / 3_600_000}h ago"1131 return "${diff / 86_400_000}d ago"1132}11331134private fun isSyncStale(lastSyncedAt: Long?): Boolean =1135 lastSyncedAt != null && System.currentTimeMillis() - lastSyncedAt > 7L * 24L * 60L * 60L * 1000L1136113711381139@Composable1140private fun ProBody(fg: Color, vm: SettingsViewModel) {1141 val ctx = LocalContext.current1142 val isPro by vm.isPro.collectAsState()1143 if (isPro) {1144 ProActiveBody(fg, vm)1145 return1146 }1147 val features = listOf(1148 "Peach Sync" to "End-to-end encrypted",1149 "Peach Codex" to "Restore from paper",1150 "Passkeys" to "Zero-knowledge WebAuthn",1151 "Advanced Vault Health" to "Reuse · age · exposure",1152 "Canary entries" to "Detects vault compromise",1153 "Duress vault" to "Decoy under coercion",1154 )1155 Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1156 Text(1157 "Everything, everywhere.",1158 modifier = Modifier.padding(top = 8.dp),1159 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,1160 )1161 Text(1162 "One key unlocks every Pro feature — for the lifetime of the app.",1163 modifier = Modifier.padding(top = 6.dp),1164 color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,1165 )1166 Spacer(Modifier.height(10.dp))1167 features.forEachIndexed { i, (name, desc) ->1168 1169 1170 1171 1172 RowLine(fg, verticalPadding = 6.dp) {1173 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1174 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))1175 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1176 }1177 Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1178 }1179 }1180 Spacer(Modifier.height(12.dp))1181 Text(1182 "$39",1183 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,1184 )1185 Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)1186 Spacer(Modifier.height(10.dp))1187 Box(1188 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1189 .background(fg.copy(alpha = 0.16f))1190 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1191 .clickable {1192 runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }1193 }1194 .padding(vertical = 12.dp),1195 contentAlignment = Alignment.Center,1196 ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }11971198 1199 1200 1201 1202 Spacer(Modifier.height(44.dp))12031204 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1205 var key by remember { mutableStateOf("") }1206 val activating by vm.activating.collectAsState()1207 val activationError by vm.activationError.collectAsState()1208 Box(1209 Modifier.fillMaxWidth().padding(top = 6.dp)1210 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))1211 .padding(horizontal = 12.dp, vertical = 10.dp),1212 ) {1213 BasicTextField(1214 value = key,1215 1216 1217 1218 1219 onValueChange = { key = it; vm.clearActivationError() },1220 singleLine = true,1221 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),1222 cursorBrush = SolidColor(fg),1223 modifier = Modifier.fillMaxWidth(),1224 decorationBox = { inner ->1225 if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)1226 inner()1227 },1228 )1229 }1230 if (activationError != null) {1231 Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))1232 }1233 Spacer(Modifier.height(8.dp))1234 Box(1235 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1236 .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))1237 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1238 .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }1239 .padding(vertical = 12.dp),1240 contentAlignment = Alignment.Center,1241 ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }1242}12431244@Composable1245private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {1246 val ctx = LocalContext.current1247 val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")1248 val licenseKey by vm.licenseKey.collectAsState()1249 val issuedAt by vm.licenseIssuedAt.collectAsState()1250 var showKey by remember { mutableStateOf(false) }1251 var copied by remember { mutableStateOf(false) }1252 val scope = rememberCoroutineScope()1253 Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {1254 com.peachpasswords.ui.components.PeachMark(size = 60.dp)1255 }1256 Text(1257 "Peach Pro",1258 modifier = Modifier.fillMaxWidth(),1259 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,1260 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1261 )1262 Text(1263 formatLicenseActiveSince(issuedAt),1264 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),1265 color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,1266 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1267 )1268 licenseKey?.let { key ->1269 Spacer(Modifier.height(12.dp))1270 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1271 RowLine(fg) {1272 Text(1273 if (showKey) key else "************************",1274 color = fg.copy(alpha = if (showKey) 0.82f else 0.58f),1275 fontFamily = PeachType.Mono,1276 fontSize = 10.sp,1277 modifier = Modifier.weight(1f),1278 )1279 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {1280 SubtleButton(if (copied) "copied" else "copy", fg) {1281 PeachClipboard.copy(ctx, "peach license", key)1282 copied = true1283 scope.launch {1284 delay(1_500)1285 copied = false1286 }1287 }1288 SubtleButton(if (showKey) "hide" else "reveal", fg) { showKey = !showKey }1289 }1290 }1291 }1292 Spacer(Modifier.height(12.dp))1293 features.forEachIndexed { i, name ->1294 RowLine(fg) {1295 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1296 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))1297 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1298 }1299 Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1300 }1301 }1302 Spacer(Modifier.height(12.dp))1303 Box(1304 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1305 .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1306 .clickable { vm.deactivate() }1307 .padding(vertical = 12.dp),1308 contentAlignment = Alignment.Center,1309 ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }1310}13111312private fun formatLicenseActiveSince(issuedAt: Long?): String {1313 if (issuedAt == null) return "Active"1314 val monthYear = SimpleDateFormat("MMMM yyyy", Locale.getDefault()).format(Date(issuedAt))1315 return "Active since $monthYear"1316}1317131813191320@OptIn(ExperimentalLayoutApi::class)1321@Composable1322private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {1323 val categories = listOf("Bug report", "Feature request", "Question", "Other")1324 var category by remember { mutableStateOf(categories[0]) }1325 var message by remember { mutableStateOf("") }1326 val state by vm.feedbackState.collectAsState()13271328 1329 DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }13301331 if (state is FeedbackState.Sent) {1332 Box(1333 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))1334 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),1335 ) {1336 Column {1337 Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)1338 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))1339 }1340 }1341 return1342 }13431344 val sending = state is FeedbackState.Sending13451346 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)1347 SubLabel("TYPE", fg)1348 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1349 categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }1350 }1351 SubLabel("MESSAGE", fg)1352 Box(1353 Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))1354 .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))1355 .padding(10.dp),1356 ) {1357 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)1358 BasicTextField(1359 value = message, onValueChange = { message = it.take(MAX_FEEDBACK_MESSAGE_LENGTH) },1360 enabled = !sending,1361 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),1362 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),1363 )1364 }1365 Text(1366 "Version ${BuildConfig.VERSION_NAME} · will be included automatically",1367 modifier = Modifier.padding(top = 6.dp),1368 color = fg.copy(alpha = 0.52f),1369 fontFamily = PeachType.Mono,1370 fontSize = 10.sp,1371 lineHeight = 14.sp,1372 )1373 Spacer(Modifier.height(8.dp))13741375 Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {1376 val canSend = !sending && sanitizeFeedbackMessage(message).isNotBlank()1377 Box(1378 Modifier.clip(RoundedCornerShape(8.dp))1379 .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))1380 .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))1381 .clickable(enabled = canSend) { vm.sendFeedback(category, message) }1382 .padding(horizontal = 12.dp, vertical = 6.dp),1383 ) {1384 Text(1385 feedbackSubmitLabel(state),1386 color = fg.copy(alpha = if (canSend) 1f else 0.4f),1387 fontFamily = PeachType.Mono, fontSize = 11.sp,1388 )1389 }1390 if (sending) {1391 CircularProgressIndicator(1392 color = LocalPeachAccent.current,1393 strokeWidth = 2.dp,1394 modifier = Modifier.size(16.dp),1395 )1396 }1397 }13981399 (state as? FeedbackState.Error)?.let { err ->1400 Text(1401 err.message,1402 modifier = Modifier.padding(top = 8.dp),1403 color = peachColors.Breach,1404 fontFamily = PeachType.Mono,1405 fontSize = 11.sp,1406 lineHeight = 15.sp,1407 )1408 }14091410 Hint("Sent anonymously · no account required", fg)1411}1412141314141415@Composable1416internal fun DuressSection(fg: Color, vm: SettingsViewModel) {1417 val configured by vm.duressConfigured.collectAsState()1418 if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)1419}14201421@Composable1422private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {1423 Text(1424 "Duress password is active",1425 color = peachColors.HealthOk,1426 fontFamily = PeachType.Mono,1427 fontSize = 11.sp,1428 modifier = Modifier.padding(top = 6.dp),1429 )1430 Spacer(Modifier.height(8.dp))1431 DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }1432 Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)1433}14341435@Composable1436private fun DuressForm(fg: Color, vm: SettingsViewModel) {1437 var enabled by remember { mutableStateOf(false) }1438 var password by remember { mutableStateOf("") }1439 var confirm by remember { mutableStateOf("") }1440 var action by remember { mutableStateOf(DuressAction.DECOY) }1441 var error by remember { mutableStateOf<String?>(null) }1442 val scope = rememberCoroutineScope()14431444 RowLine(fg) {1445 Name("Duress password", fg)1446 Toggle(enabled, fg) { on ->1447 enabled = on1448 if (!on) { password = ""; confirm = ""; error = null }1449 }1450 }1451 Text(1452 "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",1453 color = fg.copy(alpha = 0.7f),1454 fontFamily = PeachType.Mono,1455 fontSize = 10.sp,1456 modifier = Modifier.padding(top = 6.dp),1457 )14581459 AnimatedVisibility(enabled) {1460 Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1461 PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }1462 PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }14631464 Text(1465 "When your duress password is entered at the lock screen, Peach will:",1466 color = fg.copy(alpha = 0.7f),1467 fontFamily = PeachType.Mono,1468 fontSize = 10.sp,1469 modifier = Modifier.padding(top = 4.dp),1470 )14711472 DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }1473 DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }14741475 error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }14761477 val canSave = password.isNotBlank() && confirm.isNotBlank()1478 DuressSaveButton("Save duress password", fg, canSave) {1479 error = when {1480 password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"1481 password != confirm -> "Passwords do not match"1482 else -> null1483 }1484 if (error == null) scope.launch {1485 if (vm.saveDuress(password, action)) {1486 password = ""; confirm = ""; enabled = false1487 } else {1488 error = "Couldn't save — the duress passphrase must differ from your real password"1489 }1490 }1491 }1492 }1493 }1494}14951496@Composable1497private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {1498 val accent = LocalPeachAccent.current1499 Row(1500 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),1501 verticalAlignment = Alignment.CenterVertically,1502 horizontalArrangement = Arrangement.spacedBy(10.dp),1503 ) {1504 Box(1505 Modifier.size(16.dp).clip(CircleShape)1506 .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),1507 contentAlignment = Alignment.Center,1508 ) {1509 if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))1510 }1511 Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)1512 }1513}15141515@Composable1516private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {1517 val accent = LocalPeachAccent.current1518 val tint = if (enabled) accent else fg.copy(alpha = 0.3f)1519 Box(1520 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1521 .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))1522 .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))1523 .let { if (enabled) it.clickable(onClick = onClick) else it }1524 .padding(vertical = 11.dp),1525 contentAlignment = Alignment.Center,1526 ) {1527 Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)1528 }1529}15301531@Composable1532private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {1533 Box(1534 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1535 .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))1536 .clickable(onClick = onClick)1537 .padding(vertical = 11.dp),1538 contentAlignment = Alignment.Center,1539 ) {1540 Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)1541 }1542}154315441545@Composable1546private fun SyncModeRow(1547 title: String,1548 detail: String,1549 selected: Boolean,1550 fg: Color,1551 onSelect: () -> Unit,1552) {1553 RowLine(fg, Modifier.clickable(onClick = onSelect)) {1554 Column(Modifier.weight(1f)) {1555 Text(title, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1556 Text(1557 detail,1558 color = fg.copy(alpha = 0.7f),1559 fontFamily = PeachType.Body,1560 fontSize = 11.sp,1561 lineHeight = 16.sp,1562 modifier = Modifier.padding(top = 2.dp),1563 )1564 }1565 Text(1566 if (selected) "●" else "○",1567 color = if (selected) fg else fg.copy(alpha = 0.45f),1568 fontFamily = PeachType.Mono,1569 fontSize = 14.sp,1570 modifier = Modifier.padding(start = 10.dp),1571 )1572 }1573}