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.describeSyncOutcome35import com.peachpasswords.sync.syncIndicator36import com.peachpasswords.sync.syncIndicatorLabel37import com.peachpasswords.ui.components.SyncIndicatorDot38import com.peachpasswords.ui.theme.LocalPeachAccent39import com.peachpasswords.vault.DuressAction40import com.peachpasswords.ui.theme.peachColors41import androidx.compose.runtime.mutableStateOf42import androidx.compose.runtime.remember43import androidx.compose.runtime.rememberCoroutineScope44import androidx.compose.runtime.setValue45import androidx.compose.ui.Alignment46import androidx.compose.ui.Modifier47import androidx.compose.ui.draw.clip48import androidx.compose.ui.graphics.Color49import androidx.compose.ui.graphics.SolidColor50import androidx.compose.ui.platform.LocalContext51import androidx.compose.ui.text.TextStyle52import androidx.compose.ui.text.font.FontStyle53import androidx.compose.ui.text.input.PasswordVisualTransformation54import androidx.compose.ui.unit.Dp55import androidx.compose.ui.unit.dp56import androidx.compose.ui.unit.em57import androidx.compose.ui.unit.sp58import androidx.compose.material3.Text59import com.peachpasswords.BuildConfig60import com.peachpasswords.autofill.AutofillEnablement61import com.peachpasswords.ui.PeachNav62import com.peachpasswords.ui.components.PeachEmptyOrEndState63import com.peachpasswords.ui.components.PeachField64import com.peachpasswords.ui.pairing.BackgroundSyncDialog65import com.peachpasswords.ui.sync.SyncViewModel66import com.peachpasswords.ui.theme.ACCENT_COLORS67import com.peachpasswords.ui.theme.PeachSpacing68import com.peachpasswords.ui.theme.PeachType69import com.peachpasswords.ui.updates.UpdatePhase70import com.peachpasswords.ui.updates.UpdateViewModel71import androidx.hilt.navigation.compose.hiltViewModel72import com.peachpasswords.vault.VaultSettings73import com.peachpasswords.vault.VaultSnapshot74import kotlinx.coroutines.launch75import kotlinx.coroutines.delay76import java.text.SimpleDateFormat77import java.util.Date78import java.util.Locale7980private const val PRO_URL = "https://buy.polar.sh/polar_cl_IXSFIPojx67rcOTksn8LkH5mnU3osPHtYqBIl1eyuIz"818283848586878889@Composable90fun CardBody(91 id: CardId,92 fg: Color,93 vm: SettingsViewModel,94 settings: VaultSettings,95 entriesCount: Int,96 onNavigate: (PeachNav) -> Unit,97) {98 when (id) {99 CardId.Appearance -> AppearanceBody(fg, vm, settings)100 CardId.Protection -> ProtectionBody(fg, vm, settings, onNavigate)101 CardId.Vault -> VaultBody(fg, vm, settings, entriesCount, onNavigate)102 CardId.Sync -> SyncBody(fg, onNavigate)103 CardId.Pro -> ProBody(fg, vm)104 CardId.Feedback -> {105 106 107 AboutUpdatesBody(fg, onNavigate)108 FeedbackBody(fg, vm)109 }110 }111}112113114115@Composable116private fun AboutUpdatesBody(fg: Color, onNavigate: (PeachNav) -> Unit) {117 val vm: UpdateViewModel = hiltViewModel()118 val available by vm.available.collectAsState()119 val state by vm.state.collectAsState()120121 SubLabel("THIS BUILD", fg, top = 0.dp)122 RowLine(fg) {123 Name("Version", fg)124 ValueText(BuildConfig.VERSION_NAME, fg)125 }126 RowLine(fg) {127 Column(Modifier.weight(1f)) {128 Text("Updates", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)129 Text(130 when {131 available != null -> "v${available?.version} is available"132 state.phase == UpdatePhase.Checking -> "Checking…"133 state.phase == UpdatePhase.UpToDate -> "You're on the latest version"134 state.phase == UpdatePhase.Failed -> "Couldn't reach the update server"135 else -> "Peach checks once a day and tells you when there's a new version."136 },137 color = fg.copy(alpha = 0.7f),138 fontFamily = PeachType.Body,139 fontSize = 11.sp,140 lineHeight = 16.sp,141 modifier = Modifier.padding(top = 2.dp),142 )143 }144 if (available != null) {145 SubtleButton("update", fg) { onNavigate(PeachNav.Update) }146 } else {147 SubtleButton(if (state.phase == UpdatePhase.Checking) "checking" else "check now", fg) {148 vm.check()149 }150 }151 }152}153154155156@Composable157private fun SubLabel(text: String, fg: Color, top: Dp = 14.dp) {158 Text(159 text,160 modifier = Modifier.padding(top = top, bottom = 4.dp),161 color = fg.copy(alpha = 0.58f),162 fontFamily = PeachType.Mono,163 fontSize = 8.sp,164 letterSpacing = 0.22.em,165 )166}167168@Composable169private fun RowLine(170 fg: Color,171 modifier: Modifier = Modifier,172 verticalPadding: Dp = 9.dp,173 content: @Composable RowScope.() -> Unit,174) {175 Row(176 Modifier.fillMaxWidth().then(modifier).padding(vertical = verticalPadding),177 verticalAlignment = Alignment.CenterVertically,178 horizontalArrangement = Arrangement.SpaceBetween,179 content = content,180 )181 Box(Modifier.fillMaxWidth().height(1.dp).background(fg.copy(alpha = 0.12f)))182}183184@Composable185private fun RowScope.Name(text: String, fg: Color) {186 Text(text, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp, modifier = Modifier.weight(1f))187}188189@Composable190private fun ValueText(text: String, fg: Color) {191 Text(text, color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Mono, fontSize = 11.sp)192}193194@Composable195private fun SubtleButton(label: String, fg: Color, onClick: () -> Unit) {196 Box(197 Modifier.clip(RoundedCornerShape(8.dp))198 .border(1.dp, fg.copy(alpha = 0.28f), RoundedCornerShape(8.dp))199 .background(fg.copy(alpha = 0.08f))200 .clickable(onClick = onClick)201 .padding(horizontal = 12.dp, vertical = 6.dp),202 ) {203 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 11.sp)204 }205}206207@Composable208private fun Toggle(on: Boolean, fg: Color, onToggle: (Boolean) -> Unit) {209 val knob by animateDpAsState(if (on) 16.dp else 2.dp, label = "knob")210 Box(211 Modifier.size(width = 34.dp, height = 20.dp).clip(RoundedCornerShape(999.dp))212 .background(if (on) fg.copy(alpha = 0.28f) else fg.copy(alpha = 0.08f))213 .border(1.dp, fg.copy(alpha = if (on) 0.5f else 0.32f), RoundedCornerShape(999.dp))214 .clickable { onToggle(!on) },215 ) {216 Box(217 Modifier.padding(top = 2.dp).width(16.dp).fillMaxWidth().height(16.dp)218 .padding(start = knob - 2.dp)219 .size(14.dp).clip(CircleShape)220 .background(if (on) fg else fg.copy(alpha = 0.58f)),221 )222 }223}224225@Composable226private fun Pill(label: String, active: Boolean, fg: Color, onClick: () -> Unit) {227 Box(228 Modifier.clip(RoundedCornerShape(999.dp))229 .border(1.dp, fg.copy(alpha = if (active) 0.55f else 0.32f), RoundedCornerShape(999.dp))230 .background(if (active) fg.copy(alpha = 0.18f) else Color.Transparent)231 .clickable(onClick = onClick)232 .padding(horizontal = 12.dp, vertical = 5.dp),233 ) {234 Text(label, color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)235 }236}237238@Composable239private fun ProBadge(fg: Color) {240 Box(241 Modifier.padding(start = 6.dp).clip(RoundedCornerShape(4.dp))242 .background(fg.copy(alpha = 0.16f)).padding(horizontal = 5.dp, vertical = 1.dp),243 ) {244 Text("Pro", color = fg.copy(alpha = 0.85f), fontFamily = PeachType.Mono, fontSize = 8.sp)245 }246}247248@Composable249private fun Hint(text: String, fg: Color) {250 Text(251 text,252 modifier = Modifier.padding(top = 6.dp),253 color = fg.copy(alpha = 0.6f),254 fontFamily = PeachType.Display,255 fontStyle = FontStyle.Italic,256 fontSize = 11.5.sp,257 lineHeight = 16.sp,258 )259}260261262263@OptIn(ExperimentalLayoutApi::class)264@Composable265private fun AppearanceBody(fg: Color, vm: SettingsViewModel, s: VaultSettings) {266 SubLabel("ACCENT", fg, top = 0.dp)267 FlowRow(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {268 ACCENT_COLORS.forEach { (name, color) ->269 Box(270 Modifier.size(22.dp).clip(CircleShape).background(color)271 .border(272 if (s.accentColor == name) 2.dp else 1.dp,273 if (s.accentColor == name) fg else fg.copy(alpha = 0.2f),274 CircleShape,275 )276 .clickable { vm.setAccent(name) },277 )278 }279 }280 SubLabel("MOTION", fg)281 RowLine(fg) {282 Name("Reduce motion", fg)283 SubtleButton(if (s.reduceMotion) "On" else "Off", fg) { vm.setReduceMotion(!s.reduceMotion) }284 }285}286287288289@Composable290private fun ProtectionBody(fg: Color, vm: SettingsViewModel, s: VaultSettings, onNavigate: (PeachNav) -> Unit) {291 val lockOptions = listOf(1 to "1 minute", 5 to "5 minutes", 15 to "15 minutes", 30 to "30 minutes", 0 to "Never")292 val current = s.autoLockMinutes ?: 0293294 SubLabel("LOCKING", fg, top = 0.dp)295 RowLine(fg) {296 Name("Auto-lock after", fg)297 val idx = lockOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)298 SubtleButton(lockOptions[idx].second, fg) {299 val next = lockOptions[(idx + 1) % lockOptions.size].first300 vm.setAutoLockMinutes(if (next == 0) 0 else next)301 }302 }303 SubLabel("BIOMETRICS", fg)304 val bioActivity = LocalContext.current as? androidx.fragment.app.FragmentActivity305 RowLine(fg) {306 Name("Unlock with biometrics", fg)307 Toggle(s.biometricsEnabled, fg) { on ->308 if (on && bioActivity != null) vm.enableBiometrics(bioActivity) else vm.disableBiometrics()309 }310 }311 val bioError = com.peachpasswords.ui.lock.Biometrics.statusMessage(LocalContext.current)312 if (bioError != null) {313 Text(314 bioError,315 color = com.peachpasswords.ui.theme.peachColors.Breach,316 fontFamily = PeachType.Mono, fontSize = 10.sp,317 modifier = Modifier.padding(start = 2.dp, top = 2.dp, bottom = 4.dp),318 )319 }320 SubLabel("AUTOFILL", fg)321 run {322 323 324 val ctx = LocalContext.current325 val enabled = AutofillEnablement.isEnabled(ctx)326 RowLine(fg) {327 Column(Modifier.weight(1f)) {328 Text("Fill passwords in other apps", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)329 Text(330 if (enabled) {331 "Peach is your autofill service."332 } else {333 "Android decides which app fills passwords. Turn Peach on in system settings."334 },335 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,336 modifier = Modifier.padding(top = 2.dp),337 )338 }339 if (!enabled) {340 SubtleButton("enable", fg) {341 342 343 344 runCatching { ctx.startActivity(AutofillEnablement.requestIntent(ctx)) }345 .onFailure { runCatching { ctx.startActivity(AutofillEnablement.fallbackIntent()) } }346 }347 } else {348 ValueText("on", fg)349 }350 }351 }352353 SubLabel("PASSKEYS", fg)354 RowLine(fg) {355 Column(Modifier.weight(1f)) {356 Text("Credential provider", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)357 Text(358 "Peach can handle passkey sign-in and creation through Android Credential Manager.",359 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,360 modifier = Modifier.padding(top = 2.dp),361 )362 }363 Toggle(s.passkeyProviderEnabled, fg) { vm.setPasskeyProviderEnabled(it) }364 }365 RowLine(fg) {366 Name("Status", fg)367 ValueText(if (s.passkeyProviderEnabled) "enabled" else "off", fg)368 }369 SubLabel("RECOVERY", fg)370 RowLine(fg) {371 Column(Modifier.weight(1f)) {372 Text("View recovery words", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)373 Text(374 "Keep the paper copy current before rotating sync identity or replacing devices.",375 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,376 modifier = Modifier.padding(top = 2.dp),377 )378 }379 SubtleButton("view", fg) { onNavigate(PeachNav.RecoveryView) }380 }381 SubLabel("BREACH PROTECTION", fg)382 val checkingBreaches by vm.checkingBreaches.collectAsState()383 val breachResult by vm.breachResult.collectAsState()384 RowLine(fg) {385 Name("Breach monitoring", fg)386 Toggle(s.breachMonitoring, fg) { vm.setBreachMonitoring(it) }387 }388 RowLine(fg) {389 Name("Check all passwords", fg)390 SubtleButton(if (checkingBreaches) "checking..." else "run", fg) { vm.checkAllBreaches() }391 }392 breachResult?.let { result ->393 RowLine(fg) {394 Name("Last check", fg)395 ValueText(result, fg)396 }397 }398399 SubLabel("MASTER PASSWORD", fg)400 ChangePasswordRow(fg, vm)401402 SubLabel("DURESS PASSWORD", fg)403 val duressIsPro by vm.isPro.collectAsState()404 if (!duressIsPro) {405 RowLine(fg) {406 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {407 Name("Duress password", fg); ProBadge(fg)408 }409 ValueText("off", fg)410 }411 Hint("If entered under coercion, a decoy empty vault opens; your real vault stays hidden. Pro feature.", fg)412 } else {413 DuressSection(fg, vm)414 }415}416417@Composable418private fun ChangePasswordRow(fg: Color, vm: SettingsViewModel) {419 var open by remember { mutableStateOf(false) }420 var current by remember { mutableStateOf("") }421 var next by remember { mutableStateOf("") }422 var confirm by remember { mutableStateOf("") }423 var error by remember { mutableStateOf<String?>(null) }424 var done by remember { mutableStateOf(false) }425 val scope = rememberCoroutineScope()426427 RowLine(fg) {428 Name("Master password", fg)429 SubtleButton(if (open) "cancel" else "change", fg) { open = !open; error = null; done = false }430 }431 AnimatedVisibility(open) {432 Column(Modifier.fillMaxWidth().padding(top = PeachSpacing.sm), verticalArrangement = Arrangement.spacedBy(PeachSpacing.sm)) {433 PwField("current password", current, fg) { current = it }434 PwField("new password (min 12 chars)", next, fg) { next = it }435 PwField("confirm new password", confirm, fg) { confirm = it }436 error?.let { Text(it, color = Color(0xFFE5805C), fontFamily = PeachType.Mono, fontSize = 10.sp) }437 if (done) Text("password changed ✓", color = fg, fontFamily = PeachType.Mono, fontSize = 10.sp)438 SubtleButton("save new password", fg) {439 error = when {440 current.isBlank() -> "enter your current password"441 next.length < 12 -> "new password must be at least 12 characters"442 next != confirm -> "new passwords do not match"443 next == current -> "new password must differ from current"444 else -> null445 }446 if (error == null) scope.launch {447 if (vm.changePassword(current, next)) {448 current = ""; next = ""; confirm = ""; open = false; done = true449 } else error = "incorrect current password"450 }451 }452 }453 }454}455456@Composable457private fun PwField(placeholder: String, value: String, @Suppress("UNUSED_PARAMETER") fg: Color, onChange: (String) -> Unit) {458 PeachField(459 label = placeholder,460 value = value,461 onValueChange = onChange,462 keyboardType = androidx.compose.ui.text.input.KeyboardType.Password,463 visualTransformation = PasswordVisualTransformation(),464 )465}466467468469@Composable470private fun VaultBody(471 fg: Color,472 vm: SettingsViewModel,473 s: VaultSettings,474 entriesCount: Int,475 onNavigate: (PeachNav) -> Unit,476) {477 val trashOptions = listOf(7 to "7 days", 30 to "30 days", 90 to "90 days", 0 to "Never")478 val current = s.trashRetentionDays ?: 0479 val isPro by vm.isPro.collectAsState()480 val dedupCount by vm.dedupCount.collectAsState()481 val dedupRunning by vm.dedupRunning.collectAsState()482 val dedupDone by vm.dedupDone.collectAsState()483 val history by vm.vaultHistory.collectAsState()484 val restoringSnapshotId by vm.restoringSnapshotId.collectAsState()485486 SubLabel("ENTRIES", fg, top = 0.dp)487 RowLine(fg) { Name("Entries", fg); ValueText("$entriesCount", fg) }488 RowLine(fg) {489 Name("Duplicates", fg)490 val done = dedupDone491 if (done != null) {492 ValueText(if (done == 0) "already clean" else "removed $done", com.peachpasswords.ui.theme.peachColors.SyncOk)493 } else {494 val count = dedupCount495 val label = when {496 dedupRunning -> "scanning..."497 count == null -> "scan"498 count == 0 -> "none found"499 else -> "$count found"500 }501 SubtleButton(label, fg) {502 if (count == null || count == 0) vm.scanDuplicates()503 }504 }505 }506 if ((dedupCount ?: 0) > 0 && dedupDone == null) {507 Column(508 Modifier.fillMaxWidth()509 .padding(top = 2.dp, bottom = 8.dp)510 .clip(RoundedCornerShape(8.dp))511 .background(fg.copy(alpha = 0.08f))512 .border(1.dp, fg.copy(alpha = 0.18f), RoundedCornerShape(8.dp))513 .padding(10.dp),514 verticalArrangement = Arrangement.spacedBy(8.dp),515 ) {516 val count = dedupCount ?: 0517 Text(518 "$count duplicate ${if (count == 1) "entry" else "entries"} found. The newest copy of each will be kept; older duplicates will be moved to trash.",519 color = fg.copy(alpha = 0.82f),520 fontFamily = PeachType.Body,521 fontSize = 11.sp,522 lineHeight = 16.sp,523 )524 Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {525 SubtleButton("cancel", fg) { vm.cancelDuplicateRemoval() }526 SubtleButton(if (dedupRunning) "removing..." else "remove duplicates", fg) { vm.removeDuplicates() }527 }528 }529 }530531 SubLabel("MAINTENANCE", fg)532 RowLine(fg) {533 Name("Trash auto-delete", fg)534 val idx = trashOptions.indexOfFirst { it.first == current }.coerceAtLeast(0)535 SubtleButton(trashOptions[idx].second, fg) {536 vm.setTrashRetentionDays(trashOptions[(idx + 1) % trashOptions.size].first)537 }538 }539 RowLine(fg) { Name("Advanced Vault Health", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Health) } }540 RowLine(fg) { Name("Trash", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Trash) } }541542 SubLabel("DATA", fg)543 RowLine(fg) { Name("Import passwords", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Import) } }544 RowLine(fg) { Name("Export backup", fg); SubtleButton("open", fg) { onNavigate(PeachNav.Export) } }545 RowLine(fg) {546 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) { Name("Peach Codex", fg); if (!isPro) ProBadge(fg) }547 SubtleButton(if (isPro) "open" else "Pro", fg) { if (isPro) onNavigate(PeachNav.CodexGenerate) }548 }549 RowLine(fg) { Name("Restore from Codex", fg); SubtleButton("open", fg) { onNavigate(PeachNav.CodexRestore) } }550551 var historyShowAll by remember { mutableStateOf(false) }552 SubLabel("VAULT HISTORY", fg)553 if (history.isEmpty()) {554 Text(555 "No snapshots yet. Peach saves automatically before every change — saves, syncs, and imports.",556 color = fg.copy(alpha = 0.68f),557 fontFamily = PeachType.Body,558 fontSize = 11.sp,559 lineHeight = 16.sp,560 modifier = Modifier.padding(bottom = 6.dp),561 )562 } else {563 Text(564 "Restoring locks your vault. Unlock with the password that encrypted that snapshot to confirm.",565 color = fg.copy(alpha = 0.68f),566 fontFamily = PeachType.Body,567 fontSize = 11.sp,568 lineHeight = 16.sp,569 modifier = Modifier.padding(bottom = 4.dp),570 )571 history.take(if (historyShowAll) history.size else 3).forEach { snap ->572 RowLine(fg) {573 Column(Modifier.weight(1f)) {574 Text(snapshotTimeLabel(snap.savedAt), color = fg, fontFamily = PeachType.Body, fontSize = 12.sp)575 Text(snapshotSubLabel(snap), color = fg.copy(alpha = 0.62f), fontFamily = PeachType.Mono, fontSize = 10.sp)576 }577 SubtleButton(if (restoringSnapshotId == snap.id) "..." else "restore", fg) {578 vm.restoreVaultSnapshot(snap.id)579 }580 }581 }582 if (history.size > 3) {583 RowLine(fg) {584 Name(if (historyShowAll) "show less" else "${history.size - 3} older", fg)585 SubtleButton(if (historyShowAll) "hide" else "show", fg) { historyShowAll = !historyShowAll }586 }587 }588 Text(589 "${history.size} of 5 snapshots",590 color = fg.copy(alpha = 0.58f),591 fontFamily = PeachType.Mono,592 fontSize = 10.sp,593 modifier = Modifier.padding(top = 2.dp, bottom = 6.dp),594 )595 }596597 var advancedOpen by remember { mutableStateOf(false) }598 SubLabel("ADVANCED", fg)599 RowLine(fg) {600 Name("Advanced", fg)601 SubtleButton(if (advancedOpen) "hide" else "show", fg) { advancedOpen = !advancedOpen }602 }603 if (advancedOpen) {604 RowLine(fg) {605 Name("Replace vault from backup", com.peachpasswords.ui.theme.peachColors.SyncBusy)606 SubtleButton("open", com.peachpasswords.ui.theme.peachColors.SyncBusy) { onNavigate(PeachNav.Import) }607 }608 RowLine(fg) {609 Name("Destroy vault", com.peachpasswords.ui.theme.peachColors.Breach)610 SubtleButton("destroy", com.peachpasswords.ui.theme.peachColors.Breach) { onNavigate(PeachNav.Panic) }611 }612 }613}614615private fun snapshotSubLabel(snapshot: VaultSnapshot): String {616 val count = snapshot.entryCount?.let { "up to $it ${if (it == 1) "entry" else "entries"}" }617 return listOfNotNull(count, snapshotReasonLabel(snapshot.reason)).joinToString(" · ")618}619620private fun snapshotReasonLabel(reason: String): String = when (reason) {621 "local_save" -> "saved"622 "sync_received" -> "synced"623 "import" -> "imported"624 "restore" -> "restored"625 else -> reason626}627628private fun snapshotTimeLabel(savedAt: Long): String {629 val diff = System.currentTimeMillis() - savedAt630 if (diff < 60_000) return "Just now"631 if (diff < 3_600_000) return "${diff / 60_000}m ago"632 val date = Date(savedAt)633 val today = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date())634 val thenDay = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(date)635 val time = SimpleDateFormat("h:mm a", Locale.getDefault()).format(date)636 if (today == thenDay) return "Today $time"637 val yesterday = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Date(System.currentTimeMillis() - 86_400_000))638 if (yesterday == thenDay) return "Yesterday $time"639 return SimpleDateFormat("MMM d h:mm a", Locale.getDefault()).format(date)640}641642643644@Composable645private fun SyncBody(fg: Color, onNavigate: (PeachNav) -> Unit) {646 val syncVm: SyncViewModel = hiltViewModel()647 val pairedDevices by syncVm.pairedDevices.collectAsState()648 val pendingVouched by syncVm.pendingVouched.collectAsState()649 val syncStatus by syncVm.status.collectAsState()650 val configuredRelayUrl by syncVm.privateRelayUrl.collectAsState()651 val syncMode by syncVm.syncMode.collectAsState()652 val backgroundSyncEnabled by syncVm.backgroundSyncEnabled.collectAsState()653 var showBackgroundSyncPrompt by remember { mutableStateOf(false) }654 val scope = rememberCoroutineScope()655 var confirmUnpair by remember { mutableStateOf<String?>(null) }656 var rotateConfirmOpen by remember { mutableStateOf(false) }657 var rotating by remember { mutableStateOf(false) }658 var rotateError by remember { mutableStateOf<String?>(null) }659 var relayUrlDraft by remember(configuredRelayUrl) { mutableStateOf(configuredRelayUrl) }660 var relayUrlStatus by remember { mutableStateOf<String?>(null) }661662 663 664 665 SubLabel("PAIR A DEVICE", fg, top = 0.dp)666 RowLine(fg) {667 Column(Modifier.weight(1f)) {668 Row(verticalAlignment = Alignment.CenterVertically) {669 Text("Peach Sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp); ProBadge(fg)670 }671 Text(672 "End-to-end encrypted, through a relay that can read none of it.",673 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,674 modifier = Modifier.padding(top = 2.dp),675 )676 }677 }678 RowLine(fg) {679 Column(Modifier.weight(1f)) {680 Text("Show a code", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)681 Text(682 "For the other device to scan. Always use this one to pair a browser.",683 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,684 modifier = Modifier.padding(top = 2.dp),685 )686 }687 SubtleButton("show", fg) { onNavigate(PeachNav.CodePair) }688 }689 RowLine(fg) {690 Column(Modifier.weight(1f)) {691 Text("Scan a code", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)692 Text(693 "Joins that vault. Your entries are kept and the two merge; this phone's " +694 "recovery words are replaced, and shown to you first.",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("scan", fg) { onNavigate(PeachNav.AdoptVault) }700 }701702 703 704 705 706 SubLabel("SYNC STATUS", fg)707 RowLine(fg) {708 Column(Modifier.weight(1f)) {709 Text("Background sync", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)710 Text(711 if (backgroundSyncEnabled) {712 "Background sync is on. Tap to change."713 } else {714 "Background sync is off. Tap to enable."715 },716 color = fg.copy(alpha = 0.7f),717 fontFamily = PeachType.Body,718 fontSize = 11.sp,719 lineHeight = 16.sp,720 modifier = Modifier.padding(top = 2.dp),721 )722 }723 SubtleButton("change", fg) { showBackgroundSyncPrompt = true }724 }725 val indicator = syncIndicator(syncStatus, pairedDevices.size)726 RowLine(fg) {727 SyncIndicatorDot(728 indicator = indicator,729 label = syncIndicatorLabel(indicator, syncStatus),730 modifier = Modifier.padding(end = PeachSpacing.sm),731 size = 8.dp,732 )733 Text(734 describeSyncOutcome(syncStatus),735 color = fg.copy(alpha = 0.7f),736 fontFamily = PeachType.Body,737 fontSize = 11.sp,738 lineHeight = 16.sp,739 modifier = Modifier.weight(1f),740 )741 SubtleButton(if (syncStatus.syncing) "syncing..." else "sync now", fg) {742 if (!syncStatus.syncing) syncVm.syncNow()743 }744 }745746 SubLabel("PAIRED DEVICES", fg)747 if (pairedDevices.isEmpty()) {748 PeachEmptyOrEndState(749 message = "No paired devices yet.",750 detail = "Pair a nearby phone, tablet, or browser when you're ready to sync.",751 modifier = Modifier.padding(top = PeachSpacing.xs),752 )753 } else {754 pairedDevices.forEach { d ->755 RowLine(fg) {756 Column(Modifier.weight(1f)) {757 Text(d.deviceName ?: d.deviceId, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)758 Text(759 "${deviceTypeLabel(d.deviceType)} · ${syncTimeLabel(d.lastSyncedAt)}${if (isSyncStale(d.lastSyncedAt)) " · not seen recently" else ""}",760 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,761 modifier = Modifier.padding(top = 2.dp),762 )763 }764 if (confirmUnpair != d.deviceId) {765 SubtleButton("remove", fg) { confirmUnpair = d.deviceId }766 }767 }768 769 770 771 772 773 if (confirmUnpair == d.deviceId) {774 Column(Modifier.fillMaxWidth().padding(bottom = PeachSpacing.sm)) {775 Text(776 "Stops this device receiving future changes. It doesn't lock it " +777 "out of what it already has - if it's lost or stolen, also " +778 "change your master password and generate new recovery words.",779 color = fg.copy(alpha = 0.7f),780 fontFamily = PeachType.Body,781 fontSize = 11.sp,782 lineHeight = 16.sp,783 )784 Row(785 modifier = Modifier.fillMaxWidth().padding(top = PeachSpacing.sm),786 horizontalArrangement = Arrangement.End,787 ) {788 SubtleButton("cancel", fg) { confirmUnpair = null }789 Spacer(Modifier.width(PeachSpacing.sm))790 SubtleButton("remove", peachColors.Breach) { syncVm.unpairDevice(d.deviceId); confirmUnpair = null }791 }792 }793 }794 }795 }796797 798 799 800 801 802 SubLabel("HOW THIS VAULT SYNCS", fg)803 SyncModeRow(804 title = "Public relay",805 detail = "Peach's own relay. Works anywhere, nothing to set up. It never sees " +806 "your vault — everything is encrypted before it leaves this device.",807 selected = syncMode == SyncMode.PUBLIC,808 fg = fg,809 ) { syncVm.setSyncMode(SyncMode.PUBLIC) }810 SyncModeRow(811 title = "Private relay",812 detail = "Your own peach-relay, on your own domain. Same open-source code.",813 selected = syncMode == SyncMode.PRIVATE,814 fg = fg,815 ) { syncVm.setSyncMode(SyncMode.PRIVATE) }816817 if (syncMode == SyncMode.PRIVATE) {818 Text(819 "RELAY URL",820 color = fg.copy(alpha = 0.6f),821 fontFamily = PeachType.Mono,822 fontSize = 8.sp,823 letterSpacing = 0.22.em,824 modifier = Modifier.padding(top = 8.dp),825 )826 Box(827 Modifier.fillMaxWidth().padding(top = 6.dp)828 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))829 .padding(horizontal = 12.dp, vertical = 10.dp),830 ) {831 BasicTextField(832 value = relayUrlDraft,833 onValueChange = { relayUrlDraft = it; relayUrlStatus = null },834 singleLine = true,835 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 11.sp, color = fg),836 cursorBrush = SolidColor(fg),837 modifier = Modifier.fillMaxWidth(),838 )839 }840 841 842 val needsRelayUrl = configuredRelayUrl.isEmpty()843 RowLine(fg) {844 val message = relayUrlStatus845 ?: if (needsRelayUrl) {846 "Sync is paused until you enter your relay URL."847 } else {848 "Only secure wss:// relays are accepted."849 }850 val warn = relayUrlStatus?.startsWith("Use") == true ||851 (relayUrlStatus == null && needsRelayUrl)852 ValueText(message, if (warn) peachColors.Breach else fg)853 SubtleButton("save", fg) {854 relayUrlStatus = if (syncVm.setRelayUrl(relayUrlDraft)) {855 relayUrlDraft = syncVm.privateRelayUrl.value856 "Saved"857 } else {858 "Use a valid wss:// relay URL"859 }860 }861 }862 }863864 SyncModeRow(865 title = "No sync",866 detail = "This device keeps to itself. Move your vault by hand with Codex or " +867 "CSV export and import.",868 selected = syncMode == SyncMode.OFF,869 fg = fg,870 ) { syncVm.setSyncMode(SyncMode.OFF) }871872 if (pendingVouched.isNotEmpty()) {873 SubLabel("PENDING DEVICES", fg)874 pendingVouched.forEach { dev ->875 RowLine(fg) {876 Column(Modifier.weight(1f)) {877 Text(dev.deviceName, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)878 Text(879 "Was added by another of your devices. Allow it to sync with this vault?",880 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,881 modifier = Modifier.padding(top = 2.dp),882 )883 }884 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {885 SubtleButton("Allow", fg) { syncVm.confirmVouchedDevice(dev.deviceId) }886 SubtleButton("Reject", fg) { syncVm.rejectVouchedDevice(dev.deviceId) }887 }888 }889 }890 }891892 SubLabel("RECOVERY", fg)893 if (rotateConfirmOpen) {894 Hint("This will disconnect all paired devices and your 12 recovery words will change. You'll be shown the new words next.", peachColors.Breach)895 rotateError?.let {896 Text(it, color = peachColors.Breach, fontFamily = PeachType.Body, fontSize = 11.sp, modifier = Modifier.padding(top = 6.dp))897 }898 Row(Modifier.padding(top = 10.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) {899 SubtleButton("cancel", fg) { if (!rotating) rotateConfirmOpen = false }900 SubtleButton(if (rotating) "rotating..." else "Rotate sync identity", peachColors.Breach) {901 if (rotating) return@SubtleButton902 rotating = true903 rotateError = null904 scope.launch {905 val ok = syncVm.rotateSyncIdentity()906 rotating = false907 if (ok) {908 rotateConfirmOpen = false909 onNavigate(PeachNav.RecoverySetup)910 } else {911 rotateError = "Rotation failed. Unlock your real vault and try again."912 }913 }914 }915 }916 } else {917 RowLine(fg) {918 Column(Modifier.weight(1f)) {919 Text("Rotate sync identity", color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)920 Text(921 "Use this if a paired device was lost or stolen. Re-keys the vault so the old device's key is useless.",922 color = fg.copy(alpha = 0.7f), fontFamily = PeachType.Body, fontSize = 11.sp, lineHeight = 16.sp,923 modifier = Modifier.padding(top = 2.dp),924 )925 }926 SubtleButton("rotate", peachColors.Breach) { rotateError = null; rotateConfirmOpen = true }927 }928 }929930 Hint("Sync uses the same zero-knowledge vault format as backup and restore; pairing authorizes a device, not a cloud account.", fg)931932 if (showBackgroundSyncPrompt) {933 BackgroundSyncDialog { enabled ->934 showBackgroundSyncPrompt = false935 syncVm.setBackgroundSyncEnabled(enabled)936 }937 }938}939940private fun deviceTypeLabel(type: String?): String = when (type) {941 "android" -> "Android"942 "phone" -> "Phone"943 "tablet" -> "Tablet"944 "browser" -> "Browser"945 else -> "Device"946}947948private fun syncTimeLabel(lastSyncedAt: Long?): String {949 if (lastSyncedAt == null) return "never synced"950 val diff = System.currentTimeMillis() - lastSyncedAt951 if (diff < 60_000) return "just now"952 if (diff < 3_600_000) return "${diff / 60_000}m ago"953 if (diff < 86_400_000) return "${diff / 3_600_000}h ago"954 return "${diff / 86_400_000}d ago"955}956957private fun isSyncStale(lastSyncedAt: Long?): Boolean =958 lastSyncedAt != null && System.currentTimeMillis() - lastSyncedAt > 7L * 24L * 60L * 60L * 1000L959960961962@Composable963private fun ProBody(fg: Color, vm: SettingsViewModel) {964 val ctx = LocalContext.current965 val isPro by vm.isPro.collectAsState()966 if (isPro) {967 ProActiveBody(fg, vm)968 return969 }970 val features = listOf(971 "Peach Sync" to "Encrypted · peer-to-peer",972 "Peach Codex" to "Restore from paper",973 "Passkeys" to "Zero-knowledge WebAuthn",974 "Advanced Vault Health" to "Reuse · age · exposure",975 "Canary entries" to "Detects vault compromise",976 "Duress vault" to "Decoy under coercion",977 )978 Text("PEACH PRO · ONE-TIME", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)979 Text(980 "Everything, everywhere.",981 modifier = Modifier.padding(top = 8.dp),982 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 24.sp,983 )984 Text(985 "One key unlocks every Pro feature — for the lifetime of the app.",986 modifier = Modifier.padding(top = 6.dp),987 color = fg.copy(alpha = 0.72f), fontFamily = PeachType.Body, fontSize = 12.sp, lineHeight = 17.sp,988 )989 Spacer(Modifier.height(10.dp))990 features.forEachIndexed { i, (name, desc) ->991 992 993 994 995 RowLine(fg, verticalPadding = 6.dp) {996 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {997 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))998 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)999 }1000 Text(desc, color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1001 }1002 }1003 Spacer(Modifier.height(12.dp))1004 Text(1005 "$39",1006 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 28.sp,1007 )1008 Text("once · yours forever", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em)1009 Spacer(Modifier.height(10.dp))1010 Box(1011 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1012 .background(fg.copy(alpha = 0.16f))1013 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1014 .clickable {1015 runCatching { ctx.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(PRO_URL))) }1016 }1017 .padding(vertical = 12.dp),1018 contentAlignment = Alignment.Center,1019 ) { Text("Get Peach Pro", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }10201021 1022 1023 1024 1025 Spacer(Modifier.height(44.dp))10261027 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1028 var key by remember { mutableStateOf("") }1029 val activating by vm.activating.collectAsState()1030 val activationError by vm.activationError.collectAsState()1031 Box(1032 Modifier.fillMaxWidth().padding(top = 6.dp)1033 .border(1.dp, fg.copy(alpha = 0.3f), RoundedCornerShape(8.dp))1034 .padding(horizontal = 12.dp, vertical = 10.dp),1035 ) {1036 BasicTextField(1037 value = key,1038 1039 1040 1041 1042 onValueChange = { key = it; vm.clearActivationError() },1043 singleLine = true,1044 textStyle = TextStyle(fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em, color = fg),1045 cursorBrush = SolidColor(fg),1046 modifier = Modifier.fillMaxWidth(),1047 decorationBox = { inner ->1048 if (key.isEmpty()) Text("PPK-XXXX-XXXX-XXXX", color = fg.copy(alpha = 0.3f), fontFamily = PeachType.Mono, fontSize = 13.sp, letterSpacing = 0.12.em)1049 inner()1050 },1051 )1052 }1053 if (activationError != null) {1054 Text(activationError!!, color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(top = 6.dp))1055 }1056 Spacer(Modifier.height(8.dp))1057 Box(1058 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1059 .background(fg.copy(alpha = if (activating || key.isBlank()) 0.08f else 0.16f))1060 .border(1.dp, fg.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1061 .clickable(enabled = !activating && key.isNotBlank()) { vm.activateLicense(key) }1062 .padding(vertical = 12.dp),1063 contentAlignment = Alignment.Center,1064 ) { Text(if (activating) "Activating…" else "Activate", color = fg, fontFamily = PeachType.Mono, fontSize = 12.sp) }1065}10661067@Composable1068private fun ProActiveBody(fg: Color, vm: SettingsViewModel) {1069 val ctx = LocalContext.current1070 val features = listOf("Peach Sync", "Peach Codex", "Passkeys", "Advanced Vault Health", "Canary entries", "Duress vault")1071 val licenseKey by vm.licenseKey.collectAsState()1072 val issuedAt by vm.licenseIssuedAt.collectAsState()1073 var showKey by remember { mutableStateOf(false) }1074 var copied by remember { mutableStateOf(false) }1075 val scope = rememberCoroutineScope()1076 Box(Modifier.fillMaxWidth().padding(vertical = 8.dp), contentAlignment = Alignment.Center) {1077 com.peachpasswords.ui.components.PeachMark(size = 60.dp)1078 }1079 Text(1080 "Peach Pro",1081 modifier = Modifier.fillMaxWidth(),1082 color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 26.sp,1083 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1084 )1085 Text(1086 formatLicenseActiveSince(issuedAt),1087 modifier = Modifier.fillMaxWidth().padding(top = 4.dp),1088 color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 9.sp, letterSpacing = 0.18.em,1089 textAlign = androidx.compose.ui.text.style.TextAlign.Center,1090 )1091 licenseKey?.let { key ->1092 Spacer(Modifier.height(12.dp))1093 Text("LICENSE KEY", color = fg.copy(alpha = 0.6f), fontFamily = PeachType.Mono, fontSize = 8.sp, letterSpacing = 0.22.em)1094 RowLine(fg) {1095 Text(1096 if (showKey) key else "************************",1097 color = fg.copy(alpha = if (showKey) 0.82f else 0.58f),1098 fontFamily = PeachType.Mono,1099 fontSize = 10.sp,1100 modifier = Modifier.weight(1f),1101 )1102 Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {1103 SubtleButton(if (copied) "copied" else "copy", fg) {1104 PeachClipboard.copy(ctx, "peach license", key)1105 copied = true1106 scope.launch {1107 delay(1_500)1108 copied = false1109 }1110 }1111 SubtleButton(if (showKey) "hide" else "reveal", fg) { showKey = !showKey }1112 }1113 }1114 }1115 Spacer(Modifier.height(12.dp))1116 features.forEachIndexed { i, name ->1117 RowLine(fg) {1118 Row(Modifier.weight(1f), verticalAlignment = Alignment.CenterVertically) {1119 Text("%02d".format(i + 1), color = fg.copy(alpha = 0.5f), fontFamily = PeachType.Mono, fontSize = 10.sp, modifier = Modifier.padding(end = 10.dp))1120 Text(name, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1121 }1122 Text("unlocked", color = com.peachpasswords.ui.theme.peachColors.HealthOk, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 11.sp)1123 }1124 }1125 Spacer(Modifier.height(12.dp))1126 Box(1127 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp))1128 .border(1.dp, com.peachpasswords.ui.theme.peachColors.Breach.copy(alpha = 0.4f), RoundedCornerShape(10.dp))1129 .clickable { vm.deactivate() }1130 .padding(vertical = 12.dp),1131 contentAlignment = Alignment.Center,1132 ) { Text("Deactivate", color = com.peachpasswords.ui.theme.peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 12.sp) }1133}11341135private fun formatLicenseActiveSince(issuedAt: Long?): String {1136 if (issuedAt == null) return "Active"1137 val monthYear = SimpleDateFormat("MMMM yyyy", Locale.getDefault()).format(Date(issuedAt))1138 return "Active since $monthYear"1139}1140114111421143@OptIn(ExperimentalLayoutApi::class)1144@Composable1145private fun FeedbackBody(fg: Color, vm: SettingsViewModel) {1146 val categories = listOf("Bug report", "Feature request", "Question", "Other")1147 var category by remember { mutableStateOf(categories[0]) }1148 var message by remember { mutableStateOf("") }1149 val state by vm.feedbackState.collectAsState()11501151 1152 DisposableEffect(Unit) { onDispose { vm.resetFeedback() } }11531154 if (state is FeedbackState.Sent) {1155 Box(1156 Modifier.fillMaxWidth().clip(RoundedCornerShape(10.dp)).background(fg.copy(alpha = 0.08f))1157 .border(1.dp, fg.copy(alpha = 0.32f), RoundedCornerShape(10.dp)).padding(16.dp),1158 ) {1159 Column {1160 Text("Thank you", color = fg, fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 18.sp)1161 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))1162 }1163 }1164 return1165 }11661167 val sending = state is FeedbackState.Sending11681169 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)1170 SubLabel("TYPE", fg)1171 FlowRow(horizontalArrangement = Arrangement.spacedBy(6.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1172 categories.forEach { cat -> Pill(cat, category == cat, fg) { if (!sending) category = cat } }1173 }1174 SubLabel("MESSAGE", fg)1175 Box(1176 Modifier.fillMaxWidth().height(110.dp).clip(RoundedCornerShape(8.dp))1177 .background(Color(0x2E000000)).border(1.dp, fg.copy(alpha = 0.22f), RoundedCornerShape(8.dp))1178 .padding(10.dp),1179 ) {1180 if (message.isEmpty()) Text("Describe the issue or idea...", color = fg.copy(alpha = 0.42f), fontFamily = PeachType.Body, fontSize = 12.sp)1181 BasicTextField(1182 value = message, onValueChange = { message = it.take(MAX_FEEDBACK_MESSAGE_LENGTH) },1183 enabled = !sending,1184 textStyle = TextStyle(color = fg, fontFamily = PeachType.Body, fontSize = 12.sp),1185 cursorBrush = SolidColor(fg), modifier = Modifier.fillMaxWidth(),1186 )1187 }1188 Text(1189 "Version ${BuildConfig.VERSION_NAME} · will be included automatically",1190 modifier = Modifier.padding(top = 6.dp),1191 color = fg.copy(alpha = 0.52f),1192 fontFamily = PeachType.Mono,1193 fontSize = 10.sp,1194 lineHeight = 14.sp,1195 )1196 Spacer(Modifier.height(8.dp))11971198 Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {1199 val canSend = !sending && sanitizeFeedbackMessage(message).isNotBlank()1200 Box(1201 Modifier.clip(RoundedCornerShape(8.dp))1202 .border(1.dp, fg.copy(alpha = if (canSend) 0.28f else 0.14f), RoundedCornerShape(8.dp))1203 .background(fg.copy(alpha = if (canSend) 0.08f else 0.04f))1204 .clickable(enabled = canSend) { vm.sendFeedback(category, message) }1205 .padding(horizontal = 12.dp, vertical = 6.dp),1206 ) {1207 Text(1208 feedbackSubmitLabel(state),1209 color = fg.copy(alpha = if (canSend) 1f else 0.4f),1210 fontFamily = PeachType.Mono, fontSize = 11.sp,1211 )1212 }1213 if (sending) {1214 CircularProgressIndicator(1215 color = LocalPeachAccent.current,1216 strokeWidth = 2.dp,1217 modifier = Modifier.size(16.dp),1218 )1219 }1220 }12211222 (state as? FeedbackState.Error)?.let { err ->1223 Text(1224 err.message,1225 modifier = Modifier.padding(top = 8.dp),1226 color = peachColors.Breach,1227 fontFamily = PeachType.Mono,1228 fontSize = 11.sp,1229 lineHeight = 15.sp,1230 )1231 }12321233 Hint("Sent anonymously · no account required", fg)1234}1235123612371238@Composable1239internal fun DuressSection(fg: Color, vm: SettingsViewModel) {1240 val configured by vm.duressConfigured.collectAsState()1241 if (configured) DuressActiveState(fg, vm) else DuressForm(fg, vm)1242}12431244@Composable1245private fun DuressActiveState(fg: Color, vm: SettingsViewModel) {1246 Text(1247 "Duress password is active",1248 color = peachColors.HealthOk,1249 fontFamily = PeachType.Mono,1250 fontSize = 11.sp,1251 modifier = Modifier.padding(top = 6.dp),1252 )1253 Spacer(Modifier.height(8.dp))1254 DuressDangerGhostButton("Disable duress password", fg) { vm.disableDuress() }1255 Hint("Entering your duress password instead of your real one triggers the action you chose.", fg)1256}12571258@Composable1259private fun DuressForm(fg: Color, vm: SettingsViewModel) {1260 var enabled by remember { mutableStateOf(false) }1261 var password by remember { mutableStateOf("") }1262 var confirm by remember { mutableStateOf("") }1263 var action by remember { mutableStateOf(DuressAction.DECOY) }1264 var error by remember { mutableStateOf<String?>(null) }1265 val scope = rememberCoroutineScope()12661267 RowLine(fg) {1268 Name("Duress password", fg)1269 Toggle(enabled, fg) { on ->1270 enabled = on1271 if (!on) { password = ""; confirm = ""; error = null }1272 }1273 }1274 Text(1275 "Entering your duress password instead of your real one opens a decoy vault or wipes the real one.",1276 color = fg.copy(alpha = 0.7f),1277 fontFamily = PeachType.Mono,1278 fontSize = 10.sp,1279 modifier = Modifier.padding(top = 6.dp),1280 )12811282 AnimatedVisibility(enabled) {1283 Column(Modifier.fillMaxWidth().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {1284 PwField("DURESS PASSPHRASE", password, fg) { password = it; error = null }1285 PwField("CONFIRM DURESS PASSPHRASE", confirm, fg) { confirm = it; error = null }12861287 Text(1288 "When your duress password is entered at the lock screen, Peach will:",1289 color = fg.copy(alpha = 0.7f),1290 fontFamily = PeachType.Mono,1291 fontSize = 10.sp,1292 modifier = Modifier.padding(top = 4.dp),1293 )12941295 DuressRadioOption("Show a decoy vault", action == DuressAction.DECOY, fg) { action = DuressAction.DECOY }1296 DuressRadioOption("Destroy the real vault", action == DuressAction.DESTROY, fg) { action = DuressAction.DESTROY }12971298 error?.let { Text(it, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 10.sp) }12991300 val canSave = password.isNotBlank() && confirm.isNotBlank()1301 DuressSaveButton("Save duress password", fg, canSave) {1302 error = when {1303 password.isBlank() || confirm.isBlank() -> "Enter and confirm a duress password"1304 password != confirm -> "Passwords do not match"1305 else -> null1306 }1307 if (error == null) scope.launch {1308 if (vm.saveDuress(password, action)) {1309 password = ""; confirm = ""; enabled = false1310 } else {1311 error = "Couldn't save — the duress passphrase must differ from your real password"1312 }1313 }1314 }1315 }1316 }1317}13181319@Composable1320private fun DuressRadioOption(label: String, selected: Boolean, fg: Color, onClick: () -> Unit) {1321 val accent = LocalPeachAccent.current1322 Row(1323 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp)).clickable(onClick = onClick).padding(vertical = 7.dp),1324 verticalAlignment = Alignment.CenterVertically,1325 horizontalArrangement = Arrangement.spacedBy(10.dp),1326 ) {1327 Box(1328 Modifier.size(16.dp).clip(CircleShape)1329 .border(1.dp, if (selected) accent else fg.copy(alpha = 0.4f), CircleShape),1330 contentAlignment = Alignment.Center,1331 ) {1332 if (selected) Box(Modifier.size(8.dp).clip(CircleShape).background(accent))1333 }1334 Text(label, color = if (selected) accent else fg, fontFamily = PeachType.Mono, fontSize = 11.sp)1335 }1336}13371338@Composable1339private fun DuressSaveButton(label: String, fg: Color, enabled: Boolean, onClick: () -> Unit) {1340 val accent = LocalPeachAccent.current1341 val tint = if (enabled) accent else fg.copy(alpha = 0.3f)1342 Box(1343 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1344 .border(1.dp, tint.copy(alpha = if (enabled) 0.6f else 0.3f), RoundedCornerShape(8.dp))1345 .background(tint.copy(alpha = if (enabled) 0.16f else 0.06f))1346 .let { if (enabled) it.clickable(onClick = onClick) else it }1347 .padding(vertical = 11.dp),1348 contentAlignment = Alignment.Center,1349 ) {1350 Text(label, color = if (enabled) accent else fg.copy(alpha = 0.4f), fontFamily = PeachType.Mono, fontSize = 11.sp)1351 }1352}13531354@Composable1355private fun DuressDangerGhostButton(label: String, fg: Color, onClick: () -> Unit) {1356 Box(1357 Modifier.fillMaxWidth().clip(RoundedCornerShape(8.dp))1358 .border(1.dp, peachColors.Breach.copy(alpha = 0.5f), RoundedCornerShape(8.dp))1359 .clickable(onClick = onClick)1360 .padding(vertical = 11.dp),1361 contentAlignment = Alignment.Center,1362 ) {1363 Text(label, color = peachColors.Breach, fontFamily = PeachType.Mono, fontSize = 11.sp)1364 }1365}136613671368@Composable1369private fun SyncModeRow(1370 title: String,1371 detail: String,1372 selected: Boolean,1373 fg: Color,1374 onSelect: () -> Unit,1375) {1376 RowLine(fg, Modifier.clickable(onClick = onSelect)) {1377 Column(Modifier.weight(1f)) {1378 Text(title, color = fg, fontFamily = PeachType.Body, fontSize = 13.sp)1379 Text(1380 detail,1381 color = fg.copy(alpha = 0.7f),1382 fontFamily = PeachType.Body,1383 fontSize = 11.sp,1384 lineHeight = 16.sp,1385 modifier = Modifier.padding(top = 2.dp),1386 )1387 }1388 Text(1389 if (selected) "●" else "○",1390 color = if (selected) fg else fg.copy(alpha = 0.45f),1391 fontFamily = PeachType.Mono,1392 fontSize = 14.sp,1393 modifier = Modifier.padding(start = 10.dp),1394 )1395 }1396}