INTEGRATION.md

7.7 KB · raw

rendered · source

1# E3 — Additional URLs UI — Integration23UI-only. Model already has `additionalUrls: List<String>?` on `VaultEntry`. No4repository changes. Two self-contained draft files, two screens to wire, plus5ViewModel state additions to `EntryEditViewModel`.67## Files to copy89| Draft | Destination |10|---|---|11| `AdditionalUrlsEditor.kt` | `app/src/main/java/com/peachpasswords/ui/vault/AdditionalUrlsEditor.kt` |12| `AdditionalUrlsDetail.kt`  | `app/src/main/java/com/peachpasswords/ui/vault/AdditionalUrlsDetail.kt` |1314Both are `package com.peachpasswords.ui.vault` — same package as both screens, so15no new imports are needed in the screen files to call them.1617Public API the drafts expose (all in package `com.peachpasswords.ui.vault`):18- `AdditionalUrlsEditor(urls, onChange, onAdd, onRemove)`19- `AdditionalUrlRows(urls, copiedField, onCopy)`20- `additionalUrlCopyKey(index): String`21- `openUrlInBrowser(context, raw)`22- `const val MAX_ADDITIONAL_URLS = 5`2324---2526## 1. EntryEditViewModel.kt — state additions2728### 1a. Add to `EditForm` (after the `url` line, line 28)2930Anchor (existing):31```kotlin32    val url: String = "",33    val totp: String = "",34```35Insert between them:36```kotlin37    val additionalUrls: List<String> = emptyList(),38```3940### 1b. Seed from existing entry (in the `existing?.let { EditForm(...) }` block, ~line 63)4142Anchor (existing):43```kotlin44                url = it.url.orEmpty(),45                totp = it.totp.orEmpty(),46```47Insert between them:48```kotlin49                additionalUrls = it.additionalUrls.orEmpty(),50```5152### 1c. Add setters (after `fun setUrl`, ~line 76)5354Anchor (existing):55```kotlin56    fun setUrl(v: String) = _form.update { it.copy(url = v) }57```58Insert after it:59```kotlin60    fun setAdditionalUrl(index: Int, v: String) = _form.update { form ->61        form.copy(additionalUrls = form.additionalUrls.toMutableList().also { it[index] = v })62    }6364    fun addAdditionalUrl() = _form.update { form ->65        if (form.additionalUrls.size >= MAX_ADDITIONAL_URLS) form66        else form.copy(additionalUrls = form.additionalUrls + "")67    }6869    fun removeAdditionalUrl(index: Int) = _form.update { form ->70        form.copy(additionalUrls = form.additionalUrls.toMutableList().also { it.removeAt(index) })71    }72```73`MAX_ADDITIONAL_URLS` is the top-level const in `AdditionalUrlsEditor.kt` (same74package — no import needed).7576### 1d. Persist on save (in `save()`, both the `addEntry` and `updateEntry` branches)7778In `addEntry(VaultEntry(...))` — anchor (existing):79```kotlin80                            url = f.url.ifBlank { null },81                            totp = f.totp.ifBlank { null },82```83Insert between them:84```kotlin85                            additionalUrls = f.additionalUrls86                                .map { it.trim() }.filter { it.isNotBlank() }87                                .ifEmpty { null },88```8990In `updateEntry(existing!!.copy(...))` — anchor (existing):91```kotlin92                            url = f.url.ifBlank { null },93                            totp = f.totp.ifBlank { null },94```95Insert between them:96```kotlin97                            additionalUrls = f.additionalUrls98                                .map { it.trim() }.filter { it.isNotBlank() }99                                .ifEmpty { null },100```101Blank rows are dropped on save, so an empty added-but-untouched field never102persists.103104---105106## 2. EntryEditScreen.kt — insert the editor block107108In `EntryEditScreen`, inside the `if (f.type == "login") { ... }` branch, right109after the main `url` field.110111Anchor (existing, ~line 102):112```kotlin113                if (f.type == "login") {114                    Field("url", f.url, vm::setUrl)115                    Field("username", f.username, vm::setUsername)116```117Insert the call between the `url` Field and the `username` Field:118```kotlin119                    AdditionalUrlsEditor(120                        urls = f.additionalUrls,121                        onChange = vm::setAdditionalUrl,122                        onAdd = vm::addAdditionalUrl,123                        onRemove = vm::removeAdditionalUrl,124                    )125```126No new import — same package. `AdditionalUrlsEditor` renders its own underlined127rows (labeled "URL 2".."URL 6"), the ghost `+ add URL` button, and the128`Max 5 additional URLs` hint at the cap.129130Shared-file note (D2/D3/D4/E4 also edit this screen): this block is one131self-contained call sandwiched between the existing `url` and `username` Field132lines — it does not move or wrap any other field, so it merges independently of133the card-fields (D2), tags (D3), generator (D4), and identity-suggest (E4) edits.134135---136137## 3. EntryDetailScreen.kt — insert the detail rows138139In `EntryDetailScreen`, inside the scrolling field `Column`. Best placement is140directly under the main URL/domain area — i.e. right after the `username`/`email`141rows, before `password`. (Placing after the notes row also works; pick whichever142ordering D6/D7 leave intact.)143144Anchor (existing, ~line 202):145```kotlin146                e.username?.takeIf { it.isNotBlank() }?.let {147                    FieldRow("username", it, copiedField == "username") { vm.copy("username", it) }148                }149                e.email?.takeIf { it.isNotBlank() }?.let {150                    FieldRow("email", it, copiedField == "email") { vm.copy("email", it) }151                }152```153Insert immediately after the email block:154```kotlin155                e.additionalUrls?.takeIf { it.any { u -> u.isNotBlank() } }?.let { urls ->156                    AdditionalUrlRows(157                        urls = urls,158                        copiedField = copiedField,159                        onCopy = { key, value -> vm.copy(key, value) },160                    )161                }162```163No new import — same package. `AdditionalUrlRows` skips blank entries, renders164each as a hairline field row ("URL 2".."URL 6") with copy + open-in-browser, and165carries its own `FieldShell`/`CopyButton`/open-in-browser internals so it does166not depend on the screen's private composables.167168`copiedField` is already collected at the top of `EntryDetailScreen`169(`val copiedField by vm.copiedField.collectAsState()`). The per-row copy latch170uses keys `additionalUrl:0`, `additionalUrl:1`, … so each row's copy feedback is171independent and never collides with the existing `"username"`/`"password"` keys.172`vm.copy(field, value)` is the existing `EntryDetailViewModel.copy` (sig:173`fun copy(field: String, value: String?)`).174175Open-in-browser uses `Intent(ACTION_VIEW, Uri.parse(url))` with176`FLAG_ACTIVITY_NEW_TASK`, normalizing scheme-less values to `https://`, and177toasts if no browser handles it. `LocalContext.current` is read inside178`AdditionalUrlRows` — no plumbing needed.179180Shared-file note (D2/D3/D6/D7/E6 also edit this screen): the block is one181self-contained `let` between the email row and the password row. It does not182modify `FieldRow`/`PasswordRow`/`FieldShell`/`CopyButton`, so it merges183independently of card display (D2), tags display (D3), inline edit (D6), history184panel (D7), and TOTP edit (E6). If D6 (inline edit) converts `FieldRow` to an185editable variant, leave these URL rows read-only with copy + open — they are not186part of the inline-edit scope per the brief.187188---189190## Assumptions / risks191192- Label numbering: rows are labeled "URL 2"+ on the assumption the primary `url`193  field reads as "URL 1". Trivial to change to "URL 1"+ in both draft files194  (`index + 2` → `index + 1`) if preferred.195- `OpenInNew` icon is `androidx.compose.material.icons.automirrored.rounded.OpenInNew`196  (verified present in the `material-icons-extended` artifact; auto-mirrored197  namespace matches existing `ArrowBack` usage in this screen).198- No `build.gradle` changes. No nav changes. No repo/DI changes.199- The cap (5) lives as `MAX_ADDITIONAL_URLS` in `AdditionalUrlsEditor.kt` and is200  reused by the ViewModel `addAdditionalUrl` guard — single source of truth.