Review fixes: lists rows stay lazy, no edit mode from a held drag handle, undo restores the stored block, a picked source isn't called gone, one row packing (#59)
This commit is contained in:
1 parent
2a63487c08
commit
e84e19fd5c
4 files changed
+172
-57
No files matched your search
@@ -1,5 +1,8 @@
|
||||
package de.jeanlucmakiola.agendula.domain
|
||||
|
||||
import de.jeanlucmakiola.floret.components.GridSpan
|
||||
import de.jeanlucmakiola.floret.components.gridRows
|
||||
|
||||
/**
|
||||
* A stored home layout: [blocks] in order, over the tasks [scope] admits (every
|
||||
* task when `null`). Home is the first view.
|
||||
@@ -251,27 +254,8 @@ fun List<Block>.normalized(): List<Block> {
|
||||
|
||||
/**
|
||||
* The blocks laid out in rows: a full block alone, half blocks two by two. A half
|
||||
* block followed by a full one, or by nothing, sits alone in its row.
|
||||
* block followed by a full one, or by nothing, sits alone in its row. Packed by
|
||||
* floret-kit's [gridRows], as the edit grid packs them.
|
||||
*/
|
||||
fun List<Block>.rows(): List<List<Block>> {
|
||||
val rows = mutableListOf<List<Block>>()
|
||||
var pending: Block? = null
|
||||
for (block in this) {
|
||||
val half = pending
|
||||
when {
|
||||
block.width == BlockWidth.FULL -> {
|
||||
if (half != null) rows += listOf(half)
|
||||
rows += listOf(block)
|
||||
pending = null
|
||||
}
|
||||
half == null -> pending = block
|
||||
else -> {
|
||||
rows += listOf(half, block)
|
||||
pending = null
|
||||
}
|
||||
}
|
||||
}
|
||||
pending?.let { rows += listOf(it) }
|
||||
return rows
|
||||
}
|
||||
|
||||
fun List<Block>.rows(): List<List<Block>> =
|
||||
gridRows(map { if (it.width == BlockWidth.HALF) GridSpan.Half else GridSpan.Full }).map { row -> row.map(::get) }
|
||||
@@ -442,8 +442,10 @@ internal fun BlockSettings(
|
||||
GroupedSectionHeader(stringResource(R.string.block_section_tasks))
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.block_source),
|
||||
summary = block.source?.let { sourceLabel(it, state) }?.takeIf { block.id !in state.goneSources }
|
||||
?: stringResource(R.string.view_source_gone),
|
||||
// Gone only while it is still the stored source; a newly picked one is there.
|
||||
summary = block.source?.let { sourceLabel(it, state) }?.takeUnless {
|
||||
block.id in state.goneSources && block.source == state.view.blocks.firstOrNull { it.id == block.id }?.source
|
||||
} ?: stringResource(R.string.view_source_gone),
|
||||
position = Position.Alone,
|
||||
leading = { Icon(Icons.Rounded.FilterList, contentDescription = null) },
|
||||
trailing = { Icon(Icons.Rounded.ChevronRight, contentDescription = null) },
|
||||
|
||||
@@ -19,6 +19,8 @@ import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyListScope
|
||||
import androidx.compose.foundation.lazy.itemsIndexed
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
@@ -715,9 +717,10 @@ internal fun UpcomingRow(task: Task, onClick: () -> Unit, onToggle: (() -> Unit)
|
||||
@Composable
|
||||
private fun upcomingDueLabel(task: Task): String? {
|
||||
val due = task.shownValue(TaskEnd.DUE) ?: return null
|
||||
val zone = remember { ZoneId.systemDefault() }
|
||||
val today = remember { LocalDate.now(zone) }
|
||||
val dueDate = remember(task) { task.dateOf(TaskEnd.DUE, zone) }
|
||||
// Read each time, so a row composed before midnight doesn't keep yesterday's today.
|
||||
val zone = ZoneId.systemDefault()
|
||||
val today = LocalDate.now(zone)
|
||||
val dueDate = remember(task, zone) { task.dateOf(TaskEnd.DUE, zone) }
|
||||
return when (dueDate) {
|
||||
today -> stringResource(R.string.home_due_today)
|
||||
today.plusDays(1) -> stringResource(R.string.home_due_tomorrow)
|
||||
@@ -823,31 +826,11 @@ private fun ListsBlock(
|
||||
}
|
||||
Column {
|
||||
if (showHeader) {
|
||||
SectionHeader(
|
||||
text = stringResource(R.string.lists_header),
|
||||
marked = marked,
|
||||
action = if (!actionsShown) {
|
||||
null
|
||||
} else {
|
||||
{
|
||||
ActionButton(
|
||||
shape = ActionShapes.Reorder,
|
||||
icon = if (reordering) Icons.Rounded.Check else Icons.Rounded.SwapVert,
|
||||
contentDescription = stringResource(
|
||||
if (reordering) R.string.lists_reorder_done else R.string.lists_reorder,
|
||||
),
|
||||
onClick = onToggleReorder,
|
||||
)
|
||||
ActionButton(
|
||||
shape = ActionShapes.AddList,
|
||||
morphTo = ActionShapes.AddListPressed,
|
||||
icon = Icons.Rounded.Add,
|
||||
contentDescription = stringResource(R.string.list_add),
|
||||
onClick = onNewList,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
if (actionsShown) {
|
||||
ListsHeader(marked, reordering, onToggleReorder, onNewList)
|
||||
} else {
|
||||
SectionHeader(stringResource(R.string.lists_header), marked = marked)
|
||||
}
|
||||
}
|
||||
shown.forEach { group ->
|
||||
AccountHeader(group.accountName)
|
||||
@@ -1032,3 +1015,128 @@ private fun AccountHeader(text: String) {
|
||||
modifier = Modifier.padding(start = 28.dp, end = 28.dp, top = 12.dp, bottom = 4.dp),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* The lists, tags or filters block for home's lazy column, a row per item, so a
|
||||
* long list of them is only laid out as it scrolls in. [rowModifier] goes on
|
||||
* every item; lists being reordered stay one item, as the reorder needs them.
|
||||
*/
|
||||
internal fun LazyListScope.browseBlock(
|
||||
block: Block,
|
||||
state: ListsUiState.Content,
|
||||
actions: BlockActions,
|
||||
reorderingLists: Boolean,
|
||||
onToggleReorderLists: () -> Unit,
|
||||
rowModifier: Modifier,
|
||||
) {
|
||||
val key = "block-${block.id}"
|
||||
val open = { filter: TaskFilter -> actions.openFilter(filter, actions.scopeFor(block)) }
|
||||
val sections = state.sectionsFor(block)
|
||||
when (block.type) {
|
||||
BlockType.LISTS -> {
|
||||
val options = block.options as BlockOptions.Lists
|
||||
val shown = options.accounts?.let { accounts -> sections.groups.filter { it.accountName in accounts } } ?: sections.groups
|
||||
if (state.lists.isEmpty() || reorderingLists || shown.isEmpty()) {
|
||||
item(key = key) {
|
||||
Column(rowModifier) {
|
||||
BlockBody(block, state, actions, editing = false, reorderingLists = reorderingLists, onToggleReorderLists = onToggleReorderLists)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
item(key = "$key-header") {
|
||||
ListsHeader(state.marksIgnoredScope(block), reordering = false, onToggleReorderLists, actions.newList, rowModifier)
|
||||
}
|
||||
shown.forEach { group ->
|
||||
item(key = "$key-acct-${group.accountName}") { AccountHeader(group.accountName) }
|
||||
itemsIndexed(group.lists, key = { _, o -> "$key-list-${o.list.id}" }) { index, overview ->
|
||||
GroupedRow(
|
||||
title = overview.list.name,
|
||||
position = positionOf(index, group.lists.size),
|
||||
modifier = rowModifier,
|
||||
leading = { ListColorChip(overview.list.color) },
|
||||
trailing = { if (options.counts && overview.openCount > 0) Count(overview.openCount) },
|
||||
onClick = { open(TaskFilter.OfList(overview.list.id)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
BlockType.TAGS -> {
|
||||
val tags = sections.tags
|
||||
if (tags.isEmpty()) return
|
||||
item(key = "$key-header") { SectionHeader(stringResource(R.string.tags_header), marked = state.marksIgnoredScope(block)) }
|
||||
itemsIndexed(tags, key = { _, t -> "$key-tag-${t.tag}" }) { index, overview ->
|
||||
GroupedRow(
|
||||
title = overview.tag,
|
||||
position = positionOf(index, tags.size),
|
||||
modifier = rowModifier,
|
||||
leading = { Icon(Icons.Rounded.Sell, contentDescription = null, tint = MaterialTheme.colorScheme.onSurfaceVariant) },
|
||||
trailing = { Count(overview.openCount) },
|
||||
onClick = { open(TaskFilter.Tagged(overview.tag)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
val filters = sections.filters
|
||||
if (state.lists.isEmpty() || filters.isEmpty()) {
|
||||
item(key = key) { Column(rowModifier) { BlockBody(block, state, actions, editing = false) } }
|
||||
return
|
||||
}
|
||||
item(key = "$key-header") { FiltersHeader(state.marksIgnoredScope(block), actions.newFilter) }
|
||||
itemsIndexed(filters, key = { _, f -> "$key-filter-${f.filter.id}" }) { index, overview ->
|
||||
GroupedRow(
|
||||
title = overview.filter.name,
|
||||
position = positionOf(index, filters.size),
|
||||
modifier = rowModifier,
|
||||
leading = { Icon(Icons.Rounded.FilterList, contentDescription = null, tint = MaterialTheme.colorScheme.onSurfaceVariant) },
|
||||
trailing = { Count(overview.openCount) },
|
||||
onClick = { open(TaskFilter.Saved(overview.filter.id)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The Lists header with its reorder and new-list actions. */
|
||||
@Composable
|
||||
private fun ListsHeader(marked: Boolean, reordering: Boolean, onToggleReorder: () -> Unit, onNewList: () -> Unit, modifier: Modifier = Modifier) {
|
||||
Box(modifier) {
|
||||
SectionHeader(
|
||||
text = stringResource(R.string.lists_header),
|
||||
marked = marked,
|
||||
action = {
|
||||
ActionButton(
|
||||
shape = ActionShapes.Reorder,
|
||||
icon = if (reordering) Icons.Rounded.Check else Icons.Rounded.SwapVert,
|
||||
contentDescription = stringResource(if (reordering) R.string.lists_reorder_done else R.string.lists_reorder),
|
||||
onClick = onToggleReorder,
|
||||
)
|
||||
ActionButton(
|
||||
shape = ActionShapes.AddList,
|
||||
morphTo = ActionShapes.AddListPressed,
|
||||
icon = Icons.Rounded.Add,
|
||||
contentDescription = stringResource(R.string.list_add),
|
||||
onClick = onNewList,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** The Filters header with its new-filter action. */
|
||||
@Composable
|
||||
private fun FiltersHeader(marked: Boolean, onNewFilter: () -> Unit) {
|
||||
SectionHeader(
|
||||
text = stringResource(R.string.filters_header),
|
||||
marked = marked,
|
||||
action = {
|
||||
ActionButton(
|
||||
shape = ActionShapes.AddFilter,
|
||||
morphTo = ActionShapes.AddListPressed,
|
||||
icon = Icons.Rounded.Add,
|
||||
contentDescription = stringResource(R.string.filter_new_title),
|
||||
onClick = onNewFilter,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -124,10 +124,11 @@ fun ListsScreen(
|
||||
// The block whose deleted source is being replaced.
|
||||
var choosingSourceFor by rememberSaveable { mutableStateOf<Long?>(null) }
|
||||
// Adding a block: picking its kind, then its source for a kind that takes one.
|
||||
var addingBlock by rememberSaveable { mutableStateOf(false) }
|
||||
var addingType by rememberSaveable { mutableStateOf<BlockType?>(null) }
|
||||
// Plain remember: edit mode and an open block's settings don't outlive the process either.
|
||||
var addingBlock by remember { mutableStateOf(false) }
|
||||
var addingType by remember { mutableStateOf<BlockType?>(null) }
|
||||
// The source picker over an open block's settings.
|
||||
var choosingDraftSource by rememberSaveable { mutableStateOf(false) }
|
||||
var choosingDraftSource by remember { mutableStateOf(false) }
|
||||
var confirmClear by rememberSaveable { mutableStateOf(false) }
|
||||
val editing by viewModel.editingLayout.collectAsStateWithLifecycle()
|
||||
val removed by viewModel.removed.collectAsStateWithLifecycle()
|
||||
@@ -389,7 +390,11 @@ fun ListsScreen(
|
||||
onChange = viewModel::updateDraft,
|
||||
onChooseSource = { choosingDraftSource = true },
|
||||
onSave = viewModel::saveDraft,
|
||||
onRemove = { viewModel.removeBlock(content.view.id, open.block) },
|
||||
// Undo brings back the block as stored, not with these unsaved settings.
|
||||
onRemove = {
|
||||
val stored = content.view.blocks.firstOrNull { it.id == open.block.id } ?: open.block
|
||||
viewModel.removeBlock(content.view.id, stored)
|
||||
},
|
||||
onDismiss = viewModel::closeDraft,
|
||||
)
|
||||
if (choosingDraftSource) {
|
||||
@@ -502,6 +507,19 @@ private fun ListsContent(
|
||||
}
|
||||
return@forEach
|
||||
}
|
||||
if (block.type in BROWSE && block.id !in state.goneSources) {
|
||||
// A long press on a list being dragged into place is the drag's.
|
||||
val reorderingThis = reordering == block.id
|
||||
browseBlock(
|
||||
block = block,
|
||||
state = state,
|
||||
actions = actions,
|
||||
reorderingLists = reorderingThis,
|
||||
onToggleReorderLists = { reordering = if (reorderingThis) null else block.id },
|
||||
rowModifier = if (reorderingThis) Modifier else longPress,
|
||||
)
|
||||
return@forEach
|
||||
}
|
||||
item(key = "block-${block.id}") {
|
||||
androidx.compose.foundation.layout.Column(longPress) {
|
||||
BlockBody(
|
||||
@@ -518,6 +536,9 @@ private fun ListsContent(
|
||||
}
|
||||
}
|
||||
|
||||
/** The blocks that browse the lists, tags and filters, a lazy row per item. */
|
||||
private val BROWSE = setOf(BlockType.LISTS, BlockType.TAGS, BlockType.FILTERS)
|
||||
|
||||
/** A row of tiles: two half blocks side by side, or one with an empty half beside it. */
|
||||
@Composable
|
||||
private fun HalfRow(row: List<Block>, state: ListsUiState.Content, actions: BlockActions, longPress: Modifier) {
|
||||
|
||||
Reference in new issue
Block a user