INTEGRATION.md

7.7 KB · raw

rendered · source

E3 — Additional URLs UI — Integration

UI-only. Model already has additionalUrls: List<String>? on VaultEntry. No repository changes. Two self-contained draft files, two screens to wire, plus ViewModel state additions to EntryEditViewModel.

Files to copy

Draft Destination
AdditionalUrlsEditor.kt app/src/main/java/com/peachpasswords/ui/vault/AdditionalUrlsEditor.kt
AdditionalUrlsDetail.kt app/src/main/java/com/peachpasswords/ui/vault/AdditionalUrlsDetail.kt

Both are package com.peachpasswords.ui.vault — same package as both screens, so no new imports are needed in the screen files to call them.

Public API the drafts expose (all in package com.peachpasswords.ui.vault):


1. EntryEditViewModel.kt — state additions

1a. Add to EditForm (after the url line, line 28)

Anchor (existing):

    val url: String = "",
    val totp: String = "",

Insert between them:

    val additionalUrls: List<String> = emptyList(),

1b. Seed from existing entry (in the existing?.let { EditForm(...) } block, ~line 63)

Anchor (existing):

                url = it.url.orEmpty(),
                totp = it.totp.orEmpty(),

Insert between them:

                additionalUrls = it.additionalUrls.orEmpty(),

1c. Add setters (after fun setUrl, ~line 76)

Anchor (existing):

    fun setUrl(v: String) = _form.update { it.copy(url = v) }

Insert after it:

    fun setAdditionalUrl(index: Int, v: String) = _form.update { form ->
        form.copy(additionalUrls = form.additionalUrls.toMutableList().also { it[index] = v })
    }

    fun addAdditionalUrl() = _form.update { form ->
        if (form.additionalUrls.size >= MAX_ADDITIONAL_URLS) form
        else form.copy(additionalUrls = form.additionalUrls + "")
    }

    fun removeAdditionalUrl(index: Int) = _form.update { form ->
        form.copy(additionalUrls = form.additionalUrls.toMutableList().also { it.removeAt(index) })
    }

MAX_ADDITIONAL_URLS is the top-level const in AdditionalUrlsEditor.kt (same package — no import needed).

1d. Persist on save (in save(), both the addEntry and updateEntry branches)

In addEntry(VaultEntry(...)) — anchor (existing):

                            url = f.url.ifBlank { null },
                            totp = f.totp.ifBlank { null },

Insert between them:

                            additionalUrls = f.additionalUrls
                                .map { it.trim() }.filter { it.isNotBlank() }
                                .ifEmpty { null },

In updateEntry(existing!!.copy(...)) — anchor (existing):

                            url = f.url.ifBlank { null },
                            totp = f.totp.ifBlank { null },

Insert between them:

                            additionalUrls = f.additionalUrls
                                .map { it.trim() }.filter { it.isNotBlank() }
                                .ifEmpty { null },

Blank rows are dropped on save, so an empty added-but-untouched field never persists.


2. EntryEditScreen.kt — insert the editor block

In EntryEditScreen, inside the if (f.type == "login") { ... } branch, right after the main url field.

Anchor (existing, ~line 102):

                if (f.type == "login") {
                    Field("url", f.url, vm::setUrl)
                    Field("username", f.username, vm::setUsername)

Insert the call between the url Field and the username Field:

                    AdditionalUrlsEditor(
                        urls = f.additionalUrls,
                        onChange = vm::setAdditionalUrl,
                        onAdd = vm::addAdditionalUrl,
                        onRemove = vm::removeAdditionalUrl,
                    )

No new import — same package. AdditionalUrlsEditor renders its own underlined rows (labeled "URL 2".."URL 6"), the ghost + add URL button, and the Max 5 additional URLs hint at the cap.

Shared-file note (D2/D3/D4/E4 also edit this screen): this block is one self-contained call sandwiched between the existing url and username Field lines — it does not move or wrap any other field, so it merges independently of the card-fields (D2), tags (D3), generator (D4), and identity-suggest (E4) edits.


3. EntryDetailScreen.kt — insert the detail rows

In EntryDetailScreen, inside the scrolling field Column. Best placement is directly under the main URL/domain area — i.e. right after the username/email rows, before password. (Placing after the notes row also works; pick whichever ordering D6/D7 leave intact.)

Anchor (existing, ~line 202):

                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) }
                }

Insert immediately after the email block:

                e.additionalUrls?.takeIf { it.any { u -> u.isNotBlank() } }?.let { urls ->
                    AdditionalUrlRows(
                        urls = urls,
                        copiedField = copiedField,
                        onCopy = { key, value -> vm.copy(key, value) },
                    )
                }

No new import — same package. AdditionalUrlRows skips blank entries, renders each as a hairline field row ("URL 2".."URL 6") with copy + open-in-browser, and carries its own FieldShell/CopyButton/open-in-browser internals so it does not depend on the screen's private composables.

copiedField is already collected at the top of EntryDetailScreen (val copiedField by vm.copiedField.collectAsState()). The per-row copy latch uses keys additionalUrl:0, additionalUrl:1, … so each row's copy feedback is independent and never collides with the existing "username"/"password" keys. vm.copy(field, value) is the existing EntryDetailViewModel.copy (sig: fun copy(field: String, value: String?)).

Open-in-browser uses Intent(ACTION_VIEW, Uri.parse(url)) with FLAG_ACTIVITY_NEW_TASK, normalizing scheme-less values to https://, and toasts if no browser handles it. LocalContext.current is read inside AdditionalUrlRows — no plumbing needed.

Shared-file note (D2/D3/D6/D7/E6 also edit this screen): the block is one self-contained let between the email row and the password row. It does not modify FieldRow/PasswordRow/FieldShell/CopyButton, so it merges independently of card display (D2), tags display (D3), inline edit (D6), history panel (D7), and TOTP edit (E6). If D6 (inline edit) converts FieldRow to an editable variant, leave these URL rows read-only with copy + open — they are not part of the inline-edit scope per the brief.


Assumptions / risks