Fix second review round on views (#59, #141)

A task list block keeps out completed tasks when told to and takes its own
sort, subtasks loaded on expand stay within the scope, a new view can't be
saved twice nor a deleted one brought back, a failed pin says so, the start
list only opens over home, and pinned view shortcuts follow renames. The
changelog no longer claims the app opens on the last used view by default.
This commit is contained in:
makiolaj committed 2026-11-27 13:09:28 +01:00
1 parent b3eff2c3d7
commit 26bc06e1dd
13 files changed
+98 -43

No files matched your search

+4 -5
View File
@@ -11,8 +11,7 @@ All notable changes to this project are documented here. The format follows
- Views. Home is now the first of any number of views, switched from the
view's name in the top bar. That menu also opens *Lists & filters…*, every
list, saved filter and tag in one place, and *Manage views*, where views
are added, renamed, given an icon, reordered and deleted. The app opens on
the view you used last (#59).
are added, renamed, given an icon, reordered and deleted (#59).
- A list or saved filter can be pinned as a view from its ⋮ menu: the new
view shows its tasks, completed ones below, and is named after it (#59).
- A view can be narrowed to a scope. Everything in it then counts only the
@@ -21,9 +20,9 @@ All notable changes to this project are documented here. The format follows
(with a chip to search everything). A list a scope names shows even when
it is kept out of the smart lists. When a list or filter a view uses is
deleted, the view says so instead of quietly showing more (#59).
- A start screen setting under Settings: open on the last used view, a
view, a list or a saved filter. A list or filter opens over Home, so back
leads there (#141).
- A start screen setting under Settings: open on Home (the default), the
last used view, another view, a list or a saved filter. A list or filter
opens over Home, so back leads there (#141).
- Every view is also a launcher shortcut (#59).
## [1.4.0] - 2026-11-25
@@ -112,8 +112,8 @@ class MainActivity : ComponentActivity() {
viewSession.beginStart()
lifecycleScope.launch {
val push = when (val filter = viewSession.start()) {
is TaskFilter.OfList -> NavRequest.OpenList(filter.listId)
is TaskFilter.Saved -> NavRequest.OpenFilter(filter.id)
is TaskFilter.OfList -> NavRequest.OpenList(filter.listId, overHomeOnly = true)
is TaskFilter.Saved -> NavRequest.OpenFilter(filter.id, overHomeOnly = true)
else -> null
}
// Not over something the user, or another intent, opened meanwhile.
@@ -185,11 +185,15 @@ fun ListsScreen(
// The view's task list block, when it has one: it runs on the task screen's own model.
val taskBlock = content?.view?.blocks?.lastOrNull { it.type == BlockType.TASK_LIST && it.id !in content.goneSources }
val taskFilter = taskBlock?.source?.taskFilter
// Blocks open what they show within the view's scope, unless they ignore it.
val scopeFor = { block: Block -> content?.view?.takeIf { it.scope != null && !block.ignoreScope }?.id }
val blockModel: TaskListViewModel? = if (content != null && taskBlock != null && taskFilter != null) {
val model: TaskListViewModel = hiltViewModel(key = "view-${content.view.id}-block-${taskBlock.id}")
val scopeViewId = content.view.id.takeIf { content.view.scope != null && !taskBlock.ignoreScope }
val withCompleted = (taskBlock.options as BlockOptions.TaskList).showCompleted
LaunchedEffect(taskFilter, scopeViewId, withCompleted) { model.bind(taskFilter, scopeViewId, withCompleted) }
val scopeViewId = scopeFor(taskBlock)
val options = taskBlock.options as BlockOptions.TaskList
LaunchedEffect(taskFilter, scopeViewId, options) {
model.bind(taskFilter, scopeViewId, withCompleted = options.showCompleted, sort = options.sort)
}
model
} else {
null
@@ -237,8 +241,6 @@ fun ListsScreen(
ListsUiState.Failure ->
CenteredMessage(stringResource(R.string.lists_failure), PaddingValues(0.dp))
is ListsUiState.Content -> {
// Blocks open what they show within the view's scope, unless they ignore it.
val scopeFor = { block: Block -> s.view.id.takeIf { s.view.scope != null && !block.ignoreScope } }
ListsContent(
state = s,
onOpenFilter = onOpenFilter,
@@ -329,7 +331,7 @@ fun ListsScreen(
withSmartLists = true,
// A progress block shows Today only, for now.
todayOnly = choosingBlock.type == BlockType.PROGRESS,
onPick = { source -> viewModel.chooseSource(content.view, choosingBlock.id, source) },
onPick = { source -> viewModel.chooseSource(content.view.id, choosingBlock.id, source) },
onDismiss = { choosingSourceFor = null },
)
}
@@ -35,6 +35,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
@@ -335,8 +336,10 @@ class ListsViewModel @Inject constructor(
fun switchView(viewId: Long) = session.switchTo(viewId)
/** Points the block [blockId] of [view], whose source is gone, at [source] instead. */
fun chooseSource(view: View, blockId: Long, source: BlockSource) = viewModelScope.launch {
/** Points the block [blockId] of view [viewId], whose source is gone, at [source] instead. */
fun chooseSource(viewId: Long, blockId: Long, source: BlockSource) = viewModelScope.launch {
// The view as stored now, so nothing changed since the picker opened is lost.
val view = settingsPrefs.views.first().firstOrNull { it.id == viewId } ?: return@launch
val blocks = view.blocks.map { if (it.id == blockId) it.copy(source = source) else it }
settingsPrefs.saveView(view.copy(blocks = blocks))
}
@@ -74,6 +74,13 @@ fun AgendulaNavHost(
}
LaunchedEffect(navRequest) {
val startOverOther = (navRequest as? NavRequest.OpenList)?.overHomeOnly == true ||
(navRequest as? NavRequest.OpenFilter)?.overHomeOnly == true
// The start screen opens over home only, never over a screen opened while it was worked out.
if (startOverOther && nav.currentDestination?.route != Dest.LISTS) {
onNavRequestConsumed()
return@LaunchedEffect
}
when (navRequest) {
null -> return@LaunchedEffect
is NavRequest.OpenTask ->
@@ -39,6 +39,7 @@ object AppShortcuts {
* ever published, only the fixed shortcuts are refreshed and the views'
* left as they are, rather than wiped.
*/
@Synchronized
fun publish(context: Context, views: List<View>? = lastViews) {
val fixed = listOf(
ShortcutInfoCompat.Builder(context, "new_task")
@@ -60,7 +61,7 @@ object AppShortcuts {
}
lastViews = views
val room = runCatching { ShortcutManagerCompat.getMaxShortcutCountPerActivity(context) }.getOrDefault(fixed.size)
val viewShortcuts = views.take((room - fixed.size).coerceAtLeast(0)).mapIndexed { index, view ->
val all = views.mapIndexed { index, view ->
val label = view.name.ifBlank { context.getString(unnamedViewLabel(view.id)) }
ShortcutInfoCompat.Builder(context, "view_${view.id}")
.setShortLabel(label)
@@ -69,13 +70,15 @@ object AppShortcuts {
.setRank(fixed.size + index)
.build()
}
runCatching { ShortcutManagerCompat.setDynamicShortcuts(context, fixed + viewShortcuts) }
// A deleted view's shortcut pinned to the home screen stays there; it is disabled instead.
val kept = views.mapTo(HashSet()) { "view_${it.id}" }
runCatching { ShortcutManagerCompat.setDynamicShortcuts(context, fixed + all.take((room - fixed.size).coerceAtLeast(0))) }
// Pinned to the home screen, a view's shortcut follows its renames, and is disabled once it is deleted.
runCatching {
val gone = ShortcutManagerCompat.getShortcuts(context, ShortcutManagerCompat.FLAG_MATCH_PINNED)
val pinned = ShortcutManagerCompat.getShortcuts(context, ShortcutManagerCompat.FLAG_MATCH_PINNED)
.map { it.id }
.filter { it.startsWith("view_") && it !in kept }
.filter { it.startsWith("view_") }
.toSet()
val (present, gone) = pinned.partition { id -> all.any { it.id == id } }
if (present.isNotEmpty()) ShortcutManagerCompat.updateShortcuts(context, all.filter { it.id in present })
if (gone.isNotEmpty()) {
ShortcutManagerCompat.disableShortcuts(context, gone, context.getString(R.string.view_shortcut_gone))
}
@@ -45,11 +45,11 @@ sealed interface NavRequest {
/** One of the smart lists — the launcher's "Today" shortcut, a widget header. */
data class OpenSmart(val list: SmartList) : NavRequest
/** One real list — a widget header. */
data class OpenList(val listId: Long) : NavRequest
/** One real list — a widget header. [overHomeOnly]: the start screen, dropped once something else is open. */
data class OpenList(val listId: Long, val overHomeOnly: Boolean = false) : NavRequest
/** One saved filter — a widget header. */
data class OpenFilter(val filterId: Long) : NavRequest
/** One saved filter — a widget header. [overHomeOnly] as for [OpenList]. */
data class OpenFilter(val filterId: Long, val overHomeOnly: Boolean = false) : NavRequest
/** One view — its launcher shortcut. The view is switched to as the request is made. */
data class OpenView(val viewId: Long) : NavRequest
@@ -210,6 +210,7 @@ fun TaskListScreen(
// Swipe-delete and completing a task both leave a floating undo chip; the
// view model owns the window, so leaving the screen commits instead of losing it.
val undo by viewModel.undo.collectAsStateWithLifecycle()
val pinFailed by viewModel.pinFailed.collectAsStateWithLifecycle()
val onRequestDelete: (Task) -> Unit = viewModel::requestDelete
var showSort by rememberSaveable { mutableStateOf(false) }
var confirmClear by rememberSaveable { mutableStateOf(false) }
@@ -404,6 +405,7 @@ fun TaskListScreen(
is SearchReceipt.Failed, null -> stringResource(R.string.edit_save_failed)
},
)
pinFailed -> SnackChip(visible = true, message = stringResource(R.string.view_save_failed))
else -> SnackChip(
visible = readOnlyHint,
message = stringResource(R.string.list_read_only),
@@ -120,6 +120,8 @@ sealed interface TaskListUiState {
val scopeLists: Set<Long>? = null,
/** [scope]'s rule as it applies, which the rows are read through. */
val appliedScope: AppliedScope? = null,
/** The day [appliedScope] is read against. */
val ruleClock: RuleClock? = null,
) : TaskListUiState {
/** Upcoming, narrowed to a time frame the user picked. */
val upcomingLimited: Boolean
@@ -152,13 +154,15 @@ data class ScopeChip(val viewId: Long, val name: String, val icon: ViewIcon, val
/**
* What a task screen shows: [filter]'s tasks, within the scope of view
* [scopeViewId] when set, and with the completed ones too when [withCompleted]
* (which only an All list needs, the others carry their own).
* [scopeViewId] when set. [withCompleted] true adds the completed tasks to an
* All list, false leaves them out of any; `null` keeps what the filter shows.
* [sort] replaces the app's sort order when set.
*/
data class TaskListBinding(
val filter: TaskFilter,
val scopeViewId: Long? = null,
val withCompleted: Boolean = false,
val withCompleted: Boolean? = null,
val sort: TaskSortOrder? = null,
)
private const val PENDING_ADD_TIMEOUT_MS = 30_000L
@@ -224,7 +228,7 @@ class TaskListViewModel @Inject constructor(
val f = b.filter
val source: Flow<FilteredTasks> = when (f) {
is TaskFilter.Saved -> repository.filteredTasks(f)
is TaskFilter.Smart -> if (b.withCompleted && f.list == SmartList.ALL) {
is TaskFilter.Smart -> if (b.withCompleted == true && f.list == SmartList.ALL) {
combine(repository.tasks(f), repository.tasks(TaskFilter.Smart(SmartList.COMPLETED))) { open, done ->
FilteredTasks(open + done)
}
@@ -267,7 +271,10 @@ class TaskListViewModel @Inject constructor(
?: settings
val (inView, hiddenByRange) = shownBy.viewOf(f, st.tasks, now)
val clock = RuleClock(st.todayStart, st.todayEnd, ZoneId.systemDefault(), settings.effectiveWeekStart)
val visible = inView.filter { it.occurrenceKey !in pending && (scope == null || scope.admits(it, clock)) }
val visible = inView.filter {
it.occurrenceKey !in pending && (scope == null || scope.admits(it, clock)) &&
(b.withCompleted != false || !it.isCompleted)
}
val available = tagsInUse(visible) - setOfNotNull((f as? TaskFilter.Tagged)?.tag)
// A tag that vanished can no longer be unticked, so it is dropped
// for good rather than narrowing again when it comes back.
@@ -278,13 +285,14 @@ class TaskListViewModel @Inject constructor(
filter = f,
tasks = visible
.filter { TaskFiltering.hasAllTags(it, selected) }
.sortedWith(settings.sortOrder.comparator()),
.sortedWith((b.sort ?: settings.sortOrder).comparator()),
availableTags = available,
selectedTags = selected,
searchable = if (f is TaskFilter.OfList) visible else emptyList(),
showAddSubtaskRow = settings.showAddSubtaskRow,
bottomAddBar = settings.bottomAddBar,
sortOrder = settings.sortOrder,
sortOrder = b.sort ?: settings.sortOrder,
ruleClock = clock,
upcomingRange = settings.upcomingRange,
hiddenByRange = hiddenByRange,
grouping = settings.groupingFor(f).takeIf { it in groupings } ?: TaskGrouping.DUE,
@@ -325,6 +333,13 @@ class TaskListViewModel @Inject constructor(
combine(ids.map { id -> repository.subtasks(id).map { id to it } }) { it.toMap() }
}
}
// Subtasks outside the view's scope stay out, as they do from the rows.
.combine(state) { children, st ->
val content = st as? TaskListUiState.Content
val scope = content?.appliedScope
val clock = content?.ruleClock
if (scope == null || clock == null) children else children.mapValues { (_, tasks) -> tasks.filter { scope.admits(it, clock) } }
}
// Without this an exception here escapes stateIn's coroutine, past
// viewModelScope's SupervisorJob, and crashes the process.
.recoveringFromProviderFailure { emptyMap() }
@@ -338,8 +353,13 @@ class TaskListViewModel @Inject constructor(
* (see [TaskListBinding]). Binding again what is already bound changes
* nothing, so a scope dropped with [dropScope] stays dropped.
*/
fun bind(taskFilter: TaskFilter, scopeViewId: Long? = null, withCompleted: Boolean = false) {
val next = TaskListBinding(taskFilter, scopeViewId, withCompleted)
fun bind(
taskFilter: TaskFilter,
scopeViewId: Long? = null,
withCompleted: Boolean? = null,
sort: TaskSortOrder? = null,
) {
val next = TaskListBinding(taskFilter, scopeViewId, withCompleted, sort)
if (next == requested) return
if (filter != null && filter != taskFilter) {
closeSearch()
@@ -357,12 +377,23 @@ class TaskListViewModel @Inject constructor(
val content = state.value as? TaskListUiState.Content ?: return
val view = pinnedViewOf(content.list, content.savedFilter) ?: return
viewModelScope.launch {
val id = settingsPrefs.saveView(view) ?: return@launch
val id = settingsPrefs.saveView(view)
if (id == null) {
_pinFailed.value = true
delay(UNDO_WINDOW_MS)
_pinFailed.value = false
return@launch
}
viewSession.switchTo(id)
onPinned()
}
}
private val _pinFailed = MutableStateFlow(false)
/** Set for a moment when a pin couldn't be stored: the views are another version's. */
val pinFailed: StateFlow<Boolean> = _pinFailed.asStateFlow()
/** Drops the view's scope, the chip's ✕: the screen shows all of its tasks. */
fun dropScope() {
binding.update { it?.copy(scopeViewId = null) }
@@ -21,7 +21,6 @@ import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
@@ -49,6 +48,7 @@ import de.jeanlucmakiola.floret.components.FullScreenPicker
import de.jeanlucmakiola.floret.components.GroupedListInset
import de.jeanlucmakiola.floret.components.GroupedRow
import de.jeanlucmakiola.floret.components.GroupedSectionHeader
import de.jeanlucmakiola.floret.components.GroupedSwitchRow
import de.jeanlucmakiola.floret.components.Position
/**
@@ -120,13 +120,13 @@ fun EditViewScreen(
SettingsHint(stringResource(R.string.view_scope_blocks_hint))
GroupedSectionHeader(stringResource(R.string.view_section_layout))
GroupedRow(
GroupedSwitchRow(
title = stringResource(R.string.view_quick_add),
summary = stringResource(R.string.view_quick_add_hint),
checked = view.quickAdd,
onCheckedChange = viewModel::setQuickAdd,
position = Position.Alone,
summary = stringResource(R.string.view_quick_add_hint),
leading = { Icon(Icons.Rounded.PostAdd, contentDescription = null) },
trailing = { Switch(checked = view.quickAdd, onCheckedChange = viewModel::setQuickAdd) },
onClick = { viewModel.setQuickAdd(!view.quickAdd) },
)
if (view.deletable && !isNew) {
@@ -47,7 +47,7 @@ fun ManageViewsScreen(
) {
val views by viewModel.views.collectAsStateWithLifecycle()
val listNames by viewModel.listNames.collectAsStateWithLifecycle()
val home = views.firstOrNull() ?: return
val home = views.firstOrNull()
val others = views.drop(1)
CollapsingScaffold(
@@ -60,6 +60,7 @@ fun ManageViewsScreen(
}
},
) {
if (home == null) return@CollapsingScaffold
ViewRow(
view = home,
listNames = listNames,
@@ -160,6 +160,7 @@ private fun startLabel(destination: StartDestination, choices: StartChoices): St
is StartDestination.View -> choices.views.firstOrNull { it.id == destination.id }?.let { viewName(it.name, it.id) } ?: home
// Lists may not have loaded, or may not read: no name rather than a wrong one.
is StartDestination.List -> choices.lists.firstOrNull { it.id == destination.id }?.name
?: home.takeIf { choices.lists.isNotEmpty() }
is StartDestination.Filter -> choices.filters.firstOrNull { it.id == destination.id }?.name ?: home
}
}
@@ -99,14 +99,20 @@ class EditViewViewModel @Inject constructor(
saving = true
viewModelScope.launch {
val stored = settingsPrefs.views.first().firstOrNull { it.id == draft.id }
// A view deleted while it was open stays deleted.
if (stored == null && draft.id != 0L) {
onSaved()
return@launch
}
val view = stored?.copy(name = draft.name.trim(), icon = draft.icon, quickAdd = draft.quickAdd)
?: draft.copy(id = 0, name = draft.name.trim())
?: draft.copy(name = draft.name.trim())
val id = settingsPrefs.saveView(view)
saving = false
if (id == null) {
saving = false
_saveFailed.value = true
return@launch
}
// Stays saving: the screen is leaving, and a second tap mustn't add the view again.
if (stored == null) session.switchTo(id)
onSaved()
}