Narrow a task list to a view's scope, pin lists and filters as views (#59)
A list opened from a scoped view shows a chip that drops the scope. Pin as view in a list's or filter's menu makes a view of it and switches there. The task list rows are split out so a view can host them.
This commit is contained in:
1 parent
e1c3121080
commit
ff79d32a89
7 files changed
+720
-170
No files matched your search
@@ -56,30 +56,35 @@ object Dest {
|
||||
/**
|
||||
* One [TaskFilter]'s tasks. Carries one of `listId` (a real list), `smart`
|
||||
* (a [SmartList] name), `tag` or `filterId` (a saved filter); whichever is
|
||||
* set decides the filter.
|
||||
* set decides the filter. `view` narrows it to that view's scope.
|
||||
*/
|
||||
object TaskList {
|
||||
const val ARG_LIST_ID = "listId"
|
||||
const val ARG_SMART = "smart"
|
||||
const val ARG_TAG = "tag"
|
||||
const val ARG_FILTER_ID = "filterId"
|
||||
const val ARG_VIEW = "view"
|
||||
const val route = "taskList?$ARG_LIST_ID={$ARG_LIST_ID}&$ARG_SMART={$ARG_SMART}&$ARG_TAG={$ARG_TAG}" +
|
||||
"&$ARG_FILTER_ID={$ARG_FILTER_ID}"
|
||||
"&$ARG_FILTER_ID={$ARG_FILTER_ID}&$ARG_VIEW={$ARG_VIEW}"
|
||||
|
||||
val arguments = listOf(
|
||||
navArgument(ARG_LIST_ID) { type = NavType.LongType; defaultValue = NO_ID },
|
||||
navArgument(ARG_SMART) { type = NavType.StringType; nullable = true; defaultValue = null },
|
||||
navArgument(ARG_TAG) { type = NavType.StringType; nullable = true; defaultValue = null },
|
||||
navArgument(ARG_FILTER_ID) { type = NavType.LongType; defaultValue = NO_ID },
|
||||
navArgument(ARG_VIEW) { type = NavType.LongType; defaultValue = NO_ID },
|
||||
)
|
||||
|
||||
fun build(filter: TaskFilter): String = when (filter) {
|
||||
is TaskFilter.OfList -> "taskList?$ARG_LIST_ID=${filter.listId}"
|
||||
is TaskFilter.Smart -> "taskList?$ARG_SMART=${filter.list.name}"
|
||||
is TaskFilter.Tagged -> "taskList?$ARG_TAG=${android.net.Uri.encode(filter.tag)}"
|
||||
is TaskFilter.Saved -> "taskList?$ARG_FILTER_ID=${filter.id}"
|
||||
// Several lists at once only exists for the widget, which never routes here.
|
||||
is TaskFilter.OfLists -> error("OfLists has no task-list screen")
|
||||
fun build(filter: TaskFilter, scopeViewId: Long? = null): String {
|
||||
val base = when (filter) {
|
||||
is TaskFilter.OfList -> "taskList?$ARG_LIST_ID=${filter.listId}"
|
||||
is TaskFilter.Smart -> "taskList?$ARG_SMART=${filter.list.name}"
|
||||
is TaskFilter.Tagged -> "taskList?$ARG_TAG=${android.net.Uri.encode(filter.tag)}"
|
||||
is TaskFilter.Saved -> "taskList?$ARG_FILTER_ID=${filter.id}"
|
||||
// Several lists at once only exists for the widget, which never routes here.
|
||||
is TaskFilter.OfLists -> error("OfLists has no task-list screen")
|
||||
}
|
||||
return if (scopeViewId == null) base else "$base&$ARG_VIEW=$scopeViewId"
|
||||
}
|
||||
|
||||
/** Reconstruct the filter from a destination's arguments. */
|
||||
@@ -91,6 +96,18 @@ object Dest {
|
||||
}
|
||||
}
|
||||
|
||||
/** The views: reorder, add, open one to edit. */
|
||||
const val MANAGE_VIEWS = "views"
|
||||
|
||||
/** One view's name, icon, scope and quick-add. */
|
||||
object EditView {
|
||||
const val ARG_VIEW_ID = "viewId"
|
||||
const val route = "views/{$ARG_VIEW_ID}"
|
||||
val arguments = listOf(navArgument(ARG_VIEW_ID) { type = NavType.LongType })
|
||||
|
||||
fun build(viewId: Long): String = "views/$viewId"
|
||||
}
|
||||
|
||||
/** Creates a saved filter, or edits the one `filterId` names. */
|
||||
object FilterEdit {
|
||||
const val ARG_FILTER_ID = "filterId"
|
||||
|
||||
@@ -40,6 +40,7 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyListScope
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
@@ -52,6 +53,10 @@ import androidx.compose.material.icons.rounded.Delete
|
||||
import androidx.compose.material.icons.rounded.Edit
|
||||
import androidx.compose.material.icons.rounded.ExpandMore
|
||||
import androidx.compose.material.icons.rounded.Flag
|
||||
import androidx.compose.material.icons.rounded.MoreVert
|
||||
import androidx.compose.material.icons.rounded.PushPin
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Checkbox
|
||||
import androidx.compose.material3.Badge
|
||||
import androidx.compose.material3.BadgedBox
|
||||
@@ -120,6 +125,7 @@ import de.jeanlucmakiola.agendula.domain.TaskFilter
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSection
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSections
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSearch
|
||||
import de.jeanlucmakiola.agendula.domain.TaskGroup
|
||||
import de.jeanlucmakiola.agendula.domain.TaskGroupKey
|
||||
import de.jeanlucmakiola.agendula.domain.TaskGrouping
|
||||
import de.jeanlucmakiola.agendula.domain.TaskGroups
|
||||
@@ -131,6 +137,8 @@ import de.jeanlucmakiola.agendula.ui.common.priorityAccent
|
||||
import de.jeanlucmakiola.agendula.ui.lists.ListEditorSheet
|
||||
import de.jeanlucmakiola.agendula.ui.lists.listWriteFailureMessage
|
||||
import de.jeanlucmakiola.agendula.ui.lists.ListWriteFailure
|
||||
import de.jeanlucmakiola.agendula.ui.views.ScopeInputChip
|
||||
import de.jeanlucmakiola.agendula.ui.views.viewName
|
||||
import de.jeanlucmakiola.floret.components.Position
|
||||
import de.jeanlucmakiola.floret.components.SnackChip
|
||||
import de.jeanlucmakiola.floret.components.SnackChipHeight
|
||||
@@ -156,6 +164,7 @@ fun TaskListScreen(
|
||||
onBack: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
onEditFilter: (Long) -> Unit = {},
|
||||
onPinned: () -> Unit = {},
|
||||
backClosesSearch: Boolean = true,
|
||||
viewModel: TaskListViewModel = hiltViewModel(),
|
||||
) {
|
||||
@@ -203,6 +212,7 @@ fun TaskListScreen(
|
||||
val onRequestDelete: (Task) -> Unit = viewModel::requestDelete
|
||||
var showSort by rememberSaveable { mutableStateOf(false) }
|
||||
var confirmClear by rememberSaveable { mutableStateOf(false) }
|
||||
var menuOpen by remember { mutableStateOf(false) }
|
||||
|
||||
// Held by the view model, so a search survives the switch between one and two panes.
|
||||
val searchActive by viewModel.searchActive.collectAsStateWithLifecycle()
|
||||
@@ -280,6 +290,24 @@ fun TaskListScreen(
|
||||
)
|
||||
}
|
||||
}
|
||||
// A list or a saved filter can become a view of its own (#59).
|
||||
if (list != null || savedFilter != null) {
|
||||
Box {
|
||||
IconButton(onClick = { menuOpen = true }) {
|
||||
Icon(Icons.Rounded.MoreVert, contentDescription = stringResource(R.string.more_options))
|
||||
}
|
||||
DropdownMenu(expanded = menuOpen, onDismissRequest = { menuOpen = false }) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.view_pin)) },
|
||||
leadingIcon = { Icon(Icons.Rounded.PushPin, contentDescription = null) },
|
||||
onClick = {
|
||||
menuOpen = false
|
||||
viewModel.pinAsView(onPinned)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
scrollBehavior = scrollBehavior,
|
||||
)
|
||||
@@ -439,7 +467,7 @@ fun TaskListScreen(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class, ExperimentalLayoutApi::class)
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
private fun TaskListBody(
|
||||
state: TaskListUiState.Content,
|
||||
@@ -450,6 +478,75 @@ private fun TaskListBody(
|
||||
viewModel: TaskListViewModel,
|
||||
onClearCompleted: (() -> Unit)? = null,
|
||||
) {
|
||||
val rows = rememberTaskRows(state, filter, viewModel, onClearCompleted)
|
||||
val listId = (filter as? TaskFilter.OfList)?.listId
|
||||
// When the bottom quick-add bar is shown it already lives in the scaffold's
|
||||
// bottomBar (so `inner` covers it); otherwise reserve room to clear the FAB.
|
||||
val bottomBarShown = state.bottomAddBar && listId != null
|
||||
// While typing, the viewport ends at the keyboard (or at the quick-add bar
|
||||
// riding on it), so a focused add-subtask row can scroll fully above it.
|
||||
val imeVisible = WindowInsets.isImeVisible
|
||||
val viewport = when {
|
||||
!imeVisible -> Modifier
|
||||
bottomBarShown -> Modifier.padding(bottom = inner.calculateBottomPadding())
|
||||
else -> Modifier.imePadding()
|
||||
}
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize().then(viewport),
|
||||
contentPadding = PaddingValues(
|
||||
top = inner.calculateTopPadding() + 8.dp,
|
||||
// While typing the viewport already ends above the bar or keyboard.
|
||||
bottom = (if (imeVisible) 0.dp else inner.calculateBottomPadding()) +
|
||||
if (bottomBarShown) 16.dp else 96.dp,
|
||||
),
|
||||
) {
|
||||
state.scope?.let { scope ->
|
||||
item(key = "scope") { ScopeChipRow(scope, onDrop = viewModel::dropScope) }
|
||||
}
|
||||
if (state.tasks.isEmpty()) {
|
||||
val empty = if (state.hiddenByRange && state.selectedTags.isEmpty()) {
|
||||
R.string.upcoming_range_empty
|
||||
} else {
|
||||
R.string.task_list_empty
|
||||
}
|
||||
item(key = "empty") { EmptyState(stringResource(empty)) }
|
||||
}
|
||||
taskRows(rows, onOpenTask, onRequestDelete, viewModel)
|
||||
}
|
||||
}
|
||||
|
||||
/** The removable chip naming the view whose scope narrows a task screen. */
|
||||
@Composable
|
||||
private fun ScopeChipRow(scope: ScopeChip, onDrop: () -> Unit) {
|
||||
Row(Modifier.fillMaxWidth().padding(horizontal = 16.dp).padding(bottom = 8.dp)) {
|
||||
ScopeInputChip(name = viewName(scope.name, scope.viewId), icon = scope.icon, onDrop = onDrop)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A task screen's rows as grouped and folded: what [taskRows] lays out. Holds
|
||||
* which parents are expanded, and reports the ones whose subtasks it has to
|
||||
* fetch to [viewModel].
|
||||
*/
|
||||
internal class TaskRows(
|
||||
val state: TaskListUiState.Content,
|
||||
val groups: List<TaskGroup>,
|
||||
val showHeaders: Boolean,
|
||||
val sharedListNames: Set<String>,
|
||||
val mixedView: Boolean,
|
||||
val expandedParents: Set<Long>,
|
||||
val toggleExpanded: (Long) -> Unit,
|
||||
val childrenOf: (Task) -> List<Task>,
|
||||
val onClearCompleted: (() -> Unit)?,
|
||||
)
|
||||
|
||||
@Composable
|
||||
internal fun rememberTaskRows(
|
||||
state: TaskListUiState.Content,
|
||||
filter: TaskFilter,
|
||||
viewModel: TaskListViewModel,
|
||||
onClearCompleted: (() -> Unit)? = null,
|
||||
): TaskRows {
|
||||
val todayStart = state.todayStart
|
||||
val todayEnd = state.todayEnd
|
||||
// A parent represents its children via a progress chip (counts come from the
|
||||
@@ -478,11 +575,12 @@ private fun TaskListBody(
|
||||
groups.mapNotNull { (it.key as? TaskGroupKey.OfList)?.name }.groupingBy { it }.eachCount()
|
||||
.filterValues { it > 1 }.keys
|
||||
}
|
||||
val listId = (filter as? TaskFilter.OfList)?.listId
|
||||
// In a mixed view (a smart list) the list colour bar + name disambiguate
|
||||
// rows; inside a single real list both are redundant.
|
||||
val mixedView = filter is TaskFilter.Smart || filter is TaskFilter.Tagged ||
|
||||
(filter is TaskFilter.Saved && state.savedFilter?.criteria?.listIds?.size != 1)
|
||||
// rows; inside a single real list, or a scope of one, both are redundant.
|
||||
val mixedView = state.scopeLists?.size != 1 && (
|
||||
filter is TaskFilter.Smart || filter is TaskFilter.Tagged ||
|
||||
(filter is TaskFilter.Saved && state.savedFilter?.criteria?.listIds?.size != 1)
|
||||
)
|
||||
// Parents the user expanded to reveal their subtasks inline. Children are
|
||||
// grouped from the same flat task set the list already holds.
|
||||
var expandedParents by rememberSaveable { mutableStateOf(emptySet<Long>()) }
|
||||
@@ -500,157 +598,148 @@ private fun TaskListBody(
|
||||
}.toSet()
|
||||
LaunchedEffect(parentsNeedingChildren) { viewModel.setLazyChildParents(parentsNeedingChildren) }
|
||||
val lazyChildren by viewModel.lazyChildren.collectAsStateWithLifecycle()
|
||||
// A parent's full child set: the rows already in this view when we hold them
|
||||
// all, otherwise the lazily-loaded set fetched for smart lists.
|
||||
fun childrenOf(task: Task): List<Task> {
|
||||
val inList = childrenByParent[task.taskId].orEmpty()
|
||||
return if (inList.size == task.subtaskTotal) inList else lazyChildren[task.taskId].orEmpty()
|
||||
}
|
||||
return TaskRows(
|
||||
state = state,
|
||||
groups = groups,
|
||||
showHeaders = showHeaders,
|
||||
sharedListNames = sharedListNames,
|
||||
mixedView = mixedView,
|
||||
expandedParents = expandedParents,
|
||||
toggleExpanded = { id ->
|
||||
expandedParents = if (id in expandedParents) expandedParents - id else expandedParents + id
|
||||
},
|
||||
// A parent's full child set: the rows already in this view when we hold them
|
||||
// all, otherwise the lazily-loaded set fetched for smart lists.
|
||||
childrenOf = { task ->
|
||||
val inList = childrenByParent[task.taskId].orEmpty()
|
||||
if (inList.size == task.subtaskTotal) inList else lazyChildren[task.taskId].orEmpty()
|
||||
},
|
||||
onClearCompleted = onClearCompleted,
|
||||
)
|
||||
}
|
||||
|
||||
// When the bottom quick-add bar is shown it already lives in the scaffold's
|
||||
// bottomBar (so `inner` covers it); otherwise reserve room to clear the FAB.
|
||||
val bottomBarShown = state.bottomAddBar && listId != null
|
||||
// While typing, the viewport ends at the keyboard (or at the quick-add bar
|
||||
// riding on it), so a focused add-subtask row can scroll fully above it.
|
||||
val imeVisible = WindowInsets.isImeVisible
|
||||
val viewport = when {
|
||||
!imeVisible -> Modifier
|
||||
bottomBarShown -> Modifier.padding(bottom = inner.calculateBottomPadding())
|
||||
else -> Modifier.imePadding()
|
||||
}
|
||||
LazyColumn(
|
||||
modifier = Modifier.fillMaxSize().then(viewport),
|
||||
contentPadding = PaddingValues(
|
||||
top = inner.calculateTopPadding() + 8.dp,
|
||||
// While typing the viewport already ends above the bar or keyboard.
|
||||
bottom = (if (imeVisible) 0.dp else inner.calculateBottomPadding()) +
|
||||
if (bottomBarShown) 16.dp else 96.dp,
|
||||
),
|
||||
) {
|
||||
if (state.tasks.isEmpty()) {
|
||||
val empty = if (state.hiddenByRange && state.selectedTags.isEmpty()) {
|
||||
R.string.upcoming_range_empty
|
||||
} else {
|
||||
R.string.task_list_empty
|
||||
/**
|
||||
* The grouped task rows of [rows]: collapsible group headers, then each group's
|
||||
* tasks with their expanded subtasks. [keyPrefix] keeps the keys apart from the
|
||||
* other items of a list they share.
|
||||
*/
|
||||
@OptIn(ExperimentalFoundationApi::class)
|
||||
internal fun LazyListScope.taskRows(
|
||||
rows: TaskRows,
|
||||
onOpenTask: (Task) -> Unit,
|
||||
onRequestDelete: (Task) -> Unit,
|
||||
viewModel: TaskListViewModel,
|
||||
keyPrefix: String = "",
|
||||
) {
|
||||
val state = rows.state
|
||||
rows.groups.forEach { group ->
|
||||
// Every header folds its section away (#91); Done starts folded.
|
||||
val groupId = group.key.id
|
||||
// Under a list's or a priority's own header the row needn't repeat it; Done mixes them all.
|
||||
val inDone = group.key == TaskGroupKey.COMPLETED
|
||||
val showListName = rows.mixedView && (state.grouping != TaskGrouping.LIST || inDone)
|
||||
val showPriority = state.grouping != TaskGrouping.PRIORITY || inDone
|
||||
val expanded = !rows.showHeaders || groupId !in state.collapsedGroups
|
||||
if (rows.showHeaders) {
|
||||
stickyHeader(key = "${keyPrefix}hdr-$groupId") {
|
||||
CollapsibleSectionHeader(
|
||||
label = groupLabel(group.key, state.todayStart, rows.sharedListNames),
|
||||
count = group.tasks.size,
|
||||
expanded = expanded,
|
||||
onToggle = { viewModel.setGroupCollapsed(groupId, expanded) },
|
||||
onClear = rows.onClearCompleted.takeIf { group.key == TaskGroupKey.COMPLETED },
|
||||
)
|
||||
}
|
||||
item(key = "empty") { EmptyState(stringResource(empty)) }
|
||||
}
|
||||
|
||||
groups.forEach { group ->
|
||||
// Every header folds its section away (#91); Done starts folded.
|
||||
val groupId = group.key.id
|
||||
// Under a list's or a priority's own header the row needn't repeat it; Done mixes them all.
|
||||
val inDone = group.key == TaskGroupKey.COMPLETED
|
||||
val showListName = mixedView && (state.grouping != TaskGrouping.LIST || inDone)
|
||||
val showPriority = state.grouping != TaskGrouping.PRIORITY || inDone
|
||||
val expanded = !showHeaders || groupId !in state.collapsedGroups
|
||||
if (showHeaders) {
|
||||
stickyHeader(key = "hdr-$groupId") {
|
||||
CollapsibleSectionHeader(
|
||||
label = groupLabel(group.key, todayStart, sharedListNames),
|
||||
count = group.tasks.size,
|
||||
expanded = expanded,
|
||||
onToggle = { viewModel.setGroupCollapsed(groupId, expanded) },
|
||||
onClear = onClearCompleted.takeIf { group.key == TaskGroupKey.COMPLETED },
|
||||
if (expanded) {
|
||||
// Flatten the section into one grouped run: each parent, followed
|
||||
// by its subtasks when expanded. Each row's corners then come from
|
||||
// its place in the whole run (positionOf below) — so the children
|
||||
// read as a grouped list nested in the list's grouped list:
|
||||
// full-width, connecting to the parent above (small top corners),
|
||||
// and the run rounds off (full corners) only at its genuine ends.
|
||||
val run = buildList {
|
||||
val topLevel = group.tasks
|
||||
topLevel.forEachIndexed { p, task ->
|
||||
// The full child set — already in this view for a real list,
|
||||
// or fetched on demand for a smart list (childrenOf). A parent
|
||||
// is expandable whenever it has children; until a smart list's
|
||||
// set has loaded the group simply shows nothing extra.
|
||||
val children = rows.childrenOf(task)
|
||||
val canExpand = task.subtaskTotal > 0
|
||||
val isExpanded = canExpand && task.taskId in rows.expandedParents
|
||||
// No quick-add into a read-only share: it would never upload.
|
||||
val showAdd = state.showAddSubtaskRow && !task.isReadOnly
|
||||
val hasExpansionContent = children.isNotEmpty() || showAdd
|
||||
// Top-level tasks keep their own connected run — full top
|
||||
// only on the first, full bottom only on the last — so the
|
||||
// task after an expanded one stays mid-run (small top). An
|
||||
// expanded parent's bottom opens (small) to meet its subtasks.
|
||||
val parentPosition = cornerPosition(
|
||||
topFull = p == 0,
|
||||
bottomFull = if (isExpanded && hasExpansionContent) false else p == topLevel.lastIndex,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (expanded) {
|
||||
// Flatten the section into one grouped run: each parent, followed
|
||||
// by its subtasks when expanded. Each row's corners then come from
|
||||
// its place in the whole run (positionOf below) — so the children
|
||||
// read as a grouped list nested in the list's grouped list:
|
||||
// full-width, connecting to the parent above (small top corners),
|
||||
// and the run rounds off (full corners) only at its genuine ends.
|
||||
val rows = buildList {
|
||||
val topLevel = group.tasks
|
||||
topLevel.forEachIndexed { p, task ->
|
||||
// The full child set — already in this view for a real list,
|
||||
// or fetched on demand for a smart list (childrenOf). A parent
|
||||
// is expandable whenever it has children; until a smart list's
|
||||
// set has loaded the group simply shows nothing extra.
|
||||
val children = childrenOf(task)
|
||||
val canExpand = task.subtaskTotal > 0
|
||||
val isExpanded = canExpand && task.taskId in expandedParents
|
||||
// No quick-add into a read-only share: it would never upload.
|
||||
val showAdd = state.showAddSubtaskRow && !task.isReadOnly
|
||||
val hasExpansionContent = children.isNotEmpty() || showAdd
|
||||
// Top-level tasks keep their own connected run — full top
|
||||
// only on the first, full bottom only on the last — so the
|
||||
// task after an expanded one stays mid-run (small top). An
|
||||
// expanded parent's bottom opens (small) to meet its subtasks.
|
||||
val parentPosition = cornerPosition(
|
||||
topFull = p == 0,
|
||||
bottomFull = if (isExpanded && hasExpansionContent) false else p == topLevel.lastIndex,
|
||||
)
|
||||
add(RenderRow(ListRow.Parent(task, canExpand, isExpanded), parentPosition))
|
||||
if (isExpanded) {
|
||||
// When the add row is hidden (M5 setting), the last subtask
|
||||
// instead rounds the group off (full bottom).
|
||||
val sorted = children.sortedBy { it.isCompleted }
|
||||
sorted.forEachIndexed { c, sub ->
|
||||
// Subtasks connect up to the parent (small top); with the
|
||||
// add row present every subtask is mid-run, otherwise the
|
||||
// last one closes the group (full bottom).
|
||||
val closesGroup = !showAdd && c == sorted.lastIndex
|
||||
add(RenderRow(ListRow.Sub(sub), cornerPosition(topFull = false, bottomFull = closesGroup)))
|
||||
}
|
||||
// The add row rounds the group off (full bottom),
|
||||
// independent of whatever top-level task follows.
|
||||
if (showAdd) {
|
||||
add(RenderRow(ListRow.AddSub(task), cornerPosition(topFull = false, bottomFull = true)))
|
||||
}
|
||||
add(RenderRow(ListRow.Parent(task, canExpand, isExpanded), parentPosition))
|
||||
if (isExpanded) {
|
||||
// When the add row is hidden (M5 setting), the last subtask
|
||||
// instead rounds the group off (full bottom).
|
||||
val sorted = children.sortedBy { it.isCompleted }
|
||||
sorted.forEachIndexed { c, sub ->
|
||||
// Subtasks connect up to the parent (small top); with the
|
||||
// add row present every subtask is mid-run, otherwise the
|
||||
// last one closes the group (full bottom).
|
||||
val closesGroup = !showAdd && c == sorted.lastIndex
|
||||
add(RenderRow(ListRow.Sub(sub), cornerPosition(topFull = false, bottomFull = closesGroup)))
|
||||
}
|
||||
// The add row rounds the group off (full bottom),
|
||||
// independent of whatever top-level task follows.
|
||||
if (showAdd) {
|
||||
add(RenderRow(ListRow.AddSub(task), cornerPosition(topFull = false, bottomFull = true)))
|
||||
}
|
||||
}
|
||||
}
|
||||
itemsIndexed(rows, key = { _, r -> r.row.key }) { index, r ->
|
||||
val lastInRun = index == rows.lastIndex
|
||||
// animateItem so an (un)expanding group fades its subtasks in/out
|
||||
// and slides the rows below — clean whether the children were
|
||||
// already loaded (real list) or arrive a frame later (smart list).
|
||||
val rowModifier = Modifier.animateItem()
|
||||
when (val row = r.row) {
|
||||
is ListRow.Parent -> TaskRow(
|
||||
modifier = rowModifier,
|
||||
task = row.task,
|
||||
position = r.position,
|
||||
lastInRun = lastInRun,
|
||||
showListName = showListName,
|
||||
showPriority = showPriority,
|
||||
subtaskDone = row.task.subtaskDone,
|
||||
subtaskTotal = row.task.subtaskTotal,
|
||||
expanded = row.expanded,
|
||||
onToggleExpand = if (row.expandable) {
|
||||
{
|
||||
expandedParents = if (row.task.taskId in expandedParents) {
|
||||
expandedParents - row.task.taskId
|
||||
} else {
|
||||
expandedParents + row.task.taskId
|
||||
}
|
||||
}
|
||||
} else {
|
||||
null
|
||||
},
|
||||
onToggle = { viewModel.toggleComplete(row.task) },
|
||||
onDelete = { onRequestDelete(row.task) },
|
||||
onClick = { onOpenTask(row.task) },
|
||||
)
|
||||
is ListRow.Sub -> SubtaskRow(
|
||||
modifier = rowModifier,
|
||||
task = row.task,
|
||||
position = r.position,
|
||||
lastInRun = lastInRun,
|
||||
onToggle = { viewModel.toggleComplete(row.task) },
|
||||
onDelete = { onRequestDelete(row.task) },
|
||||
onClick = { onOpenTask(row.task) },
|
||||
)
|
||||
is ListRow.AddSub -> AddSubtaskRow(
|
||||
modifier = rowModifier,
|
||||
position = r.position,
|
||||
lastInRun = lastInRun,
|
||||
onAdd = { viewModel.quickAddSubtask(row.parent, it) },
|
||||
)
|
||||
}
|
||||
}
|
||||
itemsIndexed(run, key = { _, r -> keyPrefix + r.row.key }) { index, r ->
|
||||
val lastInRun = index == run.lastIndex
|
||||
// animateItem so an (un)expanding group fades its subtasks in/out
|
||||
// and slides the rows below — clean whether the children were
|
||||
// already loaded (real list) or arrive a frame later (smart list).
|
||||
val rowModifier = Modifier.animateItem()
|
||||
when (val row = r.row) {
|
||||
is ListRow.Parent -> TaskRow(
|
||||
modifier = rowModifier,
|
||||
task = row.task,
|
||||
position = r.position,
|
||||
lastInRun = lastInRun,
|
||||
showListName = showListName,
|
||||
showPriority = showPriority,
|
||||
subtaskDone = row.task.subtaskDone,
|
||||
subtaskTotal = row.task.subtaskTotal,
|
||||
expanded = row.expanded,
|
||||
onToggleExpand = if (row.expandable) {
|
||||
{ rows.toggleExpanded(row.task.taskId) }
|
||||
} else {
|
||||
null
|
||||
},
|
||||
onToggle = { viewModel.toggleComplete(row.task) },
|
||||
onDelete = { onRequestDelete(row.task) },
|
||||
onClick = { onOpenTask(row.task) },
|
||||
)
|
||||
is ListRow.Sub -> SubtaskRow(
|
||||
modifier = rowModifier,
|
||||
task = row.task,
|
||||
position = r.position,
|
||||
lastInRun = lastInRun,
|
||||
onToggle = { viewModel.toggleComplete(row.task) },
|
||||
onDelete = { onRequestDelete(row.task) },
|
||||
onClick = { onOpenTask(row.task) },
|
||||
)
|
||||
is ListRow.AddSub -> AddSubtaskRow(
|
||||
modifier = rowModifier,
|
||||
position = r.position,
|
||||
lastInRun = lastInRun,
|
||||
onAdd = { viewModel.quickAddSubtask(row.parent, it) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,14 @@ import de.jeanlucmakiola.agendula.data.tasks.FilteredTasks
|
||||
import de.jeanlucmakiola.agendula.data.tasks.StorageMode
|
||||
import de.jeanlucmakiola.agendula.data.tasks.TasksRepository
|
||||
import de.jeanlucmakiola.agendula.data.tasks.recoveringFromProviderFailure
|
||||
import de.jeanlucmakiola.agendula.domain.AppliedScope
|
||||
import de.jeanlucmakiola.agendula.domain.ListSearchResult
|
||||
import de.jeanlucmakiola.agendula.domain.RuleClock
|
||||
import de.jeanlucmakiola.agendula.domain.View
|
||||
import de.jeanlucmakiola.agendula.domain.ViewIcon
|
||||
import de.jeanlucmakiola.agendula.domain.appliedScope
|
||||
import de.jeanlucmakiola.agendula.ui.views.ViewSession
|
||||
import de.jeanlucmakiola.agendula.domain.pinnedViewOf
|
||||
import de.jeanlucmakiola.agendula.domain.SavedFilter
|
||||
import de.jeanlucmakiola.agendula.domain.SmartList
|
||||
import de.jeanlucmakiola.agendula.domain.Task
|
||||
@@ -107,6 +114,12 @@ sealed interface TaskListUiState {
|
||||
val filter: TaskFilter? = null,
|
||||
/** A real list's tasks before the tag filter narrows them, which its search looks through; empty elsewhere. */
|
||||
val searchable: List<Task> = emptyList(),
|
||||
/** The view whose scope narrows these tasks, shown as a chip that drops it; `null` when none does. */
|
||||
val scope: ScopeChip? = null,
|
||||
/** The lists a task in [scope] can be in; `null` when any. */
|
||||
val scopeLists: Set<Long>? = null,
|
||||
/** [scope]'s rule as it applies, which the rows are read through. */
|
||||
val appliedScope: AppliedScope? = null,
|
||||
) : TaskListUiState {
|
||||
/** Upcoming, narrowed to a time frame the user picked. */
|
||||
val upcomingLimited: Boolean
|
||||
@@ -134,6 +147,20 @@ sealed interface SearchReceipt {
|
||||
class Failed : SearchReceipt
|
||||
}
|
||||
|
||||
/** The view a task screen is narrowed to, by its scope. [listsGone]: the scope names a list since deleted. */
|
||||
data class ScopeChip(val viewId: Long, val name: String, val icon: ViewIcon, val listsGone: Boolean)
|
||||
|
||||
/**
|
||||
* 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).
|
||||
*/
|
||||
data class TaskListBinding(
|
||||
val filter: TaskFilter,
|
||||
val scopeViewId: Long? = null,
|
||||
val withCompleted: Boolean = false,
|
||||
)
|
||||
|
||||
private const val PENDING_ADD_TIMEOUT_MS = 30_000L
|
||||
private const val KEY_SEARCH_ACTIVE = "task_search_active"
|
||||
private const val KEY_SEARCH_QUERY = "task_search_query"
|
||||
@@ -150,6 +177,7 @@ class TaskListViewModel @Inject constructor(
|
||||
private val widgetUpdater: TaskWidgetUpdater,
|
||||
@ApplicationScope private val appScope: CoroutineScope,
|
||||
private val savedState: SavedStateHandle,
|
||||
private val viewSession: ViewSession,
|
||||
) : ViewModel() {
|
||||
|
||||
/** Pull to sync (#73); off without an account. */
|
||||
@@ -159,7 +187,12 @@ class TaskListViewModel @Inject constructor(
|
||||
|
||||
fun syncAll() = manualSync.syncAll()
|
||||
|
||||
private val filter = MutableStateFlow<TaskFilter?>(null)
|
||||
private val binding = MutableStateFlow<TaskListBinding?>(null)
|
||||
|
||||
/** The binding last asked for; a repeat of it keeps a scope the user dropped dropped. */
|
||||
private var requested: TaskListBinding? = null
|
||||
|
||||
private val filter: TaskFilter? get() = binding.value?.filter
|
||||
|
||||
private val tagFilter = MutableStateFlow<Set<String>>(emptySet())
|
||||
|
||||
@@ -186,18 +219,30 @@ class TaskListViewModel @Inject constructor(
|
||||
}.distinctUntilChanged()
|
||||
|
||||
val state: StateFlow<TaskListUiState> =
|
||||
filter.filterNotNull()
|
||||
.flatMapLatest { f ->
|
||||
binding.filterNotNull()
|
||||
.flatMapLatest { b ->
|
||||
val f = b.filter
|
||||
val source: Flow<FilteredTasks> = when (f) {
|
||||
is TaskFilter.Saved -> repository.filteredTasks(f)
|
||||
is TaskFilter.OfList, is TaskFilter.Smart, is TaskFilter.Tagged ->
|
||||
is TaskFilter.Smart -> if (b.withCompleted && f.list == SmartList.ALL) {
|
||||
combine(repository.tasks(f), repository.tasks(TaskFilter.Smart(SmartList.COMPLETED))) { open, done ->
|
||||
FilteredTasks(open + done)
|
||||
}
|
||||
} else {
|
||||
repository.tasks(f).map { FilteredTasks(it) }
|
||||
}
|
||||
is TaskFilter.OfList, is TaskFilter.Tagged -> repository.tasks(f).map { FilteredTasks(it) }
|
||||
// Several lists at once only exists for the widget, which never routes here.
|
||||
is TaskFilter.OfLists -> error("OfLists has no task-list screen")
|
||||
}
|
||||
// A view since deleted, or left without a scope, narrows nothing.
|
||||
val scopeView: Flow<View?> = b.scopeViewId
|
||||
?.let { id -> settingsPrefs.views.map { views -> views.firstOrNull { it.id == id && it.scope != null } } }
|
||||
?: flowOf(null)
|
||||
// Each read carries the day it was made for, so rows and groups always agree.
|
||||
val rows = dayWindow.flatMapLatest { window -> source.map { window to it } }
|
||||
val content: Flow<TaskListUiState> = combine(rows, repository.taskLists()) { (window, found), lists ->
|
||||
val content: Flow<TaskListUiState> = combine(rows, repository.taskLists(), scopeView) { (window, found), lists, view ->
|
||||
val applied = view?.appliedScope(lists.mapTo(HashSet()) { it.id })
|
||||
TaskListUiState.Content(
|
||||
tasks = found.tasks,
|
||||
list = (f as? TaskFilter.OfList)?.let { of -> lists.firstOrNull { it.id == of.listId } },
|
||||
@@ -205,6 +250,9 @@ class TaskListViewModel @Inject constructor(
|
||||
listOrder = lists.map { it.id },
|
||||
todayStart = window.first,
|
||||
todayEnd = window.second,
|
||||
scope = view?.let { ScopeChip(it.id, it.name, it.icon, applied?.goneLists?.isNotEmpty() == true) },
|
||||
scopeLists = applied?.lists,
|
||||
appliedScope = applied,
|
||||
)
|
||||
}
|
||||
// Drop rows pending an undoable delete so the row vanishes on swipe
|
||||
@@ -213,8 +261,13 @@ class TaskListViewModel @Inject constructor(
|
||||
combine(content, pendingDeletes, settingsPrefs.settings, tagFilter) { st, pending, settings, tags ->
|
||||
if (st is TaskListUiState.Content) {
|
||||
val now = Clock.System.now()
|
||||
val (inView, hiddenByRange) = settings.viewOf(f, st.tasks, now)
|
||||
val visible = inView.filter { it.occurrenceKey !in pending }
|
||||
val scope = st.appliedScope
|
||||
// A scope that names a list shows it even where the smart lists leave it out.
|
||||
val shownBy = scope?.let { settings.copy(hiddenFromSmartLists = it.hiddenFromSmart(settings.hiddenFromSmartLists)) }
|
||||
?: 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 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.
|
||||
@@ -280,12 +333,38 @@ class TaskListViewModel @Inject constructor(
|
||||
/** The screen reports which expanded parents need their children fetched. */
|
||||
fun setLazyChildParents(ids: Set<Long>) { lazyChildParents.value = ids }
|
||||
|
||||
fun bind(taskFilter: TaskFilter) {
|
||||
if (filter.value != null && filter.value != taskFilter) {
|
||||
/**
|
||||
* Shows [taskFilter]'s tasks, within the scope of view [scopeViewId] when set
|
||||
* (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)
|
||||
if (next == requested) return
|
||||
if (filter != null && filter != taskFilter) {
|
||||
closeSearch()
|
||||
pendingAdds.clear()
|
||||
}
|
||||
filter.value = taskFilter
|
||||
requested = next
|
||||
binding.value = next
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes this list or saved filter a view of its own (#59) and switches to it,
|
||||
* then calls [onPinned]. Nothing happens on a screen that is neither.
|
||||
*/
|
||||
fun pinAsView(onPinned: () -> Unit) {
|
||||
val content = state.value as? TaskListUiState.Content ?: return
|
||||
val view = pinnedViewOf(content.list, content.savedFilter) ?: return
|
||||
viewModelScope.launch {
|
||||
viewSession.switchTo(settingsPrefs.saveView(view))
|
||||
onPinned()
|
||||
}
|
||||
}
|
||||
|
||||
/** Drops the view's scope, the chip's ✕: the screen shows all of its tasks. */
|
||||
fun dropScope() {
|
||||
binding.update { it?.copy(scopeViewId = null) }
|
||||
}
|
||||
|
||||
fun toggleTagFilter(tag: String) {
|
||||
@@ -378,7 +457,7 @@ class TaskListViewModel @Inject constructor(
|
||||
viewModelScope.launch { settingsPrefs.setGroupCollapsed(id, collapsed) }
|
||||
|
||||
fun setGrouping(grouping: TaskGrouping) {
|
||||
val f = filter.value ?: return
|
||||
val f = filter ?: return
|
||||
viewModelScope.launch { settingsPrefs.setGrouping(f, grouping) }
|
||||
}
|
||||
|
||||
@@ -431,7 +510,7 @@ class TaskListViewModel @Inject constructor(
|
||||
private fun searchable(): List<Task> = searchableIn(state.value)
|
||||
|
||||
private fun searchableIn(state: TaskListUiState): List<Task> =
|
||||
(state as? TaskListUiState.Content)?.takeIf { it.filter == filter.value }?.searchable.orEmpty()
|
||||
(state as? TaskListUiState.Content)?.takeIf { it.filter == filter }?.searchable.orEmpty()
|
||||
|
||||
/** The list search for the current query (#95); idle while the query is blank. */
|
||||
val search: StateFlow<ListSearchResult> =
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package de.jeanlucmakiola.agendula.ui.views
|
||||
|
||||
import de.jeanlucmakiola.agendula.data.di.ApplicationScope
|
||||
import de.jeanlucmakiola.agendula.data.prefs.SettingsPrefs
|
||||
import de.jeanlucmakiola.agendula.data.tasks.TasksRepository
|
||||
import de.jeanlucmakiola.agendula.domain.StartDestination
|
||||
import de.jeanlucmakiola.agendula.domain.TaskFilter
|
||||
import de.jeanlucmakiola.agendula.domain.plan
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
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.launch
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Which view home shows. A switch shows at once and is stored as the last used
|
||||
* view behind it; [start] picks the view a fresh launch opens on (#141).
|
||||
*/
|
||||
@Singleton
|
||||
class ViewSession @Inject constructor(
|
||||
private val prefs: SettingsPrefs,
|
||||
private val repository: TasksRepository,
|
||||
@ApplicationScope private val appScope: CoroutineScope,
|
||||
) {
|
||||
private val chosen = MutableStateFlow<Long?>(null)
|
||||
private val _starting = MutableStateFlow(false)
|
||||
|
||||
/** Set while a launch works out its start destination; home waits rather than flash the last view. */
|
||||
val starting: StateFlow<Boolean> = _starting.asStateFlow()
|
||||
|
||||
/** The view shown: the one just picked, else the last used one stored. It may since have been deleted. */
|
||||
val activeViewId: Flow<Long> =
|
||||
combine(prefs.activeViewId, chosen) { stored, picked -> picked ?: stored }.distinctUntilChanged()
|
||||
|
||||
fun switchTo(viewId: Long) {
|
||||
chosen.value = viewId
|
||||
appScope.launch { prefs.setActiveView(viewId) }
|
||||
}
|
||||
|
||||
/** Call before the first frame of a fresh launch, then [start]. */
|
||||
fun beginStart() {
|
||||
_starting.value = true
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the start destination: switches to its view, and returns the list or
|
||||
* filter to open over it, if it is one that still exists.
|
||||
*/
|
||||
suspend fun start(): TaskFilter? {
|
||||
try {
|
||||
val destination = prefs.startDestination.first()
|
||||
val views = prefs.views.first().mapTo(HashSet()) { it.id }
|
||||
val filters = prefs.savedFilters.first().mapTo(HashSet()) { it.id }
|
||||
val lastUsed = prefs.activeViewId.first()
|
||||
// The view doesn't depend on the lists, so home shows before they are read.
|
||||
val viewId = destination.plan(views, lastUsed, null, filters).viewId
|
||||
if (viewId != lastUsed || chosen.value != null) switchTo(viewId)
|
||||
_starting.value = false
|
||||
if (destination !is StartDestination.List) return destination.plan(views, lastUsed, null, filters).push
|
||||
val lists = withTimeoutOrNull(LISTS_TIMEOUT_MS) {
|
||||
runCatching { repository.taskLists().first().mapTo(HashSet()) { it.id } }.getOrNull()
|
||||
}
|
||||
return destination.plan(views, lastUsed, lists, filters).push
|
||||
} finally {
|
||||
_starting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val LISTS_TIMEOUT_MS = 2_000L
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,173 @@
|
||||
package de.jeanlucmakiola.agendula.ui.views
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.MenuBook
|
||||
import androidx.compose.material.icons.rounded.AccountTree
|
||||
import androidx.compose.material.icons.rounded.Alarm
|
||||
import androidx.compose.material.icons.rounded.Apps
|
||||
import androidx.compose.material.icons.rounded.Archive
|
||||
import androidx.compose.material.icons.rounded.Bolt
|
||||
import androidx.compose.material.icons.rounded.BugReport
|
||||
import androidx.compose.material.icons.rounded.Build
|
||||
import androidx.compose.material.icons.rounded.CalendarMonth
|
||||
import androidx.compose.material.icons.rounded.Checklist
|
||||
import androidx.compose.material.icons.rounded.Close
|
||||
import androidx.compose.material.icons.rounded.Code
|
||||
import androidx.compose.material.icons.rounded.Description
|
||||
import androidx.compose.material.icons.rounded.Devices
|
||||
import androidx.compose.material.icons.rounded.Favorite
|
||||
import androidx.compose.material.icons.rounded.FilterList
|
||||
import androidx.compose.material.icons.rounded.FitnessCenter
|
||||
import androidx.compose.material.icons.rounded.Flag
|
||||
import androidx.compose.material.icons.rounded.Flight
|
||||
import androidx.compose.material.icons.rounded.Folder
|
||||
import androidx.compose.material.icons.rounded.Group
|
||||
import androidx.compose.material.icons.rounded.History
|
||||
import androidx.compose.material.icons.rounded.Home
|
||||
import androidx.compose.material.icons.rounded.Inbox
|
||||
import androidx.compose.material.icons.rounded.Lightbulb
|
||||
import androidx.compose.material.icons.rounded.Notifications
|
||||
import androidx.compose.material.icons.rounded.Palette
|
||||
import androidx.compose.material.icons.rounded.Payments
|
||||
import androidx.compose.material.icons.rounded.Person
|
||||
import androidx.compose.material.icons.rounded.Pets
|
||||
import androidx.compose.material.icons.rounded.Place
|
||||
import androidx.compose.material.icons.rounded.Public
|
||||
import androidx.compose.material.icons.rounded.Restaurant
|
||||
import androidx.compose.material.icons.rounded.School
|
||||
import androidx.compose.material.icons.rounded.Sell
|
||||
import androidx.compose.material.icons.rounded.ShoppingCart
|
||||
import androidx.compose.material.icons.rounded.Star
|
||||
import androidx.compose.material.icons.rounded.TaskAlt
|
||||
import androidx.compose.material.icons.rounded.Today
|
||||
import androidx.compose.material.icons.rounded.Work
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.InputChip
|
||||
import androidx.compose.material3.InputChipDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import de.jeanlucmakiola.agendula.R
|
||||
import de.jeanlucmakiola.agendula.domain.View
|
||||
import de.jeanlucmakiola.agendula.domain.ViewIcon
|
||||
|
||||
/** The glyph a [ViewIcon] stands for. */
|
||||
val ViewIcon.vector: ImageVector
|
||||
get() = when (this) {
|
||||
ViewIcon.HOME -> Icons.Rounded.Home
|
||||
ViewIcon.WORK -> Icons.Rounded.Work
|
||||
ViewIcon.HEART -> Icons.Rounded.Favorite
|
||||
ViewIcon.BOLT -> Icons.Rounded.Bolt
|
||||
ViewIcon.CALENDAR -> Icons.Rounded.CalendarMonth
|
||||
ViewIcon.TODAY -> Icons.Rounded.Today
|
||||
ViewIcon.INBOX -> Icons.Rounded.Inbox
|
||||
ViewIcon.LIST -> Icons.Rounded.Checklist
|
||||
ViewIcon.DONE -> Icons.Rounded.TaskAlt
|
||||
ViewIcon.FLAG -> Icons.Rounded.Flag
|
||||
ViewIcon.PERSON -> Icons.Rounded.Person
|
||||
ViewIcon.GROUP -> Icons.Rounded.Group
|
||||
ViewIcon.STAR -> Icons.Rounded.Star
|
||||
ViewIcon.FILTER -> Icons.Rounded.FilterList
|
||||
ViewIcon.TAG -> Icons.Rounded.Sell
|
||||
ViewIcon.FOLDER -> Icons.Rounded.Folder
|
||||
ViewIcon.ARCHIVE -> Icons.Rounded.Archive
|
||||
ViewIcon.ALARM -> Icons.Rounded.Alarm
|
||||
ViewIcon.NOTIFICATIONS -> Icons.Rounded.Notifications
|
||||
ViewIcon.LIGHTBULB -> Icons.Rounded.Lightbulb
|
||||
ViewIcon.SCHOOL -> Icons.Rounded.School
|
||||
ViewIcon.BOOK -> Icons.AutoMirrored.Rounded.MenuBook
|
||||
ViewIcon.SHOPPING -> Icons.Rounded.ShoppingCart
|
||||
ViewIcon.MONEY -> Icons.Rounded.Payments
|
||||
ViewIcon.FITNESS -> Icons.Rounded.FitnessCenter
|
||||
ViewIcon.PETS -> Icons.Rounded.Pets
|
||||
ViewIcon.RESTAURANT -> Icons.Rounded.Restaurant
|
||||
ViewIcon.FLIGHT -> Icons.Rounded.Flight
|
||||
ViewIcon.PLACE -> Icons.Rounded.Place
|
||||
ViewIcon.GLOBE -> Icons.Rounded.Public
|
||||
ViewIcon.PALETTE -> Icons.Rounded.Palette
|
||||
ViewIcon.DEVICES -> Icons.Rounded.Devices
|
||||
ViewIcon.CODE -> Icons.Rounded.Code
|
||||
ViewIcon.BUG -> Icons.Rounded.BugReport
|
||||
ViewIcon.BUILD -> Icons.Rounded.Build
|
||||
ViewIcon.NOTE -> Icons.Rounded.Description
|
||||
ViewIcon.HISTORY -> Icons.Rounded.History
|
||||
ViewIcon.GRID -> Icons.Rounded.Apps
|
||||
ViewIcon.TREE -> Icons.Rounded.AccountTree
|
||||
}
|
||||
|
||||
/** What a [ViewIcon] is called, for the icon row and screen readers. */
|
||||
@get:StringRes
|
||||
val ViewIcon.label: Int
|
||||
get() = when (this) {
|
||||
ViewIcon.HOME -> R.string.view_icon_home
|
||||
ViewIcon.WORK -> R.string.view_icon_work
|
||||
ViewIcon.HEART -> R.string.view_icon_heart
|
||||
ViewIcon.BOLT -> R.string.view_icon_bolt
|
||||
ViewIcon.CALENDAR -> R.string.view_icon_calendar
|
||||
ViewIcon.TODAY -> R.string.view_icon_today
|
||||
ViewIcon.INBOX -> R.string.view_icon_inbox
|
||||
ViewIcon.LIST -> R.string.view_icon_list
|
||||
ViewIcon.DONE -> R.string.view_icon_done
|
||||
ViewIcon.FLAG -> R.string.view_icon_flag
|
||||
ViewIcon.PERSON -> R.string.view_icon_person
|
||||
ViewIcon.GROUP -> R.string.view_icon_group
|
||||
ViewIcon.STAR -> R.string.view_icon_star
|
||||
ViewIcon.FILTER -> R.string.view_icon_filter
|
||||
ViewIcon.TAG -> R.string.view_icon_tag
|
||||
ViewIcon.FOLDER -> R.string.view_icon_folder
|
||||
ViewIcon.ARCHIVE -> R.string.view_icon_archive
|
||||
ViewIcon.ALARM -> R.string.view_icon_alarm
|
||||
ViewIcon.NOTIFICATIONS -> R.string.view_icon_notifications
|
||||
ViewIcon.LIGHTBULB -> R.string.view_icon_lightbulb
|
||||
ViewIcon.SCHOOL -> R.string.view_icon_school
|
||||
ViewIcon.BOOK -> R.string.view_icon_book
|
||||
ViewIcon.SHOPPING -> R.string.view_icon_shopping
|
||||
ViewIcon.MONEY -> R.string.view_icon_money
|
||||
ViewIcon.FITNESS -> R.string.view_icon_fitness
|
||||
ViewIcon.PETS -> R.string.view_icon_pets
|
||||
ViewIcon.RESTAURANT -> R.string.view_icon_restaurant
|
||||
ViewIcon.FLIGHT -> R.string.view_icon_flight
|
||||
ViewIcon.PLACE -> R.string.view_icon_place
|
||||
ViewIcon.GLOBE -> R.string.view_icon_globe
|
||||
ViewIcon.PALETTE -> R.string.view_icon_palette
|
||||
ViewIcon.DEVICES -> R.string.view_icon_devices
|
||||
ViewIcon.CODE -> R.string.view_icon_code
|
||||
ViewIcon.BUG -> R.string.view_icon_bug
|
||||
ViewIcon.BUILD -> R.string.view_icon_build
|
||||
ViewIcon.NOTE -> R.string.view_icon_note
|
||||
ViewIcon.HISTORY -> R.string.view_icon_history
|
||||
ViewIcon.GRID -> R.string.view_icon_grid
|
||||
ViewIcon.TREE -> R.string.view_icon_tree
|
||||
}
|
||||
|
||||
/**
|
||||
* A view's name as shown. Home's stored name is empty until the user renames it,
|
||||
* and shows the translated "Home"; another view left without a name shows "View".
|
||||
*/
|
||||
@Composable
|
||||
fun viewName(name: String, viewId: Long): String = name.ifBlank {
|
||||
stringResource(if (viewId == View.HOME_ID) R.string.view_home else R.string.view_unnamed)
|
||||
}
|
||||
|
||||
/** The removable chip a scope shows as: the view's icon and name, ✕ to drop it. */
|
||||
@Composable
|
||||
fun ScopeInputChip(name: String, icon: ViewIcon, onDrop: () -> Unit, modifier: Modifier = Modifier) {
|
||||
InputChip(
|
||||
selected = true,
|
||||
onClick = onDrop,
|
||||
label = { Text(name) },
|
||||
avatar = { Icon(icon.vector, contentDescription = null, modifier = Modifier.size(InputChipDefaults.AvatarSize)) },
|
||||
trailingIcon = {
|
||||
Icon(
|
||||
Icons.Rounded.Close,
|
||||
contentDescription = stringResource(R.string.view_scope_drop),
|
||||
modifier = Modifier.size(InputChipDefaults.IconSize),
|
||||
)
|
||||
},
|
||||
modifier = modifier,
|
||||
)
|
||||
}
|
||||
@@ -1074,4 +1074,110 @@
|
||||
<!-- Permission another app requests to add, change or delete Agendula's tasks -->
|
||||
<string name="permission_write_tasks_label">add, change and delete Agendula tasks</string>
|
||||
<string name="permission_write_tasks_description">Allows the app to add, change, complete and delete tasks stored in Agendula, including their reminders and tags. It cannot change or delete task lists.</string>
|
||||
<!-- Views (#59): stored home layouts the top bar switches between -->
|
||||
<string name="view_home">Home</string>
|
||||
<string name="view_unnamed">View</string>
|
||||
<string name="view_switch">Switch view</string>
|
||||
<string name="view_lists_and_filters_menu">Lists & filters…</string>
|
||||
<string name="view_lists_and_filters">Lists & filters</string>
|
||||
<string name="view_manage">Manage views</string>
|
||||
<string name="view_add">New view</string>
|
||||
<string name="view_manage_hint">Drag to reorder. The order here is the order in the view menu. Every view is also an app shortcut (long-press the launcher icon).</string>
|
||||
<string name="view_reorder_handle">Drag to reorder</string>
|
||||
<plurals name="view_blocks">
|
||||
<item quantity="one">%d block</item>
|
||||
<item quantity="other">%d blocks</item>
|
||||
</plurals>
|
||||
<!-- A view's summary in Manage views: its scope, then how many blocks it has -->
|
||||
<string name="view_summary">%1$s · %2$s</string>
|
||||
<string name="view_new_title">New view</string>
|
||||
<string name="view_edit_title">Edit view</string>
|
||||
<string name="view_name_hint">Name</string>
|
||||
<string name="view_section_icon">Icon</string>
|
||||
<string name="view_section_scope">Scope</string>
|
||||
<string name="view_section_layout">Layout</string>
|
||||
<string name="view_scope_hint">Only tasks that match show in this view</string>
|
||||
<string name="view_scope_none_hint">Every task shows in this view</string>
|
||||
<string name="view_scope_blocks_hint">Every block shows its own tasks that also match the scope. A block can ignore the scope.</string>
|
||||
<string name="view_quick_add">Quick-add bar</string>
|
||||
<string name="view_quick_add_hint">A bar at the bottom of the view to add tasks</string>
|
||||
<string name="view_delete">Delete view</string>
|
||||
<string name="view_delete_title">Delete “%1$s”?</string>
|
||||
<string name="view_delete_body">The view and its layout go. Its tasks, lists and filters stay.</string>
|
||||
<string name="view_icon_title">View icon</string>
|
||||
<string name="view_icon_suggested">Suggested</string>
|
||||
<string name="view_icon_more">More</string>
|
||||
<string name="view_pin">Pin as view</string>
|
||||
<string name="view_scope_drop">Show all tasks, not just this view’s</string>
|
||||
<string name="view_source_gone">This block’s list or filter was deleted.</string>
|
||||
<string name="view_choose_source">Choose source</string>
|
||||
<string name="view_source_smart">Smart lists</string>
|
||||
<string name="view_scope_list_gone">A list in this view’s scope was deleted. That part of the scope now matches nothing.</string>
|
||||
<string name="view_edit_scope">Edit scope</string>
|
||||
<!-- A view's scope in one line, built from these pieces -->
|
||||
<string name="view_scope_everything">Everything</string>
|
||||
<string name="view_scope_nothing">Nothing</string>
|
||||
<string name="view_scope_and">%1$s and %2$s</string>
|
||||
<string name="view_scope_or">%1$s or %2$s</string>
|
||||
<string name="view_scope_not">not %1$s</string>
|
||||
<string name="view_scope_list">List %1$s</string>
|
||||
<string name="view_scope_list_deleted">(deleted)</string>
|
||||
<string name="view_scope_list_elsewhere">(other task store)</string>
|
||||
<string name="view_scope_tag">Tag %1$s</string>
|
||||
<string name="view_scope_due_overdue">Overdue</string>
|
||||
<string name="view_scope_due_today">Due today</string>
|
||||
<string name="view_scope_due_upcoming">Due later</string>
|
||||
<string name="view_scope_due_none">No due date</string>
|
||||
<string name="view_scope_due_week">Due this week</string>
|
||||
<string name="view_scope_due_month">Due this month</string>
|
||||
<plurals name="view_scope_due_next_days">
|
||||
<item quantity="one">Due within %d day</item>
|
||||
<item quantity="other">Due within %d days</item>
|
||||
</plurals>
|
||||
<string name="view_icon_home">Home</string>
|
||||
<string name="view_icon_work">Briefcase</string>
|
||||
<string name="view_icon_heart">Heart</string>
|
||||
<string name="view_icon_bolt">Lightning</string>
|
||||
<string name="view_icon_calendar">Calendar</string>
|
||||
<string name="view_icon_today">Today</string>
|
||||
<string name="view_icon_inbox">Inbox</string>
|
||||
<string name="view_icon_list">Checklist</string>
|
||||
<string name="view_icon_done">Done</string>
|
||||
<string name="view_icon_flag">Flag</string>
|
||||
<string name="view_icon_person">Person</string>
|
||||
<string name="view_icon_group">People</string>
|
||||
<string name="view_icon_star">Star</string>
|
||||
<string name="view_icon_filter">Filter</string>
|
||||
<string name="view_icon_tag">Tag</string>
|
||||
<string name="view_icon_folder">Folder</string>
|
||||
<string name="view_icon_archive">Archive</string>
|
||||
<string name="view_icon_alarm">Alarm clock</string>
|
||||
<string name="view_icon_notifications">Bell</string>
|
||||
<string name="view_icon_lightbulb">Light bulb</string>
|
||||
<string name="view_icon_school">School</string>
|
||||
<string name="view_icon_book">Book</string>
|
||||
<string name="view_icon_shopping">Shopping cart</string>
|
||||
<string name="view_icon_money">Money</string>
|
||||
<string name="view_icon_fitness">Fitness</string>
|
||||
<string name="view_icon_pets">Pets</string>
|
||||
<string name="view_icon_restaurant">Restaurant</string>
|
||||
<string name="view_icon_flight">Plane</string>
|
||||
<string name="view_icon_place">Place</string>
|
||||
<string name="view_icon_globe">Globe</string>
|
||||
<string name="view_icon_palette">Palette</string>
|
||||
<string name="view_icon_devices">Devices</string>
|
||||
<string name="view_icon_code">Code</string>
|
||||
<string name="view_icon_bug">Bug</string>
|
||||
<string name="view_icon_build">Wrench</string>
|
||||
<string name="view_icon_note">Note</string>
|
||||
<string name="view_icon_history">History</string>
|
||||
<string name="view_icon_grid">Grid</string>
|
||||
<string name="view_icon_tree">Tree</string>
|
||||
<!-- Where the app opens (#141) -->
|
||||
<string name="start_destination">Start screen</string>
|
||||
<string name="start_last_used">Last used view</string>
|
||||
<string name="start_last_used_hint">Opens on the view you had open last</string>
|
||||
<string name="start_section_views">Views</string>
|
||||
<string name="start_section_lists">Lists</string>
|
||||
<string name="start_section_filters">Filters</string>
|
||||
</resources>
|
||||
@@ -27,4 +27,11 @@ class DestinationsTest {
|
||||
assertThat(Dest.FilterEdit.build(5)).isEqualTo("filterEdit?filterId=5")
|
||||
assertThat(Dest.TaskEdit.buildNew(filterId = 5)).isEqualTo("taskEdit?filterId=5")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a list opened from a scoped view carries the view`() {
|
||||
assertThat(Dest.TaskList.build(TaskFilter.OfList(3), scopeViewId = 2)).isEqualTo("taskList?listId=3&view=2")
|
||||
assertThat(Dest.TaskList.build(TaskFilter.OfList(3))).isEqualTo("taskList?listId=3")
|
||||
assertThat(Dest.EditView.build(4)).isEqualTo("views/4")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user