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 SubLabel("PASSKEYS", fg)416 RowLine(fg) {417 Column(Modifier.weight(1f)) {418 Text("Credential provider", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)419 Text(420 "Peach can handle passkey sign-in and creation through Android Credential Manager.",421 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,422 modifier = Modifier.padding(top = 2.dp),423 )424 }425 Toggle(s.passkeyProviderEnabled, fg) { vm.setPasskeyProviderEnabled(it) }426 }427 RowLine(fg) {428 Name("Status", fg)429 ValueText(if (s.passkeyProviderEnabled) "enabled" else "off", fg)430 }431 SubLabel("RECOVERY", fg)432 RowLine(fg) {433 Column(Modifier.weight(1f)) {434 Text("View recovery words", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)435 Text(436 "Keep the paper copy current before rotating sync identity or replacing devices.",437 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,438 modifier = Modifier.padding(top = 2.dp),439 )440 }441 SubtleButton("view", fg) {442 if (bioActivity != null) {443 com.peachpasswords.ui.lock.Biometrics.authenticate(444 activity = bioActivity,445 title = "View recovery words",446 subtitle = "Confirm your identity to view your recovery words",447 onSuccess = { onNavigate(PeachNav.RecoveryView) },448 )449 } else onNavigate(PeachNav.RecoveryView)450 }451 }452 SubLabel("BREACH PROTECTION", fg)453 val checkingBreaches by vm.checkingBreaches.collectAsState()454 val breachResult by vm.breachResult.collectAsState()455 RowLine(fg) {456 Name("Breach monitoring", fg)457 Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }458 }459 RowLine(fg) {460 Name("Check all passwords", fg)461 SubtleButton(if (checkingBreaches) "checking..." else "run", fg) { vm.checkAllBreaches() }462 }463 breachResult?.let { result ->464 RowLine(fg) {465 Name("Last check", fg)466 ValueText(result, fg)467 }468 }469470 SubLabel("MASTER PASSWORD", fg)471 ChangePasswordRow(fg, vm)472473 SubLabel("DURESS PASSWORD", fg)474 val duressIsPro by vm.isPro.collectAsState()475 if (!duressIsPro) {476 RowLine(fg) {477 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {478 Name("Duress password", fg); ProBadge(fg)479 }480 ValueText("off", fg)481 }482 Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)483 } else {484 DuressSection(fg, vm)485 }486}487488@Composable489private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {490 var open by remember { mutableStateOf(false) }491 var current by remember { mutableStateOf("") }492 var next by remember { mutableStateOf("") }493 var confirm by remember { mutableStateOf("") }494 var error by remember { mutableStateOf<String?>(null) }495 var done by remember { mutableStateOf(false) }496 val scope = rememberCoroutineScope()497498 RowLine(fg) {499 Name("Master password", fg)500 SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }501 }502 AnimatedVisibility(open) {503 Column(Modifier.fillMaxWidth().padding(top = PeachSpacing.sm), verticalArrangement = Arrangement.spacedBy(PeachSpacing.sm)) {504 PwField("current password", current, fg) { current = it }505 PwField("new password (min 12 chars)", next, fg) { next = it }506 PwField("confirm new password", confirm, fg) { confirm = it }507 error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }508 if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)509 SubtleButton("save new password", fg) {510 error = when {511 current.isBlank() -> "enter your current password"512 next.length < 12 -> "new password must be at least 12 characters"513 next != confirm -> "new passwords do not match"514 next == current -> "new password must differ from current"515 else -> null516 }517 if (error == null) scope.launch {518 if (vm.changePassword(current, next)) {519 current = ""; next = ""; confirm = ""; open = false; done = true520 } else error = "incorrect current password"521 }522 }523 }524 }525}526527@Composable528private fun PwField(placeholder: String, value: String, @Suppress("UNUSED_PARAMETER") fg: Color, onChange: (String) -> Unit) {529 PeachField(530 label = placeholder,531 value = value,532 onValueChange = onChange,533 keyboardType = androidx.compose.ui.text.input.KeyboardType.Password,534 visualTransformation = PasswordVisualTransformation(),535 )536}537538539540@Composable541private fun UpdatesRows(fg: Color, onNavigate: (PeachNav) -> Unit) {542 val vm: UpdateViewModel = hiltViewModel()543 val available by vm.available.collectAsState()544 val state by vm.state.collectAsState()545 val changelog by vm.changelog.collectAsState()546 var changelogOpen by remember { mutableStateOf(false) }547548 RowLine(fg) {549 Name("Version", fg)550 ValueText(BuildConfig.VERSION_NAME, fg)551 }552 RowLine(fg) {553 Column(Modifier.weight(1f)) {554 Text("Updates", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)555 Text(556 when {557 available != null -> "v${available?.version} is available"558 state.phase == UpdatePhase.Checking -> "Checking…"559 state.phase == UpdatePhase.UpToDate -> "You're on the latest version"560 state.phase == UpdatePhase.Failed -> "Couldn't reach the update server"561 else -> "Peach checks once a day and tells you when there's a new version."562 },563 color = fg.copy(alpha = 0.7f),564 fontFamily = PeachType.Body,565 fontSize = 11.sp,566 lineHeight = 16.sp,567 modifier = Modifier.padding(top = 2.dp),568 )569 }570 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {571 SubtleButton("changelog", fg) {572 changelogOpen = !changelogOpen573 if (changelogOpen) vm.loadChangelog()574 }575 if (available != null) {576 SubtleButton("tap to install", fg) { onNavigate(PeachNav.Update) }577 } else {578 SubtleButton(if (state.phase == UpdatePhase.Checking) "checking" else "check for updates", fg) {579 vm.check()580 }581 }582 }583 }584 if (changelogOpen) {585 when (changelog.phase) {586 ChangelogPhase.Idle -> {}587 ChangelogPhase.Loading -> Text(588 "Loading changelog…",589 color = fg.copy(alpha = 0.68f),590 fontFamily = PeachType.Body,591 fontSize = 11.sp,592 modifier = Modifier.padding(vertical = 8.dp),593 )594 ChangelogPhase.Failed -> RowLine(fg) {595 Name("Couldn't reach the update server", fg)596 SubtleButton("retry", fg) { vm.loadChangelog() }597 }598 ChangelogPhase.Loaded -> Column(Modifier.fillMaxWidth()) {599 changelog.entries.forEachIndexed { index, entry ->600 Column(Modifier.fillMaxWidth().padding(vertical = 8.dp)) {601 Row(verticalAlignment = Alignment.CenterVertically) {602 Text("v${entry.version}", color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)603 if (compareVersions(entry.version, vm.currentVersion) == 0) {604 Text(" current", color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 9.sp)605 }606 }607 Text(608 entry.notes ?: "No notes for this release.",609 color = fg.copy(alpha = 0.72f),610 fontFamily = PeachType.Body,611 fontSize = 11.sp,612 lineHeight = 16.sp,613 modifier = Modifier.padding(top = 3.dp),614 )615 }616 if (index < changelog.entries.lastIndex) {617 Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.08f)))618 }619 }620 }621 }622 }623}624625@Composable626private fun VaultBody(627 fg: Color,628 vm: SettingsViewModel,629 s: VaultSettings,630 entriesCount: Int,631 onNavigate: (PeachNav) -> Unit,632) {633 val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")634 val current = s.trashRetentionDays ?: 0635 val isPro by vm.isPro.collectAsState()636 val dedupCount by vm.dedupCount.collectAsState()637 val dedupRunning by vm.dedupRunning.collectAsState()638 val dedupDone by vm.dedupDone.collectAsState()639 val history by vm.vaultHistory.collectAsState()640 val restoringSnapshotId by vm.restoringSnapshotId.collectAsState()641642 SettingsGroup("ENTRIES", fg, top = 0.dp) {643 RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }644 RowLine(fg) {645 Name("Duplicates", fg)646 val done = dedupDone647 if (done != null) {648 ValueText(if (done == 0) "already clean" else "removed $done", com.peachpasswords.ui.theme.peachColors.SyncOk)649 } else {650 val count = dedupCount651 val label = when {652 dedupRunning -> "scanning..."653 count == null -> "scan"654 count == 0 -> "none found"655 else -> "$count found"656 }657 SubtleButton(label, fg) {658 if (count == null || count == 0) vm.scanDuplicates()659 }660 }661 }662 if ((dedupCount ?: 0) > 0 && dedupDone == null) {663 Column(664 Modifier.fillMaxWidth()665 .padding(top = 2.dp, bottom = 8.dp)666 .clip(RoundedCornerShape(8.dp))667 .background(fg.copy(alpha = 0.08f))668 .border(1.dp, fg.copy(alpha = 0.18f), RoundedCornerShape(8.dp))669 .padding(10.dp),670 verticalArrangement = Arrangement.spacedBy(8.dp),671 ) {672 val count = dedupCount ?: 0673 Text(674 "$count duplicate ${if (count == 1) "entry" else "entries"} found. The newest copy of each will be kept; older duplicates will be moved to trash.",675 color = fg.copy(alpha = 0.82f),676 fontFamily = PeachType.Body,677 fontSize = 11.sp,678 lineHeight = 16.sp,679 )680 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {681 SubtleButton("cancel", fg) { vm.cancelDuplicateRemoval() }682 SubtleButton(if (dedupRunning) "removing..." else "remove duplicates", fg) { vm.removeDuplicates() }683 }684 }685 }686 }687688 SettingsGroup("MAINTENANCE", fg) {689 RowLine(fg) {690 Name("Trash auto-delete", fg)691 val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)692 SubtleButton(trashOptions[idx].second, fg) {693 vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)694 }695 }696 RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }697 RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }698 }699700 SettingsGroup("DATA", fg) {701 RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }702 RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }703 RowLine(fg) {704 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }705 SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }706 }707 RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }708 }709710 SettingsGroup("UPDATES", fg) {711 UpdatesRows(fg, onNavigate)712 }713714 SettingsGroup("VAULT HISTORY", fg, initiallyOpen = false) {715 var historyShowAll by remember { mutableStateOf(false) }716 if (history.isEmpty()) {717 Text(718 "No snapshots yet. Peach saves automatically before every change — saves, syncs, and imports.",719 color = fg.copy(alpha = 0.68f),720 fontFamily = PeachType.Body,721 fontSize = 11.sp,722 lineHeight = 16.sp,723 modifier = Modifier.padding(bottom = 6.dp),724 )725 } else {726 Text(727 "Restoring locks your vault. Unlock with the password that encrypted that snapshot to confirm.",728 color = fg.copy(alpha = 0.68f),729 fontFamily = PeachType.Body,730 fontSize = 11.sp,731 lineHeight = 16.sp,732 modifier = Modifier.padding(bottom = 4.dp),733 )734 history.take(if (historyShowAll) history.size else 3).forEach { snap ->735 RowLine(fg) {736 Column(Modifier.weight(1f)) {737 Text(snapshotTimeLabel(snap.savedAt), color = fg, fontFamily = PeachType.Body, fontSize = 12.sp)738 Text(snapshotSubLabel(snap), color = fg.copy(alpha = 0.62f), fontFamily = PeachType.Mono, fontSize = 10.sp)739 }740 SubtleButton(if (restoringSnapshotId == snap.id) "..." else "restore", fg) {741 vm.restoreVaultSnapshot(snap.id)742 }743 }744 }745 if (history.size > 3) {746 RowLine(fg) {747 Name(if (historyShowAll) "show less" else "${history.size - 3} older", fg)748 SubtleButton(if (historyShowAll) "hide" else "show", fg) { historyShowAll = !historyShowAll }749 }750 }751 Text(752 "${history.size} of 5 snapshots",753 color = fg.copy(alpha = 0.58f),754 fontFamily = PeachType.Mono,755 fontSize = 10.sp,756 modifier = Modifier.padding(top = 2.dp, bottom = 6.dp),757 )758 }759 }760761 SettingsGroup("ADVANCED", fg, initiallyOpen = false) {762 RowLine(fg) {763 Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)764 SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }765 }766 RowLine(fg) {767 Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)768 SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }769 }770 }771}772773private fun snapshotSubLabel(snapshot: VaultSnapshot): String {774 val count = snapshot.entryCount?.let { "up to $it ${if (it == 1) "entry" else "entries"}" }775 return listOfNotNull(count, snapshotReasonLabel(snapshot.reason)).joinToString(" · ")776}777778private fun snapshotReasonLabel(reason: String): String = when (reason) {779 "local_save" -> "saved"780 "sync_received" -> "synced"781 "import" -> "imported"782 "restore" -> "restored"783 else -> reason784}785786private fun snapshotTimeLabel(savedAt: Long): String {787 val diff = System.currentTimeMillis() - savedAt788 if (diff < 60_000) return "Just now"789 if (diff < 3_600_000) return "${diff / 60_000}m ago"790 val date = Date(savedAt)791 val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())792 val thenDay = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(date)793 val time = SimpleDateFormat("h:mm a", Locale.getDefault()).format(date)794 if (today == thenDay) return "Today $time"795 val yesterday = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date(System.currentTimeMillis() - 86_400_000))796 if (yesterday == thenDay) return "Yesterday $time"797 return SimpleDateFormat("MMM d h:mm a", Locale.getDefault()).format(date)798}799800801802@Composable803private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {804 val context = LocalContext.current805 val syncVm: SyncViewModel = hiltViewModel()806 val pairedDevices by syncVm.pairedDevices.collectAsState()807 val pendingVouched by syncVm.pendingVouched.collectAsState()808 val syncStatus by syncVm.status.collectAsState()809 val configuredRelayUrl by syncVm.privateRelayUrl.collectAsState()810 val syncMode by syncVm.syncMode.collectAsState()811 val backgroundSyncEnabled by syncVm.backgroundSyncEnabled.collectAsState()812 var notificationsAvailable by remember {813 mutableStateOf(canShowBackgroundSyncNotification(context))814 }815 var showBackgroundSyncPrompt by remember { mutableStateOf(false) }816 val scope = rememberCoroutineScope()817 var confirmUnpair by remember { mutableStateOf<String?>(null) }818 var rotateConfirmOpen by remember { mutableStateOf(false) }819 var rotating by remember { mutableStateOf(false) }820 var rotateError by remember { mutableStateOf<String?>(null) }821 var relayUrlDraft by remember(configuredRelayUrl) {822 mutableStateOf(privateRelayDraftOf(configuredRelayUrl))823 }824 var relayUrlStatus by remember { mutableStateOf<String?>(null) }825 var showConnection by remember { mutableStateOf(false) }826 var showRecovery by remember { mutableStateOf(false) }827828 SubLabel("ADD A DEVICE", fg, top = 0.dp)829 RowLine(fg) {830 Column(Modifier.weight(1f)) {831 Text("Pair a device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)832 Text(833 "Either scan a QR shown on the other device, or show this device's QR for the other one to scan.",834 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,835 modifier = Modifier.padding(top = 2.dp),836 )837 }838 839 840 841 842 SubtleButton("scan", fg) { onNavigate(PeachNav.AdoptVault) }843 Spacer(Modifier.width(PeachSpacing.xs))844 SubtleButton("show code", fg) { onNavigate(PeachNav.CodePair) }845 }846847 SubLabel("SYNC STATUS", fg)848 val indicator = syncIndicator(syncStatus, pairedDevices.size)849 RowLine(fg) {850 SyncIndicatorDot(851 indicator = indicator,852 label = syncIndicatorLabel(indicator, syncStatus),853 modifier = Modifier.padding(end = PeachSpacing.sm),854 size = 8.dp,855 )856 Text(857 describeSyncOutcome(syncStatus),858 color = fg.copy(alpha = 0.7f),859 fontFamily = PeachType.Body,860 fontSize = 11.sp,861 lineHeight = 16.sp,862 modifier = Modifier.weight(1f),863 )864 SubtleButton(if (syncStatus.syncing) "syncing..." else "sync now", fg) {865 if (!syncStatus.syncing) syncVm.syncNow()866 }867 }868869 SubLabel("PAIRED DEVICES", fg)870 if (pairedDevices.isEmpty()) {871 PeachEmptyOrEndState(872 message = "No paired devices yet.",873 detail = "Pair a nearby phone, tablet, or browser when you're ready to sync.",874 modifier = Modifier.padding(top = PeachSpacing.xs),875 )876 } else {877 pairedDevices.forEach { d ->878 RowLine(fg) {879 Column(Modifier.weight(1f)) {880 Text(d.deviceName ?: d.deviceId, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)881 Text(882 "${deviceTypeLabel(d.deviceType)} · ${syncTimeLabel(d.lastSyncedAt)}${if (isSyncStale(d.lastSyncedAt)) " · not seen recently" else ""}",883 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,884 modifier = Modifier.padding(top = 2.dp),885 )886 }887 if (confirmUnpair != d.deviceId) {888 SubtleButton("remove", fg) { confirmUnpair = d.deviceId }889 }890 }891 892 893 894 895 896 if (confirmUnpair == d.deviceId) {897 Column(Modifier.fillMaxWidth().padding(bottom = PeachSpacing.sm)) {898 Text(899 "Stops this device receiving future changes. It doesn't lock it " +900 "out of what it already has - if it's lost or stolen, also " +901 "change your master password and generate new recovery words.",902 color = fg.copy(alpha = 0.7f),903 fontFamily = PeachType.Body,904 fontSize = 11.sp,905 lineHeight = 16.sp,906 )907 Row(908 modifier = Modifier.fillMaxWidth().padding(top = PeachSpacing.sm),909 horizontalArrangement = Arrangement.End,910 ) {911 SubtleButton("cancel", fg) { confirmUnpair = null }912 Spacer(Modifier.width(PeachSpacing.sm))913 SubtleButton("remove", peachColors.Breach) { syncVm.unpairDevice(d.deviceId); confirmUnpair = null }914 }915 }916 }917 }918 }919920 SyncDisclosure(921 title = "Connection",922 summary = "Background sync, relay, and privacy choices",923 expanded = showConnection,924 fg = fg,925 onToggle = { showConnection = !showConnection },926 )927 if (showConnection) {928 RowLine(fg) {929 Column(Modifier.weight(1f)) {930 Text("Background sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)931 Text(932 when {933 backgroundSyncEnabled && !notificationsAvailable ->934 "Action needed — Android notifications are off, so background sync is not visible."935 backgroundSyncEnabled ->936 "On — keeps this phone reachable for paired devices."937 else ->938 "Off — Peach syncs only while you are using the app."939 },940 color = fg.copy(alpha = 0.7f),941 fontFamily = PeachType.Body,942 fontSize = 11.sp,943 lineHeight = 16.sp,944 modifier = Modifier.padding(top = 2.dp),945 )946 }947 SubtleButton(948 if (backgroundSyncEnabled && !notificationsAvailable) "allow" else "change",949 if (backgroundSyncEnabled && !notificationsAvailable) peachColors.Breach else fg,950 ) { showBackgroundSyncPrompt = true }951 }952 SyncModeRow(953 title = "Public relay",954 detail = "Works anywhere with nothing to set up. The relay cannot read your vault.",955 selected = syncMode == SyncMode.PUBLIC,956 fg = fg,957 ) { syncVm.setSyncMode(SyncMode.PUBLIC) }958 SyncModeRow(959 title = "Private relay",960 detail = "Use your own peach-relay on your own domain.",961 selected = syncMode == SyncMode.PRIVATE,962 fg = fg,963 ) { syncVm.setSyncMode(SyncMode.PRIVATE) }964965 if (syncMode == SyncMode.PRIVATE) {966 Text(967 "RELAY URL",968 color = fg.copy(alpha = 0.6f),969 fontFamily = PeachType.Mono,970 fontSize = 8.sp,971 letterSpacing = 0.22.em,972 modifier = Modifier.padding(top = 8.dp),973 )974 Box(975 Modifier.fillMaxWidth().padding(top = 6.dp)976 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))977 .padding(horizontal = 12.dp, vertical = 10.dp),978 ) {979 BasicTextField(980 value = relayUrlDraft,981 onValueChange = { relayUrlDraft = it; relayUrlStatus = null },982 singleLine = true,983 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 11.sp, color = fg),984 cursorBrush = SolidColor(fg),985 modifier = Modifier.fillMaxWidth(),986 )987 }988 val needsRelayUrl = configuredRelayUrl.isEmpty()989 RowLine(fg) {990 val message = relayUrlStatus991 ?: if (needsRelayUrl) {992 "Sync is paused until you enter your relay URL."993 } else {994 "Only secure wss:// relays are accepted."995 }996 val warn = relayUrlStatus?.startsWith("Use") == true ||997 (relayUrlStatus == null && needsRelayUrl)998 ValueText(message, if (warn) peachColors.Breach else fg)999 SubtleButton("save", fg) {1000 relayUrlStatus = if (syncVm.setRelayUrl(relayUrlDraft)) {1001 relayUrlDraft = privateRelayDraftOf(syncVm.privateRelayUrl.value)1002 "Saved"1003 } else {1004 "Use a valid wss:// relay URL"1005 }1006 }1007 }1008 }10091010 SyncModeRow(1011 title = "No sync",1012 detail = "Keep this device separate and move backups by hand.",1013 selected = syncMode == SyncMode.OFF,1014 fg = fg,1015 ) { syncVm.setSyncMode(SyncMode.OFF) }1016 Hint("Pairing authorizes a device, not a cloud account.", fg)1017 }10181019 if (pendingVouched.isNotEmpty()) {1020 SubLabel("PENDING DEVICES", fg)1021 pendingVouched.forEach { dev ->1022 RowLine(fg) {1023 Column(Modifier.weight(1f)) {1024 Text(dev.deviceName, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1025 Text(1026 "Was added by another device. Allow it to sync?",1027 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1028 modifier = Modifier.padding(top = 2.dp),1029 )1030 }1031 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {1032 SubtleButton("Allow", fg) { syncVm.confirmVouchedDevice(dev.deviceId) }1033 SubtleButton("Reject", fg) { syncVm.rejectVouchedDevice(dev.deviceId) }1034 }1035 }1036 }1037 }10381039 SyncDisclosure(1040 title = "Recovery & security",1041 summary = "For a lost or stolen device",1042 expanded = showRecovery,1043 fg = fg,1044 onToggle = { showRecovery = !showRecovery },1045 )1046 if (showRecovery) {1047 RowLine(fg) {1048 Column(Modifier.weight(1f)) {1049 Text("Re-pair this device", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1050 Text(1051 "Scan only when this populated vault previously trusted the source device.",1052 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1053 modifier = Modifier.padding(top = 2.dp),1054 )1055 }1056 SubtleButton("scan", fg) { onNavigate(PeachNav.AdoptVault) }1057 }1058 if (rotateConfirmOpen) {1059 Hint("This disconnects every paired device and changes your 12 recovery words. You'll be shown the new words next.", peachColors.Breach)1060 rotateError?.let {1061 Text(it, color = peachColors.Breach, fontFamily = PeachType.Body, fontSize = 11.sp, modifier = Modifier.padding(top = 6.dp))1062 }1063 Row(Modifier.padding(top = 10.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {1064 SubtleButton("cancel", fg) { if (!rotating) rotateConfirmOpen = false }1065 SubtleButton(if (rotating) "rotating..." else "Rotate sync identity", peachColors.Breach) {1066 if (rotating) return@SubtleButton1067 rotating = true1068 rotateError = null1069 scope.launch {1070 val ok = syncVm.rotateSyncIdentity()1071 rotating = false1072 if (ok) {1073 rotateConfirmOpen = false1074 onNavigate(PeachNav.RecoverySetup)1075 } else {1076 rotateError = "Rotation failed. Unlock your real vault and try again."1077 }1078 }1079 }1080 }1081 } else {1082 RowLine(fg) {1083 Column(Modifier.weight(1f)) {1084 Text("Rotate sync identity", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1085 Text(1086 "Disconnects every device and replaces the keys used for sync.",1087 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,1088 modifier = Modifier.padding(top = 2.dp),1089 )1090 }1091 SubtleButton("rotate", peachColors.Breach) { rotateError = null; rotateConfirmOpen = true }1092 }1093 }1094 }10951096 if (showBackgroundSyncPrompt) {1097 BackgroundSyncDialog { enabled ->1098 showBackgroundSyncPrompt = false1099 notificationsAvailable = canShowBackgroundSyncNotification(context)1100 syncVm.setBackgroundSyncEnabled(enabled)1101 }1102 }1103}11041105private fun deviceTypeLabel(type: String?): String = when (type) {1106 "android" -> "Android"1107 "phone" -> "Phone"1108 "tablet" -> "Tablet"1109 "browser" -> "Browser"1110 else -> "Device"1111}11121113private fun syncTimeLabel(lastSyncedAt: Long?): String {1114 if (lastSyncedAt == null) return "never synced"1115 val diff = System.currentTimeMillis() - lastSyncedAt1116 if (diff < 60_000) return "just now"1117 if (diff < 3_600_000) return "${diff / 60_000}m ago"1118 if (diff < 86_400_000) return "${diff / 3_600_000}h ago"1119 return "${diff / 86_400_000}d ago"1120}11211122private fun isSyncStale(lastSyncedAt: Long?): Boolean =1123 lastSyncedAt != null && System.currentTimeMillis() - lastSyncedAt > 7L * 24L * 60L * 60L * 1000L1124112511261127@Composable1128private fun ProBody(fg: Color, vm: SettingsViewModel) {1129 val ctx = LocalContext.current1130 val isPro by vm.isPro.collectAsState()1131 if (isPro) {1132 ProActiveBody(fg, vm)1133 return1134 }1135 val features = listOf(1136 "Peach Sync" to "End-to-end encrypted",1137 "Peach Codex" to "Restore from paper",1138 "Passkeys" to "Zero-knowledge WebAuthn",1139 "Advanced Vault Health" to "Reuse · age · exposure",1140 "Canary entries" to "Detects vault compromise",1141 "Duress vault" to "Decoy under coercion",1142 )1143 Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1144 Text(1145 "Everything, everywhere.",1146 modifier = Modifier.padding(top = 8.dp),1147 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,1148 )1149 Text(1150 "One key unlocks every Pro feature — for the lifetime of the app.",1151 modifier = Modifier.padding(top = 6.dp),1152 color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,1153 )1154 Spacer(Modifier.height(10.dp))1155 features.forEachIndexed { i, (name, desc) ->1156 1157 1158 1159 1160 RowLine(fg, verticalPadding = 6.dp) {1161 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1162 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))1163 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1164 }1165 Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1166 }1167 }1168 Spacer(Modifier.height(12.dp))1169 Text(1170 "$39",1171 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,1172 )1173 Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)1174 Spacer(Modifier.height(10.dp))1175 Box(1176 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1177 .background(fg.copy(alpha = 0.16f))1178 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1179 .clickable {1180 runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }1181 }1182 .padding(vertical = 12.dp),1183 contentAlignment = Alignment.Center,1184 ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }11851186 1187 1188 1189 1190 Spacer(Modifier.height(44.dp))11911192 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1193 var key by remember { mutableStateOf("") }1194 val activating by vm.activating.collectAsState()1195 val activationError by vm.activationError.collectAsState()1196 Box(1197 Modifier.fillMaxWidth().padding(top = 6.dp)1198 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))1199 .padding(horizontal = 12.dp, vertical = 10.dp),1200 ) {1201 BasicTextField(1202 value = key,1203 1204 1205 1206 1207 onValueChange = { key = it; vm.clearActivationError() },1208 singleLine = true,1209 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),1210 cursorBrush = SolidColor(fg),1211 modifier = Modifier.fillMaxWidth(),1212 decorationBox = { inner ->1213 if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)1214 inner()1215 },1216 )1217 }1218 if (activationError != null) {1219 Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))1220 }1221 Spacer(Modifier.height(8.dp))1222 Box(1223 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1224 .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))1225 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1226 .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }1227 .padding(vertical = 12.dp),1228 contentAlignment = Alignment.Center,1229 ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }1230}12311232@Composable1233private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {1234 val ctx = LocalContext.current1235 val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")1236 val licenseKey by vm.licenseKey.collectAsState()1237 val issuedAt by vm.licenseIssuedAt.collectAsState()1238 var showKey by remember { mutableStateOf(false) }1239 var copied by remember { mutableStateOf(false) }1240 val scope = rememberCoroutineScope()1241 Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {1242 com.peachpasswords.ui.components.PeachMark(size = 60.dp)1243 }1244 Text(1245 "Peach Pro",1246 modifier = Modifier.fillMaxWidth(),1247 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,1248 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1249 )1250 Text(1251 formatLicenseActiveSince(issuedAt),1252 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),1253 color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,1254 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1255 )1256 licenseKey?.let { key ->1257 Spacer(Modifier.height(12.dp))1258 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1259 RowLine(fg) {1260 Text(1261 if (showKey) key else "************************",1262 color = fg.copy(alpha = if (showKey) 0.82f else 0.58f),1263 fontFamily = PeachType.Mono,1264 fontSize = 10.sp,1265 modifier = Modifier.weight(1f),1266 )1267 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {1268 SubtleButton(if (copied) "copied" else "copy", fg) {1269 PeachClipboard.copy(ctx, "peach license", key)1270 copied = true1271 scope.launch {1272 delay(1_500)1273 copied = false1274 }1275 }1276 SubtleButton(if (showKey) "hide" else "reveal", fg) { showKey = !showKey }1277 }1278 }1279 }1280 Spacer(Modifier.height(12.dp))1281 features.forEachIndexed { i, name ->1282 RowLine(fg) {1283 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1284 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))1285 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1286 }1287 Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1288 }1289 }1290 Spacer(Modifier.height(12.dp))1291 Box(1292 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1293 .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1294 .clickable { vm.deactivate() }1295 .padding(vertical = 12.dp),1296 contentAlignment = Alignment.Center,1297 ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }1298}12991300private fun formatLicenseActiveSince(issuedAt: Long?): String {1301 if (issuedAt == null) return "Active"1302 val monthYear = SimpleDateFormat("MMMM yyyy", Locale.getDefault()).format(Date(issuedAt))1303 return "Active since $monthYear"1304}1305130613071308@OptIn(ExperimentalLayoutApi::class)1309@Composable1310private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {1311 val categories = listOf("Bug report", "Feature request", "Question", "Other")1312 var category by remember { mutableStateOf(categories[0]) }1313 var message by remember { mutableStateOf("") }1314 val state by vm.feedbackState.collectAsState()13151316 1317 DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }13181319 if (state is FeedbackState.Sent) {1320 Box(1321 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))1322 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),1323 ) {1324 Column {1325 Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)1326 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))1327 }1328 }1329 return1330 }13311332 val sending = state is FeedbackState.Sending13331334 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)1335 SubLabel("TYPE", fg)1336 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1337 categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }1338 }1339 SubLabel("MESSAGE", fg)1340 Box(1341 Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))1342 .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))1343 .padding(10.dp),1344 ) {1345 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)1346 BasicTextField(1347 value = message, onValueChange = { message = it.take(MAX_FEEDBACK_MESSAGE_LENGTH) },1348 enabled = !sending,1349 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),1350 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),1351 )1352 }1353 Text(1354 "Version ${BuildConfig.VERSION_NAME} · will be included automatically",1355 modifier = Modifier.padding(top = 6.dp),1356 color = fg.copy(alpha = 0.52f),1357 fontFamily = PeachType.Mono,1358 fontSize = 10.sp,1359 lineHeight = 14.sp,1360 )1361 Spacer(Modifier.height(8.dp))13621363 Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {1364 val canSend = !sending && sanitizeFeedbackMessage(message).isNotBlank()1365 Box(1366 Modifier.clip(RoundedCornerShape(8.dp))1367 .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))1368 .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))1369 .clickable(enabled = canSend) { vm.sendFeedback(category, message) }1370 .padding(horizontal = 12.dp, vertical = 6.dp),1371 ) {1372 Text(1373 feedbackSubmitLabel(state),1374 color = fg.copy(alpha = if (canSend) 1f else 0.4f),1375 fontFamily = PeachType.Mono, fontSize = 11.sp,1376 )1377 }1378 if (sending) {1379 CircularProgressIndicator(1380 color = LocalPeachAccent.current,1381 strokeWidth = 2.dp,1382 modifier = Modifier.size(16.dp),1383 )1384 }1385 }13861387 (state as? FeedbackState.Error)?.let { err ->1388 Text(1389 err.message,1390 modifier = Modifier.padding(top = 8.dp),1391 color = peachColors.Breach,1392 fontFamily = PeachType.Mono,1393 fontSize = 11.sp,1394 lineHeight = 15.sp,1395 )1396 }13971398 Hint("Sent anonymously · no account required", fg)1399}1400140114021403@Composable1404internal fun DuressSection(fg: Color, vm: SettingsViewModel) {1405 val configured by vm.duressConfigured.collectAsState()1406 if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)1407}14081409@Composable1410private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {1411 Text(1412 "Duress password is active",1413 color = peachColors.HealthOk,1414 fontFamily = PeachType.Mono,1415 fontSize = 11.sp,1416 modifier = Modifier.padding(top = 6.dp),1417 )1418 Spacer(Modifier.height(8.dp))1419 DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }1420 Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)1421}14221423@Composable1424private fun DuressForm(fg: Color, vm: SettingsViewModel) {1425 var enabled by remember { mutableStateOf(false) }1426 var password by remember { mutableStateOf("") }1427 var confirm by remember { mutableStateOf("") }1428 var action by remember { mutableStateOf(DuressAction.DECOY) }1429 var error by remember { mutableStateOf<String?>(null) }1430 val scope = rememberCoroutineScope()14311432 RowLine(fg) {1433 Name("Duress password", fg)1434 Toggle(enabled, fg) { on ->1435 enabled = on1436 if (!on) { password = ""; confirm = ""; error = null }1437 }1438 }1439 Text(1440 "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",1441 color = fg.copy(alpha = 0.7f),1442 fontFamily = PeachType.Mono,1443 fontSize = 10.sp,1444 modifier = Modifier.padding(top = 6.dp),1445 )14461447 AnimatedVisibility(enabled) {1448 Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1449 PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }1450 PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }14511452 Text(1453 "When your duress password is entered at the lock screen, Peach will:",1454 color = fg.copy(alpha = 0.7f),1455 fontFamily = PeachType.Mono,1456 fontSize = 10.sp,1457 modifier = Modifier.padding(top = 4.dp),1458 )14591460 DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }1461 DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }14621463 error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }14641465 val canSave = password.isNotBlank() && confirm.isNotBlank()1466 DuressSaveButton("Save duress password", fg, canSave) {1467 error = when {1468 password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"1469 password != confirm -> "Passwords do not match"1470 else -> null1471 }1472 if (error == null) scope.launch {1473 if (vm.saveDuress(password, action)) {1474 password = ""; confirm = ""; enabled = false1475 } else {1476 error = "Couldn't save — the duress passphrase must differ from your real password"1477 }1478 }1479 }1480 }1481 }1482}14831484@Composable1485private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {1486 val accent = LocalPeachAccent.current1487 Row(1488 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),1489 verticalAlignment = Alignment.CenterVertically,1490 horizontalArrangement = Arrangement.spacedBy(10.dp),1491 ) {1492 Box(1493 Modifier.size(16.dp).clip(CircleShape)1494 .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),1495 contentAlignment = Alignment.Center,1496 ) {1497 if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))1498 }1499 Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)1500 }1501}15021503@Composable1504private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {1505 val accent = LocalPeachAccent.current1506 val tint = if (enabled) accent else fg.copy(alpha = 0.3f)1507 Box(1508 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1509 .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))1510 .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))1511 .let { if (enabled) it.clickable(onClick = onClick) else it }1512 .padding(vertical = 11.dp),1513 contentAlignment = Alignment.Center,1514 ) {1515 Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)1516 }1517}15181519@Composable1520private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {1521 Box(1522 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1523 .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))1524 .clickable(onClick = onClick)1525 .padding(vertical = 11.dp),1526 contentAlignment = Alignment.Center,1527 ) {1528 Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)1529 }1530}153115321533@Composable1534private fun SyncModeRow(1535 title: String,1536 detail: String,1537 selected: Boolean,1538 fg: Color,1539 onSelect: () -> Unit,1540) {1541 RowLine(fg, Modifier.clickable(onClick = onSelect)) {1542 Column(Modifier.weight(1f)) {1543 Text(title, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1544 Text(1545 detail,1546 color = fg.copy(alpha = 0.7f),1547 fontFamily = PeachType.Body,1548 fontSize = 11.sp,1549 lineHeight = 16.sp,1550 modifier = Modifier.padding(top = 2.dp),1551 )1552 }1553 Text(1554 if (selected) "●" else "○",1555 color = if (selected) fg else fg.copy(alpha = 0.45f),1556 fontFamily = PeachType.Mono,1557 fontSize = 14.sp,1558 modifier = Modifier.padding(start = 10.dp),1559 )1560 }1561}