INTEGRATION.md
D4 (Remainder) — Integration Guide
Two features, plus one shared-file extraction:
- D4-a [Copy] drain button in
GeneratorDrawer(EntryEditScreen). - D4-b Wrench →
GeneratorDraweras aModalBottomSheetin EntryDetailScreen, producing a local draft password with [Copy] (drain) + [Use this password]. - D4-0 Extract the private
CopyButtonfrom EntryDetailScreen to a shared file so both surfaces can reuse the exact spec §4.4 sheen+drain animation.
Drafts in this folder:
| Draft file | Destination |
|---|---|
CopyButton.kt |
app/src/main/java/com/peachpasswords/ui/components/CopyButton.kt (NEW) |
GeneratorDrawerWithCopy.kt |
merge into ui/vault/EntryEditScreen.kt (replace GeneratorDrawer, add GeneratorBody) |
EntryDetailGenerator.kt |
merge into ui/vault/EntryDetailScreen.kt (WrenchButton, GeneratorSheet) |
All drafts already declare their final package (com.peachpasswords.ui.components
or com.peachpasswords.ui.vault), so a plain move/merge compiles.
D4-0 — Extract CopyButton (do this FIRST)
CopyButton is currently a private @Composable at the bottom of
EntryDetailScreen.kt (lines ~359–416). It is used by FieldRow, PasswordRow,
and TotpBand in that file.
Steps
-
Drop
CopyButton.ktin atui/components/CopyButton.kt. It is the identical body, packagecom.peachpasswords.ui.components, visibility changedprivate→ publicfun CopyButton(...). The KDoc is preserved. -
In
EntryDetailScreen.kt, delete the privateCopyButtoncomposable (the whole block from its KDoc/** Copy button with the two-effect ... */through its closing brace, lines ~359–416). -
Add the import to
EntryDetailScreen.kt(alphabetical, beside the othercom.peachpasswords.ui.components.*imports — there are alreadyCharEnterText,FaviconInitials,TOTPRing):import com.peachpasswords.ui.components.CopyButtonAnchor (existing imports, lines ~63–65):
import com.peachpasswords.ui.components.CharEnterText import com.peachpasswords.ui.components.FaviconInitials import com.peachpasswords.ui.components.TOTPRing -
After deleting the private copy, the following imports in
EntryDetailScreen.ktbecome unused only if nothing else in the file uses them.TotpBandstill usesanimateFloat,Brush, etc., so re-check; the ones the deletedCopyButtonuniquely relied on areIcons.Rounded.Check,Icons.Rounded.ContentCopy(lines 30–31). Verify with the compiler / lint and remove any that are now dangling. (Leave anythingTotpBand/PasswordRowuse.)
No behaviour change — same composable, same call sites.
D4-a — [Copy] drain button in the inline GeneratorDrawer
VM additions (EntryEditViewModel)
The drawer's [Copy] button needs (1) a copied latch for the drain animation and
(2) a copy action. The VM already has copyHistoryPassword (clipboard) but no
latch. Add a genCopied flag to EditForm and a copyGenerated():
// in EditForm:
val genCopied: Boolean = false,
// in EntryEditViewModel:
fun copyGenerated() {
val pw = _form.value.password
if (pw.isEmpty()) return
val cm = appContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
cm.setPrimaryClip(ClipData.newPlainText("peach", pw))
viewModelScope.launch {
_form.update { it.copy(genCopied = true) }
kotlinx.coroutines.delay(1200)
_form.update { it.copy(genCopied = false) }
}
}
(ClipData, ClipboardManager, Context are already imported in
EntryEditViewModel.kt.)
Composable merge (EntryEditScreen.kt)
-
Replace the entire private
GeneratorDrawercomposable (lines ~225–276) with theGeneratorDrawer+GeneratorBodyfromGeneratorDrawerWithCopy.kt.- The replacement
GeneratorDrawerisinternal(so the detail screen could reuse it too, though detail usesGeneratorBodydirectly). - Delete the duplicate
private fun TogglePillat the bottom ofGeneratorDrawerWithCopy.ktand keep EntryEditScreen's existingTogglePill(lines ~278–290). They are identical except corner radius: the existing one usesPeachRadius.TypeTab; the draft uses8.dp. Keep the existingPeachRadius.TypeTabversion for consistency.
- The replacement
-
Add the import:
import com.peachpasswords.ui.components.CopyButton -
Update the call site. Anchor (lines ~112–120):
GeneratorDrawer( open = f.generatorOpen, length = f.genLength, upper = f.genUpper, lower = f.genLower, numbers = f.genNumbers, symbols = f.genSymbols, onLength = vm::setGenLength, onUpper = vm::setGenUpper, onLower = vm::setGenLower, onNumbers = vm::setGenNumbers, onSymbols = vm::setGenSymbols, onGenerate = vm::generate, )becomes:
GeneratorDrawer( open = f.generatorOpen, length = f.genLength, upper = f.genUpper, lower = f.genLower, numbers = f.genNumbers, symbols = f.genSymbols, password = f.password, copied = f.genCopied, onLength = vm::setGenLength, onUpper = vm::setGenUpper, onLower = vm::setGenLower, onNumbers = vm::setGenNumbers, onSymbols = vm::setGenSymbols, onGenerate = vm::generate, onCopy = vm::copyGenerated, )
Note: the drawer fixed height grew 188 → 234dp to fit the generate/copy row.
D4-b — Generator in EntryDetailScreen (wrench + bottom sheet)
VM addition (EntryDetailViewModel)
Add a method that applies a new password via updateEntry. Password history is
captured automatically by VaultRepository.updateEntry whenever the password
value changes (see VaultRepository.kt lines ~268–290: it records the prior
password into passwordHistory, capped at PASSWORD_HISTORY_MAX, skipping empty
and dup priors). So we only pass entry.copy(password = newPw) — do NOT build
history manually.
fun applyGeneratedPassword(newPassword: String, onDone: () -> Unit = {}) {
val current = entry.value ?: return
if (newPassword.isEmpty() || newPassword == current.password) { onDone(); return }
viewModelScope.launch {
runCatching { vault.updateEntry(current.copy(password = newPassword)) }
onDone()
}
}
The sheet's [Copy] uses the existing copy(field, value) + copiedField latch.
Reuse a dedicated field name, e.g. "genDraft":
// already exists — just call with a distinct field id:
vm.copy("genDraft", draftPassword)
// and observe: copiedField == "genDraft"
No new copy method needed. (updateEntry is already exposed on the repo;
viewModelScope, launch, vault are all in scope in EntryDetailViewModel.)
Composable merge (EntryDetailScreen.kt)
-
Drop
WrenchButtonandGeneratorSheetfromEntryDetailGenerator.ktinto the file (or keep them in their own file inui/vault/— same package, bothinternal, compiles either way).GeneratorSheetdepends onGeneratorBody(from D4-a) — ensure D4-a is merged first. -
Add imports to EntryDetailScreen.kt:
import androidx.compose.runtime.mutableStateOf // already present import androidx.compose.runtime.remember // already present import androidx.compose.runtime.setValue // already present(All three are already imported — nothing new needed for state.
GeneratorSheetcarries its ownModalBottomSheet/Build/PasswordGeneratorimports in its file.) -
Hoist sheet-open state in
EntryDetailScreen. Anchor — beside the existingconfirmingDeletestate (line ~88):var confirmingDelete by remember { mutableStateOf(false) }add:
var generatorOpen by remember { mutableStateOf(false) } -
Add the wrench to the password row. The password value is rendered by
PasswordRow(lines ~208–224 call site, composable ~258–280). Pass anonGeneratelambda through to it and renderWrenchButtonbesideCopyButton.Call-site anchor (lines ~208–224):
e.password?.takeIf { it.isNotBlank() }?.let { pw -> PasswordRow( value = pw, revealed = revealed, copied = copiedField == "password", onReveal = { ... }, onCopy = { vm.copy("password", pw) }, ) }Add
onGenerate = { generatorOpen = true }to thePasswordRow(...)call.In the
PasswordRowcomposable (lines ~258–280), add the paramonGenerate: () -> Unitand render the wrench between the show/hide text and the CopyButton:CopyButton(copied, onCopy) WrenchButton(onClick = onGenerate) // <-- add this line, after CopyButton -
Render the sheet (anywhere inside the
EntryDetailScreencomposable body, e.g. just before the closing ofShellBackground { ... }, after the scrolling Column at line ~234). Guard ongeneratorOpenand a non-null entry:if (generatorOpen && e != null) { GeneratorSheet( copied = copiedField == "genDraft", onCopy = { draft -> vm.copy("genDraft", draft) }, onUse = { draft -> vm.applyGeneratedPassword(draft) { generatorOpen = false } }, onDismiss = { generatorOpen = false }, ) }Note
eis captured asval e = entryat line ~97 — inside theShellBackgroundlambda use the samee/entryyou already have in scope.
Summary of new public/internal API the orchestrator must add
| Where | Member | Why |
|---|---|---|
ui/components/CopyButton.kt |
fun CopyButton(copied, onCopy) (public) |
shared §4.4 drain button |
EditForm |
val genCopied: Boolean = false |
drain latch for inline drawer |
EntryEditViewModel |
fun copyGenerated() |
clipboard + latch for drawer [Copy] |
EntryDetailViewModel |
fun applyGeneratedPassword(newPassword, onDone) |
[Use this password] → updateEntry (auto history) |
EntryDetailViewModel |
reuse copy("genDraft", ...) + copiedField=="genDraft" |
sheet [Copy] drain |
Risks / assumptions
- Icon:
Icons.Outlined.Buildis a wrench glyph and is inmaterial-icons-extended(already a dependency). If a closer wrench is desired,Icons.Outlined.Constructionis also available. - History capture is repo-driven: do NOT hand-build
PasswordHistoryItemin the detail path;updateEntryalready records the prior password on change. Verified inVaultRepository.ktlines 268–290. - Drawer height: bumped to 234dp to fit the generate+copy row; tweak if the toggle row wraps on very small screens.
- TogglePill duplication: the draft ships a local
TogglePillso it compiles standalone — delete it on merge and keep EntryEditScreen's existing one (PeachRadius.TypeTabradius). - ModalBottomSheet:
@OptIn(ExperimentalMaterial3Api::class)required on the caller (GeneratorSheetalready annotates itself); pattern mirrorsAutofillEntryPickerActivity.kt. - No nav routes added; the sheet is in-screen state only.