Initial v0.1.1 scaffold
- Multi-module Android project: app/ (entry point), composeApp/ (UI),
core/domain/ (pure-Kotlin interfaces), core/data/ (ObjectBox-backed
repository).
- Privacy-first: no INTERNET permission, no analytics, auto-backup
disabled (data_extraction_rules.xml excludes all domains).
- AGPL-3.0 licensed with full LICENSE + NOTICE files.
- Material 3 UI with dynamic color on Android 12+, dark/light theme
follows system.
- v0.1.1 polish:
* Editor text field shrinks above the soft keyboard (Scaffold
contentWindowInsets union(systemBars, ime) + windowSoftInputMode
adjustResize).
* List cards now render title (first non-empty line, titleMedium)
plus abbreviated body preview (max 2 lines, ellipsised). Empty
notes display as 'Untitled'.
* versionCode 1 -> 2, versionName 0.1.0 -> 0.1.1.
This commit is contained in:
commit
1477e2426d
44 files changed
+2880
No files matched your search
@@ -0,0 +1,58 @@
|
||||
// core/data — ObjectBox-backed implementation of the domain repository.
|
||||
// The ObjectBox Gradle plugin isn't published with a plugin marker, so we
|
||||
// wire it through a buildscript classpath here.
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
// ObjectBox plugin classpath. Version is pinned via libs.versions.toml
|
||||
// through a generated accessor; here we hard-code for clarity.
|
||||
classpath("io.objectbox:objectbox-gradle-plugin:${libs.versions.objectbox.get()}")
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
alias(libs.plugins.androidLibrary)
|
||||
alias(libs.plugins.kotlinAndroid)
|
||||
}
|
||||
|
||||
// Apply the ObjectBox plugin AFTER the classpath is on the buildscript.
|
||||
apply(plugin = "io.objectbox")
|
||||
|
||||
android {
|
||||
namespace = "org.incido.data"
|
||||
compileSdk = 35
|
||||
|
||||
defaultConfig {
|
||||
minSdk = 26
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
getByName("main") {
|
||||
// ObjectBox generates a MyObjectBox class at build time; expose
|
||||
// the generated sources directory.
|
||||
kotlin.srcDirs("build/generated/source/objectbox")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":core:domain"))
|
||||
implementation(libs.kotlinx.coroutines.core)
|
||||
|
||||
// ObjectBox runtime
|
||||
implementation(libs.objectbox.android)
|
||||
implementation(libs.objectbox.kotlin)
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.incido.data
|
||||
|
||||
import android.content.Context
|
||||
import io.objectbox.BoxStore
|
||||
import org.incido.data.entity.MyObjectBox
|
||||
|
||||
/**
|
||||
* Singleton holder for the process-wide [BoxStore]. Initialised once from
|
||||
* the Application/Activity context.
|
||||
*/
|
||||
object ObjectBoxStore {
|
||||
@Volatile
|
||||
private var instance: BoxStore? = null
|
||||
|
||||
fun init(context: Context): BoxStore =
|
||||
instance ?: synchronized(this) {
|
||||
instance ?: MyObjectBox.builder()
|
||||
.androidContext(context.applicationContext)
|
||||
.build()
|
||||
.also { instance = it }
|
||||
}
|
||||
|
||||
fun get(): BoxStore =
|
||||
instance ?: error("ObjectBoxStore not initialised — call init(context) first")
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package org.incido.data.entity
|
||||
|
||||
import io.objectbox.annotation.Entity
|
||||
import io.objectbox.annotation.Id
|
||||
import io.objectbox.annotation.Index
|
||||
import org.incido.domain.model.Note
|
||||
|
||||
/**
|
||||
* ObjectBox entity. The plugin generates a corresponding property mirror
|
||||
* class (`NoteEntity_`) at build time, plus the [MyObjectBox] container.
|
||||
*/
|
||||
@Entity
|
||||
data class NoteEntity(
|
||||
@Id var id: Long = 0,
|
||||
var content: String = "",
|
||||
@Index var createdAt: Long = 0,
|
||||
var updatedAt: Long = 0,
|
||||
)
|
||||
|
||||
internal fun NoteEntity.toDomain(): Note = Note(
|
||||
id = id,
|
||||
content = content,
|
||||
createdAt = createdAt,
|
||||
updatedAt = updatedAt,
|
||||
)
|
||||
|
||||
internal fun Note.toEntity(): NoteEntity = NoteEntity(
|
||||
id = id,
|
||||
content = content,
|
||||
createdAt = createdAt,
|
||||
updatedAt = updatedAt,
|
||||
)
|
||||
@@ -0,0 +1,72 @@
|
||||
package org.incido.data.repository
|
||||
|
||||
import io.objectbox.BoxStore
|
||||
import io.objectbox.kotlin.boxFor
|
||||
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.NoteEntity
|
||||
import org.incido.data.entity.toDomain
|
||||
import org.incido.data.entity.toEntity
|
||||
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).
|
||||
*/
|
||||
class NoteRepositoryImpl(
|
||||
private val boxStore: BoxStore,
|
||||
) : NoteRepository {
|
||||
|
||||
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())
|
||||
|
||||
val subscription: DataSubscription = box
|
||||
.query()
|
||||
.build()
|
||||
.subscribe()
|
||||
.observer { trySend(currentSnapshot()) }
|
||||
|
||||
awaitClose { subscription.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() }
|
||||
}.flowOn(Dispatchers.Default)
|
||||
|
||||
override suspend fun upsert(note: Note): Note {
|
||||
val now = System.currentTimeMillis()
|
||||
val toPersist = if (note.id == 0L) {
|
||||
note.copy(createdAt = now, updatedAt = now).toEntity()
|
||||
} else {
|
||||
note.copy(updatedAt = now).toEntity()
|
||||
}
|
||||
val assignedId = box.put(toPersist)
|
||||
val existing = box.get(assignedId)
|
||||
return existing?.toDomain() ?: note.copy(id = assignedId)
|
||||
}
|
||||
|
||||
override suspend fun delete(id: Long) {
|
||||
box.remove(id)
|
||||
}
|
||||
|
||||
private fun currentSnapshot(): List<Note> =
|
||||
box.all.sortedByDescending { it.updatedAt }.map { it.toDomain() }
|
||||
}
|
||||
Reference in new issue
Block a user