INTEGRATION.md
D3: Tags UI — Integration
UI-only. Data model + repo are already landed and verified:
VaultEntry.tags: List<String>? = null(VaultEntry.kt:28)VaultRepository.getActiveEntries(tagFilter: String? = null)(VaultRepository.kt:347)VaultRepository.getDistinctTags(): List<String>(VaultRepository.kt:355)
Files in this draft
| Draft file | Destination | Composables |
|---|---|---|
TagChipEditor.kt |
app/src/main/java/com/peachpasswords/ui/vault/TagChipEditor.kt |
TagChipEditor, internal normalizeTag |
TagListWidgets.kt |
app/src/main/java/com/peachpasswords/ui/vault/TagListWidgets.kt |
TagFilterStrip, EntryRowTags |
DetailTagRow.kt |
app/src/main/java/com/peachpasswords/ui/vault/DetailTagRow.kt |
DetailTagRow |
All three are package com.peachpasswords.ui.vault and internal, so they
drop in as new files with no import churn in the target screens.
FlowRow note: Used in
TagChipEditorandDetailTagRow, annotated@OptIn(ExperimentalLayoutApi::class).FlowRowisandroidx.compose.foundation.layout.FlowRowand is present in compose-bom 2024.06.00 (already on classpath). No new dependency. If a build warning about the opt-in surfaces elsewhere, it is contained to these two files.
Constraints (enforced in TagChipEditor / normalizeTag)
- Max 10 tags per entry.
- Max 32 chars per tag.
- Lowercase, trimmed.
- De-duplicated (case-insensitive — input is already lowered).
- Commit triggers: space character or IME Done/enter.
- At limit: input field hidden,
"Max 10 tags"hint shown.
normalizeTag is internal so the orchestrator can reuse it in
EntryEditViewModel.addTag to keep storage canonical.
1. EntryEditViewModel.kt — form state + setters
1a. Add tags to EditForm
Anchor (EntryEditViewModel.kt:30, inside data class EditForm):
val notes: String = "",
Add immediately after:
val tags: List<String> = emptyList(),
1b. Hydrate from existing entry
Anchor (EntryEditViewModel.kt:64-65):
notes = it.notes.orEmpty(),
history = it.passwordHistory.orEmpty(),
Add a line between them (or after notes):
tags = it.tags.orEmpty(),
1c. Add setters (mirror setNotes at line 78)
Place after fun setNotes(...):
fun addTag(raw: String) = _form.update { f ->
val tag = raw.trim().lowercase().take(32)
if (tag.isEmpty() || f.tags.size >= 10 || f.tags.any { it == tag }) f
else f.copy(tags = f.tags + tag)
}
fun removeTag(tag: String) = _form.update { it.copy(tags = it.tags - tag) }
The
TagChipEditoralready normalizes/dedupes before callingonAdd, but the VM re-guards so the invariant holds regardless of caller.
1d. Expose distinct-tag suggestions
Add a property (sibling style to other VM state; vault is already injected):
val allTags: List<String> = vault.getDistinctTags()
If a live flow is preferred over a snapshot, wrap it; a snapshot at VM construction is sufficient for autocomplete.
1e. Persist on save — addEntry branch
Anchor (EntryEditViewModel.kt:129):
notes = f.notes.ifBlank { null },
createdAt = 0, modifiedAt = 0,
Add between them:
tags = f.tags.ifEmpty { null },
1f. Persist on save — updateEntry branch
Anchor (EntryEditViewModel.kt:142):
notes = f.notes.ifBlank { null },
),
Add before the closing paren:
tags = f.tags.ifEmpty { null },
2. EntryEditScreen.kt — tag chip editor
Insert the editor below the NOTES field. Anchor (EntryEditScreen.kt:130):
Field("notes", f.notes, vm::setNotes, singleLine = false)
Add immediately after that line:
TagChipEditor(
tags = f.tags,
allTags = vm.allTags,
onAdd = vm::addTag,
onRemove = vm::removeTag,
)
No new imports needed (same package).
3. VaultListViewModel.kt — activeTagFilter state
3a. Add the StateFlow + setter
Anchor (VaultListViewModel.kt:34-35):
private val _search = MutableStateFlow("")
val search: StateFlow<String> = _search.asStateFlow()
Add after:
private val _tagFilter = MutableStateFlow<String?>(null)
val activeTagFilter: StateFlow<String?> = _tagFilter.asStateFlow()
Add the setter near setSearch (line 53):
fun setTagFilter(tag: String?) { _tagFilter.value = tag }
3b. Expose distinct tags for the strip
Add (snapshot is fine; recomputed on each VM creation):
val allTags: StateFlow<List<String>> =
vault.entries.map { vault.getDistinctTags() }
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())
vault.entries, map, stateIn, SharingStarted, viewModelScope are all
already imported in this file.
3c. Fold the tag filter into the entries flow
The current entries flow combines vault.entries, _sort, _search
(VaultListViewModel.kt:43-46). combine with four sources is fine:
val entries: StateFlow<List<VaultEntry>> =
combine(vault.entries, _sort, _search, _tagFilter) { list, sort, query, tag ->
val base = if (tag == null) list
else list.filter { e -> e.tags?.any { it.equals(tag, ignoreCase = true) } == true }
applyFilterSort(base, sort, query)
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())
Filtering inline against
vault.entries(rather than callingvault.getActiveEntries(tag)) keeps the reactive flow intact —getActiveEntriesis a synchronous snapshot and would not re-emit. The filter logic matchesgetActiveEntries's case-insensitivetags.anysemantics exactly. If the orchestrator prefers the repo method, it must still be invoked inside thecombineblock (on the_tagFiltertrigger) so emissions stay live.
4. VaultListScreen.kt — filter strip + row chips
4a. Collect new state
Anchor (VaultListScreen.kt:78):
val flashId by vm.flashId.collectAsState()
Add after:
val allTags by vm.allTags.collectAsState()
val activeTagFilter by vm.activeTagFilter.collectAsState()
4b. Insert the strip between SearchBar and SortBar
Anchor (VaultListScreen.kt:86-96): the SearchBar(...) call is followed by the
SortBar(...) call. Insert between them:
SearchBar(
value = search,
onChange = vm::setSearch,
count = if (search.isNotBlank()) "${entries.size}/$total" else "$total",
)
if (allTags.isNotEmpty()) {
TagFilterStrip(
allTags = allTags,
activeTagFilter = activeTagFilter,
onSelect = vm::setTagFilter,
)
}
SortBar(
4c. Row chips below the domain line
EntryRow renders the title + meta in a Column(Modifier.weight(1f))
(VaultListScreen.kt:290-305). Anchor — the close of the meta if block:
if (meta.isNotEmpty()) {
Text(
text = meta,
color = PeachColors.T2,
style = TextStyle(fontFamily = PeachType.Mono, fontSize = 9.sp),
maxLines = 1,
)
}
Add immediately after that if block, still inside the Column:
entry.tags?.takeIf { it.isNotEmpty() }?.let { tags ->
Spacer(Modifier.height(4.dp))
EntryRowTags(tags)
}
Spacer and Modifier.height are already imported in VaultListScreen.kt.
5. EntryDetailScreen.kt — read-only tag row
Insert below the NOTES field. Anchor (EntryDetailScreen.kt:229-231):
e.notes?.takeIf { it.isNotBlank() }?.let {
FieldRow("notes", it, copiedField == "notes", mono = false) { vm.copy("notes", it) }
}
Add immediately after that let block:
e.tags?.takeIf { it.isNotEmpty() }?.let { tags ->
DetailTagRow(
tags = tags,
onEditTags = { onNavigate(PeachNav.EntryEdit(e.id)) },
)
}
onNavigate and PeachNav are already in scope/imported in EntryDetailScreen.kt.
The brief asks the "+" chip to focus the editor on the tags field. There is no existing deep-link/focus-target mechanism in
EntryEditScreenorPeachNav.EntryEdit(which carries onlyid: String?). This draft navigates to the editor (tags section is already visible at the bottom of the form). Adding true field-focus would require a new nav arg + a focus requester in EntryEditScreen — out of scope for UI-only; flagged as a follow-up.
Assumptions / risks
getDistinctTags()/getActiveEntries()are synchronous snapshots over the in-memoryentryList; for the list filter the integration re-implements the filter inside the reactivecombineso the UI updates live (see §3c rationale).- The brief's pseudocode names (
setTagFilter,activeTagFilter,addTag,removeTag,allTags) do not yet exist — all are introduced by this integration (§1, §3). - No
PeachField/FlowRowexisted in the vault screens before; the editor uses the existingBasicTextFieldunderline-less bordered style local to these drafts (matching theFieldbox style) andFlowRowfrom foundation. - Detail "+" chip navigates to the editor without field focus (see §5 note).