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
@@ -1,49 +1,119 @@
|
||||
package org.incido.compose
|
||||
|
||||
import androidx.compose.material3.DrawerValue
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.ModalNavigationDrawer
|
||||
import androidx.compose.material3.rememberDrawerState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.runtime.snapshots.SnapshotStateList
|
||||
import androidx.compose.runtime.toMutableStateList
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.navigation.NavType
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.currentBackStackEntryAsState
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import androidx.navigation.navArgument
|
||||
import kotlinx.coroutines.launch
|
||||
import org.incido.compose.ui.drawer.IncidoDrawer
|
||||
import org.incido.compose.ui.editor.NoteEditorScreen
|
||||
import org.incido.compose.ui.notelist.NoteListScreen
|
||||
import org.incido.compose.ui.theme.IncidoTheme
|
||||
import org.incido.domain.model.NoteFilter
|
||||
|
||||
/** Top-level navigation destinations. */
|
||||
private object Routes {
|
||||
const val LIST = "list"
|
||||
const val EDITOR = "editor/{noteId}"
|
||||
fun editor(noteId: Long?): String =
|
||||
"editor/${noteId ?: -1L}"
|
||||
fun editor(noteId: Long?): String = "editor/${noteId ?: -1L}"
|
||||
}
|
||||
|
||||
/** Stable serialisation for [NoteFilter] so `rememberSaveable` works. */
|
||||
private fun NoteFilter.toSaveableKey(): String = key()
|
||||
|
||||
private fun String.toNoteFilter(): NoteFilter = when {
|
||||
this == "home" -> NoteFilter.Home
|
||||
this == "favorites" -> NoteFilter.Favorites
|
||||
this == "untagged" -> NoteFilter.Untagged
|
||||
startsWith("tag:") -> NoteFilter.ByTag(this.removePrefix("tag:"))
|
||||
else -> NoteFilter.Home
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@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
|
||||
val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed)
|
||||
val scope = rememberCoroutineScope()
|
||||
var filterMode by rememberSaveable(
|
||||
stateSaver = androidx.compose.runtime.saveable.Saver(
|
||||
save = { it.toSaveableKey() },
|
||||
restore = { it.toNoteFilter() },
|
||||
),
|
||||
) { mutableStateOf<NoteFilter>(NoteFilter.Home) }
|
||||
|
||||
val currentBackStack by navController.currentBackStackEntryAsState()
|
||||
val currentRoute = currentBackStack?.destination?.route?.substringBefore("/")
|
||||
// Disable the drawer on the editor so back arrow / gesture do
|
||||
// exactly what the user expects there.
|
||||
val isListRoute = currentRoute == Routes.LIST
|
||||
|
||||
LaunchedEffect(currentRoute) {
|
||||
// If we land on the editor via deep link without a list in
|
||||
// the back stack, snap the drawer closed.
|
||||
if (!isListRoute && drawerState.isOpen) drawerState.close()
|
||||
}
|
||||
|
||||
ModalNavigationDrawer(
|
||||
drawerState = drawerState,
|
||||
gesturesEnabled = isListRoute,
|
||||
drawerContent = {
|
||||
IncidoDrawer(
|
||||
currentFilter = filterMode,
|
||||
onSelectFilter = { picked ->
|
||||
filterMode = picked
|
||||
scope.launch { drawerState.close() }
|
||||
},
|
||||
),
|
||||
) { entry ->
|
||||
val raw = entry.arguments?.getLong("noteId") ?: -1L
|
||||
val id = if (raw <= 0L) null else raw
|
||||
NoteEditorScreen(
|
||||
noteId = id,
|
||||
onClose = { navController.popBackStack() },
|
||||
)
|
||||
},
|
||||
) {
|
||||
NavHost(navController = navController, startDestination = Routes.LIST) {
|
||||
composable(Routes.LIST) {
|
||||
NoteListScreen(
|
||||
filterMode = filterMode,
|
||||
onOpenDrawer = { scope.launch { drawerState.open() } },
|
||||
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() },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Suppress unused-import lint for the snapshots helper that may be
|
||||
// re-introduced in future filter-state extensions.
|
||||
@Suppress("unused")
|
||||
private fun <T> List<T>.toSnapshotStateList(): SnapshotStateList<T> = toMutableStateList()
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.incido.compose.ui.drawer
|
||||
|
||||
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.stateIn
|
||||
import org.incido.compose.IncidoApplication
|
||||
import org.incido.domain.model.HashtagUsage
|
||||
import org.incido.domain.repository.NoteRepository
|
||||
|
||||
/**
|
||||
* Tiny ViewModel the navigation drawer uses to source its "Recent
|
||||
* tags" list. Kept separate from [NoteListViewModel] because the
|
||||
* drawer may render even before the list screen is created (and
|
||||
* vice-versa).
|
||||
*/
|
||||
class DrawerViewModel(
|
||||
repository: NoteRepository,
|
||||
) : ViewModel() {
|
||||
|
||||
val recentHashtags: StateFlow<List<HashtagUsage>> =
|
||||
repository.observeHashtagsByRecentUse()
|
||||
.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.WhileSubscribed(5_000),
|
||||
initialValue = emptyList(),
|
||||
)
|
||||
|
||||
companion object {
|
||||
val Factory: ViewModelProvider.Factory = viewModelFactory {
|
||||
initializer {
|
||||
val app = this[APPLICATION_KEY] as IncidoApplication
|
||||
DrawerViewModel(app.container.noteRepository)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
package org.incido.compose.ui.drawer
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Home
|
||||
import androidx.compose.material.icons.filled.LabelOff
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material.icons.filled.Tag
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.ModalDrawerSheet
|
||||
import androidx.compose.material3.NavigationDrawerItem
|
||||
import androidx.compose.material3.NavigationDrawerItemDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import org.incido.domain.model.HashtagUsage
|
||||
import org.incido.domain.model.NoteFilter
|
||||
|
||||
/**
|
||||
* Left-side navigation drawer. Top section has three fixed entries
|
||||
* (Home / Favorites / Untagged); a `HorizontalDivider`; then a live
|
||||
* scrollable list of the user's most-recently-used hashtags.
|
||||
*
|
||||
* Tapping any entry calls [onSelectFilter] and the caller (root) is
|
||||
* responsible for closing the drawer.
|
||||
*/
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun IncidoDrawer(
|
||||
currentFilter: NoteFilter,
|
||||
onSelectFilter: (NoteFilter) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
viewModel: DrawerViewModel = viewModel(factory = DrawerViewModel.Factory),
|
||||
) {
|
||||
val recent by viewModel.recentHashtags.collectAsStateWithLifecycle()
|
||||
|
||||
ModalDrawerSheet(modifier = modifier) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||
) {
|
||||
Text(
|
||||
text = "Incido",
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
modifier = Modifier.padding(start = 12.dp, top = 4.dp, bottom = 16.dp),
|
||||
)
|
||||
|
||||
NavigationDrawerItem(
|
||||
label = { Text("Home") },
|
||||
selected = currentFilter == NoteFilter.Home,
|
||||
onClick = { onSelectFilter(NoteFilter.Home) },
|
||||
icon = { Icon(Icons.Filled.Home, contentDescription = null) },
|
||||
)
|
||||
NavigationDrawerItem(
|
||||
label = { Text("Favorites") },
|
||||
selected = currentFilter == NoteFilter.Favorites,
|
||||
onClick = { onSelectFilter(NoteFilter.Favorites) },
|
||||
icon = { Icon(Icons.Filled.Star, contentDescription = null) },
|
||||
)
|
||||
NavigationDrawerItem(
|
||||
label = { Text("Untagged") },
|
||||
selected = currentFilter == NoteFilter.Untagged,
|
||||
onClick = { onSelectFilter(NoteFilter.Untagged) },
|
||||
icon = { Icon(Icons.Filled.LabelOff, contentDescription = null) },
|
||||
)
|
||||
|
||||
HorizontalDivider(modifier = Modifier.padding(vertical = 12.dp))
|
||||
|
||||
Text(
|
||||
text = "Recent tags",
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(start = 12.dp, bottom = 4.dp),
|
||||
)
|
||||
|
||||
if (recent.isEmpty()) {
|
||||
Text(
|
||||
text = "No tags yet — add some from the editor.",
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 8.dp),
|
||||
)
|
||||
} else {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.verticalScroll(rememberScrollState()),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
) {
|
||||
recent.forEach { usage ->
|
||||
DrawerHashtagEntry(
|
||||
usage = usage,
|
||||
selected = currentFilter == NoteFilter.ByTag(usage.name),
|
||||
onClick = { onSelectFilter(NoteFilter.ByTag(usage.name)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun DrawerHashtagEntry(
|
||||
usage: HashtagUsage,
|
||||
selected: Boolean,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
NavigationDrawerItem(
|
||||
label = { Text("#${usage.name}") },
|
||||
badge = {
|
||||
val n = usage.noteCount
|
||||
val label = if (n == 1) "1 note" else "$n notes"
|
||||
Text(label, style = MaterialTheme.typography.labelSmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
},
|
||||
selected = selected,
|
||||
onClick = onClick,
|
||||
icon = { Icon(Icons.Filled.Tag, contentDescription = null) },
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
private val _ignored: Color = Color.Unspecified
|
||||
@@ -7,7 +7,8 @@ import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||
import androidx.compose.foundation.layout.FlowRow
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@@ -21,28 +22,39 @@ import androidx.compose.foundation.shape.CircleShape
|
||||
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.Add
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Done
|
||||
import androidx.compose.material.icons.filled.MoreVert
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material.icons.filled.Tag
|
||||
import androidx.compose.material.icons.outlined.StarOutline
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.AssistChip
|
||||
import androidx.compose.material3.AssistChipDefaults
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
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.MaterialTheme
|
||||
import androidx.compose.material3.ModalBottomSheet
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.SnackbarHost
|
||||
import androidx.compose.material3.SnackbarHostState
|
||||
import androidx.compose.material3.SuggestionChip
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.rememberModalBottomSheetState
|
||||
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.rememberCoroutineScope
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
@@ -54,9 +66,14 @@ import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import kotlinx.coroutines.launch
|
||||
import org.incido.compose.ui.theme.AllNoteColors
|
||||
import org.incido.compose.ui.theme.swatchBorderColor
|
||||
import org.incido.compose.ui.theme.toComposeColor
|
||||
import org.incido.domain.model.Hashtag
|
||||
import org.incido.domain.model.NoteColor
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
fun NoteEditorScreen(
|
||||
noteId: Long?,
|
||||
@@ -70,6 +87,8 @@ fun NoteEditorScreen(
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
var menuExpanded by remember { mutableStateOf(false) }
|
||||
var showDiscardDialog by rememberSaveable { mutableStateOf(false) }
|
||||
val snackbarHost = remember { SnackbarHostState() }
|
||||
val scope = rememberCoroutineScope()
|
||||
|
||||
LaunchedEffect(state.isLoading) {
|
||||
if (!state.isLoading && state.existing != null) {
|
||||
@@ -80,12 +99,21 @@ fun NoteEditorScreen(
|
||||
if (noteId == null) focusRequester.requestFocus()
|
||||
}
|
||||
|
||||
LaunchedEffect(state.snackbar) {
|
||||
val msg = state.snackbar ?: return@LaunchedEffect
|
||||
scope.launch {
|
||||
snackbarHost.showSnackbar(msg)
|
||||
viewModel.consumeSnackbar()
|
||||
}
|
||||
}
|
||||
|
||||
fun isDirty(): Boolean {
|
||||
if (state.isLoading) return false
|
||||
return state.isDirty(
|
||||
initialContent = viewModel.initialContent,
|
||||
initialFavorite = viewModel.initialFavorite,
|
||||
initialColor = viewModel.initialColor,
|
||||
initialTags = viewModel.initialHashtags,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -93,7 +121,6 @@ fun NoteEditorScreen(
|
||||
if (isDirty()) showDiscardDialog = true else onClose()
|
||||
}
|
||||
|
||||
// Intercept hardware / gesture back to honour the same discard rule.
|
||||
BackHandler(enabled = true) { tryClose() }
|
||||
|
||||
if (showDiscardDialog) {
|
||||
@@ -118,14 +145,10 @@ fun NoteEditorScreen(
|
||||
}
|
||||
|
||||
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),
|
||||
snackbarHost = { SnackbarHost(hostState = snackbarHost) },
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
CenterAlignedTopAppBar(
|
||||
title = { Text(if (state.isEditing) "Edit note" else "New note") },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = { tryClose() }) {
|
||||
@@ -133,6 +156,18 @@ fun NoteEditorScreen(
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
IconButton(
|
||||
onClick = { viewModel.openAddTagSheet() },
|
||||
enabled = state.canAddMoreTags,
|
||||
) {
|
||||
Icon(
|
||||
Icons.Filled.Tag,
|
||||
contentDescription = "Add tag",
|
||||
tint = if (state.canAddMoreTags)
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
else MaterialTheme.colorScheme.outlineVariant,
|
||||
)
|
||||
}
|
||||
IconButton(onClick = { viewModel.toggleFavorite() }) {
|
||||
Icon(
|
||||
imageVector = if (state.isFavorite) Icons.Filled.Star else Icons.Outlined.StarOutline,
|
||||
@@ -176,14 +211,25 @@ fun NoteEditorScreen(
|
||||
.fillMaxSize()
|
||||
.padding(padding),
|
||||
) {
|
||||
// Colour-picker row (above the editor).
|
||||
HashtagChipRow(
|
||||
tags = state.hashtags,
|
||||
canAddMore = state.canAddMoreTags,
|
||||
onAddClick = { viewModel.openAddTagSheet() },
|
||||
onRemove = { viewModel.removeTag(it) },
|
||||
)
|
||||
|
||||
// Colour-picker row above the editor text field.
|
||||
LazyRow(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
.padding(horizontal = 16.dp, vertical = 4.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
items(items = AllNoteColors, key = { it.storageKey.toInt() }) { color ->
|
||||
items(
|
||||
count = AllNoteColors.size,
|
||||
key = { idx -> AllNoteColors[idx].storageKey.toInt() },
|
||||
) { idx ->
|
||||
val color = AllNoteColors[idx]
|
||||
ColorSwatch(
|
||||
color = color,
|
||||
selected = state.color == color,
|
||||
@@ -191,6 +237,7 @@ fun NoteEditorScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
OutlinedTextField(
|
||||
value = state.content,
|
||||
onValueChange = viewModel::onContentChange,
|
||||
@@ -207,14 +254,134 @@ fun NoteEditorScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (state.isAddingTag) {
|
||||
AddTagSheet(
|
||||
tagInput = state.tagInput,
|
||||
suggestions = state.tagSuggestions,
|
||||
canCreate = Hashtag.parseOrNull(state.tagInput) != null &&
|
||||
Hashtag.normalise(state.tagInput) !in state.hashtags,
|
||||
onInputChange = viewModel::onTagInputChange,
|
||||
onPickSuggestion = { picked ->
|
||||
viewModel.addTag(picked)
|
||||
viewModel.closeAddTagSheet()
|
||||
},
|
||||
onCreate = {
|
||||
if (viewModel.addTag(state.tagInput)) {
|
||||
viewModel.closeAddTagSheet()
|
||||
}
|
||||
},
|
||||
onDismiss = { viewModel.closeAddTagSheet() },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun androidx.compose.foundation.lazy.LazyListScope.items(
|
||||
items: List<NoteColor>,
|
||||
key: (NoteColor) -> Any,
|
||||
itemContent: @Composable (NoteColor) -> Unit,
|
||||
@OptIn(ExperimentalLayoutApi::class, ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun HashtagChipRow(
|
||||
tags: List<String>,
|
||||
canAddMore: Boolean,
|
||||
onAddClick: () -> Unit,
|
||||
onRemove: (String) -> Unit,
|
||||
) {
|
||||
items(items.size, key = { key(items[it]) }) { idx -> itemContent(items[idx]) }
|
||||
if (tags.isEmpty() && !canAddMore) return
|
||||
FlowRow(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
if (tags.isEmpty()) {
|
||||
Text(
|
||||
text = "Tags",
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
tags.forEach { tag ->
|
||||
AssistChip(
|
||||
onClick = { onRemove(tag) },
|
||||
label = { Text("#$tag") },
|
||||
trailingIcon = {
|
||||
Icon(Icons.Filled.Close, contentDescription = "Remove $tag", modifier = Modifier.size(16.dp))
|
||||
},
|
||||
)
|
||||
}
|
||||
if (canAddMore) {
|
||||
AssistChip(
|
||||
onClick = onAddClick,
|
||||
label = { Text("+ add") },
|
||||
leadingIcon = { Icon(Icons.Filled.Add, contentDescription = null, modifier = Modifier.size(16.dp)) },
|
||||
colors = AssistChipDefaults.assistChipColors(
|
||||
labelColor = MaterialTheme.colorScheme.primary,
|
||||
leadingIconContentColor = MaterialTheme.colorScheme.primary,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
private fun AddTagSheet(
|
||||
tagInput: String,
|
||||
suggestions: List<String>,
|
||||
canCreate: Boolean,
|
||||
onInputChange: (String) -> Unit,
|
||||
onPickSuggestion: (String) -> Unit,
|
||||
onCreate: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = onDismiss,
|
||||
sheetState = sheetState,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 24.dp, vertical = 8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Text("Add a tag", style = MaterialTheme.typography.titleMedium)
|
||||
OutlinedTextField(
|
||||
value = tagInput,
|
||||
onValueChange = onInputChange,
|
||||
placeholder = { Text("#tag-name") },
|
||||
singleLine = true,
|
||||
leadingIcon = { Icon(Icons.Filled.Tag, contentDescription = null) },
|
||||
keyboardOptions = KeyboardOptions(capitalization = KeyboardCapitalization.None),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
if (suggestions.isNotEmpty()) {
|
||||
Text(
|
||||
"Suggestions",
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
LazyRow(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
items(count = suggestions.size, key = { idx -> suggestions[idx] }) { idx ->
|
||||
val s = suggestions[idx]
|
||||
SuggestionChip(
|
||||
onClick = { onPickSuggestion(s) },
|
||||
label = { Text("#$s") },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (canCreate) {
|
||||
TextButton(onClick = onCreate) {
|
||||
Text("+ Create \"${Hashtag.normalise(tagInput)}\"")
|
||||
}
|
||||
}
|
||||
Text(
|
||||
"Tags help you find notes later. Up to ${NoteEditorUiState.MAX_TAGS} per note.",
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
||||
@@ -12,35 +12,46 @@ import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import org.incido.compose.IncidoApplication
|
||||
import org.incido.domain.model.Hashtag
|
||||
import org.incido.domain.model.Note
|
||||
import org.incido.domain.model.NoteColor
|
||||
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.
|
||||
* Immutable UI state for [NoteEditorScreen].
|
||||
*/
|
||||
data class NoteEditorUiState(
|
||||
val existing: Note? = null,
|
||||
val content: String = "",
|
||||
val isFavorite: Boolean = false,
|
||||
val color: NoteColor = NoteColor.NONE,
|
||||
/** Normalised, sorted ascending. */
|
||||
val hashtags: List<String> = emptyList(),
|
||||
/** True while the add-tag sheet is open. */
|
||||
val isAddingTag: Boolean = false,
|
||||
/** Latest typing in the add-tag sheet (raw, before normalisation). */
|
||||
val tagInput: String = "",
|
||||
/** Autocomplete suggestions for the add-tag sheet. */
|
||||
val tagSuggestions: List<String> = emptyList(),
|
||||
val isLoading: Boolean = true,
|
||||
val isSaving: Boolean = false,
|
||||
val isDeleted: Boolean = false,
|
||||
val snackbar: String? = null,
|
||||
) {
|
||||
val canSave: Boolean get() = content.isNotBlank() && !isSaving
|
||||
val isEditing: Boolean get() = existing != null
|
||||
val canAddMoreTags: Boolean get() = hashtags.size < MAX_TAGS
|
||||
|
||||
/**
|
||||
* True when the editor has changes that haven't been saved. Used by
|
||||
* the discard-confirm dialog in [NoteEditorScreen] to decide whether
|
||||
* to prompt before closing.
|
||||
*/
|
||||
fun isDirty(initialContent: String, initialFavorite: Boolean, initialColor: NoteColor): Boolean {
|
||||
fun isDirty(initialContent: String, initialFavorite: Boolean, initialColor: NoteColor, initialTags: List<String>): Boolean {
|
||||
return content != initialContent ||
|
||||
isFavorite != initialFavorite ||
|
||||
color != initialColor
|
||||
color != initialColor ||
|
||||
hashtags != initialTags
|
||||
}
|
||||
|
||||
companion object {
|
||||
/** Hard cap on tags per note (matches Development Plan §6.1). */
|
||||
const val MAX_TAGS = 5
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,29 +63,48 @@ class NoteEditorViewModel(
|
||||
private val _state = MutableStateFlow(NoteEditorUiState())
|
||||
val state: StateFlow<NoteEditorUiState> = _state.asStateFlow()
|
||||
|
||||
/**
|
||||
* Snapshot of the initial state when the editor loaded. Used by
|
||||
* [NoteEditorScreen] to compute the discard-confirm predicate.
|
||||
*/
|
||||
/** Snapshot of initial values for the dirty predicate (see [NoteEditorScreen]). */
|
||||
var initialContent: String = ""
|
||||
private set
|
||||
var initialFavorite: Boolean = false
|
||||
private set
|
||||
var initialColor: NoteColor = NoteColor.NONE
|
||||
private set
|
||||
var initialHashtags: List<String> = emptyList()
|
||||
private set
|
||||
|
||||
/** Internal: re-emits suggestions whenever the tag input changes. */
|
||||
private val tagInputFlow = MutableStateFlow("")
|
||||
private val tagSuggestionsFlow = MutableStateFlow<List<String>>(emptyList())
|
||||
|
||||
init {
|
||||
// Tag autocomplete — re-query on every keystroke (debounced upstream
|
||||
// would be nice but ObjectBox is plenty fast for this size).
|
||||
viewModelScope.launch {
|
||||
tagInputFlow.collect { raw ->
|
||||
val prefix = Hashtag.normalise(raw)
|
||||
val pool = if (prefix.isEmpty()) {
|
||||
repository.observeAllHashtags()
|
||||
} else {
|
||||
repository.searchHashtags(prefix)
|
||||
}
|
||||
pool.collect { suggestions ->
|
||||
_state.update { it.copy(tagSuggestions = suggestions) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load the note if editing.
|
||||
if (noteId == null || noteId == 0L) {
|
||||
// New note
|
||||
_state.update { it.copy(isLoading = false) }
|
||||
} else {
|
||||
viewModelScope.launch {
|
||||
repository.observeById(noteId).collect { note ->
|
||||
if (note != null && _state.value.isLoading) {
|
||||
// First non-null load — capture the initial snapshot.
|
||||
initialContent = note.content
|
||||
initialFavorite = note.isFavorite
|
||||
initialColor = note.color
|
||||
initialHashtags = note.hashtags
|
||||
}
|
||||
_state.update {
|
||||
it.copy(
|
||||
@@ -82,6 +112,7 @@ class NoteEditorViewModel(
|
||||
content = note?.content ?: it.content,
|
||||
isFavorite = note?.isFavorite ?: it.isFavorite,
|
||||
color = note?.color ?: it.color,
|
||||
hashtags = note?.hashtags ?: it.hashtags,
|
||||
isLoading = false,
|
||||
)
|
||||
}
|
||||
@@ -102,23 +133,74 @@ class NoteEditorViewModel(
|
||||
_state.update { it.copy(color = color) }
|
||||
}
|
||||
|
||||
fun openAddTagSheet() {
|
||||
_state.update {
|
||||
it.copy(
|
||||
isAddingTag = true,
|
||||
tagInput = "",
|
||||
tagSuggestions = emptyList(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun closeAddTagSheet() {
|
||||
_state.update { it.copy(isAddingTag = false, tagInput = "", tagSuggestions = emptyList()) }
|
||||
}
|
||||
|
||||
fun onTagInputChange(raw: String) {
|
||||
tagInputFlow.value = raw
|
||||
_state.update { it.copy(tagInput = raw) }
|
||||
}
|
||||
|
||||
/** Add an existing tag to the note (idempotent). Returns false if the cap is hit. */
|
||||
fun addTag(name: String): Boolean {
|
||||
val normalised = Hashtag.normalise(name)
|
||||
if (normalised.isEmpty()) return false
|
||||
if (!normalised.matches(Regex("^[a-z0-9][a-z0-9._-]{0,30}$"))) return false
|
||||
val current = _state.value
|
||||
if (normalised in current.hashtags) return true // already there
|
||||
if (current.hashtags.size >= NoteEditorUiState.MAX_TAGS) {
|
||||
_state.update { it.copy(snackbar = "Maximum ${NoteEditorUiState.MAX_TAGS} tags reached.") }
|
||||
return false
|
||||
}
|
||||
_state.update { it.copy(hashtags = (it.hashtags + normalised).sorted()) }
|
||||
return true
|
||||
}
|
||||
|
||||
fun removeTag(name: String) {
|
||||
val normalised = Hashtag.normalise(name)
|
||||
_state.update { it.copy(hashtags = it.hashtags.filterNot { tag -> tag == normalised }) }
|
||||
}
|
||||
|
||||
fun consumeSnackbar() {
|
||||
_state.update { it.copy(snackbar = null) }
|
||||
}
|
||||
|
||||
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(
|
||||
val baseNote = current.existing
|
||||
val toPersist = baseNote?.copy(
|
||||
content = current.content,
|
||||
isFavorite = current.isFavorite,
|
||||
color = current.color,
|
||||
hashtags = current.hashtags,
|
||||
) ?: Note(
|
||||
content = current.content,
|
||||
createdAt = System.currentTimeMillis(),
|
||||
updatedAt = System.currentTimeMillis(),
|
||||
isFavorite = current.isFavorite,
|
||||
color = current.color,
|
||||
hashtags = current.hashtags,
|
||||
)
|
||||
repository.upsert(toPersist)
|
||||
val saved = repository.upsert(toPersist)
|
||||
// Reconcile hashtag set vs. what was previously persisted.
|
||||
val previous = baseNote?.hashtags.orEmpty().toSet()
|
||||
val currentSet = current.hashtags.toSet()
|
||||
(previous - currentSet).forEach { repository.removeHashtag(saved.id, it) }
|
||||
(currentSet - previous).forEach { repository.addHashtag(saved.id, it) }
|
||||
_state.update { it.copy(isSaving = false) }
|
||||
onDone()
|
||||
}
|
||||
|
||||
@@ -13,15 +13,18 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.CheckBox
|
||||
import androidx.compose.material.icons.filled.Delete
|
||||
import androidx.compose.material.icons.filled.Menu
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material.icons.filled.Star
|
||||
import androidx.compose.material.icons.outlined.StarOutline
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FloatingActionButton
|
||||
import androidx.compose.material3.Icon
|
||||
@@ -30,8 +33,8 @@ import androidx.compose.material3.MaterialTheme
|
||||
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
|
||||
@@ -39,41 +42,57 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.lerp
|
||||
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.ui.editor.toComposeColor
|
||||
import org.incido.compose.ui.theme.toComposeColor
|
||||
import org.incido.compose.util.rememberRelativeTimestamp
|
||||
import org.incido.domain.model.Note
|
||||
import org.incido.domain.model.NoteColor
|
||||
import org.incido.domain.model.NoteFilter
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun NoteListScreen(
|
||||
filterMode: NoteFilter,
|
||||
onOpenDrawer: () -> Unit,
|
||||
onOpenEditor: (Long?) -> Unit,
|
||||
viewModel: NoteListViewModel = viewModel(factory = NoteListViewModel.Factory),
|
||||
) {
|
||||
val state by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
var localQuery by remember { mutableStateOf("") }
|
||||
|
||||
// Keep the ViewModel in sync with the parent's filter selection.
|
||||
LaunchedEffect(filterMode) { viewModel.setFilter(filterMode) }
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = { Text("Incido") },
|
||||
CenterAlignedTopAppBar(
|
||||
title = { Text(screenTitle(filterMode)) },
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onOpenDrawer) {
|
||||
Icon(Icons.Filled.Menu, contentDescription = "Open menu")
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = {
|
||||
if (state.isSearchActive) viewModel.closeSearch() else viewModel.openSearch()
|
||||
localQuery = ""
|
||||
}) {
|
||||
Icon(Icons.Default.Search, contentDescription = "Search notes")
|
||||
if (filterMode == NoteFilter.Home) {
|
||||
IconButton(onClick = {
|
||||
if (state.isSearchActive) viewModel.closeSearch() else viewModel.openSearch()
|
||||
localQuery = ""
|
||||
}) {
|
||||
Icon(Icons.Filled.Search, contentDescription = "Search notes")
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
floatingActionButton = {
|
||||
if (!state.isSearchActive) {
|
||||
// FAB only on Home — adding notes while filtered makes less sense.
|
||||
if (filterMode == NoteFilter.Home) {
|
||||
FloatingActionButton(onClick = { onOpenEditor(null) }) {
|
||||
Icon(Icons.Default.Add, contentDescription = "New note")
|
||||
}
|
||||
@@ -81,7 +100,7 @@ fun NoteListScreen(
|
||||
},
|
||||
) { padding ->
|
||||
Column(modifier = Modifier.padding(padding)) {
|
||||
if (state.isSearchActive) {
|
||||
if (filterMode == NoteFilter.Home && state.isSearchActive) {
|
||||
OutlinedTextField(
|
||||
value = localQuery,
|
||||
onValueChange = {
|
||||
@@ -99,8 +118,8 @@ fun NoteListScreen(
|
||||
|
||||
when {
|
||||
state.isLoading -> Unit
|
||||
state.isEmpty -> EmptyState()
|
||||
state.noResults -> NoResultsState()
|
||||
state.isEmpty -> EmptyState(filterMode = filterMode)
|
||||
state.noResults -> NoResultsState(filterMode = filterMode)
|
||||
else -> NoteList(
|
||||
notes = state.notes,
|
||||
onClick = { onOpenEditor(it.id) },
|
||||
@@ -112,8 +131,21 @@ fun NoteListScreen(
|
||||
}
|
||||
}
|
||||
|
||||
private fun screenTitle(filter: NoteFilter): String = when (filter) {
|
||||
NoteFilter.Home -> "Incido"
|
||||
NoteFilter.Favorites -> "Favorites"
|
||||
NoteFilter.Untagged -> "Untagged"
|
||||
is NoteFilter.ByTag -> "#${filter.hashtag}"
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EmptyState() {
|
||||
private fun EmptyState(filterMode: NoteFilter) {
|
||||
val message = when (filterMode) {
|
||||
NoteFilter.Home -> "No notes yet. Tap + to start."
|
||||
NoteFilter.Favorites -> "No favourites yet. Tap ⭐ on a card to add one."
|
||||
NoteFilter.Untagged -> "All notes are tagged. 🎉"
|
||||
is NoteFilter.ByTag -> "No notes tagged #${filterMode.hashtag} yet."
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@@ -121,7 +153,7 @@ private fun EmptyState() {
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(
|
||||
text = "No notes yet. Tap + to start.",
|
||||
text = message,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
@@ -129,7 +161,11 @@ private fun EmptyState() {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun NoResultsState() {
|
||||
private fun NoResultsState(filterMode: NoteFilter) {
|
||||
val message = when (filterMode) {
|
||||
NoteFilter.Home -> "No matching notes."
|
||||
else -> "Nothing here."
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@@ -137,7 +173,7 @@ private fun NoResultsState() {
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Text(
|
||||
text = "No matching notes.",
|
||||
text = message,
|
||||
style = MaterialTheme.typography.bodyLarge,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
@@ -172,6 +208,13 @@ private fun NoteList(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* v0.3.0.0 card redesign — three-layer colour accent so notes of
|
||||
* different colours are visually distinct at a glance:
|
||||
* 1. 14 dp vertical gradient stripe down the left edge.
|
||||
* 2. Tinted card surface (12 % colour blend over the M3 surface).
|
||||
* 3. 10 dp solid colour chip in the top-right corner.
|
||||
*/
|
||||
@Composable
|
||||
private fun NoteCard(
|
||||
note: Note,
|
||||
@@ -182,19 +225,38 @@ private fun NoteCard(
|
||||
val (title, body) = Note.titleAndBody(note.content)
|
||||
val bodyPreview = Note.bodyPreview(body)
|
||||
val checklistSummary = Note.checklistSummary(note.content)
|
||||
val stripeColor = note.color.toComposeColor()
|
||||
val noteColor = note.color
|
||||
val hasColor = noteColor != NoteColor.NONE
|
||||
|
||||
Card(
|
||||
onClick = onClick,
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
colors = if (hasColor) {
|
||||
val tint = noteColor.toComposeColor()
|
||||
val surface = MaterialTheme.colorScheme.surface
|
||||
CardDefaults.cardColors(
|
||||
containerColor = lerp(surface, tint, 0.12f),
|
||||
)
|
||||
} else {
|
||||
CardDefaults.cardColors()
|
||||
},
|
||||
) {
|
||||
Row(modifier = Modifier.fillMaxWidth()) {
|
||||
// 4dp coloured accent stripe on the left.
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(width = 4.dp, height = 96.dp)
|
||||
.background(stripeColor),
|
||||
)
|
||||
if (hasColor) {
|
||||
// Layer 1: 14 dp gradient stripe.
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(width = 14.dp, height = 110.dp)
|
||||
.background(
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
noteColor.toComposeColor().copy(alpha = 0.95f),
|
||||
noteColor.toComposeColor().copy(alpha = 0.05f),
|
||||
),
|
||||
)
|
||||
),
|
||||
)
|
||||
}
|
||||
Column(modifier = Modifier.padding(16.dp).fillMaxWidth()) {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
@@ -207,6 +269,16 @@ private fun NoteCard(
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
// Layer 3: top-right colour chip (only when coloured).
|
||||
if (hasColor) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(10.dp)
|
||||
.clip(CircleShape)
|
||||
.background(noteColor.toComposeColor()),
|
||||
)
|
||||
Spacer(modifier = Modifier.size(8.dp))
|
||||
}
|
||||
IconButton(onClick = onToggleFavorite) {
|
||||
Icon(
|
||||
imageVector = if (note.isFavorite) Icons.Filled.Star else Icons.Outlined.StarOutline,
|
||||
@@ -267,4 +339,11 @@ private fun NoteCard(
|
||||
}
|
||||
}
|
||||
|
||||
// --- Lightweight imports used to avoid shadowed-name conflicts in
|
||||
// other files that might also import these symbols ---
|
||||
@Suppress("unused")
|
||||
private fun clip(@Suppress("UNUSED_PARAMETER") shape: androidx.compose.ui.graphics.Shape): Modifier =
|
||||
Modifier.clip(shape)
|
||||
|
||||
@Suppress("unused")
|
||||
private fun background(color: Color): Modifier = Modifier.background(color)
|
||||
@@ -17,26 +17,24 @@ import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
import org.incido.compose.IncidoApplication
|
||||
import org.incido.domain.model.HashtagUsage
|
||||
import org.incido.domain.model.Note
|
||||
import org.incido.domain.model.NoteFilter
|
||||
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).
|
||||
*
|
||||
* [isSearchActive] / [searchQuery] are now properly folded into the same
|
||||
* uiState flow (v0.2.1 fix — they used to live on a separate StateFlow
|
||||
* that the composable never observed, making the search icon a no-op).
|
||||
* Immutable UI state for [NoteListScreen].
|
||||
*/
|
||||
data class NoteListUiState(
|
||||
val notes: List<Note> = emptyList(),
|
||||
val isLoading: Boolean = true,
|
||||
val searchQuery: String = "",
|
||||
val isSearchActive: Boolean = false,
|
||||
val filter: NoteFilter = NoteFilter.Home,
|
||||
val recentHashtags: List<HashtagUsage> = emptyList(),
|
||||
) {
|
||||
val isEmpty: Boolean get() = !isLoading && notes.isEmpty() && !isSearchActive
|
||||
val noResults: Boolean get() = !isLoading && notes.isEmpty() && isSearchActive
|
||||
val isEmpty: Boolean get() = !isLoading && notes.isEmpty() && !isSearchActive && filter == NoteFilter.Home
|
||||
val noResults: Boolean get() = !isLoading && notes.isEmpty() && !isEmpty
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class)
|
||||
@@ -44,34 +42,36 @@ class NoteListViewModel(
|
||||
private val repository: NoteRepository,
|
||||
) : ViewModel() {
|
||||
|
||||
private val filterMode = MutableStateFlow<NoteFilter>(NoteFilter.Home)
|
||||
private val rawQuery = MutableStateFlow("")
|
||||
private val _isSearchActive = MutableStateFlow(false)
|
||||
|
||||
/**
|
||||
* Combines the filtered notes flow, the search-active flag, and the
|
||||
* raw query into a single [NoteListUiState] that the composable can
|
||||
* `collectAsStateWithLifecycle`. All three pieces of state are
|
||||
* updated together so `if (state.isSearchActive)` in the screen
|
||||
* actually reflects the icon's toggled value.
|
||||
*/
|
||||
/** Notes stream — switches on (filter, query) so the same ViewModel
|
||||
* instance handles Home, Favorites, Untagged, ByTag, and search. */
|
||||
private val notesFlow = combine(filterMode, rawQuery) { f, q -> f to q }
|
||||
.flatMapLatest { (f, q) ->
|
||||
when (f) {
|
||||
NoteFilter.Home -> if (q.isBlank()) repository.observeAll() else repository.search(q)
|
||||
NoteFilter.Favorites -> repository.observeFavorites()
|
||||
NoteFilter.Untagged -> repository.observeUntagged()
|
||||
is NoteFilter.ByTag -> repository.observeNotesForHashtag(f.hashtag)
|
||||
}
|
||||
}
|
||||
|
||||
val uiState: StateFlow<NoteListUiState> = combine(
|
||||
rawQuery
|
||||
.debounce(150)
|
||||
.flatMapLatest { q ->
|
||||
if (q.isBlank()) {
|
||||
repository.observeAll()
|
||||
} else {
|
||||
repository.search(q)
|
||||
}
|
||||
},
|
||||
notesFlow,
|
||||
_isSearchActive,
|
||||
filterMode,
|
||||
rawQuery,
|
||||
) { notes, searchActive, q ->
|
||||
repository.observeHashtagsByRecentUse(),
|
||||
) { notes, searchActive, filter, query, recent ->
|
||||
NoteListUiState(
|
||||
notes = notes,
|
||||
isLoading = false,
|
||||
searchQuery = q,
|
||||
searchQuery = query,
|
||||
isSearchActive = searchActive,
|
||||
filter = filter,
|
||||
recentHashtags = recent,
|
||||
)
|
||||
}.stateIn(
|
||||
scope = viewModelScope,
|
||||
@@ -79,6 +79,16 @@ class NoteListViewModel(
|
||||
initialValue = NoteListUiState(),
|
||||
)
|
||||
|
||||
fun setFilter(filter: NoteFilter) {
|
||||
filterMode.value = filter
|
||||
// Switching away from Home closes the search bar (search is
|
||||
// only meaningful in Home).
|
||||
if (filter != NoteFilter.Home && _isSearchActive.value) {
|
||||
_isSearchActive.value = false
|
||||
rawQuery.value = ""
|
||||
}
|
||||
}
|
||||
|
||||
fun onQueryChange(q: String) {
|
||||
rawQuery.value = q
|
||||
}
|
||||
|
||||
+5
-7
@@ -1,4 +1,4 @@
|
||||
package org.incido.compose.ui.editor
|
||||
package org.incido.compose.ui.theme
|
||||
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -7,8 +7,8 @@ import androidx.compose.ui.graphics.Color
|
||||
import org.incido.domain.model.NoteColor
|
||||
|
||||
/**
|
||||
* Maps a [NoteColor] enum to a Compose [Color] using Material 3 tokens so
|
||||
* the swatches adapt to light/dark theme automatically.
|
||||
* Maps a [NoteColor] enum to a Compose [Color]. Values are chosen to
|
||||
* stay readable against both light and dark surfaces.
|
||||
*/
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
@@ -21,6 +21,7 @@ fun NoteColor.toComposeColor(): Color = when (this) {
|
||||
NoteColor.PURPLE -> Color(0xFF7B5BA6)
|
||||
}
|
||||
|
||||
/** All selectable colours, including [NoteColor.NONE]. */
|
||||
val AllNoteColors: List<NoteColor> = listOf(
|
||||
NoteColor.NONE,
|
||||
NoteColor.BLUE,
|
||||
@@ -30,10 +31,7 @@ val AllNoteColors: List<NoteColor> = listOf(
|
||||
NoteColor.PURPLE,
|
||||
)
|
||||
|
||||
/**
|
||||
* A swatch surface colour for a swatch button — used to give the
|
||||
* selected swatch a visible border by reading the theme's outline.
|
||||
*/
|
||||
/** Outline colour used to highlight the selected swatch. */
|
||||
val swatchBorderColor: Color
|
||||
@Composable
|
||||
@ReadOnlyComposable
|
||||
Reference in new issue
Block a user