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:
Incido Developer committed 2026-08-14 22:51:59 +12:00
commit 1477e2426d
44 files changed
+2880

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
@@ -0,0 +1,49 @@
package org.incido.compose
import androidx.compose.runtime.Composable
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import org.incido.compose.ui.editor.NoteEditorScreen
import org.incido.compose.ui.notelist.NoteListScreen
import org.incido.compose.ui.theme.IncidoTheme
/** Top-level navigation destinations. */
private object Routes {
const val LIST = "list"
const val EDITOR = "editor/{noteId}"
fun editor(noteId: Long?): String =
"editor/${noteId ?: -1L}"
}
@Composable
fun IncidoApp() {
IncidoTheme {
val navController = rememberNavController()
NavHost(navController = navController, startDestination = Routes.LIST) {
composable(Routes.LIST) {
NoteListScreen(
onOpenEditor = { id -> navController.navigate(Routes.editor(id)) },
)
}
composable(
route = Routes.EDITOR,
arguments = listOf(
navArgument("noteId") {
type = NavType.LongType
defaultValue = -1L
},
),
) { entry ->
val raw = entry.arguments?.getLong("noteId") ?: -1L
val id = if (raw <= 0L) null else raw
NoteEditorScreen(
noteId = id,
onClose = { navController.popBackStack() },
)
}
}
}
}
@@ -0,0 +1,21 @@
package org.incido.compose
import android.app.Application
import org.incido.compose.di.AppContainer
/**
* Application class. Constructs the singleton [AppContainer] holding the
* ObjectBox store and the note repository.
*
* ViewModels reach the container via `(application as IncidoApplication).container`
* (see `NoteListViewModel.Factory` and `NoteEditorViewModel.factory`).
*/
class IncidoApplication : Application() {
lateinit var container: AppContainer
private set
override fun onCreate() {
super.onCreate()
container = AppContainer(this)
}
}
@@ -0,0 +1,17 @@
package org.incido.compose.di
import android.content.Context
import io.objectbox.BoxStore
import org.incido.data.ObjectBoxStore
import org.incido.data.repository.NoteRepositoryImpl
import org.incido.domain.repository.NoteRepository
/**
* Hand-rolled DI container. Replaces Hilt/Dagger for v0.1 — keeps the
* build simple. Constructed once from `Application.onCreate()` and
* stored as a singleton (see `IncidoApp` in the `:app` module).
*/
class AppContainer(context: Context) {
val boxStore: BoxStore = ObjectBoxStore.init(context)
val noteRepository: NoteRepository = NoteRepositoryImpl(boxStore)
}
@@ -0,0 +1,129 @@
package org.incido.compose.ui.editor
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.ime
import androidx.compose.foundation.layout.systemBars
import androidx.compose.foundation.layout.union
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.filled.Done
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun NoteEditorScreen(
noteId: Long?,
onClose: () -> Unit,
viewModel: NoteEditorViewModel = viewModel(
factory = NoteEditorViewModel.factory(noteId),
key = "editor-$noteId",
),
) {
val state by viewModel.state.collectAsStateWithLifecycle()
val focusRequester = remember { FocusRequester() }
var menuExpanded by remember { mutableStateOf(false) }
LaunchedEffect(state.isLoading) {
if (!state.isLoading && state.existing != null) {
// Focus the field so the user can immediately edit existing notes.
focusRequester.requestFocus()
}
}
LaunchedEffect(Unit) {
if (noteId == null) focusRequester.requestFocus()
}
Scaffold(
// Union systemBars + IME insets so the Scaffold's contentPadding
// shrinks the available area when the soft keyboard opens. With
// edge-to-edge enabled (MainActivity.enableEdgeToEdge), the IME
// inset is NOT applied by default, which previously caused the
// OutlinedTextField to extend behind the keyboard.
contentWindowInsets = WindowInsets.systemBars.union(WindowInsets.ime),
topBar = {
TopAppBar(
title = { Text(if (state.isEditing) "Edit note" else "New note") },
navigationIcon = {
IconButton(onClick = onClose) {
Icon(Icons.AutoMirrored.Filled.ArrowBack, contentDescription = "Back")
}
},
actions = {
IconButton(
onClick = { viewModel.save(onClose) },
enabled = state.canSave,
) {
Icon(Icons.Default.Done, contentDescription = "Save")
}
if (state.isEditing) {
IconButton(onClick = { menuExpanded = true }) {
Icon(Icons.Default.MoreVert, contentDescription = "More")
}
DropdownMenu(
expanded = menuExpanded,
onDismissRequest = { menuExpanded = false },
) {
DropdownMenuItem(
text = { Text("Delete") },
onClick = {
menuExpanded = false
viewModel.delete(onClose)
},
leadingIcon = {
Icon(Icons.Default.Delete, contentDescription = null)
},
)
}
}
},
)
},
) { padding ->
Box(
modifier = Modifier
.fillMaxSize()
.padding(padding),
) {
OutlinedTextField(
value = state.content,
onValueChange = viewModel::onContentChange,
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
.focusRequester(focusRequester),
placeholder = { Text("Write something…") },
keyboardOptions = KeyboardOptions(
capitalization = KeyboardCapitalization.Sentences,
imeAction = ImeAction.Default,
),
)
}
}
}
@@ -0,0 +1,100 @@
package org.incido.compose.ui.editor
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.CreationExtras
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.incido.compose.IncidoApplication
import org.incido.domain.model.Note
import org.incido.domain.repository.NoteRepository
/**
* Immutable UI state for [NoteEditorScreen]. The editor is in "new"
* mode when [existing] is null, otherwise it edits an existing note.
*/
data class NoteEditorUiState(
val existing: Note? = null,
val content: String = "",
val isLoading: Boolean = true,
val isSaving: Boolean = false,
val isDeleted: Boolean = false,
) {
val canSave: Boolean get() = content.isNotBlank() && !isSaving
val isEditing: Boolean get() = existing != null
}
class NoteEditorViewModel(
private val repository: NoteRepository,
private val noteId: Long?,
) : ViewModel() {
private val _state = MutableStateFlow(NoteEditorUiState())
val state: StateFlow<NoteEditorUiState> = _state.asStateFlow()
init {
if (noteId == null || noteId == 0L) {
// New note
_state.update { it.copy(isLoading = false) }
} else {
viewModelScope.launch {
repository.observeById(noteId).collect { note ->
_state.update {
it.copy(
existing = note,
content = note?.content ?: it.content,
isLoading = false,
)
}
}
}
}
}
fun onContentChange(newContent: String) {
_state.update { it.copy(content = newContent) }
}
fun save(onDone: () -> Unit) {
val current = _state.value
if (!current.canSave) return
_state.update { it.copy(isSaving = true) }
viewModelScope.launch {
val toPersist = current.existing?.copy(content = current.content)
?: Note(
content = current.content,
createdAt = System.currentTimeMillis(),
updatedAt = System.currentTimeMillis(),
)
repository.upsert(toPersist)
_state.update { it.copy(isSaving = false) }
onDone()
}
}
fun delete(onDone: () -> Unit) {
val id = _state.value.existing?.id ?: return
_state.update { it.copy(isSaving = true) }
viewModelScope.launch {
repository.delete(id)
_state.update { it.copy(isSaving = false, isDeleted = true) }
onDone()
}
}
companion object {
fun factory(noteId: Long?): ViewModelProvider.Factory = viewModelFactory {
initializer {
val app = this[APPLICATION_KEY] as IncidoApplication
NoteEditorViewModel(app.container.noteRepository, noteId)
}
}
}
}
@@ -0,0 +1,165 @@
package org.incido.compose.ui.notelist
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import org.incido.compose.util.rememberRelativeTimestamp
import org.incido.domain.model.Note
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun NoteListScreen(
onOpenEditor: (Long?) -> Unit,
viewModel: NoteListViewModel = viewModel(factory = NoteListViewModel.Factory),
) {
val state by viewModel.uiState.collectAsStateWithLifecycle()
Scaffold(
topBar = {
TopAppBar(title = { Text("Incido") })
},
floatingActionButton = {
FloatingActionButton(onClick = { onOpenEditor(null) }) {
Icon(Icons.Default.Add, contentDescription = "New note")
}
},
) { padding ->
when {
state.isLoading -> Unit // briefly blank on first composition
state.isEmpty -> EmptyState(padding)
else -> NoteList(
notes = state.notes,
contentPadding = padding,
onClick = { onOpenEditor(it.id) },
onDelete = viewModel::delete,
)
}
}
}
@Composable
private fun EmptyState(padding: PaddingValues) {
Box(
modifier = Modifier
.fillMaxSize()
.padding(padding)
.padding(24.dp),
contentAlignment = Alignment.Center,
) {
Text(
text = "No notes yet. Tap + to start.",
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
}
@Composable
private fun NoteList(
notes: List<Note>,
contentPadding: PaddingValues,
onClick: (Note) -> Unit,
onDelete: (Long) -> Unit,
) {
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(
top = contentPadding.calculateTopPadding() + 8.dp,
bottom = contentPadding.calculateBottomPadding() + 88.dp, // FAB clearance
start = 16.dp,
end = 16.dp,
),
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
items(items = notes, key = { it.id }) { note ->
NoteCard(
note = note,
onClick = { onClick(note) },
onDelete = { onDelete(note.id) },
)
}
}
}
@Composable
private fun NoteCard(
note: Note,
onClick: () -> Unit,
onDelete: () -> Unit,
) {
val (title, body) = Note.titleAndBody(note.content)
val bodyPreview = Note.bodyPreview(body)
Card(
onClick = onClick,
modifier = Modifier.fillMaxWidth(),
) {
Column(
modifier = Modifier.padding(16.dp),
) {
Text(
text = title,
style = MaterialTheme.typography.titleMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
if (bodyPreview.isNotEmpty()) {
Spacer(modifier = Modifier.padding(top = 4.dp))
Text(
text = bodyPreview,
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
maxLines = 2,
overflow = TextOverflow.Ellipsis,
)
}
Spacer(modifier = Modifier.padding(top = 8.dp))
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
) {
Text(
text = rememberRelativeTimestamp(note.updatedAt),
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
IconButton(onClick = onDelete) {
Icon(
Icons.Default.Delete,
contentDescription = "Delete note",
tint = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
}
}
}
}
@@ -0,0 +1,55 @@
package org.incido.compose.ui.notelist
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY
import androidx.lifecycle.viewModelScope
import androidx.lifecycle.viewmodel.initializer
import androidx.lifecycle.viewmodel.viewModelFactory
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import org.incido.compose.IncidoApplication
import org.incido.domain.model.Note
import org.incido.domain.repository.NoteRepository
/**
* Immutable UI state for [NoteListScreen]. A loading flag plus the
* current snapshot of notes; an empty list with [isLoading] == false
* indicates the empty-state UI should be shown (F6).
*/
data class NoteListUiState(
val notes: List<Note> = emptyList(),
val isLoading: Boolean = true,
) {
val isEmpty: Boolean get() = !isLoading && notes.isEmpty()
}
class NoteListViewModel(
private val repository: NoteRepository,
) : ViewModel() {
val uiState: StateFlow<NoteListUiState> =
repository.observeAll()
.map { NoteListUiState(notes = it, isLoading = false) }
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5_000),
initialValue = NoteListUiState(),
)
fun delete(id: Long) {
viewModelScope.launch { repository.delete(id) }
}
companion object {
val Factory: ViewModelProvider.Factory = viewModelFactory {
initializer {
val app = this[APPLICATION_KEY] as IncidoApplication
NoteListViewModel(app.container.noteRepository)
}
}
}
}
@@ -0,0 +1,15 @@
package org.incido.compose.ui.theme
import androidx.compose.ui.graphics.Color
// Brand-neutral palette in v0.1 (per Development Plan §5.3). All colors
// here are fallbacks for devices that don't support Material You dynamic
// color (i.e. Android < 12 or pre-Tiramisu).
val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
val Pink80 = Color(0xFFEFB8C8)
val Purple40 = Color(0xFF6650A4)
val PurpleGrey40 = Color(0xFF625B71)
val Pink40 = Color(0xFF7D5260)
@@ -0,0 +1,51 @@
package org.incido.compose.ui.theme
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
private val DarkColorScheme = darkColorScheme(
primary = Purple80,
secondary = PurpleGrey80,
tertiary = Pink80,
)
private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40,
)
/**
* Root theme. Uses Material You dynamic color on Android 12+, falls back
* to a brand-neutral palette elsewhere. Dark mode follows the system
* setting (N5).
*/
@Composable
fun IncidoTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
dynamicColor: Boolean = true,
content: @Composable () -> Unit,
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context)
else dynamicLightColorScheme(context)
}
darkTheme -> DarkColorScheme
else -> LightColorScheme
}
MaterialTheme(
colorScheme = colorScheme,
typography = IncidoTypography,
content = content,
)
}
@@ -0,0 +1,33 @@
package org.incido.compose.ui.theme
import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
// Default Material 3 typography. Custom fonts can be added in a future
// version when brand decisions are made.
val IncidoTypography = Typography(
bodyLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp,
),
titleLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 22.sp,
lineHeight = 28.sp,
letterSpacing = 0.sp,
),
labelSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Medium,
fontSize = 11.sp,
lineHeight = 16.sp,
letterSpacing = 0.5.sp,
),
)
@@ -0,0 +1,22 @@
package org.incido.compose.util
import android.text.format.DateUtils
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
/**
* Returns a localised "X ago" style timestamp for the given epoch millis.
* Uses Android's [DateUtils.getRelativeTimeSpanString] which handles all
* the edge cases (Today / Yesterday / N days ago / N weeks ago / …) and
* is automatically localised to the device language.
*/
@Composable
fun rememberRelativeTimestamp(epochMillis: Long): String {
val now = remember { System.currentTimeMillis() }
return DateUtils.getRelativeTimeSpanString(
epochMillis,
now,
DateUtils.MINUTE_IN_MILLIS,
DateUtils.FORMAT_ABBREV_RELATIVE,
).toString()
}