cad0d867ffdb
fix: Keep standalone notes in Notes mode (v2.14.48)
- time
- 2026-08-14 22:06 UTC · 2 months ago
- machine
- koh2
- parent
- 71251db0e447
↓ peach-android-cad0d867.tar.gzatlas at this save
files changed5 files
VERSION+1 −1app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+0 −6app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+17 −16app/src/main/java/com/peachpasswords/ui/vault/EntryEditViewModel.kt+0 −13app/src/test/java/com/peachpasswords/ui/vault/EntryEditScreenTest.kt+6 −7app/src/main/java/com/peachpasswords/ui/PeachAppNavHost.kt+0 −6
@@ -286,18 +286,12 @@286286 id = null,287287 onBack = back,288288 onHome = { nav(PeachNav.VaultList) },289- onOpenNote = { noteId ->290- navController.navigate(PeachNav.NotesMode.of(noteId)) {291- popUpTo(PeachNav.EntryEdit.ROUTE) { inclusive = true }292- }293- },294289 )295290 } else {296291 EntryEditScreen(297292 id = editId,298293 onBack = back,299294 onHome = { nav(PeachNav.VaultList) },300- onOpenNote = { noteId -> nav(PeachNav.NotesMode(noteId)) },301295 )302296 }303297 }app/src/main/java/com/peachpasswords/ui/vault/EntryEditScreen.kt+17 −16
@@ -65,7 +65,6 @@6565 id: String?,6666 onBack: () -> Unit,6767 onHome: () -> Unit,68- onOpenNote: (String) -> Unit = {},6968 vm: EntryEditViewModel = hiltViewModel(),7069 ) {7170 SecureFlagEffect()@@ -110,18 +109,9 @@110109 Modifier.fillMaxSize().verticalScroll(rememberScrollState()),111110 ) {112111 PeachSegmentedControl(113- segments = listOf(114- PeachSegment("login", "login"),115- PeachSegment("note", "note"),116- PeachSegment("card", "card"),117- ),112+ segments = entryEditTypeSegments(vm.isNew),118113 selectedKey = f.type,119- onSelected = { t ->120- // A brand-new note skips the form entirely and drops straight121- // into the full-screen notes editor (brief Fix 6 item 7).122- if (shouldOpenNotesMode(vm.isNew, t)) vm.createNoteAndOpen(onOpenNote)123- else vm.setType(t)124- },114+ onSelected = vm::setType,125115 )126116 Spacer(Modifier.height(PeachSpacing.lg))127117 @@ -202,7 +192,12 @@202192 if (f.type == "login") {203193 OptionalLoginAddLinks(204194 showTotpLink = shouldShowAddTotpLink(f.type, f.showTotp, f.totp),205- showNotesLink = shouldShowAddNotesLink(f.type, f.showNotes, f.notes),195+ showNotesLink = shouldShowLoginNotesLink(196+ isNew = vm.isNew,197+ type = f.type,198+ revealed = f.showNotes,199+ notes = f.notes,200+ ),206201 onAddTotp = vm::revealTotp,207202 onAddNotes = vm::revealNotes,208203 )@@ -279,6 +274,12 @@279274 else -> "new entry"280275 }281276 277+internal fun entryEditTypeSegments(isNew: Boolean): List<PeachSegment> = buildList {278+ add(PeachSegment("login", "login"))279+ if (!isNew) add(PeachSegment("note", "note"))280+ add(PeachSegment("card", "card"))281+}282+282283 internal fun entryEditPrimaryActionLabel(isNew: Boolean, saving: Boolean): String = when {283284 saving -> "saving..."284285 isNew -> "create"@@ -291,9 +292,6 @@291292 return true292293 }293294 294-/** A brand-new note opens the full-screen notes editor instead of the form. */295-internal fun shouldOpenNotesMode(isNew: Boolean, type: String): Boolean = isNew && type == "note"296-297295 /** Target alpha for the edit-screen ghost watermark — visible only once a title exists. */298296 internal fun editGhostWatermarkTarget(title: String): Float = if (title.isNotBlank()) 0.03f else 0f299297 @@ -308,6 +306,9 @@308306 309307 internal fun shouldShowAddNotesLink(type: String, revealed: Boolean, notes: String): Boolean =310308 type == "login" && !shouldShowLoginNotes(type, revealed, notes)309+310+internal fun shouldShowLoginNotesLink(isNew: Boolean, type: String, revealed: Boolean, notes: String): Boolean =311+ !isNew && shouldShowAddNotesLink(type, revealed, notes)311312 312313 @Composable313314 private fun OptionalLoginAddLinks(app/src/main/java/com/peachpasswords/ui/vault/EntryEditViewModel.kt+0 −13
@@ -134,19 +134,6 @@134134 135135 fun setType(t: String) = _form.update { it.copy(type = t) }136136 137- /**138- * Create a blank NOTE entry and hand its id to [onOpen] so the caller can139- * navigate straight into the full-screen notes editor (brief Fix 6 item 7) —140- * a new note never shows the generic edit form.141- */142- fun createNoteAndOpen(onOpen: (String) -> Unit) {143- viewModelScope.launch {144- runCatching {145- vault.addEntry(VaultEntry(id = "", type = "note", title = "", createdAt = 0, modifiedAt = 0))146- }.onSuccess { onOpen(it.id) }147- .onFailure { e -> _form.update { it.copy(error = e.message ?: "could not create note") } }148- }149- }150137 fun setTitle(v: String) = _form.update { it.copy(title = v, error = null) }151138 fun setUsername(v: String) = _form.update { it.copy(username = v) }152139 fun setEmail(v: String) = _form.update { it.copy(email = v) }app/src/test/java/com/peachpasswords/ui/vault/EntryEditScreenTest.kt+6 −7
@@ -35,14 +35,11 @@3535 assertTrue(canSaveEditForm(EditForm(type = "card", title = "Visa", cardholderName = "June", cardNumber = "4242")))3636 }3737 38- // ── New note routes to NotesMode, not the form ────────────────────────────38+ // ── New Entry creates logins/cards; Notes mode creates notes ─────────────3939 40- @Test fun new_note_routes_to_notes_mode() {41- assertTrue(shouldOpenNotesMode(isNew = true, type = "note"))42- // Existing note stays in the form; new login/card stay in the form.43- assertFalse(shouldOpenNotesMode(isNew = false, type = "note"))44- assertFalse(shouldOpenNotesMode(isNew = true, type = "login"))45- assertFalse(shouldOpenNotesMode(isNew = true, type = "card"))40+ @Test fun new_entry_type_picker_excludes_notes() {41+ assertEquals(listOf("login", "card"), entryEditTypeSegments(isNew = true).map { it.key })42+ assertEquals(listOf("login", "note", "card"), entryEditTypeSegments(isNew = false).map { it.key })4643 }4744 4845 // ── Ghost watermark fades in as the title is typed ────────────────────────@@ -60,6 +57,8 @@6057 assertFalse(shouldShowLoginNotes("login", revealed = false, notes = ""))6158 assertTrue(shouldShowAddTotpLink("login", revealed = false, totp = ""))6259 assertTrue(shouldShowAddNotesLink("login", revealed = false, notes = ""))60+ assertFalse(shouldShowLoginNotesLink(isNew = true, type = "login", revealed = false, notes = ""))61+ assertTrue(shouldShowLoginNotesLink(isNew = false, type = "login", revealed = false, notes = ""))6362 }6463 6564 @Test fun optional_login_fields_show_when_revealed_or_populated() {