feat: v0.4.1.0 — colour filters, drafts, empty trash, editor polish
dev / Build debug APK (push) Successful in 58s
release / Build & attach release APK (push) Successful in 1m27s

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:
Incido Developer committed 2026-09-23 05:24:23 +12:00
1 parent d45cb7c31e
commit d9043db857
20 files changed
+777 -112

No files matched your search

@@ -43,6 +43,8 @@ data class NoteEntity(
@Index var isTrashed: Boolean = false,
/** v0.3.8.0 — [org.incido.domain.model.NoteType] storage key (0 text, 1 task, 2 shopping). */
var typeKey: Short = 0,
/** True while a new note is being drafted; only the Drafts view shows these rows. */
@Index var isDraft: Boolean = false,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
@@ -57,6 +59,7 @@ data class NoteEntity(
if (cipherVersion != other.cipherVersion) return false
if (!contentBlob.contentEquals(other.contentBlob)) return false
if (typeKey != other.typeKey) return false
if (isDraft != other.isDraft) return false
return true
}
@@ -71,6 +74,7 @@ data class NoteEntity(
result = 31 * result + cipherVersion.hashCode()
result = 31 * result + contentBlob.contentHashCode()
result = 31 * result + typeKey.hashCode()
result = 31 * result + isDraft.hashCode()
return result
}
}
@@ -84,6 +88,7 @@ internal fun NoteEntity.toDomain(): Note = Note(
color = NoteColor.fromStorageKey(colorKey),
isTrashed = isTrashed,
type = NoteType.fromStorageKey(typeKey),
isDraft = isDraft,
)
internal fun Note.toEntity(): NoteEntity = NoteEntity(
@@ -95,4 +100,5 @@ internal fun Note.toEntity(): NoteEntity = NoteEntity(
colorKey = color.storageKey,
isTrashed = isTrashed,
typeKey = type.storageKey,
isDraft = isDraft,
)
@@ -34,6 +34,7 @@ import org.incido.domain.model.Hashtag
import org.incido.domain.model.HashtagUsage
import org.incido.domain.model.Note
import org.incido.domain.model.NoteAttachment
import org.incido.domain.model.NoteColor
import org.incido.domain.model.NoteType
import org.incido.domain.repository.NoteRepository
@@ -119,6 +120,45 @@ class NoteRepositoryImpl(
awaitClose { sub.cancel() }
}.flowOn(Dispatchers.Default)
override fun observeDrafts(): Flow<List<Note>> = callbackFlow {
trySend(snapshotDrafts())
val sub = noteBox.query()
.equal(NoteEntity_.isDraft, true)
.build()
.subscribe()
.observer { trySend(snapshotDrafts()) }
awaitClose { sub.cancel() }
}.flowOn(Dispatchers.Default)
override fun searchDrafts(query: String): Flow<List<Note>> = callbackFlow {
trySend(snapshotDraftsSearch(query))
val sub = noteBox.query().build().subscribe().observer {
trySend(snapshotDraftsSearch(query))
}
awaitClose { sub.cancel() }
}.flowOn(Dispatchers.Default)
override fun observeByColor(color: NoteColor): Flow<List<Note>> = callbackFlow {
trySend(snapshotByColor(color))
// Kotlin stubs expose only equal(Property, Long) for integer
// columns — widen the Short storage key (ObjectBox integer
// columns are width-agnostic, so the match is exact).
val sub = noteBox.query()
.equal(NoteEntity_.colorKey, color.storageKey.toLong())
.build()
.subscribe()
.observer { trySend(snapshotByColor(color)) }
awaitClose { sub.cancel() }
}.flowOn(Dispatchers.Default)
override fun searchByColor(query: String, color: NoteColor): Flow<List<Note>> = callbackFlow {
trySend(snapshotByColorSearch(query, color))
val sub = noteBox.query().build().subscribe().observer {
trySend(snapshotByColorSearch(query, color))
}
awaitClose { sub.cancel() }
}.flowOn(Dispatchers.Default)
override fun observeNotesForHashtag(name: String): Flow<List<Note>> = callbackFlow {
trySend(snapshotForHashtag(name))
val sub = noteBox.query().build().subscribe().observer { trySend(snapshotForHashtag(name)) }
@@ -318,6 +358,7 @@ class NoteRepositoryImpl(
private fun contentMatchingNoteIds(
query: String,
includeTrashed: Boolean = false,
includeDrafts: Boolean = false,
): List<Long> {
val q = query.trim()
if (q.isEmpty()) return emptyList()
@@ -332,13 +373,15 @@ class NoteRepositoryImpl(
noteBox.all.filter { toReadable(it).content.lowercase().contains(needle) }
}
return candidates
.filter { it.isTrashed == includeTrashed }
.filter {
it.isTrashed == includeTrashed && (includeDrafts || !it.isDraft)
}
.map { it.id }
}
/** IDs of rows eligible for all active-note queries. */
/** IDs of rows eligible for all active-note queries (never trashed, never drafts). */
private fun activeNoteIds(): Set<Long> =
noteBox.all.filter { !it.isTrashed }.mapTo(HashSet()) { it.id }
noteBox.all.filter { !it.isTrashed && !it.isDraft }.mapTo(HashSet()) { it.id }
/** IDs of tags currently used by at least one active note. */
private fun activeTagIds(): Set<Long> {
@@ -374,7 +417,7 @@ class NoteRepositoryImpl(
.build()
.find()
.mapNotNull { ref -> noteBox.get(ref.noteId) }
.filter { it.isTrashed == includeTrashed }
.filter { it.isTrashed == includeTrashed && !it.isDraft }
.map { it.id }
}
@@ -453,11 +496,47 @@ class NoteRepositoryImpl(
}
}
/**
* "Empty Trash": permanently delete every trashed row with the
* exact same cascade as [delete] — note row, hashtag cross-links,
* and attachment rows (their blobs live inside the attachment
* entities, so removing the row frees them too).
*/
override suspend fun deleteAllTrashed() {
val trashedIds: LongArray = noteBox.query()
.equal(NoteEntity_.isTrashed, true)
.build()
.find()
.map { it.id }
.toLongArray()
if (trashedIds.isEmpty()) return
noteBox.remove(*trashedIds)
trashedIds.forEach { id ->
val orphanXrefs: List<NoteHashtagCrossRef> = xrefBox.query()
.equal(NoteHashtagCrossRef_.noteId, id)
.build()
.find()
if (orphanXrefs.isNotEmpty()) {
xrefBox.remove(*orphanXrefs.map { it.id }.toLongArray())
}
val orphanAttachments: List<NoteAttachmentEntity> = attachmentBox.query()
.equal(NoteAttachmentEntity_.noteId, id)
.build()
.find()
if (orphanAttachments.isNotEmpty()) {
attachmentBox.remove(*orphanAttachments.map { it.id }.toLongArray())
}
}
}
/** Soft-delete only changes state; the row, links, and blobs remain intact. */
override suspend fun softDelete(id: Long) {
val entity = noteBox.get(id) ?: return
if (entity.isTrashed) return
entity.isTrashed = true
// A trashed draft comes back as a normal note on Restore — the
// draft lifecycle ends the moment it moves to Trash.
entity.isDraft = false
// `put` is intentional here: content may be ciphertext already,
// so do not pass it through toWritable and encrypt the ciphertext a
// second time. Only the additive flag is changing.
@@ -603,11 +682,15 @@ class NoteRepositoryImpl(
private fun decorate(
entities: List<NoteEntity>,
includeTrashed: Boolean? = false,
includeDrafts: Boolean = false,
): List<Note> {
val tags = hashtagsByNoteId()
val attachments = attachmentsByNoteId()
return entities
.filter { includeTrashed == null || it.isTrashed == includeTrashed }
.filter {
(includeTrashed == null || it.isTrashed == includeTrashed) &&
(includeDrafts || !it.isDraft)
}
.sortedWith(
compareByDescending<NoteEntity> { it.isFavorite }
.thenByDescending { it.updatedAt },
@@ -636,7 +719,8 @@ class NoteRepositoryImpl(
private fun snapshotAll(): List<Note> = decorate(noteBox.all)
private fun snapshotAllIncludingTrashed(): List<Note> = decorate(noteBox.all, includeTrashed = null)
private fun snapshotAllIncludingTrashed(): List<Note> =
decorate(noteBox.all, includeTrashed = null, includeDrafts = true)
private fun snapshotSearch(query: String): List<Note> {
val allIds = matchingNoteIds(query, includeTrashed = false)
@@ -661,6 +745,66 @@ class NoteRepositoryImpl(
return decorate(trashedEntities, includeTrashed = true)
}
private fun snapshotDrafts(): List<Note> {
val draftEntities: List<NoteEntity> = noteBox.query()
.equal(NoteEntity_.isDraft, true)
.build()
.find()
return decorate(draftEntities, includeTrashed = null, includeDrafts = true)
}
/**
* Content search restricted to drafts (tag-name matches are not
* folded in, mirroring the plain-text scope of the Drafts view).
*/
private fun snapshotDraftsSearch(query: String): List<Note> {
val q = query.trim()
if (q.isEmpty()) return snapshotDrafts()
val draftIds: Set<Long> = noteBox.query()
.equal(NoteEntity_.isDraft, true)
.build()
.find()
.mapTo(HashSet()) { it.id }
val matches: List<Long> = contentMatchingNoteIds(
q,
includeTrashed = false,
includeDrafts = true,
).filter { it in draftIds }
val entities: List<NoteEntity> = matches.mapNotNull { noteBox.get(it) }
return decorate(entities, includeTrashed = null, includeDrafts = true)
}
/**
* Active notes of one accent colour. The colour query already
* excludes nothing on trash state, so `decorate` (default
* `includeTrashed = false`) drops trashed rows exactly like
* [snapshotFavorites] / [snapshotUntagged] do.
*/
private fun snapshotByColor(color: NoteColor): List<Note> {
val colorEntities: List<NoteEntity> = noteBox.query()
.equal(NoteEntity_.colorKey, color.storageKey.toLong())
.build()
.find()
return decorate(colorEntities)
}
/**
* Context-aware search across notes of [color] only. Blank [query]
* degrades to [snapshotByColor]. Otherwise runs the same content +
* hashtag-name matching as [snapshotFavoritesSearch] and intersects
* with the colour (never trashed rows — matchingNoteIds already
* excludes them via includeTrashed = false).
*/
private fun snapshotByColorSearch(query: String, color: NoteColor): List<Note> {
val q = query.trim()
if (q.isEmpty()) return snapshotByColor(color)
val allIds: Set<Long> = matchingNoteIds(q, includeTrashed = false)
if (allIds.isEmpty()) return emptyList()
val entities: List<NoteEntity> = allIds.mapNotNull { id -> noteBox.get(id) }
.filter { it.colorKey == color.storageKey }
return decorate(entities)
}
private fun snapshotUntagged(): List<Note> {
val activeIds = activeNoteIds()
val noteIdsWithTags: Set<Long> = xrefBox.all
@@ -24,6 +24,14 @@ data class Note(
val attachments: List<NoteAttachment> = emptyList(),
/** True only for notes moved to the Trash view; active-note queries exclude these rows. */
val isTrashed: Boolean = false,
/**
* True while a new note is being drafted. Drafts auto-save every
* edit and are visible only in the Drafts view — Home / Favorites /
* Untagged / tag / colour views / ordinary search / Trash all
* exclude them. Saving from the editor (or moving to Trash) clears
* the flag.
*/
val isDraft: Boolean = false,
/** v0.3.8.0 — which editor surface opens this note (see [NoteType]). */
val type: NoteType = NoteType.TEXT,
) {
@@ -31,7 +39,8 @@ data class Note(
val firstImageAttachment: NoteAttachment?
get() = attachments.firstOrNull { it.isImage }
companion object {
private const val UNTITLED = "Untitled"
/** Shown when a note's content has no usable first line. */
const val UNTITLED = "Untitled"
/**
* Splits [content] into a (title, body) pair. The title is the first
@@ -5,13 +5,13 @@ package org.incido.domain.model
* Stored as a short (`SHORT`) in ObjectBox — additive-safe migration from
* the v0.1 schema.
*/
enum class NoteColor(val storageKey: Short) {
NONE(0),
BLUE(1),
GREEN(2),
AMBER(3),
RED(4),
PURPLE(5);
enum class NoteColor(val storageKey: Short, val label: String) {
NONE(0, "None"),
BLUE(1, "Blue"),
GREEN(2, "Green"),
AMBER(3, "Amber"),
RED(4, "Red"),
PURPLE(5, "Purple");
companion object {
/** Convert from the stored [Short] back to the enum, defaulting to [NONE]. */
@@ -9,21 +9,29 @@ package org.incido.domain.model
* - [Favorites] — only notes with `isFavorite = true`; ordinary search is enabled.
* - [Untagged] — only notes that have zero hashtags; ordinary search is enabled.
* - [ByTag] — only notes tagged with [hashtag]; text search is not offered.
* - [ByColor] — active notes with accent colour [color]; ordinary search is
* enabled and narrows within the colour (like Favorites).
* - [Drafts] — auto-saved new notes; visible nowhere else until saved
* or trashed. Ordinary search is enabled.
* - [Trash] — only notes moved out of the active list; no edit actions.
*/
sealed class NoteFilter {
object Home : NoteFilter()
object Favorites : NoteFilter()
object Untagged : NoteFilter()
object Drafts : NoteFilter()
object Trash : NoteFilter()
data class ByTag(val hashtag: String) : NoteFilter()
data class ByColor(val color: NoteColor) : NoteFilter()
/** Stable identifier used by the drawer for `selected` matching. */
fun key(): String = when (this) {
Home -> "home"
Favorites -> "favorites"
Untagged -> "untagged"
Drafts -> "drafts"
Trash -> "trash"
is ByTag -> "tag:$hashtag"
is ByColor -> "color:${color.name}"
}
}
@@ -13,15 +13,15 @@ package org.incido.domain.model
* Stored as a `Short` in ObjectBox — additive-safe migration from
* the pre-v0.3.8.0 schema (rows without the column default to [TEXT]).
*/
enum class NoteType(val storageKey: Short) {
enum class NoteType(val storageKey: Short, val displayName: String) {
/** Free-form body edited in the plain multi-line field. */
TEXT(0),
TEXT(0, "Text Note"),
/** Editable checklist: checkbox + item text rows. */
TASK_LIST(1),
TASK_LIST(1, "Task List"),
/** Checklist plus a per-item cost (number pad) and a running total. */
SHOPPING_LIST(2);
SHOPPING_LIST(2, "Shopping List");
companion object {
/** Convert from the stored [Short] back to the enum, defaulting to [TEXT]. */
@@ -3,6 +3,7 @@ package org.incido.domain.repository
import kotlinx.coroutines.flow.Flow
import org.incido.domain.model.HashtagUsage
import org.incido.domain.model.Note
import org.incido.domain.model.NoteColor
import org.incido.domain.model.NoteAttachment
/**
@@ -37,6 +38,13 @@ interface NoteRepository {
/** Permanently delete a note by id. No-op if it doesn't exist. */
suspend fun delete(id: Long)
/**
* "Empty Trash": permanently delete EVERY trashed note in one go,
* with the same cascade as [delete] (row + hashtag links +
* attachment blobs). No-op when the Trash is already empty.
*/
suspend fun deleteAllTrashed()
/** Move a note to Trash without removing its row, tags, or attachments. */
suspend fun softDelete(id: Long)
@@ -56,6 +64,35 @@ interface NoteRepository {
/** Only notes in Trash, sorted by updatedAt DESC. */
fun observeTrashed(): Flow<List<Note>>
/**
* Only auto-saved draft notes (new notes the user hasn't saved yet),
* sorted favourites-first then newest-first. Drafts appear in no
* other view — see [Note.isDraft].
*/
fun observeDrafts(): Flow<List<Note>>
/**
* Context-aware content search across drafts only; blank [query]
* returns the same as [observeDrafts].
*/
fun searchDrafts(query: String): Flow<List<Note>>
/**
* Only **active** notes (never trashed) whose accent colour is
* [color], sorted favourites-first then newest-first. Tagged and
* untagged notes are both eligible — only the colour matters.
*/
fun observeByColor(color: NoteColor): Flow<List<Note>>
/**
* Context-aware search across notes of [color] only — matches
* [Note.content] (contains, case-insensitive) AND any of the
* note's hashtags (case-insensitive equality), intersected with
* the colour and the active (non-trashed) set. Blank [query]
* returns the same as [observeByColor].
*/
fun searchByColor(query: String, color: NoteColor): Flow<List<Note>>
/**
* Context-aware search across **favourites only** — matches
* [Note.content] (contains, case-insensitive) AND any of the note's