# D6 — Inline Field Editing in EntryDetailScreen — Integration Per-field inline edit (view↔edit toggle, underlined `BasicTextField`, ✓ save / ✗ cancel), a biometric/password gate before editing the password field, and an identity-suggest `DropdownMenu` on USERNAME/EMAIL fed by a new repo method. **Shared-file note:** D6, D7, E6 all touch `EntryDetailScreen.kt`. This block is self-contained — the composables live in `EditableFieldRow.kt` and only the call sites + one VM method + one repo method change in the real files. Anchors below. --- ## 1. Files ### A. Drop-in composable file `app/drafts/D6/EditableFieldRow.kt` → `app/src/main/java/com/peachpasswords/ui/vault/EditableFieldRow.kt` It reuses two private helpers that already exist in `EntryDetailScreen.kt`: `FieldShell` and `CopyButton`. **Choose ONE wiring approach:** - **Inline (simplest):** paste the public composables `EditableFieldRow` and `EditablePasswordRow` (plus the private `InlineEditor` / `UnderlinedField` / `SaveCancelRow`) directly into `EntryDetailScreen.kt`. No visibility changes needed — they share the file with `FieldShell`/`CopyButton`. Drop the package + import lines that duplicate ones already in the target. - **Separate file (as drafted):** keep `EditableFieldRow.kt` as its own file and change the visibility of the two helpers in `EntryDetailScreen.kt` from `private` to `internal`: - `private fun FieldShell(` → `internal fun FieldShell(` - `private fun CopyButton(` → `internal fun CopyButton(` Either works; inline is recommended since the orchestrator is already editing that file for D7/E6. --- ## 2. EntryDetailScreen.kt — call-site swaps Collect the suggestion list at the top of the composable, next to the existing state collectors. **Anchor (existing, ~line 83-85):** ```kotlin val entry by vm.entry.collectAsState() val revealed by vm.revealed.collectAsState() val copiedField by vm.copiedField.collectAsState() ``` **Add immediately below:** ```kotlin val identitySuggestions by vm.identitySuggestions.collectAsState() ``` ### USERNAME / EMAIL rows **Anchor (existing, ~line 202-207):** ```kotlin e.username?.takeIf { it.isNotBlank() }?.let { FieldRow("username", it, copiedField == "username") { vm.copy("username", it) } } e.email?.takeIf { it.isNotBlank() }?.let { FieldRow("email", it, copiedField == "email") { vm.copy("email", it) } } ``` **Replace with:** ```kotlin e.username?.takeIf { it.isNotBlank() }?.let { v -> EditableFieldRow( label = "username", field = "username", value = v, copied = copiedField == "username", onCopy = { vm.copy("username", v) }, onSave = { vm.updateField("username", it) }, suggestions = identitySuggestions, ) } e.email?.takeIf { it.isNotBlank() }?.let { v -> EditableFieldRow( label = "email", field = "email", value = v, copied = copiedField == "email", onCopy = { vm.copy("email", v) }, onSave = { vm.updateField("email", it) }, suggestions = identitySuggestions, ) } ``` > Email and username share the same value pool in the Peach data model, so both > use `getDistinctFieldValues("username")` (see §4). ### PASSWORD row **Anchor (existing, ~line 208-224):** the whole `PasswordRow(...)` block inside `e.password?.takeIf { it.isNotBlank() }?.let { pw -> ... }`. **Replace the `PasswordRow(...)` call with:** ```kotlin EditablePasswordRow( value = pw, copied = copiedField == "password", entryTitle = e.title, onCopy = { vm.copy("password", pw) }, onSave = { vm.updateField("password", it) }, ) ``` > This drops the reveal-only `PasswordRow` in favor of the gated editable row, > which itself runs the biometric prompt before entering edit mode (same > `Biometrics.isAvailable` / `Biometrics.authenticate` flow). If you want to KEEP > the separate reveal-only view alongside inline edit, leave `PasswordRow` in and > only add `EditablePasswordRow` — but the brief specifies inline edit replaces > the read-only rows, so the swap above is the intended path. `vm.reveal/mask` > and the `revealed` state become unused if `PasswordRow` is fully removed — > delete them only if no other row needs them. ### NOTES row (optional, recommended for parity) **Anchor (existing, ~line 229-231):** ```kotlin e.notes?.takeIf { it.isNotBlank() }?.let { FieldRow("notes", it, copiedField == "notes", mono = false) { vm.copy("notes", it) } } ``` **Replace with:** ```kotlin e.notes?.takeIf { it.isNotBlank() }?.let { v -> EditableFieldRow( label = "notes", field = "notes", value = v, copied = copiedField == "notes", onCopy = { vm.copy("notes", v) }, onSave = { vm.updateField("notes", it) }, mono = false, singleLine = false, ) } ``` ### Imports to add to EntryDetailScreen.kt Only if using the **inline** approach the imports already land with the pasted code. For the **separate-file** approach the call sites need nothing new beyond what is already imported (the new composables are same-package). If they end up in a different package, add: ```kotlin import com.peachpasswords.ui.vault.EditableFieldRow import com.peachpasswords.ui.vault.EditablePasswordRow ``` --- ## 3. EntryDetailViewModel.kt — additions Add the `updateField` method and the `identitySuggestions` flow. **Anchor (existing, ~line 33):** end of the `entry` StateFlow declaration: ```kotlin val entry: StateFlow = vault.entries.map { list -> list.firstOrNull { it.id == id } } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), vault.getEntry(id)) ``` **Add below it:** ```kotlin /** Distinct prior username/email values for the identity-suggest dropdown. */ val identitySuggestions: StateFlow> = vault.entries .map { vault.getDistinctFieldValues("username").take(4) } .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList()) ``` **Anchor (existing, ~line 69):** the `delete(...)` method. Add this method alongside it (e.g. just above `delete`): ```kotlin /** * Persist a single field's inline edit. Reads the live entry, applies the new * value to the named field, and writes a full-entry patch via updateEntry * (which handles password-history capture and timestamps). No-op if the entry * is gone. Trim/normalisation is the caller's responsibility for text fields; * the password is written verbatim. */ fun updateField(field: String, value: String) { val current = entry.value ?: return val patch = when (field) { "username" -> current.copy(username = value.ifBlank { null }) "email" -> current.copy(email = value.ifBlank { null }) "password" -> current.copy(password = value.ifBlank { null }) "notes" -> current.copy(notes = value.ifBlank { null }) "totp" -> current.copy(totp = value.ifBlank { null }) else -> return } viewModelScope.launch { runCatching { vault.updateEntry(patch) } } } ``` `launch`, `map`, `stateIn`, `SharingStarted` are all already imported in the VM. > The `"totp"` branch is included for E6 (TOTP inline edit) so that item can reuse > this same method — harmless for D6. Remove if the orchestrator prefers E6 to add > its own branch. --- ## 4. VaultRepository.kt — new method Add `getDistinctFieldValues` next to the existing `getDistinctTags` (~line 355). **Anchor (existing, ~line 354-363):** ```kotlin /** Sorted, de-duplicated tags across all active entries. */ fun getDistinctTags(): List = entryList.asSequence() .filter { it.deletedAt == null } .flatMap { it.tags?.asSequence() ?: emptySequence() } .map { it.trim().lowercase() } .filter { it.isNotEmpty() } .distinct() .sorted() .toList() ``` **Add below it:** ```kotlin /** * Distinct non-blank values for [field] across all active entries, ordered by * descending frequency (most-used first). Currently supports "username" — * which pools both the username and email columns, since the Peach data model * treats them as the same identity field for suggestions. Used by the * identity-suggest dropdown in inline field editing (D6) and EntryEditScreen (E4). */ fun getDistinctFieldValues(field: String): List { val active = entryList.filter { it.deletedAt == null } val values: Sequence = when (field) { "username" -> active.asSequence().flatMap { sequenceOf(it.username, it.email) }.filterNotNull() "email" -> active.asSequence().mapNotNull { it.email } "password" -> emptySequence() else -> emptySequence() } return values .map { it.trim() } .filter { it.isNotEmpty() } .groupingBy { it } .eachCount() .entries .sortedWith(compareByDescending> { it.value }.thenBy { it.key }) .map { it.key } } ``` > Frequency-sorted as the brief (§14) requires. "password" deliberately returns > empty — never suggest passwords. "email" is provided for completeness; D6 only > calls "username". --- ## 5. Risks / assumptions - **Verified:** `VaultEntry` has `username`, `email`, `password`, `notes`, `totp` (all `String?`). `VaultRepository.updateEntry(patch: VaultEntry)` exists and handles password-history + timestamps. `Biometrics.isAvailable` / `Biometrics.authenticate(activity, title, subtitle, onSuccess)` exist and are already used by the current `PasswordRow` reveal flow — `EditablePasswordRow` mirrors it exactly. - **No new imports/deps** beyond Compose Material3 `DropdownMenu` / `DropdownMenuItem` (already on the classpath; EntryEditScreen-area uses M3). - **`remember(value)` keying:** `editing`/`draft` are keyed on `value` so an external entry update (e.g. from sync) resets a stale open editor. Acceptable; if a sync lands mid-edit the editor closes rather than clobbering — matches last-write-wins intent. - **Password reveal state:** if you fully replace `PasswordRow`, the VM's `reveal()`/`mask()`/`revealed` may become dead code. Leave them if any other surface (D7/E6) needs reveal; otherwise the orchestrator can prune. - **DropdownMenu anchoring:** M3 `DropdownMenu` anchors to its parent `Box`; it opens on entering edit mode (when suggestions exist) and on dismiss/pick. If a focus-driven open is preferred, gate `dropdownOpen` on a `FocusRequester`/`onFocusChanged` instead — left simple per the brief. - **`✓`/`✗` glyphs:** rendered via `PeachType.labelMono` (IBM Plex Mono). If the bundled Mono lacks these glyphs, substitute the rounded `Check`/`Close` Material icons already imported in EntryDetailScreen.kt.