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 renamingDeviceId by remember { mutableStateOf<String?>(null) }831 var renameDraft by remember { mutableStateOf("") }832 var rotateConfirmOpen by remember { mutableStateOf(false) }833 var rotating by remember { mutableStateOf(false) }834 var rotateError by remember { mutableStateOf<String?>(null) }835 var relayUrlDraft by remember(configuredRelayUrl) {836 mutableStateOf(privateRelayDraftOf(configuredRelayUrl))837 }838 var relayUrlStatus by remember { mutableStateOf<String?>(null) }839 var showConnection by remember { mutableStateOf(false) }840 var showRecovery by remember { mutableStateOf(false) }841842 SubLabel("ADD A DEVICE", fg, top = 0.dp)843 RowLine(fg) {844 Column(Modifier.weight(1f)) {845 Text("Pair a device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)846 Text(847 "Either scan a QR shown on the other device, or show this device's QR for the other one to scan.",848 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,849 modifier = Modifier.padding(top = 2.dp),850 )851 }852 853 854 855 856 SubtleButton("scan", fg) { onNavigate(PeachNav.AdoptVault) }857 Spacer(Modifier.width(PeachSpacing.xs))858 SubtleButton("show code", fg) { onNavigate(PeachNav.CodePair) }859 }860861 SubLabel("SYNC STATUS", fg)862 val indicator = syncIndicator(syncStatus, pairedDevices.size)863 RowLine(fg) {864 SyncIndicatorDot(865 indicator = indicator,866 label = syncIndicatorLabel(indicator, syncStatus),867 modifier = Modifier.padding(end = PeachSpacing.sm),868 size = 8.dp,869 )870 Text(871 describeSyncOutcome(syncStatus),872 color = fg.copy(alpha = 0.7f),873 fontFamily = PeachType.Body,874 fontSize = 11.sp,875 lineHeight = 16.sp,876 modifier = Modifier.weight(1f),877 )878 SubtleButton(if (syncStatus.syncing) "syncing..." else "sync now", fg) {879 if (!syncStatus.syncing) syncVm.syncNow()880 }881 }882883 SubLabel("PAIRED DEVICES", fg)884 if (pairedDevices.isEmpty()) {885 PeachEmptyOrEndState(886 message = "No paired devices yet.",887 detail = "Pair a nearby phone, tablet, or browser when you're ready to sync.",888 modifier = Modifier.padding(top = PeachSpacing.xs),889 )890 } else {891 pairedDevices.forEach { d ->892 RowLine(fg) {893 Column(Modifier.weight(1f)) {894 if (renamingDeviceId == d.deviceId) {895 Box(896 Modifier.fillMaxWidth()897 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))898 .padding(horizontal = 10.dp, vertical = 8.dp),899 ) {900 BasicTextField(901 value = renameDraft,902 onValueChange = { renameDraft = it.take(64) },903 singleLine = true,904 textStyle = TextStyle(fontFamily = PeachType.Body, fontSize = 13.sp, color = fg),905 cursorBrush = SolidColor(fg),906 modifier = Modifier.fillMaxWidth(),907 )908 }909 } else {910 Text(d.localAlias ?: d.deviceName ?: d.deviceId, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)911 }912 Text(913 "${deviceTypeLabel(d.deviceType)} · ${syncTimeLabel(d.lastSyncedAt)}${if (isSyncStale(d.lastSyncedAt)) " · not seen recently" else ""}",914 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,915 modifier = Modifier.padding(top = 2.dp),916 )917 }918 if (confirmUnpair != d.deviceId) {919 if (renamingDeviceId == d.deviceId) {920 SubtleButton("cancel", fg) { renamingDeviceId = null }921 Spacer(Modifier.width(PeachSpacing.xs))922 SubtleButton("save", fg) {923 if (renameDraft.isNotBlank()) {924 syncVm.renameDevice(d.deviceId, renameDraft)925 renamingDeviceId = null926 }927 }928 } else {929 SubtleButton("rename", fg) {930 renameDraft = d.localAlias ?: d.deviceName ?: ""931 renamingDeviceId = d.deviceId932 }933 }934 Spacer(Modifier.width(PeachSpacing.xs))935 SubtleButton("remove", fg) { confirmUnpair = d.deviceId }936 }937 }938 939 940 941 942 943 if (confirmUnpair == d.deviceId) {944 Column(Modifier.fillMaxWidth().padding(bottom = PeachSpacing.sm)) {945 Text(946 "Stops this device receiving future changes. It doesn't lock it " +947 "out of what it already has - if it's lost or stolen, also " +948 "change your master password and generate new recovery words.",949 color = fg.copy(alpha = 0.7f),950 fontFamily = PeachType.Body,951 fontSize = 11.sp,952 lineHeight = 16.sp,953 )954 Row(955 modifier = Modifier.fillMaxWidth().padding(top = PeachSpacing.sm),956 horizontalArrangement = Arrangement.End,957 ) {958 SubtleButton("cancel", fg) { confirmUnpair = null }959 Spacer(Modifier.width(PeachSpacing.sm))960 SubtleButton("remove", peachColors.Breach) { syncVm.unpairDevice(d.deviceId); confirmUnpair = null }961 }962 }963 }964 }965 }966967 SyncDisclosure(968 title = "Connection",969 summary = "Background sync, relay, and privacy choices",970 expanded = showConnection,971 fg = fg,972 onToggle = { showConnection = !showConnection },973 )974 if (showConnection) {975 RowLine(fg) {976 Column(Modifier.weight(1f)) {977 Text("Background sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)978 Text(979 when {980 backgroundSyncEnabled && !notificationsAvailable ->981 "Action needed — Android notifications are off, so background sync is not visible."982 backgroundSyncEnabled ->983 "On — keeps this phone reachable for paired devices."984 else ->985 "Off — Peach syncs only while you are using the app."986 },987 color = fg.copy(alpha = 0.7f),988 fontFamily = PeachType.Body,989 fontSize = 11.sp,990 lineHeight = 16.sp,991 modifier = Modifier.padding(top = 2.dp),992 )993 }994 SubtleButton(995 if (backgroundSyncEnabled && !notificationsAvailable) "allow" else "change",996 if (backgroundSyncEnabled && !notificationsAvailable) peachColors.Breach else fg,997 ) { showBackgroundSyncPrompt = true }998 }999 SyncModeRow(1000 title = "Public relay",1001 detail = "Works anywhere with nothing to set up. The relay cannot read your vault.",1002 selected = syncMode == SyncMode.PUBLIC,1003 fg = fg,1004 ) { syncVm.setSyncMode(SyncMode.PUBLIC) }1005 SyncModeRow(1006 title = "Private relay",1007 detail = "Use your own peach-relay on your own domain.",1008 selected = syncMode == SyncMode.PRIVATE,1009 fg = fg,1010 ) { syncVm.setSyncMode(SyncMode.PRIVATE) }10111012 if (syncMode == SyncMode.PRIVATE) {1013 Text(1014 "RELAY URL",1015 color = fg.copy(alpha = 0.6f),1016 fontFamily = PeachType.Mono,1017 fontSize = 8.sp,1018 letterSpacing = 0.22.em,1019 modifier = Modifier.padding(top = 8.dp),1020 )1021 Box(1022 Modifier.fillMaxWidth().padding(top = 6.dp)1023 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))1024 .padding(horizontal = 12.dp, vertical = 10.dp),1025 ) {1026 BasicTextField(1027 value = relayUrlDraft,1028 onValueChange = { relayUrlDraft = it; relayUrlStatus = null },1029 singleLine = true,1030 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 11.sp, color = fg),1031 cursorBrush = SolidColor(fg),1032 modifier = Modifier.fillMaxWidth(),1033 )1034 }1035 val needsRelayUrl = configuredRelayUrl.isEmpty()1036 RowLine(fg) {1037 val message = relayUrlStatus1038 ?: if (needsRelayUrl) {1039 "Sync is paused until you enter your relay URL."1040 } else {1041 "Only secure wss:// relays are accepted."1042 }1043 val warn = relayUrlStatus?.startsWith("Use") == true ||1044 (relayUrlStatus == null && needsRelayUrl)1045 ValueText(message, if (warn) peachColors.Breach else fg)1046 SubtleButton("save", fg) {1047 relayUrlStatus = if (syncVm.setRelayUrl(relayUrlDraft)) {1048 relayUrlDraft = privateRelayDraftOf(syncVm.privateRelayUrl.value)1049 "Saved"1050 } else {1051 "Use a valid wss:// relay URL"1052 }1053 }1054 }1055 }10561057 SyncModeRow(1058 title = "No sync",1059 detail = "Keep this device separate and move backups by hand.",1060 selected = syncMode == SyncMode.OFF,1061 fg = fg,1062 ) { syncVm.setSyncMode(SyncMode.OFF) }1063 Hint("Pairing authorizes a device, not a cloud account.", fg)1064 }10651066 if (pendingVouched.isNotEmpty()) {1067 SubLabel("PENDING DEVICES", fg)1068 pendingVouched.forEach { dev ->1069 RowLine(fg) {1070 Column(Modifier.weight(1f)) {1071 Text(dev.deviceName, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1072 Text(1073 "Was added by another device. Allow it to sync?",1074 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1075 modifier = Modifier.padding(top = 2.dp),1076 )1077 }1078 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {1079 SubtleButton("Allow", fg) { syncVm.confirmVouchedDevice(dev.deviceId) }1080 SubtleButton("Reject", fg) { syncVm.rejectVouchedDevice(dev.deviceId) }1081 }1082 }1083 }1084 }10851086 SyncDisclosure(1087 title = "Recovery & security",1088 summary = "For a lost or stolen device",1089 expanded = showRecovery,1090 fg = fg,1091 onToggle = { showRecovery = !showRecovery },1092 )1093 if (showRecovery) {1094 RowLine(fg) {1095 Column(Modifier.weight(1f)) {1096 Text("Re-pair this device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1097 Text(1098 "Scan only when this populated vault previously trusted the source device.",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("scan", fg) { onNavigate(PeachNav.AdoptVault) }1104 }1105 if (rotateConfirmOpen) {1106 Hint("This disconnects every paired device and changes your 12 recovery words. You'll be shown the new words next.", peachColors.Breach)1107 rotateError?.let {1108 Text(it, color = peachColors.Breach, fontFamily = PeachType.Body, fontSize = 11.sp, modifier = Modifier.padding(top = 6.dp))1109 }1110 Row(Modifier.padding(top = 10.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {1111 SubtleButton("cancel", fg) { if (!rotating) rotateConfirmOpen = false }1112 SubtleButton(if (rotating) "rotating..." else "Rotate sync identity", peachColors.Breach) {1113 if (rotating) return@SubtleButton1114 rotating = true1115 rotateError = null1116 scope.launch {1117 val ok = syncVm.rotateSyncIdentity()1118 rotating = false1119 if (ok) {1120 rotateConfirmOpen = false1121 onNavigate(PeachNav.RecoverySetup)1122 } else {1123 rotateError = "Rotation failed. Unlock your real vault and try again."1124 }1125 }1126 }1127 }1128 } else {1129 RowLine(fg) {1130 Column(Modifier.weight(1f)) {1131 Text("Rotate sync identity", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1132 Text(1133 "Disconnects every device and replaces the keys used for sync.",1134 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1135 modifier = Modifier.padding(top = 2.dp),1136 )1137 }1138 SubtleButton("rotate", peachColors.Breach) { rotateError = null; rotateConfirmOpen = true }1139 }1140 }1141 }11421143 if (showBackgroundSyncPrompt) {1144 BackgroundSyncDialog { enabled ->1145 showBackgroundSyncPrompt = false1146 notificationsAvailable = canShowBackgroundSyncNotification(context)1147 syncVm.setBackgroundSyncEnabled(enabled)1148 }1149 }1150}11511152private fun deviceTypeLabel(type: String?): String = when (type) {1153 "android" -> "Android"1154 "phone" -> "Phone"1155 "tablet" -> "Tablet"1156 "browser" -> "Browser"1157 else -> "Device"1158}11591160private fun syncTimeLabel(lastSyncedAt: Long?): String {1161 if (lastSyncedAt == null) return "never synced"1162 val diff = System.currentTimeMillis() - lastSyncedAt1163 if (diff < 60_000) return "just now"1164 if (diff < 3_600_000) return "${diff / 60_000}m ago"1165 if (diff < 86_400_000) return "${diff / 3_600_000}h ago"1166 return "${diff / 86_400_000}d ago"1167}11681169private fun isSyncStale(lastSyncedAt: Long?): Boolean =1170 lastSyncedAt != null && System.currentTimeMillis() - lastSyncedAt > 7L * 24L * 60L * 60L * 1000L1171117211731174@Composable1175private fun ProBody(fg: Color, vm: SettingsViewModel) {1176 val ctx = LocalContext.current1177 val isPro by vm.isPro.collectAsState()1178 if (isPro) {1179 ProActiveBody(fg, vm)1180 return1181 }1182 val features = listOf(1183 "Peach Sync" to "End-to-end encrypted",1184 "Peach Codex" to "Restore from paper",1185 "Passkeys" to "Zero-knowledge WebAuthn",1186 "Advanced Vault Health" to "Reuse · age · exposure",1187 "Canary entries" to "Detects vault compromise",1188 "Duress vault" to "Decoy under coercion",1189 )1190 Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1191 Text(1192 "Everything, everywhere.",1193 modifier = Modifier.padding(top = 8.dp),1194 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,1195 )1196 Text(1197 "One key unlocks every Pro feature — for the lifetime of the app.",1198 modifier = Modifier.padding(top = 6.dp),1199 color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,1200 )1201 Spacer(Modifier.height(10.dp))1202 features.forEachIndexed { i, (name, desc) ->1203 1204 1205 1206 1207 RowLine(fg, verticalPadding = 6.dp) {1208 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1209 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))1210 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1211 }1212 Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1213 }1214 }1215 Spacer(Modifier.height(12.dp))1216 Text(1217 "$39",1218 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,1219 )1220 Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)1221 Spacer(Modifier.height(10.dp))1222 Box(1223 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1224 .background(fg.copy(alpha = 0.16f))1225 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1226 .clickable {1227 runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }1228 }1229 .padding(vertical = 12.dp),1230 contentAlignment = Alignment.Center,1231 ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }12321233 1234 1235 1236 1237 Spacer(Modifier.height(44.dp))12381239 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1240 var key by remember { mutableStateOf("") }1241 val activating by vm.activating.collectAsState()1242 val activationError by vm.activationError.collectAsState()1243 Box(1244 Modifier.fillMaxWidth().padding(top = 6.dp)1245 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))1246 .padding(horizontal = 12.dp, vertical = 10.dp),1247 ) {1248 BasicTextField(1249 value = key,1250 1251 1252 1253 1254 onValueChange = { key = it; vm.clearActivationError() },1255 singleLine = true,1256 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),1257 cursorBrush = SolidColor(fg),1258 modifier = Modifier.fillMaxWidth(),1259 decorationBox = { inner ->1260 if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)1261 inner()1262 },1263 )1264 }1265 if (activationError != null) {1266 Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))1267 }1268 Spacer(Modifier.height(8.dp))1269 Box(1270 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1271 .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))1272 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1273 .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }1274 .padding(vertical = 12.dp),1275 contentAlignment = Alignment.Center,1276 ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }1277}12781279@Composable1280private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {1281 val ctx = LocalContext.current1282 val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")1283 val licenseKey by vm.licenseKey.collectAsState()1284 val issuedAt by vm.licenseIssuedAt.collectAsState()1285 var showKey by remember { mutableStateOf(false) }1286 var copied by remember { mutableStateOf(false) }1287 val scope = rememberCoroutineScope()1288 Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {1289 com.peachpasswords.ui.components.PeachMark(size = 60.dp)1290 }1291 Text(1292 "Peach Pro",1293 modifier = Modifier.fillMaxWidth(),1294 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,1295 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1296 )1297 Text(1298 formatLicenseActiveSince(issuedAt),1299 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),1300 color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,1301 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1302 )1303 licenseKey?.let { key ->1304 Spacer(Modifier.height(12.dp))1305 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1306 RowLine(fg) {1307 Text(1308 if (showKey) key else "************************",1309 color = fg.copy(alpha = if (showKey) 0.82f else 0.58f),1310 fontFamily = PeachType.Mono,1311 fontSize = 10.sp,1312 modifier = Modifier.weight(1f),1313 )1314 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {1315 SubtleButton(if (copied) "copied" else "copy", fg) {1316 PeachClipboard.copy(ctx, "peach license", key)1317 copied = true1318 scope.launch {1319 delay(1_500)1320 copied = false1321 }1322 }1323 SubtleButton(if (showKey) "hide" else "reveal", fg) { showKey = !showKey }1324 }1325 }1326 }1327 Spacer(Modifier.height(12.dp))1328 features.forEachIndexed { i, name ->1329 RowLine(fg) {1330 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1331 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))1332 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1333 }1334 Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1335 }1336 }1337 Spacer(Modifier.height(12.dp))1338 Box(1339 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1340 .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1341 .clickable { vm.deactivate() }1342 .padding(vertical = 12.dp),1343 contentAlignment = Alignment.Center,1344 ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }1345}13461347private fun formatLicenseActiveSince(issuedAt: Long?): String {1348 if (issuedAt == null) return "Active"1349 val monthYear = SimpleDateFormat("MMMM yyyy", Locale.getDefault()).format(Date(issuedAt))1350 return "Active since $monthYear"1351}1352135313541355@OptIn(ExperimentalLayoutApi::class)1356@Composable1357private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {1358 val categories = listOf("Bug report", "Feature request", "Question", "Other")1359 var category by remember { mutableStateOf(categories[0]) }1360 var message by remember { mutableStateOf("") }1361 val state by vm.feedbackState.collectAsState()13621363 1364 DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }13651366 if (state is FeedbackState.Sent) {1367 Box(1368 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))1369 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),1370 ) {1371 Column {1372 Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)1373 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))1374 }1375 }1376 return1377 }13781379 val sending = state is FeedbackState.Sending13801381 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)1382 SubLabel("TYPE", fg)1383 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1384 categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }1385 }1386 SubLabel("MESSAGE", fg)1387 Box(1388 Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))1389 .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))1390 .padding(10.dp),1391 ) {1392 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)1393 BasicTextField(1394 value = message, onValueChange = { message = it.take(MAX_FEEDBACK_MESSAGE_LENGTH) },1395 enabled = !sending,1396 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),1397 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),1398 )1399 }1400 Text(1401 "Version ${BuildConfig.VERSION_NAME} · will be included automatically",1402 modifier = Modifier.padding(top = 6.dp),1403 color = fg.copy(alpha = 0.52f),1404 fontFamily = PeachType.Mono,1405 fontSize = 10.sp,1406 lineHeight = 14.sp,1407 )1408 Spacer(Modifier.height(8.dp))14091410 Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {1411 val canSend = !sending && sanitizeFeedbackMessage(message).isNotBlank()1412 Box(1413 Modifier.clip(RoundedCornerShape(8.dp))1414 .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))1415 .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))1416 .clickable(enabled = canSend) { vm.sendFeedback(category, message) }1417 .padding(horizontal = 12.dp, vertical = 6.dp),1418 ) {1419 Text(1420 feedbackSubmitLabel(state),1421 color = fg.copy(alpha = if (canSend) 1f else 0.4f),1422 fontFamily = PeachType.Mono, fontSize = 11.sp,1423 )1424 }1425 if (sending) {1426 CircularProgressIndicator(1427 color = LocalPeachAccent.current,1428 strokeWidth = 2.dp,1429 modifier = Modifier.size(16.dp),1430 )1431 }1432 }14331434 (state as? FeedbackState.Error)?.let { err ->1435 Text(1436 err.message,1437 modifier = Modifier.padding(top = 8.dp),1438 color = peachColors.Breach,1439 fontFamily = PeachType.Mono,1440 fontSize = 11.sp,1441 lineHeight = 15.sp,1442 )1443 }14441445 Hint("Sent anonymously · no account required", fg)1446}1447144814491450@Composable1451internal fun DuressSection(fg: Color, vm: SettingsViewModel) {1452 val configured by vm.duressConfigured.collectAsState()1453 if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)1454}14551456@Composable1457private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {1458 Text(1459 "Duress password is active",1460 color = peachColors.HealthOk,1461 fontFamily = PeachType.Mono,1462 fontSize = 11.sp,1463 modifier = Modifier.padding(top = 6.dp),1464 )1465 Spacer(Modifier.height(8.dp))1466 DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }1467 Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)1468}14691470@Composable1471private fun DuressForm(fg: Color, vm: SettingsViewModel) {1472 var enabled by remember { mutableStateOf(false) }1473 var password by remember { mutableStateOf("") }1474 var confirm by remember { mutableStateOf("") }1475 var action by remember { mutableStateOf(DuressAction.DECOY) }1476 var error by remember { mutableStateOf<String?>(null) }1477 val scope = rememberCoroutineScope()14781479 RowLine(fg) {1480 Name("Duress password", fg)1481 Toggle(enabled, fg) { on ->1482 enabled = on1483 if (!on) { password = ""; confirm = ""; error = null }1484 }1485 }1486 Text(1487 "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",1488 color = fg.copy(alpha = 0.7f),1489 fontFamily = PeachType.Mono,1490 fontSize = 10.sp,1491 modifier = Modifier.padding(top = 6.dp),1492 )14931494 AnimatedVisibility(enabled) {1495 Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1496 PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }1497 PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }14981499 Text(1500 "When your duress password is entered at the lock screen, Peach will:",1501 color = fg.copy(alpha = 0.7f),1502 fontFamily = PeachType.Mono,1503 fontSize = 10.sp,1504 modifier = Modifier.padding(top = 4.dp),1505 )15061507 DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }1508 DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }15091510 error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }15111512 val canSave = password.isNotBlank() && confirm.isNotBlank()1513 DuressSaveButton("Save duress password", fg, canSave) {1514 error = when {1515 password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"1516 password != confirm -> "Passwords do not match"1517 else -> null1518 }1519 if (error == null) scope.launch {1520 if (vm.saveDuress(password, action)) {1521 password = ""; confirm = ""; enabled = false1522 } else {1523 error = "Couldn't save — the duress passphrase must differ from your real password"1524 }1525 }1526 }1527 }1528 }1529}15301531@Composable1532private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {1533 val accent = LocalPeachAccent.current1534 Row(1535 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),1536 verticalAlignment = Alignment.CenterVertically,1537 horizontalArrangement = Arrangement.spacedBy(10.dp),1538 ) {1539 Box(1540 Modifier.size(16.dp).clip(CircleShape)1541 .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),1542 contentAlignment = Alignment.Center,1543 ) {1544 if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))1545 }1546 Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)1547 }1548}15491550@Composable1551private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {1552 val accent = LocalPeachAccent.current1553 val tint = if (enabled) accent else fg.copy(alpha = 0.3f)1554 Box(1555 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1556 .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))1557 .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))1558 .let { if (enabled) it.clickable(onClick = onClick) else it }1559 .padding(vertical = 11.dp),1560 contentAlignment = Alignment.Center,1561 ) {1562 Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)1563 }1564}15651566@Composable1567private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {1568 Box(1569 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1570 .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))1571 .clickable(onClick = onClick)1572 .padding(vertical = 11.dp),1573 contentAlignment = Alignment.Center,1574 ) {1575 Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)1576 }1577}157815791580@Composable1581private fun SyncModeRow(1582 title: String,1583 detail: String,1584 selected: Boolean,1585 fg: Color,1586 onSelect: () -> Unit,1587) {1588 RowLine(fg, Modifier.clickable(onClick = onSelect)) {1589 Column(Modifier.weight(1f)) {1590 Text(title, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1591 Text(1592 detail,1593 color = fg.copy(alpha = 0.7f),1594 fontFamily = PeachType.Body,1595 fontSize = 11.sp,1596 lineHeight = 16.sp,1597 modifier = Modifier.padding(top = 2.dp),1598 )1599 }1600 Text(1601 if (selected) "●" else "○",1602 color = if (selected) fg else fg.copy(alpha = 0.45f),1603 fontFamily = PeachType.Mono,1604 fontSize = 14.sp,1605 modifier = Modifier.padding(start = 10.dp),1606 )1607 }1608}