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() }
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// core/domain — pure-Kotlin domain module (no Android dependencies).
|
||||
// Contains business types and repository interfaces only.
|
||||
// Implementation lives in :core:data.
|
||||
plugins {
|
||||
alias(libs.plugins.kotlinJvm)
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlin {
|
||||
jvmToolchain(17)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.kotlinx.coroutines.core)
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package org.incido.domain.model
|
||||
|
||||
/**
|
||||
* Domain representation of a note. This is the only [Note] type the UI layer
|
||||
* should depend on. The ObjectBox-backed implementation in `:core:data` maps
|
||||
* to/from its own entity type.
|
||||
*/
|
||||
data class Note(
|
||||
val id: Long = 0L,
|
||||
val content: String,
|
||||
val createdAt: Long,
|
||||
val updatedAt: Long,
|
||||
) {
|
||||
companion object {
|
||||
private const val UNTITLED = "Untitled"
|
||||
|
||||
/**
|
||||
* Splits [content] into a (title, body) pair. The title is the first
|
||||
* non-empty line (trimmed); the body is everything after the first
|
||||
* newline, with leading blank lines stripped.
|
||||
*
|
||||
* If the content is empty or has no non-empty line, the title is
|
||||
* `"Untitled"` and the body is empty.
|
||||
*/
|
||||
fun titleAndBody(content: String): Pair<String, String> {
|
||||
val lines = content.split('\n')
|
||||
val title = lines.firstOrNull { it.isNotBlank() }?.trim() ?: UNTITLED
|
||||
val firstTitleIdx = lines.indexOfFirst { it.isNotBlank() }
|
||||
val bodyLines = if (firstTitleIdx >= 0) lines.drop(firstTitleIdx + 1) else emptyList()
|
||||
// Strip leading blank lines from the body.
|
||||
val bodyStart = bodyLines.indexOfFirst { it.isNotBlank() }
|
||||
val body = if (bodyStart >= 0) {
|
||||
bodyLines.drop(bodyStart).joinToString("\n").trimEnd()
|
||||
} else {
|
||||
""
|
||||
}
|
||||
return title to body
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a single-line preview of [content] for places that don't
|
||||
* care about title vs. body (e.g. share previews, toasts).
|
||||
*
|
||||
* For the list-card title+body split, prefer [titleAndBody].
|
||||
*/
|
||||
fun preview(content: String, maxChars: Int = 240): String {
|
||||
val collapsed = content.replace('\n', ' ').trim()
|
||||
if (collapsed.length <= maxChars) return collapsed
|
||||
return collapsed.take(maxChars).trimEnd() + "…"
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a multi-line preview of [body] for list-card body display.
|
||||
* Whitespace runs are collapsed to single spaces, then truncated to
|
||||
* [maxChars]. An ellipsis is appended when truncated.
|
||||
*/
|
||||
fun bodyPreview(body: String, maxChars: Int = 160): String {
|
||||
if (body.isBlank()) return ""
|
||||
val collapsed = body.replace(Regex("\\s+"), " ").trim()
|
||||
if (collapsed.length <= maxChars) return collapsed
|
||||
return collapsed.take(maxChars).trimEnd() + "…"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package org.incido.domain.repository
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import org.incido.domain.model.Note
|
||||
|
||||
/**
|
||||
* Persistence boundary for [Note]s. The UI layer depends on this interface
|
||||
* only — never on the ObjectBox-backed implementation in `:core:data`.
|
||||
*
|
||||
* Implementations are expected to:
|
||||
* - Return a [Flow] that emits whenever the underlying data changes,
|
||||
* 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.
|
||||
*/
|
||||
interface NoteRepository {
|
||||
/** Stream of all notes, newest-first. */
|
||||
fun observeAll(): Flow<List<Note>>
|
||||
|
||||
/** Stream of a single note by id, or `null` if it has been deleted. */
|
||||
fun observeById(id: Long): Flow<Note?>
|
||||
|
||||
/** Persist a new note or update an existing one. Returns the persisted [Note]. */
|
||||
suspend fun upsert(note: Note): Note
|
||||
|
||||
/** Delete a note by id. No-op if it doesn't exist. */
|
||||
suspend fun delete(id: Long)
|
||||
}
|
||||
Reference in new issue
Block a user