feat: v0.4.1.0 — colour filters, drafts, empty trash, editor polish
Ships everything staged since v0.4.0.0 as v0.4.1.0: - Colour filters: a five-swatch strip under the drawer's Favorites narrows the list to active notes of that colour (NoteFilter ByColor, observeByColor/searchByColor, color:<NAME> route). - Auto-saved drafts: new notes persist as drafts while typed (Note.isDraft, Drafts filter + drawer row, debounced autosave with flush-on-exit) and ride along in encrypted backups. - Empty Trash: a DeleteForever button + confirmation dialog in the Trash view; deleteAllTrashed() cascades hashtag xrefs and attachments exactly like delete(). - Editor row rebuild: EditorLineField unified on one underlined BasicTextField (M3 TextField's 56 dp min container was the root of the double-height rows); checklist controls centre vertically beside wrapping labels. - Untitled drafts read "Shopping List — (draft)" on cards and in the editor bar via NoteType.displayName (display-only; stored content untouched). Version lockstep per §11.1: versionCode 36, versionName 0.4.1.0, APP_VERSION, README intro + smoke-test checklist, PREVIOUS_HISTORY.md section, ReleaseNotes.RECENT (v0.3.7.0 drops off the tail), Dev Plan §10 row.
This commit is contained in:
1 parent
d45cb7c31e
commit
d9043db857
20 files changed
+777
-112
No files matched your search
@@ -40,6 +40,7 @@ import org.incido.compose.ui.settings.auth.PinChangeScreen
|
||||
import org.incido.compose.ui.settings.auth.PinEntryScreen
|
||||
import org.incido.compose.ui.settings.auth.PinSetupScreen
|
||||
import org.incido.compose.ui.theme.IncidoTheme
|
||||
import org.incido.domain.model.NoteColor
|
||||
import org.incido.domain.model.NoteFilter
|
||||
import org.incido.domain.repository.NoteRepository
|
||||
|
||||
@@ -61,8 +62,13 @@ private fun String.toNoteFilter(): NoteFilter = when {
|
||||
this == "home" -> NoteFilter.Home
|
||||
this == "favorites" -> NoteFilter.Favorites
|
||||
this == "untagged" -> NoteFilter.Untagged
|
||||
this == "drafts" -> NoteFilter.Drafts
|
||||
this == "trash" -> NoteFilter.Trash
|
||||
startsWith("tag:") -> NoteFilter.ByTag(this.removePrefix("tag:"))
|
||||
startsWith("color:") -> NoteColor.values()
|
||||
.firstOrNull { it.name == this.removePrefix("color:") }
|
||||
?.let { NoteFilter.ByColor(it) }
|
||||
?: NoteFilter.Home
|
||||
else -> NoteFilter.Home
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,8 @@ data class BackupNote(
|
||||
val attachments: List<BackupAttachment> = emptyList(),
|
||||
/** Preserve soft-delete state; defaults to false for older backups. */
|
||||
val isTrashed: Boolean = false,
|
||||
/** Preserve draft state; defaults to false for older backups. */
|
||||
val isDraft: Boolean = false,
|
||||
/**
|
||||
* v0.3.8.0 — serialised as the [org.incido.domain.model.NoteType]
|
||||
* enum name ("TEXT" / "TASK_LIST" / "SHOPPING_LIST"). Defaulted so
|
||||
@@ -163,6 +165,7 @@ private suspend fun Note.toBackup(repository: NoteRepository): BackupNote {
|
||||
isFavorite = isFavorite,
|
||||
color = color.name,
|
||||
isTrashed = isTrashed,
|
||||
isDraft = isDraft,
|
||||
noteType = type.name,
|
||||
hashtags = hashtags,
|
||||
attachments = backups,
|
||||
@@ -180,6 +183,7 @@ private fun Note.toBackup(): BackupNote = BackupNote(
|
||||
isFavorite = isFavorite,
|
||||
color = color.name,
|
||||
isTrashed = isTrashed,
|
||||
isDraft = isDraft,
|
||||
noteType = type.name,
|
||||
hashtags = hashtags,
|
||||
attachments = emptyList(),
|
||||
@@ -193,6 +197,7 @@ private fun BackupNote.toDomain(): Note = Note(
|
||||
isFavorite = isFavorite,
|
||||
color = runCatching { NoteColor.valueOf(color) }.getOrDefault(NoteColor.NONE),
|
||||
isTrashed = isTrashed,
|
||||
isDraft = isDraft,
|
||||
type = runCatching { NoteType.valueOf(noteType) }.getOrDefault(NoteType.TEXT),
|
||||
hashtags = hashtags,
|
||||
// Attachments are inserted separately by importSnapshot so they
|
||||
|
||||
@@ -25,6 +25,35 @@ object ReleaseNotes {
|
||||
* Append a new entry on top each release.
|
||||
*/
|
||||
val RECENT: List<ReleaseNote> = listOf(
|
||||
ReleaseNote(
|
||||
version = "0.4.1.0",
|
||||
date = "2026-09-23",
|
||||
bullets = listOf(
|
||||
"Colour filters in the drawer: a strip of five swatches " +
|
||||
"\u2014 Blue, Green, Amber, Red, Purple \u2014 sits " +
|
||||
"right under Favorites. Tap one and the list shows " +
|
||||
"ONLY notes of that colour; tap it again for Home.",
|
||||
"Colour views follow the Favorites / Untagged rules: " +
|
||||
"trashed notes never show, untagged ones do, and " +
|
||||
"search narrows within the selected colour.",
|
||||
"Auto-saved drafts: a new note saves itself while you " +
|
||||
"type, so nothing is ever lost \u2014 an unfinished " +
|
||||
"note waits in the new Drafts drawer row, and opening " +
|
||||
"it again picks up exactly where you stopped.",
|
||||
"An untitled draft names itself after its kind \u2014 " +
|
||||
"\"Task List \u2014 (draft)\", \"Shopping List \u2014 " +
|
||||
"(draft)\" \u2014 on its card and in the editor bar. " +
|
||||
"Drafts survive encrypted backup and restore too.",
|
||||
"Empty Trash: a one-tap button appears whenever the " +
|
||||
"Trash holds notes \u2014 a confirmation dialog " +
|
||||
"stands between that tap and permanently deleting " +
|
||||
"every trashed note, attachments included.",
|
||||
"Editor rows rebuilt: title, item and quantity fields " +
|
||||
"share one even underlined height, long checklist " +
|
||||
"labels wrap instead of stretching the row, and " +
|
||||
"checkbox / +/- controls stay centred alongside.",
|
||||
),
|
||||
),
|
||||
ReleaseNote(
|
||||
version = "0.4.0.0",
|
||||
date = "2026-09-18",
|
||||
@@ -113,19 +142,6 @@ object ReleaseNotes {
|
||||
"and pen-nib artwork.",
|
||||
),
|
||||
),
|
||||
ReleaseNote(
|
||||
version = "0.3.7.0",
|
||||
date = "2026-08-20",
|
||||
bullets = listOf(
|
||||
"Trash / soft delete. Deleting a note now moves it to a new " +
|
||||
"Trash section in the navigation drawer instead of " +
|
||||
"destroying it immediately \u2014 it disappears from Home, " +
|
||||
"Favorites, Untagged, tag views, and ordinary search.",
|
||||
"Inside Trash, each note's menu offers Restore (puts it back " +
|
||||
"where it was) or Delete permanently (destroys it for " +
|
||||
"good, including attachments).",
|
||||
),
|
||||
),
|
||||
// v0.4.0.0 push drops v0.3.6.0 off the "5 most recent" tail.
|
||||
// v0.4.1.0 push drops v0.3.7.0 off the "5 most recent" tail.
|
||||
)
|
||||
}
|
||||
@@ -1,8 +1,15 @@
|
||||
package org.incido.compose.ui.drawer
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
@@ -11,7 +18,9 @@ import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material.icons.filled.LabelOff
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Drafts
|
||||
import androidx.compose.material.icons.filled.Settings
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material.icons.filled.Tag
|
||||
@@ -25,17 +34,24 @@ import androidx.compose.material3.NavigationDrawerItemDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import org.incido.compose.ui.theme.AllNoteColors
|
||||
import org.incido.compose.ui.theme.toComposeColor
|
||||
import org.incido.domain.model.HashtagUsage
|
||||
import org.incido.domain.model.NoteColor
|
||||
import org.incido.domain.model.NoteFilter
|
||||
|
||||
/**
|
||||
* Left-side navigation drawer. Top section has five fixed entries
|
||||
* (Home / Favorites / Untagged / Trash / Settings); a `HorizontalDivider`; then
|
||||
* Left-side navigation drawer. Top section has the fixed entries
|
||||
* (Home / Favorites / the colour-swatch strip / Drafts / Untagged /
|
||||
* Trash / Settings); a `HorizontalDivider`; then
|
||||
* a live scrollable list of the user's most-recently-used hashtags.
|
||||
*
|
||||
* Tapping a filter entry calls [onSelectFilter]; tapping Settings
|
||||
@@ -44,6 +60,16 @@ import org.incido.domain.model.NoteFilter
|
||||
*
|
||||
* v0.3.2.0 — Settings is a new entry directly underneath "Untagged"
|
||||
* with its own divider for visual separation.
|
||||
*
|
||||
* Colour filters sit between "Favorites" and "Drafts" as one
|
||||
* horizontal strip of swatches — the colours are self-explanatory, so
|
||||
* there are no labels. Selecting one shows ONLY active notes of that
|
||||
* colour — trashed notes never appear, untagged ones do (see
|
||||
* NoteFilter.ByColor); tapping the selected swatch again returns to
|
||||
* Home.
|
||||
*
|
||||
* "Drafts" lists auto-saved new notes (see Note.isDraft) — a new note
|
||||
* is persisted automatically while it is being written.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -82,6 +108,64 @@ fun IncidoDrawer(
|
||||
onClick = { onSelectFilter(NoteFilter.Favorites) },
|
||||
icon = { Icon(Icons.Filled.Star, contentDescription = null) },
|
||||
)
|
||||
// Colour filters: one horizontal strip of swatches under
|
||||
// Favorites (NONE is not offered; the colours are
|
||||
// self-explanatory, so there are no labels). Each shows
|
||||
// ONLY active notes of that colour — trashed notes never
|
||||
// appear, untagged ones do. Tapping the selected swatch
|
||||
// again returns to Home.
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(vertical = 6.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(
|
||||
space = 14.dp,
|
||||
alignment = Alignment.CenterHorizontally,
|
||||
),
|
||||
) {
|
||||
AllNoteColors.filter { it != NoteColor.NONE }.forEach { color ->
|
||||
val selected = currentFilter == NoteFilter.ByColor(color)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(30.dp)
|
||||
.clip(CircleShape)
|
||||
.background(color.toComposeColor())
|
||||
.then(
|
||||
if (selected) {
|
||||
Modifier.border(
|
||||
width = 3.dp,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
shape = CircleShape,
|
||||
)
|
||||
} else {
|
||||
Modifier
|
||||
},
|
||||
)
|
||||
.clickable {
|
||||
onSelectFilter(
|
||||
if (selected) NoteFilter.Home
|
||||
else NoteFilter.ByColor(color),
|
||||
)
|
||||
},
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
if (selected) {
|
||||
Icon(
|
||||
Icons.Filled.Check,
|
||||
contentDescription = "${color.label} filter selected",
|
||||
modifier = Modifier.size(16.dp),
|
||||
tint = Color.White,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
NavigationDrawerItem(
|
||||
label = { Text("Drafts") },
|
||||
selected = currentFilter == NoteFilter.Drafts,
|
||||
onClick = { onSelectFilter(NoteFilter.Drafts) },
|
||||
icon = { Icon(Icons.Filled.Drafts, contentDescription = null) },
|
||||
)
|
||||
NavigationDrawerItem(
|
||||
label = { Text("Untagged") },
|
||||
selected = currentFilter == NoteFilter.Untagged,
|
||||
|
||||
@@ -24,7 +24,6 @@ import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.ime
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
@@ -37,6 +36,8 @@ import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||
@@ -71,12 +72,11 @@ import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.SuggestionChip
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.material3.TextFieldDefaults
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -88,10 +88,14 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.drawBehind
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.focus.onFocusEvent
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.graphics.painter.BitmapPainter
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
@@ -271,11 +275,25 @@ fun NoteEditorScreen(
|
||||
}
|
||||
|
||||
fun tryClose() {
|
||||
// Drafts (new notes and draft editing) autosave every edit, so
|
||||
// leaving is always lossless: flush any in-flight change and pop
|
||||
// — no "Discard changes?" prompt.
|
||||
if (viewModel.isDraftFlow) {
|
||||
viewModel.flushDraft()
|
||||
onClose()
|
||||
return
|
||||
}
|
||||
if (isDirty()) showDiscardDialog = true else onClose()
|
||||
}
|
||||
|
||||
BackHandler(enabled = true) { tryClose() }
|
||||
|
||||
// Any other exit path (rotation, nav teardown) also flushes pending
|
||||
// draft edits immediately.
|
||||
DisposableEffect(viewModel) {
|
||||
onDispose { viewModel.flushDraft() }
|
||||
}
|
||||
|
||||
if (showDiscardDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showDiscardDialog = false },
|
||||
@@ -308,7 +326,11 @@ fun NoteEditorScreen(
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
text = if (state.isEditing) "Edit note" else "New note",
|
||||
text = when {
|
||||
state.isDraft -> draftBarTitle(state)
|
||||
state.isEditing -> "Edit note"
|
||||
else -> "New note"
|
||||
},
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
@@ -428,6 +450,7 @@ fun NoteEditorScreen(
|
||||
onItemCostChange = viewModel::setItemCost,
|
||||
onRemoveItem = viewModel::removeListItem,
|
||||
onAddItem = viewModel::addListItem,
|
||||
onAddItemAfter = viewModel::addListItemAfter,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -996,7 +1019,12 @@ private fun ChecklistEditorBody(
|
||||
onItemCostChange: (Int, String) -> Unit,
|
||||
onRemoveItem: (Int) -> Unit,
|
||||
onAddItem: () -> Unit,
|
||||
onAddItemAfter: (Int) -> Unit,
|
||||
) {
|
||||
// Enter/Return in a task/product row inserts the next row and moves
|
||||
// the cursor into it. The nonce re-fires the new row's focus effect
|
||||
// even when the same index is targeted repeatedly.
|
||||
var focusTarget by remember { mutableStateOf(-1 to 0L) }
|
||||
LazyColumn(modifier = modifier.fillMaxWidth()) {
|
||||
item {
|
||||
// Title / preamble. Kept as plain lines above the checkbox
|
||||
@@ -1015,10 +1043,19 @@ private fun ChecklistEditorBody(
|
||||
.padding(horizontal = 16.dp, vertical = 4.dp),
|
||||
)
|
||||
}
|
||||
if (isShopping) {
|
||||
item { ShoppingColumnHeader() }
|
||||
}
|
||||
itemsIndexed(items) { index, item ->
|
||||
ChecklistItemRow(
|
||||
item = item,
|
||||
isShopping = isShopping,
|
||||
focusOnCompose = focusTarget.first == index,
|
||||
focusNonce = focusTarget.second,
|
||||
onAddAfter = {
|
||||
onAddItemAfter(index)
|
||||
focusTarget = (index + 1) to focusTarget.second + 1
|
||||
},
|
||||
onToggle = { checked -> onToggleItem(index, checked) },
|
||||
onTextChange = { text -> onItemTextChange(index, text) },
|
||||
onQuantityChange = { qty -> onItemQuantityChange(index, qty) },
|
||||
@@ -1040,21 +1077,80 @@ private fun ChecklistEditorBody(
|
||||
}
|
||||
}
|
||||
|
||||
/** One row: `[ ]` · Product · Qty picker · per-item price · remove. */
|
||||
/**
|
||||
* Small "Product / Amnt. / Price" label line above the shopping rows.
|
||||
* Mirrors [ChecklistItemRow]'s column geometry (checkbox spacer +
|
||||
* weighted product + fixed qty/price widths) so the labels sit over
|
||||
* their columns and the fields themselves stay uncluttered.
|
||||
*/
|
||||
@Composable
|
||||
private fun ShoppingColumnHeader() {
|
||||
val labelStyle = MaterialTheme.typography.labelSmall
|
||||
val labelColor = MaterialTheme.colorScheme.onSurfaceVariant
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 8.dp),
|
||||
) {
|
||||
Spacer(Modifier.size(48.dp)) // checkbox column
|
||||
Text(
|
||||
"Product",
|
||||
style = labelStyle,
|
||||
color = labelColor,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(start = 16.dp, top = 16.dp),
|
||||
)
|
||||
Spacer(Modifier.size(6.dp))
|
||||
Text(
|
||||
"Amnt.",
|
||||
style = labelStyle,
|
||||
color = labelColor,
|
||||
modifier = Modifier
|
||||
.width(44.dp)
|
||||
.padding(start = 4.dp, top = 16.dp),
|
||||
)
|
||||
Spacer(Modifier.size(6.dp))
|
||||
Text(
|
||||
"Price",
|
||||
style = labelStyle,
|
||||
color = labelColor,
|
||||
modifier = Modifier
|
||||
.width(56.dp)
|
||||
.padding(start = 4.dp, top = 16.dp),
|
||||
)
|
||||
Spacer(Modifier.size(48.dp)) // remove-button column
|
||||
}
|
||||
}
|
||||
|
||||
/** One row: `[ ]` · Product (grows multi-line) · Qty · price · remove. */
|
||||
@Composable
|
||||
private fun ChecklistItemRow(
|
||||
item: ChecklistItem,
|
||||
isShopping: Boolean,
|
||||
focusOnCompose: Boolean,
|
||||
focusNonce: Long,
|
||||
onAddAfter: () -> Unit,
|
||||
onToggle: (Boolean) -> Unit,
|
||||
onTextChange: (String) -> Unit,
|
||||
onQuantityChange: (String) -> Unit,
|
||||
onCostChange: (String) -> Unit,
|
||||
onRemove: () -> Unit,
|
||||
) {
|
||||
// Enter on the row above lands the cursor here (see [focusOnCompose]
|
||||
// in ChecklistEditorBody — the target is always a freshly inserted
|
||||
// row, so focusing on first composition is enough).
|
||||
val textFocus = remember { FocusRequester() }
|
||||
LaunchedEffect(focusNonce) {
|
||||
if (focusOnCompose) textFocus.requestFocus()
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 8.dp),
|
||||
// Controls hug the field's vertical centre, so the checkbox,
|
||||
// quantity / price columns and the remove ✕ travel with the
|
||||
// row as a long entry wraps onto extra lines.
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Checkbox(checked = item.checked, onCheckedChange = onToggle)
|
||||
@@ -1065,24 +1161,32 @@ private fun ChecklistItemRow(
|
||||
EditorLineField(
|
||||
value = item.text,
|
||||
onValueChange = onTextChange,
|
||||
placeholder = if (isShopping) "Product" else "Task",
|
||||
// Shopping rows are labelled by the ShoppingColumnHeader
|
||||
// above, so the fields stay empty-clean; plain task rows keep
|
||||
// their single "Task" hint.
|
||||
placeholder = if (isShopping) "" else "Task",
|
||||
keyboardOptions = KeyboardOptions(
|
||||
capitalization = KeyboardCapitalization.Sentences,
|
||||
imeAction = ImeAction.Next,
|
||||
),
|
||||
// Enter/Return (IME "Next") creates the following row and
|
||||
// moves the cursor there instead of tabbing sideways.
|
||||
keyboardActions = KeyboardActions(onNext = { onAddAfter() }),
|
||||
// Long text wraps onto more lines (field grows downward)
|
||||
// instead of scrolling sideways out of view.
|
||||
singleLine = false,
|
||||
maxLines = 6,
|
||||
fieldModifier = Modifier.focusRequester(textFocus),
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
if (isShopping) {
|
||||
Spacer(Modifier.size(6.dp))
|
||||
// Free-text quantity line (replaced the 1–9 dropdown, whose
|
||||
// digit never fit its box). Blank means quantity 1: while
|
||||
// focused an empty line shows the "Quan." hint; on focus
|
||||
// Free-text quantity line. Blank means quantity 1: on focus
|
||||
// loss it settles on "1" — display-only, storage keeps the
|
||||
// blank default so {q1} never enters the saved text.
|
||||
EditorLineField(
|
||||
value = item.quantity,
|
||||
onValueChange = onQuantityChange,
|
||||
placeholder = "Quan.",
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Number,
|
||||
imeAction = ImeAction.Next,
|
||||
@@ -1090,7 +1194,8 @@ private fun ChecklistItemRow(
|
||||
formatUnfocused = { digits ->
|
||||
if (digits.isEmpty()) "1" else digits
|
||||
},
|
||||
modifier = Modifier.width(72.dp),
|
||||
compact = true,
|
||||
modifier = Modifier.width(44.dp),
|
||||
)
|
||||
Spacer(Modifier.size(6.dp))
|
||||
// Supermarket-style cents entry: while focused the line shows
|
||||
@@ -1100,7 +1205,6 @@ private fun ChecklistItemRow(
|
||||
EditorLineField(
|
||||
value = item.cost,
|
||||
onValueChange = onCostChange,
|
||||
placeholder = "Price",
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Number,
|
||||
imeAction = ImeAction.Next,
|
||||
@@ -1108,7 +1212,8 @@ private fun ChecklistItemRow(
|
||||
formatUnfocused = { digits ->
|
||||
if (digits.isEmpty()) "" else "$" + Note.amountFromPriceDigits(digits)
|
||||
},
|
||||
modifier = Modifier.width(110.dp),
|
||||
compact = true,
|
||||
modifier = Modifier.width(56.dp),
|
||||
)
|
||||
}
|
||||
IconButton(onClick = onRemove) {
|
||||
@@ -1130,6 +1235,21 @@ private fun ChecklistItemRow(
|
||||
private fun editorFieldStyle(): TextStyle =
|
||||
MaterialTheme.typography.bodyMedium.copy(fontSize = 13.sp, lineHeight = 18.sp)
|
||||
|
||||
/**
|
||||
* Top-bar label while a draft session is live. A draft that already
|
||||
* carries a title just says "Draft"; one with NO title names itself
|
||||
* after its kind — "Task List - (draft)", "Shopping List - (draft)" —
|
||||
* mirroring the Drafts card title so both surfaces agree. (TEXT drafts
|
||||
* take their title from the first content line, so they always land in
|
||||
* the "Draft" branch.)
|
||||
*/
|
||||
private fun draftBarTitle(state: NoteEditorUiState): String {
|
||||
val titleSource =
|
||||
if (state.type == NoteType.TEXT) state.content else state.listHeader
|
||||
val hasTitle = titleSource.lineSequence().any { it.isNotBlank() }
|
||||
return if (hasTitle) "Draft" else "${state.type.displayName} - (draft)"
|
||||
}
|
||||
|
||||
/**
|
||||
* v0.3.8.0 — one plain underlined editing line, shared by every editable
|
||||
* field in the editor (title, task/product, quantity, price). Replaces
|
||||
@@ -1147,7 +1267,11 @@ private fun EditorLineField(
|
||||
onValueChange: (String) -> Unit,
|
||||
placeholder: String = "",
|
||||
keyboardOptions: KeyboardOptions = KeyboardOptions.Default,
|
||||
keyboardActions: KeyboardActions = KeyboardActions.Default,
|
||||
formatUnfocused: ((String) -> String)? = null,
|
||||
singleLine: Boolean = true,
|
||||
maxLines: Int = 1,
|
||||
compact: Boolean = false,
|
||||
fieldModifier: Modifier = Modifier,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
@@ -1156,43 +1280,65 @@ private fun EditorLineField(
|
||||
var focused by remember { mutableStateOf(false) }
|
||||
val displayed =
|
||||
if (focused || formatUnfocused == null) value else formatUnfocused(value)
|
||||
Row(
|
||||
modifier = modifier.heightIn(min = 44.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
// Material 3 filled TextField with fully transparent containers:
|
||||
// what remains visible is just the text line and the 2 dp bottom
|
||||
// indicator — exactly the "one line per field" look, for free.
|
||||
TextField(
|
||||
value = displayed,
|
||||
onValueChange = onValueChange,
|
||||
singleLine = true,
|
||||
placeholder = {
|
||||
Text(
|
||||
text = placeholder,
|
||||
style = fieldStyle,
|
||||
color = hintColor,
|
||||
maxLines = 1,
|
||||
)
|
||||
},
|
||||
textStyle = fieldStyle.copy(
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
),
|
||||
keyboardOptions = keyboardOptions,
|
||||
colors = TextFieldDefaults.colors(
|
||||
focusedContainerColor = Color.Transparent,
|
||||
unfocusedContainerColor = Color.Transparent,
|
||||
disabledContainerColor = Color.Transparent,
|
||||
errorContainerColor = Color.Transparent,
|
||||
focusedIndicatorColor = MaterialTheme.colorScheme.primary,
|
||||
unfocusedIndicatorColor = MaterialTheme.colorScheme.outlineVariant,
|
||||
cursorColor = MaterialTheme.colorScheme.primary,
|
||||
),
|
||||
modifier = fieldModifier
|
||||
.weight(1f)
|
||||
.onFocusEvent { focused = it.isFocused },
|
||||
)
|
||||
// v0.4.x: EVERY field — product/task text, quantity, price, header —
|
||||
// is one content-hugging BasicTextField with a hand-drawn 2 dp
|
||||
// bottom rule (the [compact] flag no longer changes rendering). The
|
||||
// Material 3 TextField's baked-in 56 dp minimum container made even
|
||||
// an empty field look double-height and pinned the row's checkbox /
|
||||
// price controls to the top edge; now a single line of text is a
|
||||
// single line of field, and singleLine = false fields grow
|
||||
// line-by-line up to [maxLines] as the entry wraps.
|
||||
val indicatorColor = if (focused) {
|
||||
MaterialTheme.colorScheme.primary
|
||||
} else {
|
||||
MaterialTheme.colorScheme.outlineVariant
|
||||
}
|
||||
BasicTextField(
|
||||
value = displayed,
|
||||
onValueChange = onValueChange,
|
||||
singleLine = singleLine,
|
||||
maxLines = maxLines,
|
||||
textStyle = fieldStyle.copy(color = MaterialTheme.colorScheme.onSurface),
|
||||
keyboardOptions = keyboardOptions,
|
||||
keyboardActions = keyboardActions,
|
||||
cursorBrush = SolidColor(MaterialTheme.colorScheme.primary),
|
||||
decorationBox = { innerTextField ->
|
||||
// The 10 / 4 dp block gives a slim underlined line a comfy
|
||||
// tap target; the rule below lands on the block's bottom
|
||||
// edge, so it always sits 4 dp under the LAST text line —
|
||||
// one line or six.
|
||||
Box(
|
||||
modifier = Modifier.padding(top = 10.dp, bottom = 4.dp),
|
||||
contentAlignment = Alignment.CenterStart,
|
||||
) {
|
||||
if (displayed.isEmpty() && placeholder.isNotEmpty()) {
|
||||
Text(
|
||||
text = placeholder,
|
||||
style = fieldStyle,
|
||||
color = hintColor,
|
||||
maxLines = 1,
|
||||
)
|
||||
}
|
||||
innerTextField()
|
||||
}
|
||||
},
|
||||
// NOTE: the caller's [modifier] (weight(1f) for the product
|
||||
// column, fixed 44/56.dp for quantity/price) MUST stay in the
|
||||
// chain — dropping it lets fillMaxWidth() win the Row and
|
||||
// swallow the neighbouring columns.
|
||||
modifier = fieldModifier
|
||||
.then(modifier)
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 2.dp)
|
||||
.drawBehind {
|
||||
drawRect(
|
||||
color = indicatorColor,
|
||||
topLeft = Offset(0f, size.height - 2.dp.toPx()),
|
||||
size = Size(size.width, 2.dp.toPx()),
|
||||
)
|
||||
}
|
||||
.onFocusEvent { focused = it.isFocused },
|
||||
)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
@@ -8,11 +8,15 @@ import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.FlowPreview
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
@@ -95,6 +99,9 @@ data class NoteEditorUiState(
|
||||
/** `true` when editing an existing note (existing != null). */
|
||||
val isEditing: Boolean get() = existing != null
|
||||
|
||||
/** `true` while this note is an auto-saved draft (see Note.isDraft). */
|
||||
val isDraft: Boolean get() = existing?.isDraft == true
|
||||
|
||||
/** `true` when there's still room to add another tag. */
|
||||
val canAddMoreTags: Boolean get() = hashtags.size < MAX_TAGS
|
||||
|
||||
@@ -145,7 +152,7 @@ data class PendingAttachment(
|
||||
val isImage: Boolean get() = mimeType.startsWith("image/")
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
|
||||
class NoteEditorViewModel(
|
||||
private val repository: NoteRepository,
|
||||
private val noteId: Long?,
|
||||
@@ -209,6 +216,36 @@ class NoteEditorViewModel(
|
||||
*/
|
||||
private var nextPendingTempId: Long = -System.currentTimeMillis()
|
||||
|
||||
/**
|
||||
* Draft autosave. A NEW note (or one still flagged as a draft) is
|
||||
* persisted automatically: every edit lands in the DB ~400 ms after
|
||||
* the last keystroke (coalesced so typing doesn't write per char),
|
||||
* and [flushDraft] forces an immediate write whenever the editor
|
||||
* closes or disposes. A crash can therefore only ever lose the last
|
||||
* few keystrokes — never a whole draft.
|
||||
*/
|
||||
private val draftAutosave = noteId == null || noteId == 0L
|
||||
|
||||
/** True while this session autosaves: brand-new notes and draft editing. */
|
||||
val isDraftFlow: Boolean
|
||||
get() = draftAutosave || _state.value.isDraft
|
||||
|
||||
private var draftPersistInProgress = false
|
||||
|
||||
init {
|
||||
// Signature-driven debounced autosave: whenever anything a draft
|
||||
// persists changes, write the draft row shortly after.
|
||||
viewModelScope.launch {
|
||||
_state
|
||||
.map { s ->
|
||||
listOf(s.content, s.isFavorite, s.color, s.type, s.hashtags)
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.debounce(DRAFT_AUTOSAVE_DEBOUNCE_MS)
|
||||
.collect { persistDraftNow() }
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
// Tag autocomplete — re-query on every keystroke (debounced upstream
|
||||
// would be nice but ObjectBox is plenty fast for this size).
|
||||
@@ -294,6 +331,10 @@ class NoteEditorViewModel(
|
||||
initialHashtags = note.hashtags
|
||||
initialType = note.type
|
||||
}
|
||||
// Draft echoes: emissions caused by our own autosave
|
||||
// must not clobber in-progress edits mid-typing —
|
||||
// the local state is authoritative while drafting.
|
||||
if (note != null && note.isDraft && !firstLoad) return@collect
|
||||
// Parse list rows once on first load; later DB
|
||||
// emissions must not clobber in-progress edits.
|
||||
val listSeed: Pair<String, List<ChecklistItem>>? =
|
||||
@@ -459,6 +500,20 @@ class NoteEditorViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a blank row right after [index] (or append it on the last
|
||||
* row). Driven by Enter/Return in the task/product field so the
|
||||
* writer flows downward into a fresh row instead of tabbing sideways.
|
||||
*/
|
||||
fun addListItemAfter(index: Int) {
|
||||
_state.update { s ->
|
||||
if (s.type == NoteType.TEXT) return@update s
|
||||
if (index !in s.items.indices) return@update s
|
||||
val updated = s.items.toMutableList().also { it.add(index + 1, ChecklistItem("")) }
|
||||
s.withListEdits(items = updated)
|
||||
}
|
||||
}
|
||||
|
||||
fun removeListItem(index: Int) {
|
||||
_state.update { s ->
|
||||
if (index !in s.items.indices) return@update s
|
||||
@@ -587,17 +642,74 @@ class NoteEditorViewModel(
|
||||
|
||||
// ---- save ----
|
||||
|
||||
/**
|
||||
* Force-write the current draft state to the DB right now — used
|
||||
* when the editor closes / disposes so pending edits never sit in
|
||||
* the debounce window. No-op for non-draft sessions and blank
|
||||
* content (see [persistDraftNow]).
|
||||
*/
|
||||
fun flushDraft() {
|
||||
viewModelScope.launch { persistDraftNow() }
|
||||
}
|
||||
|
||||
/** Write the draft row if this session is in the draft lifecycle. */
|
||||
private suspend fun persistDraftNow() {
|
||||
val current = _state.value
|
||||
if (current.isLoading || current.isSaving) return
|
||||
if (draftPersistInProgress) return
|
||||
val baseNote = current.existing
|
||||
if (baseNote != null && !baseNote.isDraft) return // already published
|
||||
if (!draftAutosave && baseNote?.isDraft != true) return
|
||||
if (current.content.isBlank()) return
|
||||
draftPersistInProgress = true
|
||||
try {
|
||||
val now = System.currentTimeMillis()
|
||||
val draft = baseNote?.copy(
|
||||
content = current.content,
|
||||
isFavorite = current.isFavorite,
|
||||
color = current.color,
|
||||
type = current.type,
|
||||
isDraft = true,
|
||||
) ?: Note(
|
||||
content = current.content,
|
||||
createdAt = now,
|
||||
updatedAt = now,
|
||||
isFavorite = current.isFavorite,
|
||||
color = current.color,
|
||||
type = current.type,
|
||||
isDraft = true,
|
||||
)
|
||||
val previous = baseNote?.hashtags.orEmpty().toSet()
|
||||
val currentSet = current.hashtags.toSet()
|
||||
val saved = repository.saveNoteWithHashtags(
|
||||
note = draft,
|
||||
hashtagsToAdd = currentSet - previous,
|
||||
hashtagsToRemove = previous - currentSet,
|
||||
)
|
||||
// Adopt the persisted row so every later write updates the
|
||||
// SAME note — one draft per editing session.
|
||||
_state.update {
|
||||
it.copy(existing = saved.copy(isDraft = true, hashtags = current.hashtags))
|
||||
}
|
||||
} finally {
|
||||
draftPersistInProgress = false
|
||||
}
|
||||
}
|
||||
|
||||
fun save(onDone: () -> Unit) {
|
||||
val current = _state.value
|
||||
if (!current.canSave) return
|
||||
_state.update { it.copy(isSaving = true) }
|
||||
viewModelScope.launch {
|
||||
val baseNote = current.existing
|
||||
// An explicit Save PUBLISHES the note: a draft row loses
|
||||
// its flag here and joins the normal views for good.
|
||||
val toPersist = baseNote?.copy(
|
||||
content = current.content,
|
||||
isFavorite = current.isFavorite,
|
||||
color = current.color,
|
||||
type = current.type,
|
||||
isDraft = false,
|
||||
) ?: Note(
|
||||
content = current.content,
|
||||
createdAt = System.currentTimeMillis(),
|
||||
@@ -643,6 +755,9 @@ class NoteEditorViewModel(
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** Typing-pause before a draft autosave fires (ms). */
|
||||
const val DRAFT_AUTOSAVE_DEBOUNCE_MS = 400L
|
||||
|
||||
fun factory(
|
||||
noteId: Long?,
|
||||
initialSharedText: String? = null,
|
||||
|
||||
@@ -29,6 +29,7 @@ import androidx.compose.material.icons.filled.AttachFile
|
||||
import androidx.compose.material.icons.filled.CheckBox
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.DeleteForever
|
||||
import androidx.compose.material.icons.filled.Lock
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
@@ -38,6 +39,7 @@ import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material.icons.filled.ShoppingBasket
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material.icons.outlined.StarOutline
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
@@ -51,6 +53,7 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
@@ -127,6 +130,7 @@ fun NoteListScreen(
|
||||
) {
|
||||
val state by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
var localQuery by remember { mutableStateOf("") }
|
||||
var showEmptyTrashDialog by remember { mutableStateOf(false) }
|
||||
val searchFocusRequester = remember { FocusRequester() }
|
||||
|
||||
LaunchedEffect(filterMode) { viewModel.setFilter(filterMode) }
|
||||
@@ -139,6 +143,36 @@ fun NoteListScreen(
|
||||
}
|
||||
}
|
||||
|
||||
// "Empty Trash" confirmation. The whole trash goes, attachments
|
||||
// included — say so plainly before the one tap that does it.
|
||||
if (showEmptyTrashDialog) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showEmptyTrashDialog = false },
|
||||
title = { Text("Empty Trash?") },
|
||||
text = {
|
||||
Text(
|
||||
"Every note in the Trash, including attachments, will be " +
|
||||
"permanently deleted. This cannot be undone.",
|
||||
)
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
showEmptyTrashDialog = false
|
||||
viewModel.emptyTrash()
|
||||
},
|
||||
) {
|
||||
Text("Empty Trash", color = MaterialTheme.colorScheme.error)
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showEmptyTrashDialog = false }) {
|
||||
Text("Cancel")
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
CenterAlignedTopAppBar(
|
||||
@@ -162,6 +196,17 @@ fun NoteListScreen(
|
||||
Icon(Icons.Default.Search, contentDescription = "Search notes")
|
||||
}
|
||||
}
|
||||
// Trash view gains an "Empty Trash" button whenever it
|
||||
// holds something; the destructive action is confirmed
|
||||
// through a dialog before anything is touched.
|
||||
if (filterMode == NoteFilter.Trash && state.notes.isNotEmpty()) {
|
||||
IconButton(onClick = { showEmptyTrashDialog = true }) {
|
||||
Icon(
|
||||
Icons.Default.DeleteForever,
|
||||
contentDescription = "Empty trash",
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
@@ -234,8 +279,10 @@ private fun screenTitle(filter: NoteFilter): String = when (filter) {
|
||||
NoteFilter.Home -> "Incido"
|
||||
NoteFilter.Favorites -> "Favorites"
|
||||
NoteFilter.Untagged -> "Untagged"
|
||||
NoteFilter.Drafts -> "Drafts"
|
||||
NoteFilter.Trash -> "Trash"
|
||||
is NoteFilter.ByTag -> "#${filter.hashtag}"
|
||||
is NoteFilter.ByColor -> filter.color.label
|
||||
}
|
||||
|
||||
@Composable
|
||||
@@ -244,8 +291,10 @@ private fun EmptyState(filterMode: NoteFilter) {
|
||||
NoteFilter.Home -> "No notes yet. Tap + to start."
|
||||
NoteFilter.Favorites -> "No favourites yet. Tap ⭐ on a card to add one."
|
||||
NoteFilter.Untagged -> "All notes are tagged. 🎉"
|
||||
NoteFilter.Drafts -> "No drafts yet. Start typing a new note and it lands here."
|
||||
NoteFilter.Trash -> "Trash is empty."
|
||||
is NoteFilter.ByTag -> "No notes tagged #${filterMode.hashtag} yet."
|
||||
is NoteFilter.ByColor -> "No " + filterMode.color.label.lowercase() + " notes yet. Pick a colour in the editor."
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
@@ -265,7 +314,9 @@ private fun EmptyState(filterMode: NoteFilter) {
|
||||
private fun NoResultsState(filterMode: NoteFilter) {
|
||||
val message = when (filterMode) {
|
||||
NoteFilter.Home -> "No matching notes."
|
||||
NoteFilter.Drafts -> "No drafts match your search."
|
||||
NoteFilter.Trash -> "No notes in Trash match your search."
|
||||
is NoteFilter.ByColor -> "No matching notes of this colour."
|
||||
else -> "Nothing here."
|
||||
}
|
||||
Box(
|
||||
@@ -395,6 +446,14 @@ private fun NoteCard(
|
||||
// text. The checkbox state lives in the summary row below instead.
|
||||
val (title, body) = if (note.type == NoteType.TEXT) Note.titleAndBody(note.content)
|
||||
else Note.cardPresentation(note.content, note.type)
|
||||
// Drafts with no title introduce themselves by kind — "Shopping
|
||||
// List - (draft)" beats a bare "Untitled" in the Drafts view. The
|
||||
// stored content is untouched; this is display-only, so typing a
|
||||
// real title (or publishing) reverts the card to normal instantly.
|
||||
val displayTitle =
|
||||
if (note.isDraft && title == Note.UNTITLED)
|
||||
"${note.type.displayName} - (draft)"
|
||||
else title
|
||||
val bodyPreview = Note.bodyPreview(body)
|
||||
val checklistSummary = Note.checklistSummary(note.content)
|
||||
val noteColor = note.color
|
||||
@@ -508,7 +567,7 @@ private fun NoteCard(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
text = displayTitle,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = titleColor,
|
||||
maxLines = 1,
|
||||
|
||||
@@ -44,7 +44,8 @@ data class NoteListUiState(
|
||||
) {
|
||||
val isEmpty: Boolean
|
||||
get() = !isLoading && notes.isEmpty() && !isSearchActive &&
|
||||
(filter == NoteFilter.Home || filter == NoteFilter.Trash)
|
||||
(filter == NoteFilter.Home || filter == NoteFilter.Trash ||
|
||||
filter == NoteFilter.Drafts)
|
||||
val noResults: Boolean get() = !isLoading && notes.isEmpty() && !isEmpty
|
||||
}
|
||||
|
||||
@@ -73,8 +74,11 @@ class NoteListViewModel(
|
||||
NoteFilter.Home -> if (q.isBlank()) repository.observeAll() else repository.search(q)
|
||||
NoteFilter.Favorites -> if (q.isBlank()) repository.observeFavorites() else repository.searchFavorites(q)
|
||||
NoteFilter.Untagged -> if (q.isBlank()) repository.observeUntagged() else repository.searchUntagged(q)
|
||||
NoteFilter.Drafts -> if (q.isBlank()) repository.observeDrafts() else repository.searchDrafts(q)
|
||||
NoteFilter.Trash -> if (q.isBlank()) repository.observeTrashed() else repository.searchTrashed(q)
|
||||
is NoteFilter.ByTag -> repository.observeNotesForHashtag(f.hashtag)
|
||||
is NoteFilter.ByColor ->
|
||||
if (q.isBlank()) repository.observeByColor(f.color) else repository.searchByColor(q, f.color)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +160,11 @@ class NoteListViewModel(
|
||||
viewModelScope.launch { repository.delete(id) }
|
||||
}
|
||||
|
||||
/** "Empty Trash": permanently destroy every note in the Trash. */
|
||||
fun emptyTrash() {
|
||||
viewModelScope.launch { repository.deleteAllTrashed() }
|
||||
}
|
||||
|
||||
/** Restore a note from Trash. */
|
||||
fun restore(id: Long) {
|
||||
viewModelScope.launch { repository.restore(id) }
|
||||
|
||||
@@ -354,7 +354,7 @@ class SettingsViewModel(
|
||||
/** The version string baked into backup payloads and shown on
|
||||
* the About card. Mirrors `app/build.gradle.kts` `versionName`
|
||||
* — if you bump one, bump both. */
|
||||
const val APP_VERSION = "0.4.0.0"
|
||||
const val APP_VERSION = "0.4.1.0"
|
||||
|
||||
val Factory: ViewModelProvider.Factory = viewModelFactory {
|
||||
initializer {
|
||||
|
||||
Reference in new issue
Block a user