29a0599352cf

feat: E2 NotesModeScreen — full-screen note editor (inline title, B/I/U span toolbar, 800ms debounced auto-save + saved pulse, FLAG_SECURE); VaultList routes note taps here + NOTES filter pill (v2.1.37)

time
2026-06-09 04:56 UTC · 5 months ago
machine
koh2
agent
claude-opus-4-8
session
peach remaining gaps
parent
ee4e7604872f
7 files app/drafts/E2/NotesModeViewModel.kt+0 −78app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+7 −0app/src/main/java/com/peachpasswords/ui/PeachNav.kt+7 −0app/src/main/java/com/peachpasswords/ui/vault/NotesModeScreen.kt+231 −0app/src/main/java/com/peachpasswords/ui/vault/NotesModeViewModel.kt+78 −0app/src/main/java/com/peachpasswords/ui/vault/VaultListScreen.kt+24 −1app/src/main/java/com/peachpasswords/ui/vault/VaultListViewModel.kt+8 −2
app/drafts/E2/NotesModeViewModel.kt+0 −78
@@ -1,78 +0,0 @@1-package com.peachpasswords.ui.vault2-3-import androidx.lifecycle.SavedStateHandle4-import androidx.lifecycle.ViewModel5-import androidx.lifecycle.viewModelScope6-import com.peachpasswords.vault.VaultEntry7-import com.peachpasswords.vault.VaultRepository8-import dagger.hilt.android.lifecycle.HiltViewModel9-import kotlinx.coroutines.Job10-import kotlinx.coroutines.delay11-import kotlinx.coroutines.flow.MutableStateFlow12-import kotlinx.coroutines.flow.SharingStarted13-import kotlinx.coroutines.flow.StateFlow14-import kotlinx.coroutines.flow.asStateFlow15-import kotlinx.coroutines.flow.map16-import kotlinx.coroutines.flow.stateIn17-import kotlinx.coroutines.launch18-import javax.inject.Inject19-20-/**21- * Backs [NotesModeScreen]. Holds the live note entry, an 800ms-debounced22- * auto-save, and a transient "saved." pulse the screen fades in/out.23- *24- * Title and body are committed independently through [updateEntry] — both25- * funnel through a single debounced job so a rapid title-then-body change26- * coalesces into one write. The repository's updateEntry is a full-entry27- * replace, so each save patches the latest known entry, never a stale copy.28- */29-@HiltViewModel30-class NotesModeViewModel @Inject constructor(31-    private val vault: VaultRepository,32-    savedStateHandle: SavedStateHandle,33-) : ViewModel() {34-    private val id: String = savedStateHandle.get<String>("id").orEmpty()35-36-    val entry: StateFlow<VaultEntry?> =37-        vault.entries.map { list -> list.firstOrNull { it.id == id } }38-            .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), vault.getEntry(id))39-40-    private val _savedPulse = MutableStateFlow(0L)41-    /** Increments on each successful auto-save so the screen can re-trigger its fade. */42-    val savedPulse: StateFlow<Long> = _savedPulse.asStateFlow()43-44-    private var saveJob: Job? = null45-46-    /** Debounced note-body save. Reschedules on every keystroke; fires 800ms after the last. */47-    fun onContentChanged(plainText: String) =48-        scheduleSave { it.copy(notes = plainText.ifBlank { null }) }49-50-    /**51-     * Title save. Debounced like the body so blur-after-typing still lands;52-     * callers may also force an immediate save on blur via [saveTitleNow].53-     */54-    fun onTitleChanged(title: String) =55-        scheduleSave { it.copy(title = title) }56-57-    /** Commit the title immediately (e.g. on field blur), bypassing the debounce. */58-    fun saveTitleNow(title: String) {59-        saveJob?.cancel()60-        commit { it.copy(title = title) }61-    }62-63-    private fun scheduleSave(patch: (VaultEntry) -> VaultEntry) {64-        saveJob?.cancel()65-        saveJob = viewModelScope.launch {66-            delay(800)67-            commit(patch)68-        }69-    }70-71-    private fun commit(patch: (VaultEntry) -> VaultEntry) {72-        val current = entry.value ?: return73-        viewModelScope.launch {74-            runCatching { vault.updateEntry(patch(current)) }75-                .onSuccess { _savedPulse.value = System.currentTimeMillis() }76-        }77-    }78-}

view file at the parent

app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+7 −0
@@ -26,6 +26,7 @@2626 import com.peachpasswords.ui.vault.EntryEditScreen2727 import com.peachpasswords.ui.vault.ExportScreen2828 import com.peachpasswords.ui.vault.ImportScreen29+import com.peachpasswords.ui.vault.NotesModeScreen2930 import com.peachpasswords.ui.vault.RecoveryWordsScreen3031 import com.peachpasswords.ui.vault.TrashScreen3132 import com.peachpasswords.ui.vault.VaultListScreen@@ -101,6 +102,12 @@101102             EntryEditScreen(id = backStack.arguments?.getString("id"), onBack = back)102103         }103104 105+        composable(106+            route = PeachNav.NotesMode.ROUTE,107+            arguments = listOf(navArgument("id") { type = NavType.StringType }),108+        ) {109+            NotesModeScreen(onBack = back)110+        }104111         composable(PeachNav.Settings.route) { SettingsScreen(onBack = back, onNavigate = nav) }105112         composable(PeachNav.SettingsProtection.route) { SimpleStub("Protection", back) }106113         composable(PeachNav.SettingsVault.route) { SimpleStub("Vault settings", back) }

view file

app/src/main/java/com/peachpasswords/ui/PeachNav.kt+7 −0
@@ -17,6 +17,13 @@1717         }1818     }1919 20+    data class NotesMode(val id: String) : PeachNav("notes/$id") {21+        companion object {22+            const val ROUTE = "notes/{id}"23+            fun of(id: String) = "notes/$id"24+        }25+    }26+2027     data class EntryEdit(val id: String?) : PeachNav("edit?id=${id ?: ""}") {2128         companion object {2229             const val ROUTE = "edit?id={id}"

view file

app/src/main/java/com/peachpasswords/ui/vault/NotesModeScreen.kt+231 −0
@@ -0,0 +1,231 @@1+package com.peachpasswords.ui.vault2+3+import android.view.WindowManager4+import androidx.compose.animation.core.animateFloatAsState5+import androidx.compose.animation.core.tween6+import androidx.compose.foundation.background7+import androidx.compose.foundation.clickable8+import androidx.compose.foundation.layout.Arrangement9+import androidx.compose.foundation.layout.Box10+import androidx.compose.foundation.layout.Column11+import androidx.compose.foundation.layout.Row12+import androidx.compose.foundation.layout.Spacer13+import androidx.compose.foundation.layout.fillMaxSize14+import androidx.compose.foundation.layout.fillMaxWidth15+import androidx.compose.foundation.layout.height16+import androidx.compose.foundation.layout.padding17+import androidx.compose.foundation.layout.size18+import androidx.compose.foundation.layout.statusBarsPadding19+import androidx.compose.foundation.layout.width20+import androidx.compose.foundation.shape.CircleShape21+import androidx.compose.foundation.shape.RoundedCornerShape22+import androidx.compose.foundation.text.BasicTextField23+import androidx.compose.material.icons.Icons24+import androidx.compose.material.icons.automirrored.rounded.ArrowBack25+import androidx.compose.material3.Icon26+import androidx.compose.material3.Text27+import androidx.compose.runtime.Composable28+import androidx.compose.runtime.LaunchedEffect29+import androidx.compose.runtime.getValue30+import androidx.compose.runtime.mutableStateOf31+import androidx.compose.runtime.remember32+import androidx.compose.runtime.setValue33+import androidx.compose.ui.Alignment34+import androidx.compose.ui.Modifier35+import androidx.compose.ui.draw.alpha36+import androidx.compose.ui.draw.clip37+import androidx.compose.ui.graphics.SolidColor38+import androidx.compose.ui.platform.LocalContext39+import androidx.compose.ui.text.AnnotatedString40+import androidx.compose.ui.text.SpanStyle41+import androidx.compose.ui.text.TextStyle42+import androidx.compose.ui.text.buildAnnotatedString43+import androidx.compose.ui.text.font.FontStyle44+import androidx.compose.ui.text.font.FontWeight45+import androidx.compose.ui.text.input.TextFieldValue46+import androidx.compose.ui.text.style.TextDecoration47+import androidx.compose.ui.text.withStyle48+import androidx.compose.ui.unit.dp49+import androidx.compose.ui.unit.sp50+import androidx.compose.runtime.collectAsState51+import androidx.fragment.app.FragmentActivity52+import androidx.hilt.navigation.compose.hiltViewModel53+import com.peachpasswords.ui.theme.LocalPeachAccent54+import com.peachpasswords.ui.theme.PeachColors55+import com.peachpasswords.ui.theme.PeachType56+import com.peachpasswords.ui.theme.ShellBackground57+58+/**59+ * E2 — full-screen editor for NOTE-type entries. Editable inline title, a B/I/U60+ * formatting toolbar that applies [SpanStyle] to the current selection, a61+ * full-width Inter body field, and an 800ms-debounced auto-save with a "saved."62+ * pulse. FLAG_SECURE blocks screenshots while open (same as EntryDetail).63+ *64+ * Span support is intentionally basic (no markdown/persistence of styles): the65+ * toolbar styles the live [AnnotatedString] selection; only the plain text is66+ * persisted via the ViewModel.67+ */68+@Composable69+fun NotesModeScreen(70+    onBack: () -> Unit,71+    vm: NotesModeViewModel = hiltViewModel(),72+) {73+    val entry by vm.entry.collectAsState()74+    val savedPulse by vm.savedPulse.collectAsState()75+    val accent = LocalPeachAccent.current76+    val context = LocalContext.current77+78+    // FLAG_SECURE only while shown.79+    androidx.compose.runtime.DisposableEffect(Unit) {80+        val window = (context as? FragmentActivity)?.window81+        window?.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)82+        onDispose { window?.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) }83+    }84+85+    val e = entry86+87+    // "saved." indicator fades in on each save pulse, holds, then fades out.88+    var showSaved by remember { mutableStateOf(false) }89+    LaunchedEffect(savedPulse) {90+        if (savedPulse == 0L) return@LaunchedEffect91+        showSaved = true92+        kotlinx.coroutines.delay(1300)93+        showSaved = false94+    }95+    val savedAlpha by animateFloatAsState(96+        targetValue = if (showSaved) 1f else 0f,97+        animationSpec = tween(300),98+        label = "saved-fade",99+    )100+101+    var title by remember(e?.id) { mutableStateOf(e?.title ?: "") }102+    var body by remember(e?.id) { mutableStateOf(TextFieldValue(e?.notes ?: "")) }103+104+    ShellBackground {105+        Column(Modifier.fillMaxSize().statusBarsPadding()) {106+            // Top bar: back · editable title · "saved." indicator107+            Row(108+                Modifier.fillMaxWidth().height(56.dp).padding(horizontal = 8.dp),109+                verticalAlignment = Alignment.CenterVertically,110+            ) {111+                Icon(112+                    Icons.AutoMirrored.Rounded.ArrowBack, contentDescription = "back", tint = PeachColors.T0,113+                    modifier = Modifier.size(40.dp).clip(CircleShape)114+                        .clickable { vm.saveTitleNow(title); onBack() }.padding(8.dp),115+                )116+                Box(Modifier.weight(1f).padding(horizontal = 4.dp)) {117+                    if (title.isEmpty()) {118+                        Text(119+                            "untitled note",120+                            color = PeachColors.T2,121+                            style = TextStyle(fontFamily = PeachType.Display, fontStyle = FontStyle.Italic, fontSize = 22.sp),122+                        )123+                    }124+                    BasicTextField(125+                        value = title,126+                        onValueChange = { title = it; vm.onTitleChanged(it) },127+                        singleLine = true,128+                        textStyle = TextStyle(129+                            color = PeachColors.T0,130+                            fontFamily = PeachType.Display,131+                            fontStyle = FontStyle.Italic,132+                            fontSize = 22.sp,133+                        ),134+                        cursorBrush = SolidColor(accent),135+                        modifier = Modifier.fillMaxWidth(),136+                    )137+                }138+                Text(139+                    "saved.",140+                    color = PeachColors.T2,141+                    style = TextStyle(fontFamily = PeachType.Mono, fontSize = 9.sp),142+                    modifier = Modifier.padding(end = 8.dp).alpha(savedAlpha),143+                )144+            }145+146+            if (e == null) {147+                Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {148+                    Text("note not found", color = PeachColors.T1, style = PeachType.bodyMono)149+                }150+                return@Column151+            }152+153+            // Formatting toolbar: B / I / U — apply span to current selection.154+            Row(155+                Modifier.fillMaxWidth().padding(horizontal = 12.dp, vertical = 4.dp),156+                horizontalArrangement = Arrangement.spacedBy(6.dp),157+                verticalAlignment = Alignment.CenterVertically,158+            ) {159+                FormatButton("B", FontWeight.Bold) { body = applySpan(body, SpanStyle(fontWeight = FontWeight.Bold)) }160+                FormatButton("I", fontStyle = FontStyle.Italic) { body = applySpan(body, SpanStyle(fontStyle = FontStyle.Italic)) }161+                FormatButton("U", underline = true) { body = applySpan(body, SpanStyle(textDecoration = TextDecoration.Underline)) }162+            }163+164+            // Content area.165+            Box(Modifier.fillMaxSize().padding(horizontal = 16.dp, vertical = 12.dp)) {166+                if (body.text.isEmpty()) {167+                    Text(168+                        "Start writing…",169+                        color = PeachColors.T2,170+                        style = TextStyle(fontFamily = PeachType.Body, fontStyle = FontStyle.Italic, fontSize = 14.sp),171+                    )172+                }173+                BasicTextField(174+                    value = body,175+                    onValueChange = { body = it; vm.onContentChanged(it.text) },176+                    textStyle = TextStyle(color = PeachColors.T0, fontFamily = PeachType.Body, fontSize = 14.sp, lineHeight = 22.sp),177+                    cursorBrush = SolidColor(accent),178+                    modifier = Modifier.fillMaxSize(),179+                )180+            }181+        }182+    }183+}184+185+/**186+ * Apply [style] to the current selection of [value], preserving the text and187+ * existing spans. If the selection is collapsed, the value is returned unchanged188+ * (basic span support — styling needs a non-empty selection).189+ */190+private fun applySpan(value: TextFieldValue, style: SpanStyle): TextFieldValue {191+    val sel = value.selection192+    if (sel.collapsed) return value193+    val start = sel.min194+    val end = sel.max195+    val existing = value.annotatedString196+    val merged: AnnotatedString = buildAnnotatedString {197+        append(existing)198+        addStyle(style, start, end)199+    }200+    return value.copy(annotatedString = merged)201+}202+203+@Composable204+private fun FormatButton(205+    label: String,206+    fontWeight: FontWeight? = null,207+    fontStyle: FontStyle? = null,208+    underline: Boolean = false,209+    onClick: () -> Unit,210+) {211+    Box(212+        Modifier213+            .size(30.dp)214+            .clip(RoundedCornerShape(6.dp))215+            .background(PeachColors.S2)216+            .clickable(onClick = onClick),217+        contentAlignment = Alignment.Center,218+    ) {219+        Text(220+            label,221+            color = PeachColors.T0,222+            style = TextStyle(223+                fontFamily = PeachType.Body,224+                fontSize = 14.sp,225+                fontWeight = fontWeight,226+                fontStyle = fontStyle,227+                textDecoration = if (underline) TextDecoration.Underline else null,228+            ),229+        )230+    }231+}

view file

app/src/main/java/com/peachpasswords/ui/vault/NotesModeViewModel.kt+78 −0
@@ -0,0 +1,78 @@1+package com.peachpasswords.ui.vault2+3+import androidx.lifecycle.SavedStateHandle4+import androidx.lifecycle.ViewModel5+import androidx.lifecycle.viewModelScope6+import com.peachpasswords.vault.VaultEntry7+import com.peachpasswords.vault.VaultRepository8+import dagger.hilt.android.lifecycle.HiltViewModel9+import kotlinx.coroutines.Job10+import kotlinx.coroutines.delay11+import kotlinx.coroutines.flow.MutableStateFlow12+import kotlinx.coroutines.flow.SharingStarted13+import kotlinx.coroutines.flow.StateFlow14+import kotlinx.coroutines.flow.asStateFlow15+import kotlinx.coroutines.flow.map16+import kotlinx.coroutines.flow.stateIn17+import kotlinx.coroutines.launch18+import javax.inject.Inject19+20+/**21+ * Backs [NotesModeScreen]. Holds the live note entry, an 800ms-debounced22+ * auto-save, and a transient "saved." pulse the screen fades in/out.23+ *24+ * Title and body are committed independently through [updateEntry] — both25+ * funnel through a single debounced job so a rapid title-then-body change26+ * coalesces into one write. The repository's updateEntry is a full-entry27+ * replace, so each save patches the latest known entry, never a stale copy.28+ */29+@HiltViewModel30+class NotesModeViewModel @Inject constructor(31+    private val vault: VaultRepository,32+    savedStateHandle: SavedStateHandle,33+) : ViewModel() {34+    private val id: String = savedStateHandle.get<String>("id").orEmpty()35+36+    val entry: StateFlow<VaultEntry?> =37+        vault.entries.map { list -> list.firstOrNull { it.id == id } }38+            .stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), vault.getEntry(id))39+40+    private val _savedPulse = MutableStateFlow(0L)41+    /** Increments on each successful auto-save so the screen can re-trigger its fade. */42+    val savedPulse: StateFlow<Long> = _savedPulse.asStateFlow()43+44+    private var saveJob: Job? = null45+46+    /** Debounced note-body save. Reschedules on every keystroke; fires 800ms after the last. */47+    fun onContentChanged(plainText: String) =48+        scheduleSave { it.copy(notes = plainText.ifBlank { null }) }49+50+    /**51+     * Title save. Debounced like the body so blur-after-typing still lands;52+     * callers may also force an immediate save on blur via [saveTitleNow].53+     */54+    fun onTitleChanged(title: String) =55+        scheduleSave { it.copy(title = title) }56+57+    /** Commit the title immediately (e.g. on field blur), bypassing the debounce. */58+    fun saveTitleNow(title: String) {59+        saveJob?.cancel()60+        commit { it.copy(title = title) }61+    }62+63+    private fun scheduleSave(patch: (VaultEntry) -> VaultEntry) {64+        saveJob?.cancel()65+        saveJob = viewModelScope.launch {66+            delay(800)67+            commit(patch)68+        }69+    }70+71+    private fun commit(patch: (VaultEntry) -> VaultEntry) {72+        val current = entry.value ?: return73+        viewModelScope.launch {74+            runCatching { vault.updateEntry(patch(current)) }75+                .onSuccess { _savedPulse.value = System.currentTimeMillis() }76+        }77+    }78+}

view file

app/src/main/java/com/peachpasswords/ui/vault/VaultListScreen.kt+24 −1
@@ -73,6 +73,7 @@7373 import com.peachpasswords.vault.TOTPGenerator7474 import com.peachpasswords.vault.VaultEntry7575 import com.peachpasswords.vault.hasTOTP76+import com.peachpasswords.vault.isNote7677 import kotlinx.coroutines.delay7778 import kotlin.math.abs7879 @@ -88,6 +89,7 @@8889     val flashId by vm.flashId.collectAsState()8990     val allTags by vm.allTags.collectAsState()9091     val activeTagFilter by vm.activeTagFilter.collectAsState()92+    val noteOnly by vm.noteOnly.collectAsState()9193     val isMultiSelect by vm.isMultiSelectMode.collectAsState()9294     val selectedIds by vm.selectedIds.collectAsState()9395     val undoEvent by vm.undoEvent.collectAsState()@@ -135,7 +137,9 @@135137             }136138             SortBar(137139                 active = sort,140+                noteOnly = noteOnly,138141                 onSort = vm::setSort,142+                onToggleNote = vm::toggleNoteFilter,139143                 onHealth = { onNavigate(PeachNav.Health) },140144                 onTrash = { onNavigate(PeachNav.Trash) },141145             )@@ -152,6 +156,7 @@152156                         selected = entry.id in selectedIds,153157                         onTap = {154158                             if (isMultiSelect) vm.toggleSelected(entry.id)159+                            else if (entry.isNote()) onNavigate(PeachNav.NotesMode(entry.id))155160                             else onNavigate(PeachNav.EntryDetail(entry.id))156161                         },157162                         onLongPress = {@@ -273,7 +278,14 @@273278 }274279 275280 @Composable276-private fun SortBar(active: SortOrder, onSort: (SortOrder) -> Unit, onHealth: () -> Unit, onTrash: () -> Unit) {281+private fun SortBar(282+    active: SortOrder,283+    noteOnly: Boolean,284+    onSort: (SortOrder) -> Unit,285+    onToggleNote: () -> Unit,286+    onHealth: () -> Unit,287+    onTrash: () -> Unit,288+) {277289     val accent = LocalPeachAccent.current278290     Row(279291         modifier = Modifier@@ -303,6 +315,17 @@303315                     .padding(horizontal = 8.dp, vertical = 3.dp),304316             )305317         }318+        Text(319+            text = "NOTES",320+            color = if (noteOnly) Color.Black else PeachColors.T2,321+            style = PeachType.sortPill,322+            modifier = Modifier323+                .padding(end = 6.dp)324+                .clip(RoundedCornerShape(4.dp))325+                .background(if (noteOnly) accent else Color.Transparent)326+                .clickable { onToggleNote() }327+                .padding(horizontal = 8.dp, vertical = 3.dp),328+        )306329         Spacer(Modifier.weight(1f))307330         Icon(308331             Icons.Outlined.FavoriteBorder, contentDescription = "health", tint = PeachColors.T1,

view file

app/src/main/java/com/peachpasswords/ui/vault/VaultListViewModel.kt+8 −2
@@ -9,6 +9,7 @@99 import com.peachpasswords.vault.VaultEntry1010 import com.peachpasswords.vault.VaultRepository1111 import com.peachpasswords.vault.isLogin12+import com.peachpasswords.vault.isNote1213 import dagger.hilt.android.lifecycle.HiltViewModel1314 import dagger.hilt.android.qualifiers.ApplicationContext1415 import kotlinx.coroutines.flow.MutableStateFlow@@ -38,6 +39,9 @@3839     private val _tagFilter = MutableStateFlow<String?>(null)3940     val activeTagFilter: StateFlow<String?> = _tagFilter.asStateFlow()4041 42+    private val _noteOnly = MutableStateFlow(false)43+    val noteOnly: StateFlow<Boolean> = _noteOnly.asStateFlow()44+4145     private val _flashId = MutableStateFlow<String?>(null)4246     val flashId: StateFlow<String?> = _flashId.asStateFlow()4347 @@ -45,9 +49,10 @@4549 4650     /** Live, filtered + sorted active entries. */4751     val entries: StateFlow<List<VaultEntry>> =48-        combine(vault.entries, _sort, _search, _tagFilter) { list, sort, query, tag ->49-            val base = if (tag == null) list52+        combine(vault.entries, _sort, _search, _tagFilter, _noteOnly) { list, sort, query, tag, noteOnly ->53+            var base = if (tag == null) list5054                        else list.filter { e -> e.tags?.any { it.equals(tag, ignoreCase = true) } == true }55+            if (noteOnly) base = base.filter { it.isNote() }5156             applyFilterSort(base, sort, query)5257         }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())5358 @@ -62,6 +67,7 @@6267     fun setSort(order: SortOrder) { _sort.value = order }6368     fun setSearch(q: String) { _search.value = q }6469     fun setTagFilter(tag: String?) { _tagFilter.value = tag }70+    fun toggleNoteFilter() { _noteOnly.value = !_noteOnly.value }6571 6672     fun lock() = vault.lock()6773 

view file