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
@@ -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
|
||||
|
||||
Reference in new issue
Block a user