1package com.peachpasswords.ui.settings23import androidx.lifecycle.ViewModel4import androidx.lifecycle.viewModelScope5import com.peachpasswords.vault.VaultRepository6import com.peachpasswords.vault.VaultSettings7import dagger.hilt.android.lifecycle.HiltViewModel8import kotlinx.coroutines.flow.StateFlow9import kotlinx.coroutines.launch10import javax.inject.Inject1112@HiltViewModel13class SettingsViewModel @Inject constructor(14 private val vault: VaultRepository,15) : ViewModel() {16 val entries: StateFlow<List<com.peachpasswords.vault.VaultEntry>> = vault.entries17 val settings: StateFlow<VaultSettings> = vault.settings1819 20 val isPro: Boolean = false2122 private fun mutate(block: (VaultSettings) -> VaultSettings) {23 viewModelScope.launch { vault.updateSettings(block(vault.settings.value)) }24 }2526 fun setTheme(theme: String) = mutate { it.copy(theme = theme) }27 fun setAccent(name: String) = mutate { it.copy(accentColor = name) }28 fun setTextSize(size: String) = mutate { it.copy(textSize = size) }29 fun setReduceMotion(on: Boolean) = mutate { it.copy(reduceMotion = on) }30 fun setBreachMonitoring(on: Boolean) = mutate { it.copy(breachMonitoring = on) }31 fun setBiometrics(on: Boolean) = mutate { it.copy(biometricsEnabled = on) }32 fun setAutoLockMinutes(min: Int?) = mutate { it.copy(autoLockMinutes = min) }33 fun setTrashRetentionDays(days: Int?) = mutate { it.copy(trashRetentionDays = days) }3435 suspend fun changePassword(current: String, next: String): Boolean =36 vault.changePassword(current, next)3738 39 fun lede(id: CardId, entriesCount: Int, s: VaultSettings): String = when (id) {40 CardId.Pro -> if (isPro) "active · paid once, yours forever" else "$39 once · yours forever"41 CardId.Protection ->42 "${if (s.breachMonitoring) "breaches watched" else "breach watch off"} · manual lock"43 CardId.Vault ->44 "$entriesCount ${if (entriesCount == 1) "entry" else "entries"} · backups, history, cleanup"45 CardId.Sync -> if (isPro) "pair by chirp, keep in step" else "Pro · encrypted device pairing"46 CardId.Appearance -> "${s.theme} · ${s.accentColor} · ${s.textSize}"47 CardId.Shortcuts -> "bindings · what your fingers know"48 CardId.Feedback -> "tell us what would make it better"49 }50}