feat: v0.3.0.0 — hashtags (visible on editor) + bolder colour accent + centred title + nav drawer + new version scheme
v0.3.0.0 bundles four user-facing features, the plan-compliance polish
that was deferred from v0.2, and a permanent change to how we name
releases going forward.
VERSION SCHEME (app/build.gradle.kts)
- versionName = '0.3.0.0' (MAJOR.MINOR.MAINTENANCE.EMERGENCY)
- versionCode = 5
- New gradle taskGraph validator fails the build if versionName
doesn't match ^\d+\.\d+\.\d+\.\d+$ — we can't accidentally
regress the scheme.
- History re-keyed across README, Plan §10, CONTRIBUTING.md.
HASHTAGS
- value class Hashtag (domain/model) with normalise/parseOrNull
helpers; pattern: ^[a-z0-9][a-z0-9._-]{0,30}$
- data class HashtagUsage (name, noteCount, lastUsedAt)
- sealed class NoteFilter { Home, Favorites, Untagged, ByTag(name) }
- Note gains hashtags: List<String> (sorted ascending)
- Repository:
- new entities HashtagEntity (@Index on name) and
NoteHashtagCrossRef (many-to-many junction)
- new methods: observeFavorites / observeUntagged /
observeNotesForHashtag / observeHashtagsByRecentUse /
observeAllHashtags / searchHashtags / addHashtag / removeHashtag
- search() now matches content OR hashtag-name (case-insensitive)
- ObjectBox queries use explicit StringOrder + type annotations
(kapt's stubs are finicky around Property<String> overloads)
UI
- CenterAlignedTopAppBar on both list and editor screens
- List:
- Hamburger top-left opens a ModalNavigationDrawer (Home /
Favorites / Untagged / divider / scrollable Recent tags)
- Drawer selection drives a NoteFilter state held at root
- Search bar visible only when filter == Home
- NoteCard redesign — 14 dp vertical gradient stripe +
tinted surface (12 % colour blend) + 10 dp corner chip
- Empty-state copy is filter-aware
- Editor:
- Persistent hashtag chip row above the text field
- Tag # icon in the top bar + '+ add' chip opens a ModalBottomSheet
- Autocomplete suggestions live from repository.searchHashtags
- '+ Create name' button when the typed value is valid + new
- Snackbar 'Maximum 5 tags reached.' when the cap is hit
- Reconciled on save via addHashtag / removeHashtag diff
DOCS
- README v0.3.0.0 section + re-keyed changelog
- Development Plan §10 history re-keyed (0.1.0.0 / 0.1.1.0 /
0.2.0.0 / 0.2.0.1 / 0.3.0.0)
- CONTRIBUTING.md release-process note updated for the new scheme
VERIFIED
- ./gradlew assembleDebug assembleRelease both green
- Debug 25.7 MB, release 19.8 MB (v2-signed)
- versionCode=5, versionName='0.3.0.0'
- No INTERNET permission
- Validator regression: setting versionName='0.3' causes
assembleDebug to fail with the new scheme error message
This commit is contained in:
1 parent
84900838f7
commit
d616ce3021
20 files changed
+1285
-251
No files matched your search
@@ -0,0 +1,19 @@
|
||||
package org.incido.data.entity
|
||||
|
||||
import io.objectbox.annotation.Entity
|
||||
import io.objectbox.annotation.Id
|
||||
import io.objectbox.annotation.Index
|
||||
|
||||
/**
|
||||
* A single normalised hashtag. Case-insensitive uniqueness is
|
||||
* enforced at the repository layer (`NoteRepositoryImpl.addHashtag`
|
||||
* uses `findFirst` and reuses the existing row); the index here just
|
||||
* speeds up the lookup.
|
||||
*
|
||||
* The "many-to-many" link to notes lives in [NoteHashtagCrossRef].
|
||||
*/
|
||||
@Entity
|
||||
data class HashtagEntity(
|
||||
@Id var id: Long = 0,
|
||||
@Index var name: String = "",
|
||||
)
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.incido.data.entity
|
||||
|
||||
import io.objectbox.annotation.Entity
|
||||
import io.objectbox.annotation.Id
|
||||
import io.objectbox.annotation.Index
|
||||
|
||||
/**
|
||||
* Many-to-many junction between [NoteEntity] and [HashtagEntity].
|
||||
* Each row is one (`noteId`, `hashtagId`) pair.
|
||||
*
|
||||
* Both columns are indexed for fast lookups in either direction
|
||||
* (notes for a hashtag, hashtags for a note).
|
||||
*/
|
||||
@Entity
|
||||
data class NoteHashtagCrossRef(
|
||||
@Id var id: Long = 0,
|
||||
@Index var noteId: Long = 0,
|
||||
@Index var hashtagId: Long = 0,
|
||||
)
|
||||
@@ -2,72 +2,113 @@ package org.incido.data.repository
|
||||
|
||||
import io.objectbox.BoxStore
|
||||
import io.objectbox.kotlin.boxFor
|
||||
import io.objectbox.query.QueryBuilder
|
||||
import io.objectbox.reactive.DataSubscription
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import org.incido.data.entity.HashtagEntity
|
||||
import org.incido.data.entity.HashtagEntity_
|
||||
import org.incido.data.entity.NoteEntity
|
||||
import org.incido.data.entity.NoteEntity_
|
||||
import org.incido.data.entity.NoteHashtagCrossRef
|
||||
import org.incido.data.entity.NoteHashtagCrossRef_
|
||||
import org.incido.data.entity.toDomain
|
||||
import org.incido.data.entity.toEntity
|
||||
import org.incido.domain.model.Hashtag
|
||||
import org.incido.domain.model.HashtagUsage
|
||||
import org.incido.domain.model.Note
|
||||
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).
|
||||
* ObjectBox-backed implementation of [NoteRepository]. Hashtags live
|
||||
* in two extra tables (`HashtagEntity`, `NoteHashtagCrossRef`); every
|
||||
* "list of notes" snapshot here loads the cross-ref + tags in one
|
||||
* pass so callers get fully-populated [Note.hashtags] lists.
|
||||
*
|
||||
* Sort order is `isFavorite DESC, updatedAt DESC` for both [observeAll] and
|
||||
* [search] so favourites always float to the top.
|
||||
* Sort order for [observeAll] / [search] / filter streams:
|
||||
* `isFavorite DESC, updatedAt DESC`.
|
||||
*
|
||||
* Note: ObjectBox 4.0.3's Kotlin stubs are finicky around
|
||||
* `QueryBuilder.equal(Property, String, ...)` — passing the
|
||||
* `StringOrder` argument explicitly is the most reliable way to call it.
|
||||
*/
|
||||
class NoteRepositoryImpl(
|
||||
private val boxStore: BoxStore,
|
||||
) : NoteRepository {
|
||||
|
||||
private val box = boxStore.boxFor<NoteEntity>()
|
||||
private val noteBox = boxStore.boxFor<NoteEntity>()
|
||||
private val tagBox = boxStore.boxFor<HashtagEntity>()
|
||||
private val xrefBox = boxStore.boxFor<NoteHashtagCrossRef>()
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// List / observation streams
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
override fun observeAll(): Flow<List<Note>> = callbackFlow {
|
||||
trySend(sortedSnapshot(""))
|
||||
|
||||
val subscription = box
|
||||
.query()
|
||||
.build()
|
||||
.subscribe()
|
||||
.observer { trySend(sortedSnapshot("")) }
|
||||
|
||||
awaitClose { subscription.cancel() }
|
||||
trySend(snapshotAll())
|
||||
val sub = noteBox.query().build().subscribe().observer { trySend(snapshotAll()) }
|
||||
awaitClose { sub.cancel() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
override fun search(query: String): Flow<List<Note>> = callbackFlow {
|
||||
trySend(sortedSnapshot(query))
|
||||
trySend(snapshotSearch(query))
|
||||
val sub = noteBox.query().build().subscribe().observer { trySend(snapshotSearch(query)) }
|
||||
awaitClose { sub.cancel() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
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)) }
|
||||
override fun observeFavorites(): Flow<List<Note>> = callbackFlow {
|
||||
trySend(snapshotFavorites())
|
||||
val sub = noteBox.query().build().subscribe().observer { trySend(snapshotFavorites()) }
|
||||
awaitClose { sub.cancel() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
awaitClose { subscription.cancel() }
|
||||
override fun observeUntagged(): Flow<List<Note>> = callbackFlow {
|
||||
trySend(snapshotUntagged())
|
||||
val sub = noteBox.query().build().subscribe().observer { trySend(snapshotUntagged()) }
|
||||
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)) }
|
||||
awaitClose { sub.cancel() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
override fun observeHashtagsByRecentUse(): Flow<List<HashtagUsage>> = callbackFlow {
|
||||
trySend(hashtagUsageSnapshot())
|
||||
val sub = noteBox.query().build().subscribe().observer { trySend(hashtagUsageSnapshot()) }
|
||||
awaitClose { sub.cancel() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
override fun observeAllHashtags(): Flow<List<String>> = callbackFlow {
|
||||
trySend(allHashtagsSnapshot().sorted())
|
||||
val sub = noteBox.query().build().subscribe().observer {
|
||||
trySend(allHashtagsSnapshot().sorted())
|
||||
}
|
||||
awaitClose { sub.cancel() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
override fun searchHashtags(prefix: String): Flow<List<String>> = callbackFlow {
|
||||
trySend(searchHashtagsSnapshot(prefix))
|
||||
val sub = noteBox.query().build().subscribe().observer {
|
||||
trySend(searchHashtagsSnapshot(prefix))
|
||||
}
|
||||
awaitClose { sub.cancel() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
override fun observeById(id: Long): Flow<Note?> = callbackFlow {
|
||||
trySend(box.get(id)?.toDomain())
|
||||
|
||||
val subscription = box
|
||||
.query()
|
||||
.build()
|
||||
.subscribe()
|
||||
.observer { trySend(box.get(id)?.toDomain()) }
|
||||
|
||||
awaitClose { subscription.cancel() }
|
||||
trySend(noteByIdSnapshot(id))
|
||||
val sub = noteBox.query().build().subscribe().observer { trySend(noteByIdSnapshot(id)) }
|
||||
awaitClose { sub.cancel() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Writes
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
override suspend fun upsert(note: Note): Note {
|
||||
val now = System.currentTimeMillis()
|
||||
val toPersist = if (note.id == 0L) {
|
||||
@@ -75,39 +116,213 @@ class NoteRepositoryImpl(
|
||||
} else {
|
||||
note.copy(updatedAt = now).toEntity()
|
||||
}
|
||||
val assignedId = box.put(toPersist)
|
||||
val existing = box.get(assignedId)
|
||||
return existing?.toDomain() ?: note.copy(id = assignedId)
|
||||
val assignedId = noteBox.put(toPersist)
|
||||
return noteBox.get(assignedId)?.toDomain() ?: note.copy(id = assignedId)
|
||||
}
|
||||
|
||||
override suspend fun delete(id: Long) {
|
||||
box.remove(id)
|
||||
noteBox.remove(id)
|
||||
val orphanXrefs: List<NoteHashtagCrossRef> = xrefBox.query()
|
||||
.equal(NoteHashtagCrossRef_.noteId, id)
|
||||
.build()
|
||||
.find()
|
||||
if (orphanXrefs.isNotEmpty()) {
|
||||
xrefBox.remove(*orphanXrefs.map { it.id }.toLongArray())
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun setFavorite(id: Long, isFavorite: Boolean) {
|
||||
val entity = box.get(id) ?: return
|
||||
val entity = noteBox.get(id) ?: return
|
||||
if (entity.isFavorite == isFavorite) return
|
||||
entity.isFavorite = isFavorite
|
||||
box.put(entity)
|
||||
noteBox.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(
|
||||
override suspend fun addHashtag(noteId: Long, name: String) {
|
||||
val normalised = Hashtag.normalise(name)
|
||||
if (!normalised.matches(Regex("^[a-z0-9][a-z0-9._-]{0,30}$"))) return
|
||||
|
||||
val tag: HashtagEntity = tagBox.query()
|
||||
.equal(HashtagEntity_.name, normalised, QueryBuilder.StringOrder.CASE_INSENSITIVE)
|
||||
.build()
|
||||
.findFirst() ?: run {
|
||||
tagBox.put(HashtagEntity(name = normalised))
|
||||
// Re-query to get the freshly-inserted row (with its new id).
|
||||
tagBox.query()
|
||||
.equal(HashtagEntity_.name, normalised, QueryBuilder.StringOrder.CASE_INSENSITIVE)
|
||||
.build()
|
||||
.findFirst()
|
||||
} ?: return
|
||||
|
||||
val existing: NoteHashtagCrossRef? = xrefBox.query()
|
||||
.equal(NoteHashtagCrossRef_.noteId, noteId)
|
||||
.equal(NoteHashtagCrossRef_.hashtagId, tag.id)
|
||||
.build()
|
||||
.findFirst()
|
||||
if (existing != null) return
|
||||
|
||||
xrefBox.put(NoteHashtagCrossRef(noteId = noteId, hashtagId = tag.id))
|
||||
}
|
||||
|
||||
override suspend fun removeHashtag(noteId: Long, name: String) {
|
||||
val normalised = Hashtag.normalise(name)
|
||||
val tag: HashtagEntity = tagBox.query()
|
||||
.equal(HashtagEntity_.name, normalised, QueryBuilder.StringOrder.CASE_INSENSITIVE)
|
||||
.build()
|
||||
.findFirst() ?: return
|
||||
val xref: NoteHashtagCrossRef = xrefBox.query()
|
||||
.equal(NoteHashtagCrossRef_.noteId, noteId)
|
||||
.equal(NoteHashtagCrossRef_.hashtagId, tag.id)
|
||||
.build()
|
||||
.findFirst() ?: return
|
||||
xrefBox.remove(xref.id)
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Snapshots
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/** Map of noteId -> ordered list of hashtag names. */
|
||||
private fun hashtagsByNoteId(): Map<Long, List<String>> {
|
||||
val xrefs: List<NoteHashtagCrossRef> = xrefBox.all
|
||||
if (xrefs.isEmpty()) return emptyMap()
|
||||
val tagIds: Set<Long> = xrefs.map { it.hashtagId }.toSet()
|
||||
val tagById: Map<Long, String> = tagIds.associateWith { id ->
|
||||
tagBox.get(id)?.name ?: ""
|
||||
}.filterValues { it.isNotEmpty() }
|
||||
|
||||
return xrefs.groupBy { it.noteId }
|
||||
.mapValues { (_, refs) ->
|
||||
refs.mapNotNull { tagById[it.hashtagId] }.sorted()
|
||||
}
|
||||
}
|
||||
|
||||
private fun decorate(entities: List<NoteEntity>): List<Note> {
|
||||
val tags = hashtagsByNoteId()
|
||||
return entities.sortedWith(
|
||||
compareByDescending<NoteEntity> { it.isFavorite }
|
||||
.thenByDescending { it.updatedAt }
|
||||
).map { it.toDomain() }
|
||||
).map { e ->
|
||||
val base = e.toDomain()
|
||||
base.copy(hashtags = tags[e.id].orEmpty())
|
||||
}
|
||||
}
|
||||
|
||||
private fun snapshotAll(): List<Note> = decorate(noteBox.all)
|
||||
|
||||
private fun snapshotSearch(query: String): List<Note> {
|
||||
val q = query.trim()
|
||||
if (q.isEmpty()) return snapshotAll()
|
||||
|
||||
// Match against content (contains, case-insensitive).
|
||||
val contentMatches: List<Long> = noteBox.query()
|
||||
.contains(NoteEntity_.content, q, QueryBuilder.StringOrder.CASE_INSENSITIVE)
|
||||
.build()
|
||||
.find()
|
||||
.map { it.id }
|
||||
|
||||
// Match against hashtag names (case-insensitive exact equality).
|
||||
val matchingTag: HashtagEntity? = tagBox.query()
|
||||
.equal(HashtagEntity_.name, q, QueryBuilder.StringOrder.CASE_INSENSITIVE)
|
||||
.build()
|
||||
.findFirst()
|
||||
val tagMatches: List<Long> = if (matchingTag == null) emptyList() else {
|
||||
xrefBox.query()
|
||||
.equal(NoteHashtagCrossRef_.hashtagId, matchingTag.id)
|
||||
.build()
|
||||
.find()
|
||||
.map { it.noteId }
|
||||
}
|
||||
|
||||
val allIds: Set<Long> = (contentMatches + tagMatches).toSet()
|
||||
if (allIds.isEmpty()) return emptyList()
|
||||
val entities: List<NoteEntity> = allIds.mapNotNull { noteBox.get(it) }
|
||||
return decorate(entities)
|
||||
}
|
||||
|
||||
private fun snapshotFavorites(): List<Note> {
|
||||
val favEntities: List<NoteEntity> = noteBox.query()
|
||||
.equal(NoteEntity_.isFavorite, true)
|
||||
.build()
|
||||
.find()
|
||||
return decorate(favEntities)
|
||||
}
|
||||
|
||||
private fun snapshotUntagged(): List<Note> {
|
||||
val noteIdsWithTags: Set<Long> = xrefBox.all.map { it.noteId }.toSet()
|
||||
val untaggedEntities: List<NoteEntity> = noteBox.all.filter { it.id !in noteIdsWithTags }
|
||||
return decorate(untaggedEntities)
|
||||
}
|
||||
|
||||
private fun snapshotForHashtag(name: String): List<Note> {
|
||||
val normalised = Hashtag.normalise(name)
|
||||
val tag: HashtagEntity = tagBox.query()
|
||||
.equal(HashtagEntity_.name, normalised, QueryBuilder.StringOrder.CASE_INSENSITIVE)
|
||||
.build()
|
||||
.findFirst() ?: return emptyList()
|
||||
val xrefs: List<NoteHashtagCrossRef> = xrefBox.query()
|
||||
.equal(NoteHashtagCrossRef_.hashtagId, tag.id)
|
||||
.build()
|
||||
.find()
|
||||
val noteIds: Set<Long> = xrefs.map { it.id }.let { _ -> xrefs.map { it.noteId }.toSet() }
|
||||
if (noteIds.isEmpty()) return emptyList()
|
||||
val entities: List<NoteEntity> = noteIds.mapNotNull { noteBox.get(it) }
|
||||
return decorate(entities)
|
||||
}
|
||||
|
||||
private fun noteByIdSnapshot(id: Long): Note? {
|
||||
val entity = noteBox.get(id) ?: return null
|
||||
val tags = hashtagsByNoteId()[id].orEmpty()
|
||||
return entity.toDomain().copy(hashtags = tags)
|
||||
}
|
||||
|
||||
/** Build [HashtagUsage] for every distinct tag, sorted by lastUsedAt DESC. */
|
||||
private fun hashtagUsageSnapshot(): List<HashtagUsage> {
|
||||
val xrefs: List<NoteHashtagCrossRef> = xrefBox.all
|
||||
if (xrefs.isEmpty()) return emptyList()
|
||||
|
||||
// For each hashtagId, accumulate (lastUsedAt, count).
|
||||
data class Agg(var lastUsedAt: Long, var count: Int)
|
||||
val aggregate = HashMap<Long, Agg>(xrefs.size)
|
||||
for (x in xrefs) {
|
||||
val note: NoteEntity = noteBox.get(x.noteId) ?: continue
|
||||
val cur = aggregate[x.hashtagId]
|
||||
if (cur == null) {
|
||||
aggregate[x.hashtagId] = Agg(note.updatedAt, 1)
|
||||
} else {
|
||||
if (note.updatedAt > cur.lastUsedAt) cur.lastUsedAt = note.updatedAt
|
||||
cur.count += 1
|
||||
}
|
||||
}
|
||||
return aggregate.mapNotNull { (tagId, agg) ->
|
||||
val tag: HashtagEntity = tagBox.get(tagId) ?: return@mapNotNull null
|
||||
HashtagUsage(name = tag.name, noteCount = agg.count, lastUsedAt = agg.lastUsedAt)
|
||||
}.sortedWith(
|
||||
compareByDescending<HashtagUsage> { it.lastUsedAt }
|
||||
.thenByDescending { it.noteCount }
|
||||
.thenBy { it.name }
|
||||
)
|
||||
}
|
||||
|
||||
private fun allHashtagsSnapshot(): List<String> =
|
||||
tagBox.all.map { it.name }
|
||||
|
||||
private fun searchHashtagsSnapshot(prefix: String): List<String> {
|
||||
val p = prefix.trim()
|
||||
if (p.isEmpty()) return allHashtagsSnapshot().sorted()
|
||||
|
||||
val byPrefix: List<HashtagEntity> = tagBox.query()
|
||||
.startsWith(HashtagEntity_.name, p.lowercase(), QueryBuilder.StringOrder.CASE_INSENSITIVE)
|
||||
.build()
|
||||
.find()
|
||||
|
||||
// Sort by usage count (most-used first), then name.
|
||||
val usageById: Map<Long, Int> = xrefBox.all.groupingBy { it.hashtagId }.eachCount()
|
||||
return byPrefix
|
||||
.sortedWith(
|
||||
compareByDescending<HashtagEntity> { usageById[it.id] ?: 0 }
|
||||
.thenBy { it.name }
|
||||
)
|
||||
.map { it.name }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user