GeneratorDrawerWithCopy.kt

6.8 KB · raw

1package com.peachpasswords.ui.vault23/*4 * D4 drafts — drop-in replacement for the private GeneratorDrawer in5 * EntryEditScreen.kt PLUS a shared generator body + a detail bottom-sheet wrapper.6 *7 * This file is a DRAFT staging area. The orchestrator should:8 *   1. Replace the existing private GeneratorDrawer in EntryEditScreen.kt with the9 *      GeneratorDrawer below (signature gains `password`, `copied`, `onCopy`).10 *   2. Move GeneratorBody + the detail sheet into the real ui/vault package11 *      (they already declare `package com.peachpasswords.ui.vault`).12 *13 * See INTEGRATION.md for exact anchors and the VM additions required.14 */1516import androidx.compose.animation.core.animateDpAsState17import androidx.compose.animation.core.tween18import androidx.compose.foundation.background19import androidx.compose.foundation.border20import androidx.compose.foundation.clickable21import androidx.compose.foundation.layout.Arrangement22import androidx.compose.foundation.layout.Box23import androidx.compose.foundation.layout.Column24import androidx.compose.foundation.layout.Row25import androidx.compose.foundation.layout.Spacer26import androidx.compose.foundation.layout.fillMaxWidth27import androidx.compose.foundation.layout.height28import androidx.compose.foundation.layout.padding29import androidx.compose.foundation.layout.width30import androidx.compose.foundation.shape.RoundedCornerShape31import androidx.compose.material3.Slider32import androidx.compose.material3.SliderDefaults33import androidx.compose.material3.Text34import androidx.compose.runtime.Composable35import androidx.compose.ui.Alignment36import androidx.compose.ui.Modifier37import androidx.compose.ui.draw.clip38import androidx.compose.ui.draw.clipToBounds39import androidx.compose.ui.graphics.Color40import androidx.compose.ui.unit.dp41import androidx.compose.ui.unit.sp42import com.peachpasswords.ui.components.CopyButton43import com.peachpasswords.ui.theme.LocalPeachAccent44import com.peachpasswords.ui.theme.PeachColors45import com.peachpasswords.ui.theme.PeachMotion46import com.peachpasswords.ui.theme.PeachType4748/**49 * Drop-in replacement for the private GeneratorDrawer in EntryEditScreen.kt.50 *51 * Adds a [Copy] drain button beside "generate" that copies the *current* password52 * to the clipboard using the shared spec §4.4 CopyButton. The drawer still fills53 * the password field on generate; copy is an explicit extra affordance.54 *55 * New params vs the original: `password`, `copied`, `onCopy`. The drawer height56 * grows to fit the extra action row.57 */58@Composable59internal fun GeneratorDrawer(60    open: Boolean,61    length: Int,62    upper: Boolean, lower: Boolean, numbers: Boolean, symbols: Boolean,63    password: String,64    copied: Boolean,65    onLength: (Int) -> Unit,66    onUpper: (Boolean) -> Unit, onLower: (Boolean) -> Unit,67    onNumbers: (Boolean) -> Unit, onSymbols: (Boolean) -> Unit,68    onGenerate: () -> Unit,69    onCopy: () -> Unit,70) {71    val height by animateDpAsState(72        targetValue = if (open) 234.dp else 0.dp,73        animationSpec = tween(320, easing = PeachMotion.Spring),74        label = "gen-drawer",75    )76    Box(77        Modifier.fillMaxWidth().height(height).clipToBounds()78            .clip(RoundedCornerShape(12.dp)).background(PeachColors.S2),79    ) {80        GeneratorBody(81            length = length,82            upper = upper, lower = lower, numbers = numbers, symbols = symbols,83            password = password, copied = copied,84            onLength = onLength,85            onUpper = onUpper, onLower = onLower, onNumbers = onNumbers, onSymbols = onSymbols,86            onGenerate = onGenerate, onCopy = onCopy,87        )88    }89    if (open) Spacer(Modifier.height(14.dp))90}9192/**93 * Shared generator UI body — used both inside the inline drawer (EntryEditScreen)94 * and inside the detail ModalBottomSheet. Stateless: parent owns option state and95 * the generated password. The "generate" row carries the [Copy] drain button.96 */97@Composable98internal fun GeneratorBody(99    length: Int,100    upper: Boolean, lower: Boolean, numbers: Boolean, symbols: Boolean,101    password: String,102    copied: Boolean,103    onLength: (Int) -> Unit,104    onUpper: (Boolean) -> Unit, onLower: (Boolean) -> Unit,105    onNumbers: (Boolean) -> Unit, onSymbols: (Boolean) -> Unit,106    onGenerate: () -> Unit,107    onCopy: () -> Unit,108) {109    val accent = LocalPeachAccent.current110    Column(Modifier.fillMaxWidth().padding(16.dp)) {111        Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {112            Text("GENERATOR", color = PeachColors.T1, fontFamily = PeachType.Mono, fontSize = 8.sp)113            Text("length $length", color = accent, fontFamily = PeachType.Mono, fontSize = 9.sp)114        }115        Slider(116            value = length.toFloat(),117            onValueChange = { onLength(it.toInt()) },118            valueRange = 8f..128f,119            colors = SliderDefaults.colors(120                thumbColor = accent, activeTrackColor = accent, inactiveTrackColor = PeachColors.T3,121            ),122        )123        Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {124            TogglePill("A-Z", upper, onUpper)125            TogglePill("a-z", lower, onLower)126            TogglePill("0-9", numbers, onNumbers)127            TogglePill("!@#", symbols, onSymbols)128        }129        Spacer(Modifier.height(12.dp))130        Row(verticalAlignment = Alignment.CenterVertically) {131            Box(132                Modifier.weight(1f).clip(RoundedCornerShape(10.dp))133                    .border(1.dp, accent.copy(alpha = 0.5f), RoundedCornerShape(10.dp))134                    .background(accent.copy(alpha = 0.10f))135                    .clickable(onClick = onGenerate).padding(vertical = 12.dp),136                contentAlignment = Alignment.Center,137            ) {138                Text("generate", color = accent, fontFamily = PeachType.Mono, fontSize = 12.sp)139            }140            // [Copy] drain button — disabled-feel when no password yet (no-op click).141            Spacer(Modifier.width(8.dp))142            CopyButton(copied = copied, onCopy = { if (password.isNotEmpty()) onCopy() })143        }144    }145}146147/**148 * Local copy of the option toggle pill. Identical to the private TogglePill in149 * EntryEditScreen — when the orchestrator merges GeneratorBody into the real file150 * it should DELETE this duplicate and reuse the existing private TogglePill.151 */152@Composable153private fun TogglePill(label: String, on: Boolean, onToggle: (Boolean) -> Unit) {154    val accent = LocalPeachAccent.current155    Box(156        Modifier.clip(RoundedCornerShape(8.dp))157            .border(1.dp, if (on) accent.copy(alpha = 0.5f) else PeachColors.T3, RoundedCornerShape(8.dp))158            .background(if (on) accent.copy(alpha = 0.10f) else Color.Transparent)159            .clickable { onToggle(!on) }160            .padding(horizontal = 10.dp, vertical = 6.dp),161    ) {162        Text(label, color = if (on) accent else PeachColors.T2, fontFamily = PeachType.Mono, fontSize = 9.sp)163    }164}