feat: v0.2 - polish, favourites, search, colours, checklists, signing
v0.2 bundles all four phases from the planning session into a single
shippable release. versionCode 2 -> 3, versionName 0.1.1 -> 0.2.
DOMAIN
- Add NoteColor enum (NONE / BLUE / GREEN / AMBER / RED / PURPLE).
- Note: isFavorite + color fields; checklistCounts / checklistSummary
helpers parsing '- [ ]' / '- [x]' lines.
- NoteRepository: new search(query) + setFavorite(id, value) methods.
DATA
- NoteEntity: additive @Index isFavorite + colorKey (Short).
- NoteRepositoryImpl: search uses ObjectBox 'contains' case-insensitive;
observeAll + search sort favourites-first then updatedAt DESC.
UI
- NoteListViewModel: debounced(150ms) query -> repository.search;
openSearch / closeSearch helpers; toggleFavorite.
- NoteListScreen: search bar in top app bar; star icon + 4dp colour
stripe per card; checklist summary line ('N open - M done').
- NoteEditorViewModel: toggleFavorite + setColor; initial-snapshot
fields captured on first non-null observeById for dirty detection.
- NoteEditorScreen: BackHandler + AlertDialog 'Discard changes?' on
unsaved edits; star toggle in top bar; LazyRow of colour swatches.
POLISH
- Discard-confirm dialog implements Development Plan §5.2.
- Real release signing config (signingConfigs.release pointing at the
dev keystore in keystore/); keystore/release.jks gitignored;
keystore/README.md documents generation & rotation.
- KMP migration deferred to v0.5 (tracked in plan §10).
COMMUNITY / GITEA
- .gitea/workflows/build.yml: assembleDebug on push & PR, APK as
artefact.
- CONTRIBUTING.md, CODE_OF_CONDUCT.md (Contributor Covenant v2.1),
.gitea/ISSUE_TEMPLATE/{bug_report,feature_request}.yml,
.gitea/PULL_REQUEST_TEMPLATE.md.
- README: v0.2 changelog + Gitea remote-setup instructions.
VERIFIED
- ./gradlew assembleDebug assembleRelease both green.
- Debug APK 25.6 MB, release 19.8 MB, both v0.2 / versionCode 3.
- apksigner verify: 'Verifies' / v2 scheme true.
- No INTERNET permission in either APK (privacy posture unchanged).
This commit is contained in:
1 parent
2215c3447b
commit
5e1b77bedf
21 files changed
+1242
-118
No files matched your search
@@ -4,10 +4,14 @@ import io.objectbox.annotation.Entity
|
||||
import io.objectbox.annotation.Id
|
||||
import io.objectbox.annotation.Index
|
||||
import org.incido.domain.model.Note
|
||||
import org.incido.domain.model.NoteColor
|
||||
|
||||
/**
|
||||
* ObjectBox entity. The plugin generates a corresponding property mirror
|
||||
* class (`NoteEntity_`) at build time, plus the [MyObjectBox] container.
|
||||
*
|
||||
* v0.2 adds [isFavorite] and [color]. Both are additive (the prior v0.1
|
||||
* schema had neither) so existing user notes auto-migrate on first launch.
|
||||
*/
|
||||
@Entity
|
||||
data class NoteEntity(
|
||||
@@ -15,6 +19,8 @@ data class NoteEntity(
|
||||
var content: String = "",
|
||||
@Index var createdAt: Long = 0,
|
||||
var updatedAt: Long = 0,
|
||||
@Index var isFavorite: Boolean = false,
|
||||
var colorKey: Short = 0,
|
||||
)
|
||||
|
||||
internal fun NoteEntity.toDomain(): Note = Note(
|
||||
@@ -22,6 +28,8 @@ internal fun NoteEntity.toDomain(): Note = Note(
|
||||
content = content,
|
||||
createdAt = createdAt,
|
||||
updatedAt = updatedAt,
|
||||
isFavorite = isFavorite,
|
||||
color = NoteColor.fromStorageKey(colorKey),
|
||||
)
|
||||
|
||||
internal fun Note.toEntity(): NoteEntity = NoteEntity(
|
||||
@@ -29,4 +37,6 @@ internal fun Note.toEntity(): NoteEntity = NoteEntity(
|
||||
content = content,
|
||||
createdAt = createdAt,
|
||||
updatedAt = updatedAt,
|
||||
isFavorite = isFavorite,
|
||||
colorKey = color.storageKey,
|
||||
)
|
||||
@@ -9,6 +9,7 @@ import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import org.incido.data.entity.NoteEntity
|
||||
import org.incido.data.entity.NoteEntity_
|
||||
import org.incido.data.entity.toDomain
|
||||
import org.incido.data.entity.toEntity
|
||||
import org.incido.domain.model.Note
|
||||
@@ -18,6 +19,9 @@ import org.incido.domain.repository.NoteRepository
|
||||
* ObjectBox-backed implementation of [NoteRepository]. All writes are
|
||||
* dispatched to `Default`; reads use ObjectBox's reactive subscription so
|
||||
* the UI auto-refreshes whenever a row changes (F7).
|
||||
*
|
||||
* Sort order is `isFavorite DESC, updatedAt DESC` for both [observeAll] and
|
||||
* [search] so favourites always float to the top.
|
||||
*/
|
||||
class NoteRepositoryImpl(
|
||||
private val boxStore: BoxStore,
|
||||
@@ -26,15 +30,28 @@ class NoteRepositoryImpl(
|
||||
private val box = boxStore.boxFor<NoteEntity>()
|
||||
|
||||
override fun observeAll(): Flow<List<Note>> = callbackFlow {
|
||||
// Emit the current snapshot first so the UI renders without waiting
|
||||
// for the first change.
|
||||
trySend(currentSnapshot())
|
||||
trySend(sortedSnapshot(""))
|
||||
|
||||
val subscription: DataSubscription = box
|
||||
val subscription = box
|
||||
.query()
|
||||
.build()
|
||||
.subscribe()
|
||||
.observer { trySend(currentSnapshot()) }
|
||||
.observer { trySend(sortedSnapshot("")) }
|
||||
|
||||
awaitClose { subscription.cancel() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
override fun search(query: String): Flow<List<Note>> = callbackFlow {
|
||||
trySend(sortedSnapshot(query))
|
||||
|
||||
val subscription = if (query.isBlank()) {
|
||||
box.query().build().subscribe()
|
||||
} else {
|
||||
box.query()
|
||||
.contains(NoteEntity_.content, query, io.objectbox.query.QueryBuilder.StringOrder.CASE_INSENSITIVE)
|
||||
.build()
|
||||
.subscribe()
|
||||
}.observer { trySend(sortedSnapshot(query)) }
|
||||
|
||||
awaitClose { subscription.cancel() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
@@ -67,6 +84,30 @@ class NoteRepositoryImpl(
|
||||
box.remove(id)
|
||||
}
|
||||
|
||||
private fun currentSnapshot(): List<Note> =
|
||||
box.all.sortedByDescending { it.updatedAt }.map { it.toDomain() }
|
||||
override suspend fun setFavorite(id: Long, isFavorite: Boolean) {
|
||||
val entity = box.get(id) ?: return
|
||||
if (entity.isFavorite == isFavorite) return
|
||||
entity.isFavorite = isFavorite
|
||||
box.put(entity)
|
||||
}
|
||||
|
||||
/**
|
||||
* Snapshot helper. If [query] is non-blank, only notes whose content
|
||||
* contains it (case-insensitive) are included; otherwise all notes.
|
||||
* The result is sorted favourites-first, then newest-first.
|
||||
*/
|
||||
private fun sortedSnapshot(query: String): List<Note> {
|
||||
val raw = if (query.isBlank()) {
|
||||
box.all
|
||||
} else {
|
||||
box.query()
|
||||
.contains(NoteEntity_.content, query, io.objectbox.query.QueryBuilder.StringOrder.CASE_INSENSITIVE)
|
||||
.build()
|
||||
.find()
|
||||
}
|
||||
return raw.sortedWith(
|
||||
compareByDescending<NoteEntity> { it.isFavorite }
|
||||
.thenByDescending { it.updatedAt }
|
||||
).map { it.toDomain() }
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ data class Note(
|
||||
val content: String,
|
||||
val createdAt: Long,
|
||||
val updatedAt: Long,
|
||||
val isFavorite: Boolean = false,
|
||||
val color: NoteColor = NoteColor.NONE,
|
||||
) {
|
||||
companion object {
|
||||
private const val UNTITLED = "Untitled"
|
||||
@@ -60,5 +62,35 @@ data class Note(
|
||||
if (collapsed.length <= maxChars) return collapsed
|
||||
return collapsed.take(maxChars).trimEnd() + "…"
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses GitHub-flavoured task-list lines from [content] and
|
||||
* returns (openCount, doneCount). Lines starting with `- [ ]` count
|
||||
* as open; `- [x]` (case-insensitive) count as done.
|
||||
*/
|
||||
fun checklistCounts(content: String): Pair<Int, Int> {
|
||||
val pattern = Regex("""^\s*-\s+\[( x| )]""", RegexOption.IGNORE_CASE)
|
||||
var open = 0
|
||||
var done = 0
|
||||
content.lineSequence().forEach { line ->
|
||||
val match = pattern.find(line) ?: return@forEach
|
||||
val isDone = match.groupValues[1].equals("x", ignoreCase = true)
|
||||
if (isDone) done++ else open++
|
||||
}
|
||||
return open to done
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience: "1 open" / "2 open · 3 done" / empty when no items.
|
||||
*/
|
||||
fun checklistSummary(content: String): String {
|
||||
val (open, done) = checklistCounts(content)
|
||||
return when {
|
||||
open == 0 && done == 0 -> ""
|
||||
done == 0 -> "$open open"
|
||||
open == 0 -> "$done done"
|
||||
else -> "$open open · $done done"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.incido.domain.model
|
||||
|
||||
/**
|
||||
* Six preset accent colours for notes, plus a sentinel "no colour" value.
|
||||
* 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);
|
||||
|
||||
companion object {
|
||||
/** Convert from the stored [Short] back to the enum, defaulting to [NONE]. */
|
||||
fun fromStorageKey(key: Short): NoteColor =
|
||||
values().firstOrNull { it.storageKey == key } ?: NONE
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,20 @@ import org.incido.domain.model.Note
|
||||
* so the list screen satisfies F7 (auto-refresh).
|
||||
* - Assign a fresh id (0 or 0L on construction) for new notes and use the
|
||||
* ObjectBox-managed id once persisted.
|
||||
* - Sort [observeAll] / [search] with favourites first, then by [Note.updatedAt]
|
||||
* descending.
|
||||
*/
|
||||
interface NoteRepository {
|
||||
/** Stream of all notes, newest-first. */
|
||||
/** Stream of all notes, newest-first, favourites pinned to the top. */
|
||||
fun observeAll(): Flow<List<Note>>
|
||||
|
||||
/**
|
||||
* Stream of notes whose [Note.content] contains [query] (case-insensitive),
|
||||
* favourites first then newest-first. An empty / blank [query] returns
|
||||
* the same list as [observeAll].
|
||||
*/
|
||||
fun search(query: String): Flow<List<Note>>
|
||||
|
||||
/** Stream of a single note by id, or `null` if it has been deleted. */
|
||||
fun observeById(id: Long): Flow<Note?>
|
||||
|
||||
@@ -25,4 +34,7 @@ interface NoteRepository {
|
||||
|
||||
/** Delete a note by id. No-op if it doesn't exist. */
|
||||
suspend fun delete(id: Long)
|
||||
|
||||
/** Toggle the favourite flag on a single note. */
|
||||
suspend fun setFavorite(id: Long, isFavorite: Boolean)
|
||||
}
|
||||
Reference in new issue
Block a user