f291581522e2
feat: E4 identity suggest dropdown for username/email in EntryEdit + VaultRepository.getDistinctFieldValues (frequency-sorted) (v2.1.37)
- time
- 2026-06-09 04:24 UTC · 5 months ago
- machine
- koh2
- agent
- claude-opus-4-8
- session
- peach remaining gaps
- parent
- 60022bcd8419
↓ peach-android-f2915815.tar.gzatlas at this save
files changed5 files
app/drafts/E4/IdentitySuggestDropdown.kt+0 −133app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+3 −2app/src/main/java/com/peachpasswords/ui/vault/EntryEditViewModel.kt+8 −0app/src/main/java/com/peachpasswords/ui/vault/IdentitySuggestDropdown.kt+133 −0app/src/main/java/com/peachpasswords/vault/VaultRepository.kt+26 −0app/drafts/E4/IdentitySuggestDropdown.kt+0 −133
@@ -1,133 +0,0 @@1-package com.peachpasswords.ui.vault2-3-import androidx.compose.foundation.background4-import androidx.compose.foundation.border5-import androidx.compose.foundation.layout.Box6-import androidx.compose.foundation.layout.Column7-import androidx.compose.foundation.layout.Spacer8-import androidx.compose.foundation.layout.fillMaxWidth9-import androidx.compose.foundation.layout.height10-import androidx.compose.foundation.layout.padding11-import androidx.compose.foundation.shape.RoundedCornerShape12-import androidx.compose.foundation.text.BasicTextField13-import androidx.compose.material3.DropdownMenu14-import androidx.compose.material3.DropdownMenuItem15-import androidx.compose.material3.Text16-import androidx.compose.runtime.Composable17-import androidx.compose.runtime.getValue18-import androidx.compose.runtime.mutableStateOf19-import androidx.compose.runtime.remember20-import androidx.compose.runtime.setValue21-import androidx.compose.ui.Modifier22-import androidx.compose.ui.draw.clip23-import androidx.compose.ui.focus.onFocusChanged24-import androidx.compose.ui.graphics.SolidColor25-import androidx.compose.ui.text.TextStyle26-import androidx.compose.ui.unit.dp27-import androidx.compose.ui.unit.sp28-import androidx.compose.ui.window.PopupProperties29-import com.peachpasswords.ui.theme.LocalPeachAccent30-import com.peachpasswords.ui.theme.PeachColors31-import com.peachpasswords.ui.theme.PeachType32-33-/**34- * Anchored suggestion dropdown for identity-style fields (username/email).35- *36- * Self-contained for clean merge into EntryEditScreen.kt. The brief uses37- * `DropdownMenu(expanded = focused && suggestions.isNotEmpty())`; we keep that38- * shape but mark the popup non-focusable so it never steals focus from the39- * BasicTextField that drives `expanded` — otherwise the field blurs the instant40- * the menu opens and the dropdown flickers shut.41- *42- * Mirrors the editor's visual language: IBM Plex Mono rows on the S2 glass43- * surface with a hairline T3 border. Suggestions are expected pre-trimmed to44- * <=4 by the ViewModel (see usernameSuggestions in INTEGRATION.md).45- */46-@Composable47-fun IdentitySuggestDropdown(48- expanded: Boolean,49- suggestions: List<String>,50- onPick: (String) -> Unit,51- onDismiss: () -> Unit,52-) {53- DropdownMenu(54- expanded = expanded && suggestions.isNotEmpty(),55- onDismissRequest = onDismiss,56- properties = PopupProperties(focusable = false),57- modifier = Modifier58- .background(PeachColors.S2)59- .border(1.dp, PeachColors.T3, RoundedCornerShape(10.dp))60- .clip(RoundedCornerShape(10.dp)),61- ) {62- suggestions.forEach { suggestion ->63- DropdownMenuItem(64- text = {65- Text(66- suggestion,67- style = TextStyle(68- color = PeachColors.T1,69- fontFamily = PeachType.Mono,70- fontSize = 11.sp,71- ),72- )73- },74- onClick = { onPick(suggestion) },75- modifier = Modifier.fillMaxWidth(),76- )77- }78- }79-}80-81-/**82- * Identity field + anchored suggest dropdown, wired to focus state.83- *84- * Drop-in replacement for the bare `Field(...)` calls for username/email in85- * EntryEditScreen. It owns the focus tracking the dropdown needs; the parent86- * supplies value, suggestions, and the change callback. The dropdown is wrapped87- * with the field so the popup anchors directly beneath it.88- *89- * `Field` is `private` in EntryEditScreen.kt, so this re-implements the same90- * underline input rather than calling it. Keep this composable in the same file91- * when merging, or make `Field` accept `onFocusChanged` and reuse it (see92- * INTEGRATION.md "Option A").93- */94-@Composable95-fun IdentitySuggestField(96- label: String,97- value: String,98- suggestions: List<String>,99- onChange: (String) -> Unit,100-) {101- val accent = LocalPeachAccent.current102- var focused by remember { mutableStateOf(false) }103-104- Column(Modifier.fillMaxWidth().padding(bottom = 14.dp)) {105- Text(label.uppercase(), color = PeachColors.T1, fontFamily = PeachType.Mono, fontSize = 8.sp)106- Spacer(Modifier.height(6.dp))107- Box(108- Modifier.fillMaxWidth()109- .border(1.dp, PeachColors.T3, RoundedCornerShape(10.dp))110- .padding(horizontal = 12.dp, vertical = 12.dp),111- ) {112- BasicTextField(113- value = value,114- onValueChange = onChange,115- singleLine = true,116- textStyle = TextStyle(color = PeachColors.T0, fontFamily = PeachType.Mono, fontSize = 13.sp),117- cursorBrush = SolidColor(accent),118- modifier = Modifier119- .fillMaxWidth()120- .onFocusChanged { focused = it.isFocused },121- )122- }123- IdentitySuggestDropdown(124- expanded = focused,125- suggestions = suggestions.filter { it != value },126- onPick = { picked ->127- onChange(picked)128- focused = false129- },130- onDismiss = { focused = false },131- )132- }133-}app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+3 −2
@@ -60,6 +60,7 @@6060 vm: EntryEditViewModel = hiltViewModel(),6161 ) {6262 val f by vm.form.collectAsState()63+ val usernameSuggestions by vm.usernameSuggestions.collectAsState()6364 val accent = LocalPeachAccent.current6465 6566 ShellBackground {@@ -100,8 +101,8 @@100101 Field("title", f.title, vm::setTitle)101102 if (f.type == "login") {102103 Field("url", f.url, vm::setUrl)103- Field("username", f.username, vm::setUsername)104- Field("email", f.email, vm::setEmail)104+ IdentitySuggestField("username", f.username, usernameSuggestions, vm::setUsername)105+ IdentitySuggestField("email", f.email, usernameSuggestions, vm::setEmail)105106 PasswordField(106107 value = f.password,107108 show = f.showPassword,app/src/main/java/com/peachpasswords/ui/vault/EntryEditViewModel.kt+8 −0
@@ -81,6 +81,14 @@8181 )8282 val form: StateFlow<EditForm> = _form.asStateFlow()8383 84+ /**85+ * Up to 4 previously-used identity values, frequency-sorted. Username and86+ * email share one field in the Peach model, so both editor fields suggest87+ * from "username".88+ */89+ val usernameSuggestions: StateFlow<List<String>> =90+ MutableStateFlow(vault.getDistinctFieldValues("username").take(4)).asStateFlow()91+8492 fun setType(t: String) = _form.update { it.copy(type = t) }8593 fun setTitle(v: String) = _form.update { it.copy(title = v, error = null) }8694 fun setUsername(v: String) = _form.update { it.copy(username = v) }app/src/main/java/com/peachpasswords/ui/vault/IdentitySuggestDropdown.kt+133 −0
@@ -0,0 +1,133 @@1+package com.peachpasswords.ui.vault2+3+import androidx.compose.foundation.background4+import androidx.compose.foundation.border5+import androidx.compose.foundation.layout.Box6+import androidx.compose.foundation.layout.Column7+import androidx.compose.foundation.layout.Spacer8+import androidx.compose.foundation.layout.fillMaxWidth9+import androidx.compose.foundation.layout.height10+import androidx.compose.foundation.layout.padding11+import androidx.compose.foundation.shape.RoundedCornerShape12+import androidx.compose.foundation.text.BasicTextField13+import androidx.compose.material3.DropdownMenu14+import androidx.compose.material3.DropdownMenuItem15+import androidx.compose.material3.Text16+import androidx.compose.runtime.Composable17+import androidx.compose.runtime.getValue18+import androidx.compose.runtime.mutableStateOf19+import androidx.compose.runtime.remember20+import androidx.compose.runtime.setValue21+import androidx.compose.ui.Modifier22+import androidx.compose.ui.draw.clip23+import androidx.compose.ui.focus.onFocusChanged24+import androidx.compose.ui.graphics.SolidColor25+import androidx.compose.ui.text.TextStyle26+import androidx.compose.ui.unit.dp27+import androidx.compose.ui.unit.sp28+import androidx.compose.ui.window.PopupProperties29+import com.peachpasswords.ui.theme.LocalPeachAccent30+import com.peachpasswords.ui.theme.PeachColors31+import com.peachpasswords.ui.theme.PeachType32+33+/**34+ * Anchored suggestion dropdown for identity-style fields (username/email).35+ *36+ * Self-contained for clean merge into EntryEditScreen.kt. The brief uses37+ * `DropdownMenu(expanded = focused && suggestions.isNotEmpty())`; we keep that38+ * shape but mark the popup non-focusable so it never steals focus from the39+ * BasicTextField that drives `expanded` — otherwise the field blurs the instant40+ * the menu opens and the dropdown flickers shut.41+ *42+ * Mirrors the editor's visual language: IBM Plex Mono rows on the S2 glass43+ * surface with a hairline T3 border. Suggestions are expected pre-trimmed to44+ * <=4 by the ViewModel (see usernameSuggestions in INTEGRATION.md).45+ */46+@Composable47+fun IdentitySuggestDropdown(48+ expanded: Boolean,49+ suggestions: List<String>,50+ onPick: (String) -> Unit,51+ onDismiss: () -> Unit,52+) {53+ DropdownMenu(54+ expanded = expanded && suggestions.isNotEmpty(),55+ onDismissRequest = onDismiss,56+ properties = PopupProperties(focusable = false),57+ modifier = Modifier58+ .background(PeachColors.S2)59+ .border(1.dp, PeachColors.T3, RoundedCornerShape(10.dp))60+ .clip(RoundedCornerShape(10.dp)),61+ ) {62+ suggestions.forEach { suggestion ->63+ DropdownMenuItem(64+ text = {65+ Text(66+ suggestion,67+ style = TextStyle(68+ color = PeachColors.T1,69+ fontFamily = PeachType.Mono,70+ fontSize = 11.sp,71+ ),72+ )73+ },74+ onClick = { onPick(suggestion) },75+ modifier = Modifier.fillMaxWidth(),76+ )77+ }78+ }79+}80+81+/**82+ * Identity field + anchored suggest dropdown, wired to focus state.83+ *84+ * Drop-in replacement for the bare `Field(...)` calls for username/email in85+ * EntryEditScreen. It owns the focus tracking the dropdown needs; the parent86+ * supplies value, suggestions, and the change callback. The dropdown is wrapped87+ * with the field so the popup anchors directly beneath it.88+ *89+ * `Field` is `private` in EntryEditScreen.kt, so this re-implements the same90+ * underline input rather than calling it. Keep this composable in the same file91+ * when merging, or make `Field` accept `onFocusChanged` and reuse it (see92+ * INTEGRATION.md "Option A").93+ */94+@Composable95+fun IdentitySuggestField(96+ label: String,97+ value: String,98+ suggestions: List<String>,99+ onChange: (String) -> Unit,100+) {101+ val accent = LocalPeachAccent.current102+ var focused by remember { mutableStateOf(false) }103+104+ Column(Modifier.fillMaxWidth().padding(bottom = 14.dp)) {105+ Text(label.uppercase(), color = PeachColors.T1, fontFamily = PeachType.Mono, fontSize = 8.sp)106+ Spacer(Modifier.height(6.dp))107+ Box(108+ Modifier.fillMaxWidth()109+ .border(1.dp, PeachColors.T3, RoundedCornerShape(10.dp))110+ .padding(horizontal = 12.dp, vertical = 12.dp),111+ ) {112+ BasicTextField(113+ value = value,114+ onValueChange = onChange,115+ singleLine = true,116+ textStyle = TextStyle(color = PeachColors.T0, fontFamily = PeachType.Mono, fontSize = 13.sp),117+ cursorBrush = SolidColor(accent),118+ modifier = Modifier119+ .fillMaxWidth()120+ .onFocusChanged { focused = it.isFocused },121+ )122+ }123+ IdentitySuggestDropdown(124+ expanded = focused,125+ suggestions = suggestions.filter { it != value },126+ onPick = { picked ->127+ onChange(picked)128+ focused = false129+ },130+ onDismiss = { focused = false },131+ )132+ }133+}app/src/main/java/com/peachpasswords/vault/VaultRepository.kt+26 −0
@@ -361,6 +361,32 @@361361 .distinct()362362 .sorted()363363 .toList()364+365+ /**366+ * Distinct non-blank values for an identity field across active entries,367+ * most-frequently-used first. Supports "username" and "email"; unknown field368+ * names return an empty list. Values keep original casing (deduped369+ * case-insensitively) so a suggestion matches what the user typed.370+ */371+ fun getDistinctFieldValues(field: String): List<String> {372+ val select: (VaultEntry) -> String? = when (field) {373+ "username" -> { e -> e.username }374+ "email" -> { e -> e.email }375+ else -> return emptyList()376+ }377+ return entryList.asSequence()378+ .filter { it.deletedAt == null }379+ .mapNotNull { select(it)?.trim() }380+ .filter { it.isNotEmpty() }381+ .groupingBy { it.lowercase() }382+ .aggregate { _, acc: Pair<String, Int>?, value, _ ->383+ Pair(acc?.first ?: value, (acc?.second ?: 0) + 1)384+ }385+ .values386+ .sortedWith(compareByDescending<Pair<String, Int>> { it.second }.thenBy { it.first.lowercase() })387+ .map { it.first }388+ }389+364390 fun getTombstones(): List<Tombstone> =365391 entryList.filter { it.deletedAt != null }.map { Tombstone(it.id, it.deletedAt!!) }366392 fun getVaultVersion(): Long = store.version()