1package com.peachpasswords.ui.settings23import android.content.Intent4import android.net.Uri5import androidx.compose.animation.AnimatedVisibility6import androidx.compose.animation.core.animateDpAsState7import androidx.compose.foundation.background8import androidx.compose.foundation.border9import androidx.compose.foundation.clickable10import androidx.compose.foundation.layout.Arrangement11import androidx.compose.foundation.layout.Box12import androidx.compose.foundation.layout.Column13import androidx.compose.foundation.layout.FlowRow14import androidx.compose.foundation.layout.ExperimentalLayoutApi15import androidx.compose.foundation.layout.Row16import androidx.compose.foundation.layout.RowScope17import androidx.compose.foundation.layout.Spacer18import androidx.compose.foundation.layout.fillMaxWidth19import androidx.compose.foundation.layout.height20import androidx.compose.foundation.layout.padding21import androidx.compose.foundation.layout.size22import androidx.compose.foundation.layout.width23import androidx.compose.foundation.shape.CircleShape24import androidx.compose.foundation.shape.RoundedCornerShape25import androidx.compose.foundation.text.BasicTextField26import androidx.compose.runtime.Composable27import androidx.compose.material3.CircularProgressIndicator28import androidx.compose.runtime.DisposableEffect29import androidx.compose.runtime.collectAsState30import androidx.compose.runtime.getValue31import com.peachpasswords.feedback.FeedbackState32import com.peachpasswords.shared.PeachClipboard33import com.peachpasswords.sync.SyncMode34import com.peachpasswords.sync.SyncStatus35import com.peachpasswords.ui.theme.LocalPeachAccent36import com.peachpasswords.vault.DuressAction37import com.peachpasswords.ui.theme.peachColors38import androidx.compose.runtime.mutableStateOf39import androidx.compose.runtime.remember40import androidx.compose.runtime.rememberCoroutineScope41import androidx.compose.runtime.setValue42import androidx.compose.ui.Alignment43import androidx.compose.ui.Modifier44import androidx.compose.ui.draw.clip45import androidx.compose.ui.graphics.Color46import androidx.compose.ui.graphics.SolidColor47import androidx.compose.ui.platform.LocalContext48import androidx.compose.ui.text.TextStyle49import androidx.compose.ui.text.font.FontStyle50import androidx.compose.ui.text.input.PasswordVisualTransformation51import androidx.compose.ui.unit.Dp52import androidx.compose.ui.unit.dp53import androidx.compose.ui.unit.em54import androidx.compose.ui.unit.sp55import androidx.compose.material3.Text56import com.peachpasswords.BuildConfig57import com.peachpasswords.autofill.AutofillEnablement58import com.peachpasswords.ui.PeachNav59import com.peachpasswords.ui.components.PeachEmptyOrEndState60import com.peachpasswords.ui.components.PeachField61import com.peachpasswords.ui.sync.SyncViewModel62import com.peachpasswords.ui.theme.ACCENT_COLORS63import com.peachpasswords.ui.theme.PeachSpacing64import com.peachpasswords.ui.theme.PeachType65import com.peachpasswords.ui.updates.UpdatePhase66import com.peachpasswords.ui.updates.UpdateViewModel67import androidx.hilt.navigation.compose.hiltViewModel68import com.peachpasswords.vault.VaultSettings69import com.peachpasswords.vault.VaultSnapshot70import kotlinx.coroutines.launch71import kotlinx.coroutines.delay72import java.text.SimpleDateFormat73import java.util.Date74import java.util.Locale7576private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz"777879808182838485@Composable86fun CardBody(87 id: CardId,88 fg: Color,89 vm: SettingsViewModel,90 settings: VaultSettings,91 entriesCount: Int,92 onNavigate: (PeachNav) -> Unit,93) {94 when (id) {95 CardId.Appearance -> AppearanceBody(fg, vm, settings)96 CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)97 CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)98 CardId.Sync -> SyncBody(fg, onNavigate)99 CardId.Shortcuts -> ShortcutsBody(fg)100 CardId.Pro -> ProBody(fg, vm)101 CardId.Feedback -> {102 103 104 AboutUpdatesBody(fg, onNavigate)105 FeedbackBody(fg, vm)106 }107 }108}109110111112@Composable113private fun AboutUpdatesBody(fg: Color, onNavigate: (PeachNav) -> Unit) {114 val vm: UpdateViewModel = hiltViewModel()115 val available by vm.available.collectAsState()116 val state by vm.state.collectAsState()117118 SubLabel("THIS BUILD", fg, top = 0.dp)119 RowLine(fg) {120 Name("Version", fg)121 ValueText(BuildConfig.VERSION_NAME, fg)122 }123 RowLine(fg) {124 Column(Modifier.weight(1f)) {125 Text("Updates", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)126 Text(127 when {128 available != null -> "v${available?.version} is available"129 state.phase == UpdatePhase.Checking -> "Checking…"130 state.phase == UpdatePhase.UpToDate -> "You're on the latest version"131 state.phase == UpdatePhase.Failed -> "Couldn't reach the update server"132 else -> "Peach checks once a day and tells you when there's a new version."133 },134 color = fg.copy(alpha = 0.7f),135 fontFamily = PeachType.Body,136 fontSize = 11.sp,137 lineHeight = 16.sp,138 modifier = Modifier.padding(top = 2.dp),139 )140 }141 if (available != null) {142 SubtleButton("update", fg) { onNavigate(PeachNav.Update) }143 } else {144 SubtleButton(if (state.phase == UpdatePhase.Checking) "checking" else "check now", fg) {145 vm.check()146 }147 }148 }149}150151152153@Composable154private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) {155 Text(156 text,157 modifier = Modifier.padding(top = top, bottom = 4.dp),158 color = fg.copy(alpha = 0.58f),159 fontFamily = PeachType.Mono,160 fontSize = 8.sp,161 letterSpacing = 0.22.em,162 )163}164165@Composable166private fun RowLine(167 fg: Color,168 modifier: Modifier = Modifier,169 verticalPadding: Dp = 9.dp,170 content: @Composable RowScope.() -> Unit,171) {172 Row(173 Modifier.fillMaxWidth().then(modifier).padding(vertical = verticalPadding),174 verticalAlignment = Alignment.CenterVertically,175 horizontalArrangement = Arrangement.SpaceBetween,176 content = content,177 )178 Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f)))179}180181@Composable182private fun RowScope.Name(text: String, fg: Color) {183 Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f))184}185186@Composable187private fun ValueText(text: String, fg: Color) {188 Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp)189}190191@Composable192private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) {193 Box(194 Modifier.clip(RoundedCornerShape(8.dp))195 .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp))196 .background(fg.copy(alpha = 0.08f))197 .clickable(onClick = onClick)198 .padding(horizontal = 12.dp, vertical = 6.dp),199 ) {200 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)201 }202}203204@Composable205private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) {206 val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob")207 Box(208 Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp))209 .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f))210 .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp))211 .clickable { onToggle(!on) },212 ) {213 Box(214 Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp)215 .padding(start = knob - 2.dp)216 .size(14.dp).clip(CircleShape)217 .background(if (on) fg else fg.copy(alpha = 0.58f)),218 )219 }220}221222@Composable223private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) {224 Box(225 Modifier.clip(RoundedCornerShape(999.dp))226 .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp))227 .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent)228 .clickable(onClick = onClick)229 .padding(horizontal = 12.dp, vertical = 5.dp),230 ) {231 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)232 }233}234235@Composable236private fun ProBadge(fg: Color) {237 Box(238 Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp))239 .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp),240 ) {241 Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp)242 }243}244245@Composable246private fun Hint(text: String, fg: Color) {247 Text(248 text,249 modifier = Modifier.padding(top = 6.dp),250 color = fg.copy(alpha = 0.6f),251 fontFamily = PeachType.Display,252 fontStyle = FontStyle.Italic,253 fontSize = 11.5.sp,254 lineHeight = 16.sp,255 )256}257258259260@OptIn(ExperimentalLayoutApi::class)261@Composable262private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {263 SubLabel("THEME", fg, top = 0.dp)264 RowLine(fg) {265 Name("Theme", fg)266 val (label, next) = when (s.theme) {267 "dark" -> "Switch to light" to "light"268 else -> "Switch to dark" to "dark"269 }270 SubtleButton(label, fg) { vm.setTheme(next) }271 }272 SubLabel("ACCENT", fg)273 FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {274 ACCENT_COLORS.forEach { (name, color) ->275 Box(276 Modifier.size(22.dp).clip(CircleShape).background(color)277 .border(278 if (s.accentColor == name) 2.dp else 1.dp,279 if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),280 CircleShape,281 )282 .clickable { vm.setAccent(name) },283 )284 }285 }286 SubLabel("TEXT SIZE", fg)287 RowLine(fg) {288 Name("Size", fg)289 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {290 Pill("Default", s.textSize == "medium", fg) { vm.setTextSize("medium") }291 Pill("Large", s.textSize == "large", fg) { vm.setTextSize("large") }292 }293 }294 SubLabel("MOTION", fg)295 RowLine(fg) {296 Name("Reduce motion", fg)297 SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }298 }299}300301302303@Composable304private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {305 val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")306 val current = s.autoLockMinutes ?: 0307308 SubLabel("LOCKING", fg, top = 0.dp)309 RowLine(fg) {310 Name("Auto-lock after", fg)311 val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)312 SubtleButton(lockOptions[idx].second, fg) {313 val next = lockOptions[(idx + 1) % lockOptions.size].first314 vm.setAutoLockMinutes(if (next == 0) 0 else next)315 }316 }317 SubLabel("BIOMETRICS", fg)318 val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity319 RowLine(fg) {320 Name("Unlock with biometrics", fg)321 Toggle(s.biometricsEnabled, fg) { on ->322 if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()323 }324 }325 val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)326 if (bioError != null) {327 Text(328 bioError,329 color = com.peachpasswords.ui.theme.peachColors.Breach,330 fontFamily = PeachType.Mono, fontSize = 10.sp,331 modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),332 )333 }334 SubLabel("AUTOFILL", fg)335 run {336 337 338 val ctx = LocalContext.current339 val enabled = AutofillEnablement.isEnabled(ctx)340 RowLine(fg) {341 Column(Modifier.weight(1f)) {342 Text("Fill passwords in other apps", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)343 Text(344 if (enabled) {345 "Peach is your autofill service."346 } else {347 "Android decides which app fills passwords. Turn Peach on in system settings."348 },349 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,350 modifier = Modifier.padding(top = 2.dp),351 )352 }353 if (!enabled) {354 SubtleButton("enable", fg) {355 356 357 358 runCatching { ctx.startActivity(AutofillEnablement.requestIntent(ctx)) }359 .onFailure { runCatching { ctx.startActivity(AutofillEnablement.fallbackIntent()) } }360 }361 } else {362 ValueText("on", fg)363 }364 }365 }366367 SubLabel("PASSKEYS", fg)368 RowLine(fg) {369 Column(Modifier.weight(1f)) {370 Text("Credential provider", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)371 Text(372 "Peach can handle passkey sign-in and creation through Android Credential Manager.",373 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,374 modifier = Modifier.padding(top = 2.dp),375 )376 }377 Toggle(s.passkeyProviderEnabled, fg) { vm.setPasskeyProviderEnabled(it) }378 }379 RowLine(fg) {380 Name("Status", fg)381 ValueText(if (s.passkeyProviderEnabled) "enabled" else "off", fg)382 }383 SubLabel("RECOVERY", fg)384 RowLine(fg) {385 Column(Modifier.weight(1f)) {386 Text("View recovery words", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)387 Text(388 "Keep the paper copy current before rotating sync identity or replacing devices.",389 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,390 modifier = Modifier.padding(top = 2.dp),391 )392 }393 SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) }394 }395 SubLabel("BREACH PROTECTION", fg)396 val checkingBreaches by vm.checkingBreaches.collectAsState()397 val breachResult by vm.breachResult.collectAsState()398 RowLine(fg) {399 Name("Breach monitoring", fg)400 Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }401 }402 RowLine(fg) {403 Name("Check all passwords", fg)404 SubtleButton(if (checkingBreaches) "checking..." else "run", fg) { vm.checkAllBreaches() }405 }406 breachResult?.let { result ->407 RowLine(fg) {408 Name("Last check", fg)409 ValueText(result, fg)410 }411 }412413 SubLabel("MASTER PASSWORD", fg)414 ChangePasswordRow(fg, vm)415416 SubLabel("DURESS PASSWORD", fg)417 val duressIsPro by vm.isPro.collectAsState()418 if (!duressIsPro) {419 RowLine(fg) {420 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {421 Name("Duress password", fg); ProBadge(fg)422 }423 ValueText("off", fg)424 }425 Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)426 } else {427 DuressSection(fg, vm)428 }429}430431@Composable432private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {433 var open by remember { mutableStateOf(false) }434 var current by remember { mutableStateOf("") }435 var next by remember { mutableStateOf("") }436 var confirm by remember { mutableStateOf("") }437 var error by remember { mutableStateOf<String?>(null) }438 var done by remember { mutableStateOf(false) }439 val scope = rememberCoroutineScope()440441 RowLine(fg) {442 Name("Master password", fg)443 SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }444 }445 AnimatedVisibility(open) {446 Column(Modifier.fillMaxWidth().padding(top = PeachSpacing.sm), verticalArrangement = Arrangement.spacedBy(PeachSpacing.sm)) {447 PwField("current password", current, fg) { current = it }448 PwField("new password (min 12 chars)", next, fg) { next = it }449 PwField("confirm new password", confirm, fg) { confirm = it }450 error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }451 if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)452 SubtleButton("save new password", fg) {453 error = when {454 current.isBlank() -> "enter your current password"455 next.length < 12 -> "new password must be at least 12 characters"456 next != confirm -> "new passwords do not match"457 next == current -> "new password must differ from current"458 else -> null459 }460 if (error == null) scope.launch {461 if (vm.changePassword(current, next)) {462 current = ""; next = ""; confirm = ""; open = false; done = true463 } else error = "incorrect current password"464 }465 }466 }467 }468}469470@Composable471private fun PwField(placeholder: String, value: String, @Suppress("UNUSED_PARAMETER") fg: Color, onChange: (String) -> Unit) {472 PeachField(473 label = placeholder,474 value = value,475 onValueChange = onChange,476 keyboardType = androidx.compose.ui.text.input.KeyboardType.Password,477 visualTransformation = PasswordVisualTransformation(),478 )479}480481482483@Composable484private fun VaultBody(485 fg: Color,486 vm: SettingsViewModel,487 s: VaultSettings,488 entriesCount: Int,489 onNavigate: (PeachNav) -> Unit,490) {491 val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")492 val current = s.trashRetentionDays ?: 0493 val isPro by vm.isPro.collectAsState()494 val dedupCount by vm.dedupCount.collectAsState()495 val dedupRunning by vm.dedupRunning.collectAsState()496 val dedupDone by vm.dedupDone.collectAsState()497 val history by vm.vaultHistory.collectAsState()498 val restoringSnapshotId by vm.restoringSnapshotId.collectAsState()499500 SubLabel("ENTRIES", fg, top = 0.dp)501 RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }502 RowLine(fg) {503 Name("Duplicates", fg)504 val done = dedupDone505 if (done != null) {506 ValueText(if (done == 0) "already clean" else "removed $done", com.peachpasswords.ui.theme.peachColors.SyncOk)507 } else {508 val count = dedupCount509 val label = when {510 dedupRunning -> "scanning..."511 count == null -> "scan"512 count == 0 -> "none found"513 else -> "$count found"514 }515 SubtleButton(label, fg) {516 if (count == null || count == 0) vm.scanDuplicates()517 }518 }519 }520 if ((dedupCount ?: 0) > 0 && dedupDone == null) {521 Column(522 Modifier.fillMaxWidth()523 .padding(top = 2.dp, bottom = 8.dp)524 .clip(RoundedCornerShape(8.dp))525 .background(fg.copy(alpha = 0.08f))526 .border(1.dp, fg.copy(alpha = 0.18f), RoundedCornerShape(8.dp))527 .padding(10.dp),528 verticalArrangement = Arrangement.spacedBy(8.dp),529 ) {530 val count = dedupCount ?: 0531 Text(532 "$count duplicate ${if (count == 1) "entry" else "entries"} found. The newest copy of each will be kept; older duplicates will be moved to trash.",533 color = fg.copy(alpha = 0.82f),534 fontFamily = PeachType.Body,535 fontSize = 11.sp,536 lineHeight = 16.sp,537 )538 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {539 SubtleButton("cancel", fg) { vm.cancelDuplicateRemoval() }540 SubtleButton(if (dedupRunning) "removing..." else "remove duplicates", fg) { vm.removeDuplicates() }541 }542 }543 }544545 SubLabel("MAINTENANCE", fg)546 RowLine(fg) {547 Name("Trash auto-delete", fg)548 val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)549 SubtleButton(trashOptions[idx].second, fg) {550 vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)551 }552 }553 RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }554 RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }555556 SubLabel("DATA", fg)557 RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }558 RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }559 RowLine(fg) {560 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }561 SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }562 }563 RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }564565 var historyShowAll by remember { mutableStateOf(false) }566 SubLabel("VAULT HISTORY", fg)567 if (history.isEmpty()) {568 Text(569 "No snapshots yet. Peach saves automatically before every change — saves, syncs, and imports.",570 color = fg.copy(alpha = 0.68f),571 fontFamily = PeachType.Body,572 fontSize = 11.sp,573 lineHeight = 16.sp,574 modifier = Modifier.padding(bottom = 6.dp),575 )576 } else {577 Text(578 "Restoring locks your vault. Unlock with the password that encrypted that snapshot to confirm.",579 color = fg.copy(alpha = 0.68f),580 fontFamily = PeachType.Body,581 fontSize = 11.sp,582 lineHeight = 16.sp,583 modifier = Modifier.padding(bottom = 4.dp),584 )585 history.take(if (historyShowAll) history.size else 3).forEach { snap ->586 RowLine(fg) {587 Column(Modifier.weight(1f)) {588 Text(snapshotTimeLabel(snap.savedAt), color = fg, fontFamily = PeachType.Body, fontSize = 12.sp)589 Text(snapshotSubLabel(snap), color = fg.copy(alpha = 0.62f), fontFamily = PeachType.Mono, fontSize = 10.sp)590 }591 SubtleButton(if (restoringSnapshotId == snap.id) "..." else "restore", fg) {592 vm.restoreVaultSnapshot(snap.id)593 }594 }595 }596 if (history.size > 3) {597 RowLine(fg) {598 Name(if (historyShowAll) "show less" else "${history.size - 3} older", fg)599 SubtleButton(if (historyShowAll) "hide" else "show", fg) { historyShowAll = !historyShowAll }600 }601 }602 Text(603 "${history.size} of 5 snapshots",604 color = fg.copy(alpha = 0.58f),605 fontFamily = PeachType.Mono,606 fontSize = 10.sp,607 modifier = Modifier.padding(top = 2.dp, bottom = 6.dp),608 )609 }610611 var advancedOpen by remember { mutableStateOf(false) }612 SubLabel("ADVANCED", fg)613 RowLine(fg) {614 Name("Advanced", fg)615 SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }616 }617 if (advancedOpen) {618 RowLine(fg) {619 Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)620 SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }621 }622 RowLine(fg) {623 Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)624 SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }625 }626 }627}628629private fun snapshotSubLabel(snapshot: VaultSnapshot): String {630 val count = snapshot.entryCount?.let { "up to $it ${if (it == 1) "entry" else "entries"}" }631 return listOfNotNull(count, snapshotReasonLabel(snapshot.reason)).joinToString(" · ")632}633634private fun snapshotReasonLabel(reason: String): String = when (reason) {635 "local_save" -> "saved"636 "sync_received" -> "synced"637 "import" -> "imported"638 "restore" -> "restored"639 else -> reason640}641642private fun snapshotTimeLabel(savedAt: Long): String {643 val diff = System.currentTimeMillis() - savedAt644 if (diff < 60_000) return "Just now"645 if (diff < 3_600_000) return "${diff / 60_000}m ago"646 val date = Date(savedAt)647 val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())648 val thenDay = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(date)649 val time = SimpleDateFormat("h:mm a", Locale.getDefault()).format(date)650 if (today == thenDay) return "Today $time"651 val yesterday = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date(System.currentTimeMillis() - 86_400_000))652 if (yesterday == thenDay) return "Yesterday $time"653 return SimpleDateFormat("MMM d h:mm a", Locale.getDefault()).format(date)654}655656657658@Composable659private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {660 val syncVm: SyncViewModel = hiltViewModel()661 val pairedDevices by syncVm.pairedDevices.collectAsState()662 val pendingVouched by syncVm.pendingVouched.collectAsState()663 val syncStatus by syncVm.status.collectAsState()664 val configuredRelayUrl by syncVm.relayUrl.collectAsState()665 val syncMode by syncVm.syncMode.collectAsState()666 val scope = rememberCoroutineScope()667 var confirmUnpair by remember { mutableStateOf<String?>(null) }668 var rotateConfirmOpen by remember { mutableStateOf(false) }669 var rotating by remember { mutableStateOf(false) }670 var rotateError by remember { mutableStateOf<String?>(null) }671 var relayUrlDraft by remember(configuredRelayUrl) { mutableStateOf(configuredRelayUrl) }672 var relayUrlStatus by remember { mutableStateOf<String?>(null) }673674 675 676 677 SubLabel("PAIR A DEVICE", fg, top = 0.dp)678 RowLine(fg) {679 Column(Modifier.weight(1f)) {680 Row(verticalAlignment = Alignment.CenterVertically) {681 Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg)682 }683 Text(684 "End-to-end encrypted, through a relay that can read none of it.",685 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,686 modifier = Modifier.padding(top = 2.dp),687 )688 }689 }690 RowLine(fg) {691 Column(Modifier.weight(1f)) {692 Text("Show a code", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)693 Text(694 "For the other device to scan. Always use this one to pair a browser.",695 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,696 modifier = Modifier.padding(top = 2.dp),697 )698 }699 SubtleButton("show", fg) { onNavigate(PeachNav.CodePair) }700 }701 RowLine(fg) {702 Column(Modifier.weight(1f)) {703 Text("Scan a code", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)704 Text(705 "Joins that vault. Your entries are kept and the two merge; this phone's " +706 "recovery words are replaced, and shown to you first.",707 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,708 modifier = Modifier.padding(top = 2.dp),709 )710 }711 SubtleButton("scan", fg) { onNavigate(PeachNav.AdoptVault) }712 }713714 SubLabel("PAIRED DEVICES", fg)715 if (pairedDevices.isEmpty()) {716 PeachEmptyOrEndState(717 message = "No paired devices yet.",718 detail = "Pair a nearby phone, tablet, or browser when you're ready to sync.",719 modifier = Modifier.padding(top = PeachSpacing.xs),720 )721 } else {722 pairedDevices.forEach { d ->723 RowLine(fg) {724 Column(Modifier.weight(1f)) {725 Text(d.deviceName ?: d.deviceId, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)726 Text(727 "${deviceTypeLabel(d.deviceType)} · ${syncTimeLabel(d.lastSyncedAt)}${if (isSyncStale(d.lastSyncedAt)) " · not seen recently" else ""}",728 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,729 modifier = Modifier.padding(top = 2.dp),730 )731 }732 if (confirmUnpair != d.deviceId) {733 SubtleButton("remove", fg) { confirmUnpair = d.deviceId }734 }735 }736 737 738 739 740 741 if (confirmUnpair == d.deviceId) {742 Column(Modifier.fillMaxWidth().padding(bottom = PeachSpacing.sm)) {743 Text(744 "Stops this device receiving future changes. It doesn't lock it " +745 "out of what it already has - if it's lost or stolen, also " +746 "change your master password and generate new recovery words.",747 color = fg.copy(alpha = 0.7f),748 fontFamily = PeachType.Body,749 fontSize = 11.sp,750 lineHeight = 16.sp,751 )752 Row(753 modifier = Modifier.fillMaxWidth().padding(top = PeachSpacing.sm),754 horizontalArrangement = Arrangement.End,755 ) {756 SubtleButton("cancel", fg) { confirmUnpair = null }757 Spacer(Modifier.width(PeachSpacing.sm))758 SubtleButton("remove", peachColors.Breach) { syncVm.unpairDevice(d.deviceId); confirmUnpair = null }759 }760 }761 }762 }763 RowLine(fg) {764 ValueText(syncFlashLabel(syncStatus), fg)765 SubtleButton(if (syncStatus == SyncStatus.Syncing) "syncing..." else "sync now", fg) {766 if (syncStatus != SyncStatus.Syncing) syncVm.syncNow()767 }768 }769 }770771 772 773 774 775 776 SubLabel("HOW THIS VAULT SYNCS", fg)777 SyncModeRow(778 title = "Public relay",779 detail = "Peach's own relay. Works anywhere, nothing to set up. It never sees " +780 "your vault — everything is encrypted before it leaves this device.",781 selected = syncMode == SyncMode.PUBLIC,782 fg = fg,783 ) { syncVm.setSyncMode(SyncMode.PUBLIC) }784 SyncModeRow(785 title = "Private relay",786 detail = "Your own peach-relay, on your own domain. Same open-source code.",787 selected = syncMode == SyncMode.PRIVATE,788 fg = fg,789 ) { syncVm.setSyncMode(SyncMode.PRIVATE) }790791 if (syncMode == SyncMode.PRIVATE) {792 Text(793 "RELAY URL",794 color = fg.copy(alpha = 0.6f),795 fontFamily = PeachType.Mono,796 fontSize = 8.sp,797 letterSpacing = 0.22.em,798 modifier = Modifier.padding(top = 8.dp),799 )800 Box(801 Modifier.fillMaxWidth().padding(top = 6.dp)802 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))803 .padding(horizontal = 12.dp, vertical = 10.dp),804 ) {805 BasicTextField(806 value = relayUrlDraft,807 onValueChange = { relayUrlDraft = it; relayUrlStatus = null },808 singleLine = true,809 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 11.sp, color = fg),810 cursorBrush = SolidColor(fg),811 modifier = Modifier.fillMaxWidth(),812 )813 }814 RowLine(fg) {815 ValueText(relayUrlStatus ?: "Only secure wss:// relays are accepted.", fg)816 SubtleButton("save", fg) {817 relayUrlStatus = if (syncVm.setPrivateRelayUrl(relayUrlDraft)) {818 relayUrlDraft = syncVm.relayUrl.value819 "Saved"820 } else {821 "Use a valid wss:// relay URL"822 }823 }824 }825 }826827 SyncModeRow(828 title = "No sync",829 detail = "This device keeps to itself. Move your vault by hand with Codex or " +830 "CSV export and import.",831 selected = syncMode == SyncMode.OFF,832 fg = fg,833 ) { syncVm.setSyncMode(SyncMode.OFF) }834835 if (pendingVouched.isNotEmpty()) {836 SubLabel("PENDING DEVICES", fg)837 pendingVouched.forEach { dev ->838 RowLine(fg) {839 Column(Modifier.weight(1f)) {840 Text(dev.deviceName, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)841 Text(842 "Was added by another of your devices. Allow it to sync with this vault?",843 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,844 modifier = Modifier.padding(top = 2.dp),845 )846 }847 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {848 SubtleButton("Allow", fg) { syncVm.confirmVouchedDevice(dev.deviceId) }849 SubtleButton("Reject", fg) { syncVm.rejectVouchedDevice(dev.deviceId) }850 }851 }852 }853 }854855 SubLabel("RECOVERY", fg)856 if (rotateConfirmOpen) {857 Hint("This will disconnect all paired devices and your 12 recovery words will change. You'll be shown the new words next.", peachColors.Breach)858 rotateError?.let {859 Text(it, color = peachColors.Breach, fontFamily = PeachType.Body, fontSize = 11.sp, modifier = Modifier.padding(top = 6.dp))860 }861 Row(Modifier.padding(top = 10.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {862 SubtleButton("cancel", fg) { if (!rotating) rotateConfirmOpen = false }863 SubtleButton(if (rotating) "rotating..." else "Rotate sync identity", peachColors.Breach) {864 if (rotating) return@SubtleButton865 rotating = true866 rotateError = null867 scope.launch {868 val ok = syncVm.rotateSyncIdentity()869 rotating = false870 if (ok) {871 rotateConfirmOpen = false872 onNavigate(PeachNav.RecoverySetup)873 } else {874 rotateError = "Rotation failed. Unlock your real vault and try again."875 }876 }877 }878 }879 } else {880 RowLine(fg) {881 Column(Modifier.weight(1f)) {882 Text("Rotate sync identity", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)883 Text(884 "Use this if a paired device was lost or stolen. Re-keys the vault so the old device's key is useless.",885 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,886 modifier = Modifier.padding(top = 2.dp),887 )888 }889 SubtleButton("rotate", peachColors.Breach) { rotateError = null; rotateConfirmOpen = true }890 }891 }892893 Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg)894}895896private fun deviceTypeLabel(type: String?): String = when (type) {897 "android" -> "Android"898 "phone" -> "Phone"899 "tablet" -> "Tablet"900 "browser" -> "Browser"901 else -> "Device"902}903904private fun syncTimeLabel(lastSyncedAt: Long?): String {905 if (lastSyncedAt == null) return "never synced"906 val diff = System.currentTimeMillis() - lastSyncedAt907 if (diff < 60_000) return "just now"908 if (diff < 3_600_000) return "${diff / 60_000}m ago"909 if (diff < 86_400_000) return "${diff / 3_600_000}h ago"910 return "${diff / 86_400_000}d ago"911}912913private fun isSyncStale(lastSyncedAt: Long?): Boolean =914 lastSyncedAt != null && System.currentTimeMillis() - lastSyncedAt > 7L * 24L * 60L * 60L * 1000L915916private fun syncFlashLabel(status: SyncStatus): String = when (status) {917 SyncStatus.Idle -> ""918 SyncStatus.Syncing -> "syncing..."919 SyncStatus.Offline -> "offline"920 is SyncStatus.Error -> status.message921 is SyncStatus.LastSynced -> "synced ${syncTimeLabel(status.timestamp)}"922}923924925926@Composable927private fun ShortcutsBody(fg: Color) {928 val bindings = listOf(929 "Copy password" to "⌘C", "Copy username" to "⌘⇧C", "Open entry" to "↵",930 "Edit entry" to "E", "New entry" to "⌘N", "Search" to "/",931 )932 SubLabel("KEYBINDINGS", fg, top = 0.dp)933 Hint("Shortcuts apply when a hardware keyboard is attached. Defaults shown below.", fg)934 Spacer(Modifier.height(8.dp))935 bindings.forEach { (label, key) ->936 RowLine(fg) {937 Name(label, fg)938 Box(939 Modifier.clip(RoundedCornerShape(4.dp)).background(fg.copy(alpha = 0.06f))940 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(4.dp))941 .padding(horizontal = 7.dp, vertical = 2.dp),942 ) { Text(key, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp) }943 }944 }945}946947948949@Composable950private fun ProBody(fg: Color, vm: SettingsViewModel) {951 val ctx = LocalContext.current952 val isPro by vm.isPro.collectAsState()953 if (isPro) {954 ProActiveBody(fg, vm)955 return956 }957 val features = listOf(958 "Peach Sync" to "Encrypted · peer-to-peer",959 "Peach Codex" to "Restore from paper",960 "Passkeys" to "Zero-knowledge WebAuthn",961 "Advanced Vault Health" to "Reuse · age · exposure",962 "Canary entries" to "Detects vault compromise",963 "Duress vault" to "Decoy under coercion",964 )965 Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)966 Text(967 "Everything, everywhere.",968 modifier = Modifier.padding(top = 8.dp),969 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,970 )971 Text(972 "One key unlocks every Pro feature — for the lifetime of the app.",973 modifier = Modifier.padding(top = 6.dp),974 color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,975 )976 Spacer(Modifier.height(10.dp))977 features.forEachIndexed { i, (name, desc) ->978 979 980 981 982 RowLine(fg, verticalPadding = 6.dp) {983 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {984 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))985 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)986 }987 Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)988 }989 }990 Spacer(Modifier.height(12.dp))991 Text(992 "$39",993 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,994 )995 Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)996 Spacer(Modifier.height(10.dp))997 Box(998 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))999 .background(fg.copy(alpha = 0.16f))1000 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1001 .clickable {1002 runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }1003 }1004 .padding(vertical = 12.dp),1005 contentAlignment = Alignment.Center,1006 ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }10071008 1009 1010 1011 1012 Spacer(Modifier.height(44.dp))10131014 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1015 var key by remember { mutableStateOf("") }1016 val activating by vm.activating.collectAsState()1017 val activationError by vm.activationError.collectAsState()1018 Box(1019 Modifier.fillMaxWidth().padding(top = 6.dp)1020 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))1021 .padding(horizontal = 12.dp, vertical = 10.dp),1022 ) {1023 BasicTextField(1024 value = key,1025 1026 1027 1028 1029 onValueChange = { key = it; vm.clearActivationError() },1030 singleLine = true,1031 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),1032 cursorBrush = SolidColor(fg),1033 modifier = Modifier.fillMaxWidth(),1034 decorationBox = { inner ->1035 if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)1036 inner()1037 },1038 )1039 }1040 if (activationError != null) {1041 Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))1042 }1043 Spacer(Modifier.height(8.dp))1044 Box(1045 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1046 .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))1047 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1048 .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }1049 .padding(vertical = 12.dp),1050 contentAlignment = Alignment.Center,1051 ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }1052}10531054@Composable1055private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {1056 val ctx = LocalContext.current1057 val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")1058 val licenseKey by vm.licenseKey.collectAsState()1059 val issuedAt by vm.licenseIssuedAt.collectAsState()1060 var showKey by remember { mutableStateOf(false) }1061 var copied by remember { mutableStateOf(false) }1062 val scope = rememberCoroutineScope()1063 Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {1064 com.peachpasswords.ui.components.PeachMark(size = 60.dp)1065 }1066 Text(1067 "Peach Pro",1068 modifier = Modifier.fillMaxWidth(),1069 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,1070 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1071 )1072 Text(1073 formatLicenseActiveSince(issuedAt),1074 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),1075 color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,1076 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1077 )1078 licenseKey?.let { key ->1079 Spacer(Modifier.height(12.dp))1080 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1081 RowLine(fg) {1082 Text(1083 if (showKey) key else "************************",1084 color = fg.copy(alpha = if (showKey) 0.82f else 0.58f),1085 fontFamily = PeachType.Mono,1086 fontSize = 10.sp,1087 modifier = Modifier.weight(1f),1088 )1089 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {1090 SubtleButton(if (copied) "copied" else "copy", fg) {1091 PeachClipboard.copy(ctx, "peach license", key)1092 copied = true1093 scope.launch {1094 delay(1_500)1095 copied = false1096 }1097 }1098 SubtleButton(if (showKey) "hide" else "reveal", fg) { showKey = !showKey }1099 }1100 }1101 }1102 Spacer(Modifier.height(12.dp))1103 features.forEachIndexed { i, name ->1104 RowLine(fg) {1105 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1106 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))1107 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1108 }1109 Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1110 }1111 }1112 Spacer(Modifier.height(12.dp))1113 Box(1114 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1115 .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1116 .clickable { vm.deactivate() }1117 .padding(vertical = 12.dp),1118 contentAlignment = Alignment.Center,1119 ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }1120}11211122private fun formatLicenseActiveSince(issuedAt: Long?): String {1123 if (issuedAt == null) return "Active"1124 val monthYear = SimpleDateFormat("MMMM yyyy", Locale.getDefault()).format(Date(issuedAt))1125 return "Active since $monthYear"1126}1127112811291130@OptIn(ExperimentalLayoutApi::class)1131@Composable1132private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {1133 val categories = listOf("Bug report", "Feature request", "Question", "Other")1134 var category by remember { mutableStateOf(categories[0]) }1135 var message by remember { mutableStateOf("") }1136 val state by vm.feedbackState.collectAsState()11371138 1139 DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }11401141 if (state is FeedbackState.Sent) {1142 Box(1143 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))1144 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),1145 ) {1146 Column {1147 Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)1148 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))1149 }1150 }1151 return1152 }11531154 val sending = state is FeedbackState.Sending11551156 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)1157 SubLabel("TYPE", fg)1158 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1159 categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }1160 }1161 SubLabel("MESSAGE", fg)1162 Box(1163 Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))1164 .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))1165 .padding(10.dp),1166 ) {1167 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)1168 BasicTextField(1169 value = message, onValueChange = { message = it.take(MAX_FEEDBACK_MESSAGE_LENGTH) },1170 enabled = !sending,1171 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),1172 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),1173 )1174 }1175 Text(1176 "Version ${BuildConfig.VERSION_NAME} · will be included automatically",1177 modifier = Modifier.padding(top = 6.dp),1178 color = fg.copy(alpha = 0.52f),1179 fontFamily = PeachType.Mono,1180 fontSize = 10.sp,1181 lineHeight = 14.sp,1182 )1183 Spacer(Modifier.height(8.dp))11841185 Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {1186 val canSend = !sending && sanitizeFeedbackMessage(message).isNotBlank()1187 Box(1188 Modifier.clip(RoundedCornerShape(8.dp))1189 .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))1190 .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))1191 .clickable(enabled = canSend) { vm.sendFeedback(category, message) }1192 .padding(horizontal = 12.dp, vertical = 6.dp),1193 ) {1194 Text(1195 feedbackSubmitLabel(state),1196 color = fg.copy(alpha = if (canSend) 1f else 0.4f),1197 fontFamily = PeachType.Mono, fontSize = 11.sp,1198 )1199 }1200 if (sending) {1201 CircularProgressIndicator(1202 color = LocalPeachAccent.current,1203 strokeWidth = 2.dp,1204 modifier = Modifier.size(16.dp),1205 )1206 }1207 }12081209 (state as? FeedbackState.Error)?.let { err ->1210 Text(1211 err.message,1212 modifier = Modifier.padding(top = 8.dp),1213 color = peachColors.Breach,1214 fontFamily = PeachType.Mono,1215 fontSize = 11.sp,1216 lineHeight = 15.sp,1217 )1218 }12191220 Hint("Sent anonymously · no account required", fg)1221}1222122312241225@Composable1226internal fun DuressSection(fg: Color, vm: SettingsViewModel) {1227 val configured by vm.duressConfigured.collectAsState()1228 if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)1229}12301231@Composable1232private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {1233 Text(1234 "Duress password is active",1235 color = peachColors.HealthOk,1236 fontFamily = PeachType.Mono,1237 fontSize = 11.sp,1238 modifier = Modifier.padding(top = 6.dp),1239 )1240 Spacer(Modifier.height(8.dp))1241 DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }1242 Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)1243}12441245@Composable1246private fun DuressForm(fg: Color, vm: SettingsViewModel) {1247 var enabled by remember { mutableStateOf(false) }1248 var password by remember { mutableStateOf("") }1249 var confirm by remember { mutableStateOf("") }1250 var action by remember { mutableStateOf(DuressAction.DECOY) }1251 var error by remember { mutableStateOf<String?>(null) }1252 val scope = rememberCoroutineScope()12531254 RowLine(fg) {1255 Name("Duress password", fg)1256 Toggle(enabled, fg) { on ->1257 enabled = on1258 if (!on) { password = ""; confirm = ""; error = null }1259 }1260 }1261 Text(1262 "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",1263 color = fg.copy(alpha = 0.7f),1264 fontFamily = PeachType.Mono,1265 fontSize = 10.sp,1266 modifier = Modifier.padding(top = 6.dp),1267 )12681269 AnimatedVisibility(enabled) {1270 Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1271 PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }1272 PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }12731274 Text(1275 "When your duress password is entered at the lock screen, Peach will:",1276 color = fg.copy(alpha = 0.7f),1277 fontFamily = PeachType.Mono,1278 fontSize = 10.sp,1279 modifier = Modifier.padding(top = 4.dp),1280 )12811282 DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }1283 DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }12841285 error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }12861287 val canSave = password.isNotBlank() && confirm.isNotBlank()1288 DuressSaveButton("Save duress password", fg, canSave) {1289 error = when {1290 password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"1291 password != confirm -> "Passwords do not match"1292 else -> null1293 }1294 if (error == null) scope.launch {1295 if (vm.saveDuress(password, action)) {1296 password = ""; confirm = ""; enabled = false1297 } else {1298 error = "Couldn't save — the duress passphrase must differ from your real password"1299 }1300 }1301 }1302 }1303 }1304}13051306@Composable1307private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {1308 val accent = LocalPeachAccent.current1309 Row(1310 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),1311 verticalAlignment = Alignment.CenterVertically,1312 horizontalArrangement = Arrangement.spacedBy(10.dp),1313 ) {1314 Box(1315 Modifier.size(16.dp).clip(CircleShape)1316 .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),1317 contentAlignment = Alignment.Center,1318 ) {1319 if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))1320 }1321 Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)1322 }1323}13241325@Composable1326private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {1327 val accent = LocalPeachAccent.current1328 val tint = if (enabled) accent else fg.copy(alpha = 0.3f)1329 Box(1330 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1331 .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))1332 .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))1333 .let { if (enabled) it.clickable(onClick = onClick) else it }1334 .padding(vertical = 11.dp),1335 contentAlignment = Alignment.Center,1336 ) {1337 Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)1338 }1339}13401341@Composable1342private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {1343 Box(1344 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1345 .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))1346 .clickable(onClick = onClick)1347 .padding(vertical = 11.dp),1348 contentAlignment = Alignment.Center,1349 ) {1350 Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)1351 }1352}135313541355@Composable1356private fun SyncModeRow(1357 title: String,1358 detail: String,1359 selected: Boolean,1360 fg: Color,1361 onSelect: () -> Unit,1362) {1363 RowLine(fg, Modifier.clickable(onClick = onSelect)) {1364 Column(Modifier.weight(1f)) {1365 Text(title, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1366 Text(1367 detail,1368 color = fg.copy(alpha = 0.7f),1369 fontFamily = PeachType.Body,1370 fontSize = 11.sp,1371 lineHeight = 16.sp,1372 modifier = Modifier.padding(top = 2.dp),1373 )1374 }1375 Text(1376 if (selected) "●" else "○",1377 color = if (selected) fg else fg.copy(alpha = 0.45f),1378 fontFamily = PeachType.Mono,1379 fontSize = 14.sp,1380 modifier = Modifier.padding(start = 10.dp),1381 )1382 }1383}