Edit layout: rearrange, resize, add and remove blocks, block settings, and the full block catalog (#59)
The new blocks are count tiles with their own title, colour and icon, a half progress tile, previews and recently completed with check-off, the week strip and section headings. Tiles follow the compact density.
This commit is contained in:
1 parent
88922adf7b
commit
8abbe79ab6
10 files changed
+2287
-751
No files matched your search
@@ -44,4 +44,13 @@ object ActionShapes {
|
||||
|
||||
/** The overflow menu — a puffy cloud. */
|
||||
val More: RoundedPolygon get() = MaterialShapes.Puffy
|
||||
|
||||
/** Add a block to a view's layout — the same burst as the other "add" actions. */
|
||||
val AddBlock: RoundedPolygon get() = MaterialShapes.Sunny
|
||||
|
||||
/** Switch a block between half and full width — a pill, wide like what it makes. */
|
||||
val ResizeBlock: RoundedPolygon get() = MaterialShapes.Pill
|
||||
|
||||
/** Take a block out of a layout — a soft burst, apart from [Delete], since it can be undone. */
|
||||
val RemoveBlock: RoundedPolygon get() = MaterialShapes.SoftBurst
|
||||
}
|
||||
@@ -0,0 +1,706 @@
|
||||
package de.jeanlucmakiola.agendula.ui.lists
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
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.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
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.layout.windowInsetsPadding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ListAlt
|
||||
import androidx.compose.material.icons.automirrored.rounded.ShortText
|
||||
import androidx.compose.material.icons.rounded.Add
|
||||
import androidx.compose.material.icons.rounded.Apps
|
||||
import androidx.compose.material.icons.rounded.CalendarViewWeek
|
||||
import androidx.compose.material.icons.rounded.Check
|
||||
import androidx.compose.material.icons.rounded.Checklist
|
||||
import androidx.compose.material.icons.rounded.ChevronRight
|
||||
import androidx.compose.material.icons.rounded.Close
|
||||
import androidx.compose.material.icons.rounded.Delete
|
||||
import androidx.compose.material.icons.rounded.DragHandle
|
||||
import androidx.compose.material.icons.rounded.FilterList
|
||||
import androidx.compose.material.icons.rounded.History
|
||||
import androidx.compose.material.icons.rounded.Palette
|
||||
import androidx.compose.material.icons.rounded.Sell
|
||||
import androidx.compose.material.icons.rounded.Sort
|
||||
import androidx.compose.material.icons.rounded.SwapHoriz
|
||||
import androidx.compose.material.icons.rounded.TaskAlt
|
||||
import androidx.compose.material.icons.rounded.ViewAgenda
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
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.draw.drawBehind
|
||||
import androidx.compose.ui.geometry.CornerRadius
|
||||
import androidx.compose.ui.graphics.PathEffect
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.clearAndSetSemantics
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import de.jeanlucmakiola.agendula.R
|
||||
import de.jeanlucmakiola.agendula.domain.Block
|
||||
import de.jeanlucmakiola.agendula.domain.BlockOptions
|
||||
import de.jeanlucmakiola.agendula.domain.BlockType
|
||||
import de.jeanlucmakiola.agendula.domain.BlockWidth
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSortOrder
|
||||
import de.jeanlucmakiola.agendula.domain.TileColor
|
||||
import de.jeanlucmakiola.agendula.domain.canAdd
|
||||
import de.jeanlucmakiola.agendula.ui.common.ActionShapes
|
||||
import de.jeanlucmakiola.agendula.ui.common.NameField
|
||||
import de.jeanlucmakiola.agendula.ui.settings.CategoryIcon
|
||||
import de.jeanlucmakiola.agendula.ui.settings.ChipAccent
|
||||
import de.jeanlucmakiola.agendula.ui.tasklist.sortLabel
|
||||
import de.jeanlucmakiola.agendula.ui.views.ViewIconPicker
|
||||
import de.jeanlucmakiola.agendula.ui.views.label
|
||||
import de.jeanlucmakiola.agendula.ui.views.vector
|
||||
import de.jeanlucmakiola.agendula.ui.views.viewName
|
||||
import de.jeanlucmakiola.floret.components.ActionButton
|
||||
import de.jeanlucmakiola.floret.components.ConnectedChoiceRow
|
||||
import de.jeanlucmakiola.floret.components.FullScreenPicker
|
||||
import de.jeanlucmakiola.floret.components.GridSpan
|
||||
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.OptionPicker
|
||||
import de.jeanlucmakiola.floret.components.Position
|
||||
import de.jeanlucmakiola.floret.components.ReorderableGrid
|
||||
import de.jeanlucmakiola.floret.components.SelectedCheck
|
||||
import de.jeanlucmakiola.floret.components.positionOf
|
||||
import de.jeanlucmakiola.floret.identity.FloretDensity
|
||||
|
||||
/** The top bar while a layout is edited: its title, *Add block* and ✓ Done. */
|
||||
@Composable
|
||||
internal fun EditLayoutTopBar(onAdd: () -> Unit, onDone: () -> Unit) {
|
||||
Surface(color = MaterialTheme.colorScheme.surface) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.windowInsetsPadding(TopAppBarDefaults.windowInsets)
|
||||
.height(72.dp)
|
||||
.padding(start = 24.dp, end = 12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
stringResource(R.string.view_edit_layout),
|
||||
style = MaterialTheme.typography.titleLarge,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
ActionButton(
|
||||
shape = ActionShapes.AddBlock,
|
||||
morphTo = ActionShapes.AddListPressed,
|
||||
icon = Icons.Rounded.Add,
|
||||
contentDescription = stringResource(R.string.block_add),
|
||||
onClick = onAdd,
|
||||
size = 48.dp,
|
||||
)
|
||||
Button(onClick = onDone, modifier = Modifier.padding(start = 8.dp)) {
|
||||
Icon(Icons.Rounded.Check, contentDescription = null, modifier = Modifier.size(ButtonDefaults.IconSize))
|
||||
Spacer(Modifier.width(ButtonDefaults.IconSpacing))
|
||||
Text(stringResource(R.string.edit_layout_done))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The view's blocks to rearrange: dragged by their handle or after a long
|
||||
* press, made half or full width, removed, or tapped for their settings. *Add
|
||||
* block* closes the grid. The task list stays last and doesn't move.
|
||||
*/
|
||||
@Composable
|
||||
internal fun EditLayoutContent(
|
||||
state: ListsUiState.Content,
|
||||
onMove: (List<Long>) -> Unit,
|
||||
onResize: (Block, BlockWidth) -> Unit,
|
||||
onRemove: (Block) -> Unit,
|
||||
onOpenSettings: (Block) -> Unit,
|
||||
onAdd: () -> Unit,
|
||||
bottomPadding: Dp,
|
||||
) {
|
||||
val scroll = rememberScrollState()
|
||||
// Blocks show what they hold, but nothing in them opens while the layout is edited.
|
||||
val inert = BlockActions(
|
||||
openFilter = { _, _ -> },
|
||||
openTask = {},
|
||||
toggleDone = {},
|
||||
chooseSource = {},
|
||||
newList = {},
|
||||
newFilter = {},
|
||||
reorderLists = {},
|
||||
scopeFor = { null },
|
||||
)
|
||||
Column(Modifier.fillMaxSize().verticalScroll(scroll).padding(top = 8.dp, bottom = bottomPadding)) {
|
||||
ReorderableGrid(
|
||||
items = state.view.blocks,
|
||||
keyOf = { it.id },
|
||||
spanOf = { if (it.width == BlockWidth.HALF) GridSpan.Half else GridSpan.Full },
|
||||
onReorder = { blocks -> onMove(blocks.map { it.id }) },
|
||||
canDrag = { it.type != BlockType.TASK_LIST },
|
||||
scrollState = scroll,
|
||||
moveEarlierLabel = stringResource(R.string.block_move_earlier),
|
||||
moveLaterLabel = stringResource(R.string.block_move_later),
|
||||
) { block, column, dragHandle, dragging ->
|
||||
EditBlockFrame(
|
||||
block = block,
|
||||
state = state,
|
||||
actions = inert,
|
||||
column = column,
|
||||
dragHandle = dragHandle,
|
||||
dragging = dragging,
|
||||
onResize = { onResize(block, it) },
|
||||
onRemove = { onRemove(block) },
|
||||
onOpenSettings = { onOpenSettings(block) },
|
||||
)
|
||||
}
|
||||
AddBlockTile(onAdd)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One block in the edit grid with its controls: a tile carries them in its
|
||||
* corner, a section on its title line. Tapping the block opens its settings.
|
||||
*/
|
||||
@Composable
|
||||
private fun EditBlockFrame(
|
||||
block: Block,
|
||||
state: ListsUiState.Content,
|
||||
actions: BlockActions,
|
||||
column: Int,
|
||||
dragHandle: Modifier,
|
||||
dragging: Boolean,
|
||||
onResize: (BlockWidth) -> Unit,
|
||||
onRemove: () -> Unit,
|
||||
onOpenSettings: () -> Unit,
|
||||
) {
|
||||
// A heading's own text shows as its content, under the name of its kind.
|
||||
val heading = block.type == BlockType.SECTION_HEADING
|
||||
val typeName = stringResource(block.type.label)
|
||||
val title = if (heading) typeName else blockTitle(block, state).ifBlank { typeName }
|
||||
val settingsLabel = stringResource(R.string.block_settings)
|
||||
// A long press belongs to the grid, which starts a drag; letting go of one doesn't open the settings.
|
||||
val tapTarget = Modifier
|
||||
.clickable(onClickLabel = settingsLabel) { if (!dragging) onOpenSettings() }
|
||||
.semantics { contentDescription = if (title == typeName) title else "$typeName, $title" }
|
||||
val controls: @Composable () -> Unit = {
|
||||
BlockControls(block, dragHandle, onResize, onRemove)
|
||||
}
|
||||
if (block.type in TILES) {
|
||||
val inset = when {
|
||||
block.width == BlockWidth.FULL -> Modifier.padding(horizontal = GroupedListInset)
|
||||
column == 0 -> Modifier.padding(start = GroupedListInset)
|
||||
else -> Modifier.padding(end = GroupedListInset)
|
||||
}
|
||||
Box(inset) {
|
||||
Box(Modifier.clearAndSetSemantics {}) { Tile(block, state, actions, Modifier.fillMaxWidth()) }
|
||||
Box(Modifier.matchParentSize().clip(RoundedCornerShape(22.dp)).then(tapTarget))
|
||||
Row(Modifier.align(Alignment.TopEnd).padding(4.dp)) { controls() }
|
||||
}
|
||||
return
|
||||
}
|
||||
Column {
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().padding(start = 28.dp, end = 12.dp, top = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
title,
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
controls()
|
||||
}
|
||||
Box {
|
||||
Box(Modifier.clearAndSetSemantics {}) {
|
||||
BlockBody(block, state, actions, editing = true, showHeader = heading)
|
||||
}
|
||||
Box(Modifier.matchParentSize().then(tapTarget))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A block's drag handle, its half/full switch where its type has both, and ✕. */
|
||||
@Composable
|
||||
private fun BlockControls(
|
||||
block: Block,
|
||||
dragHandle: Modifier,
|
||||
onResize: (BlockWidth) -> Unit,
|
||||
onRemove: () -> Unit,
|
||||
) {
|
||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||
if (block.type != BlockType.TASK_LIST) {
|
||||
Box(
|
||||
modifier = dragHandle
|
||||
.size(36.dp)
|
||||
.clip(CircleShape)
|
||||
.background(MaterialTheme.colorScheme.surfaceContainerHighest.copy(alpha = 0.7f)),
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Icon(
|
||||
Icons.Rounded.DragHandle,
|
||||
contentDescription = stringResource(R.string.block_drag),
|
||||
modifier = Modifier.size(20.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
if (block.type.widths.size > 1) {
|
||||
val toFull = block.width == BlockWidth.HALF
|
||||
ActionButton(
|
||||
shape = ActionShapes.ResizeBlock,
|
||||
icon = Icons.Rounded.SwapHoriz,
|
||||
contentDescription = stringResource(if (toFull) R.string.block_make_full else R.string.block_make_half),
|
||||
onClick = { onResize(if (toFull) BlockWidth.FULL else BlockWidth.HALF) },
|
||||
size = 36.dp,
|
||||
iconSize = 20.dp,
|
||||
)
|
||||
}
|
||||
ActionButton(
|
||||
shape = ActionShapes.RemoveBlock,
|
||||
icon = Icons.Rounded.Close,
|
||||
contentDescription = stringResource(R.string.block_remove),
|
||||
onClick = onRemove,
|
||||
size = 36.dp,
|
||||
iconSize = 20.dp,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** The dashed *Add block* tile that closes the edit grid. */
|
||||
@Composable
|
||||
private fun AddBlockTile(onAdd: () -> Unit) {
|
||||
val outline = MaterialTheme.colorScheme.outline
|
||||
Surface(
|
||||
onClick = onAdd,
|
||||
shape = RoundedCornerShape(22.dp),
|
||||
color = MaterialTheme.colorScheme.surface,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = GroupedListInset, vertical = 16.dp)
|
||||
.drawBehind {
|
||||
drawRoundRect(
|
||||
color = outline,
|
||||
cornerRadius = CornerRadius(22.dp.toPx()),
|
||||
style = Stroke(width = 1.5.dp.toPx(), pathEffect = PathEffect.dashPathEffect(floatArrayOf(8.dp.toPx(), 6.dp.toPx()))),
|
||||
)
|
||||
},
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.heightIn(min = FloretDensity.cardRowHeight),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Icon(Icons.Rounded.Add, contentDescription = null, modifier = Modifier.size(20.dp))
|
||||
Spacer(Modifier.width(8.dp))
|
||||
Text(stringResource(R.string.block_add), style = MaterialTheme.typography.labelLarge)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** A block kind's name. */
|
||||
internal val BlockType.label: Int
|
||||
get() = when (this) {
|
||||
BlockType.PROGRESS -> R.string.block_progress
|
||||
BlockType.COUNT_TILE -> R.string.block_count
|
||||
BlockType.PREVIEW -> R.string.block_preview
|
||||
BlockType.RECENTLY_COMPLETED -> R.string.block_recent
|
||||
BlockType.WEEK_STRIP -> R.string.block_week
|
||||
BlockType.TASK_LIST -> R.string.block_task_list
|
||||
BlockType.LISTS -> R.string.lists_header
|
||||
BlockType.TAGS -> R.string.tags_header
|
||||
BlockType.FILTERS -> R.string.filters_header
|
||||
BlockType.SECTION_HEADING -> R.string.block_heading
|
||||
}
|
||||
|
||||
/** What a block kind shows, in a line. */
|
||||
private val BlockType.hint: Int
|
||||
get() = when (this) {
|
||||
BlockType.PROGRESS -> R.string.block_progress_hint
|
||||
BlockType.COUNT_TILE -> R.string.block_count_hint
|
||||
BlockType.PREVIEW -> R.string.block_preview_hint
|
||||
BlockType.RECENTLY_COMPLETED -> R.string.block_recent_hint
|
||||
BlockType.WEEK_STRIP -> R.string.block_week_hint
|
||||
BlockType.TASK_LIST -> R.string.block_task_list_hint
|
||||
BlockType.LISTS -> R.string.block_lists_hint
|
||||
BlockType.TAGS -> R.string.block_tags_hint
|
||||
BlockType.FILTERS -> R.string.block_filters_hint
|
||||
BlockType.SECTION_HEADING -> R.string.block_heading_hint
|
||||
}
|
||||
|
||||
private val BlockType.icon: ImageVector
|
||||
get() = when (this) {
|
||||
BlockType.PROGRESS -> Icons.Rounded.TaskAlt
|
||||
BlockType.COUNT_TILE -> Icons.Rounded.Apps
|
||||
BlockType.PREVIEW -> Icons.Rounded.ViewAgenda
|
||||
BlockType.RECENTLY_COMPLETED -> Icons.Rounded.History
|
||||
BlockType.WEEK_STRIP -> Icons.Rounded.CalendarViewWeek
|
||||
BlockType.TASK_LIST -> Icons.Rounded.Checklist
|
||||
BlockType.LISTS -> Icons.AutoMirrored.Rounded.ListAlt
|
||||
BlockType.TAGS -> Icons.Rounded.Sell
|
||||
BlockType.FILTERS -> Icons.Rounded.FilterList
|
||||
BlockType.SECTION_HEADING -> Icons.AutoMirrored.Rounded.ShortText
|
||||
}
|
||||
|
||||
/** The add picker's groups of block kinds, in order. */
|
||||
private val BlockGroups = listOf(
|
||||
R.string.block_group_tasks to listOf(
|
||||
BlockType.PROGRESS,
|
||||
BlockType.COUNT_TILE,
|
||||
BlockType.PREVIEW,
|
||||
BlockType.RECENTLY_COMPLETED,
|
||||
BlockType.WEEK_STRIP,
|
||||
BlockType.TASK_LIST,
|
||||
),
|
||||
R.string.block_group_browse to listOf(BlockType.LISTS, BlockType.TAGS, BlockType.FILTERS),
|
||||
R.string.block_group_layout to listOf(BlockType.SECTION_HEADING),
|
||||
)
|
||||
|
||||
/**
|
||||
* The block kinds to add, grouped; a second task list is offered but can't be
|
||||
* picked. Picking one closes the picker.
|
||||
*/
|
||||
@Composable
|
||||
internal fun AddBlockPicker(blocks: List<Block>, onPick: (BlockType) -> Unit, onDismiss: () -> Unit) {
|
||||
FullScreenPicker(title = stringResource(R.string.block_add), onDismiss = onDismiss) {
|
||||
BlockGroups.forEach { (header, types) ->
|
||||
GroupedSectionHeader(stringResource(header))
|
||||
types.forEachIndexed { index, type ->
|
||||
val addable = blocks.canAdd(type)
|
||||
GroupedRow(
|
||||
title = stringResource(type.label),
|
||||
summary = stringResource(if (addable) type.hint else R.string.block_task_list_taken),
|
||||
position = positionOf(index, types.size),
|
||||
dimmed = !addable,
|
||||
leading = { CategoryIcon(type.icon, ChipAccent.Primary) },
|
||||
onClick = if (addable) ({ onDismiss(); onPick(type) }) else null,
|
||||
)
|
||||
}
|
||||
}
|
||||
Spacer(Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A block's settings, full screen: its title (or a heading's text), its source,
|
||||
* the options of its kind, *Ignore view scope* where the view has a scope, and
|
||||
* remove. Changes are kept until Save; back leaves them.
|
||||
*/
|
||||
@Composable
|
||||
internal fun BlockSettings(
|
||||
block: Block,
|
||||
state: ListsUiState.Content,
|
||||
onChange: ((Block) -> Block) -> Unit,
|
||||
onChooseSource: () -> Unit,
|
||||
onSave: () -> Unit,
|
||||
onRemove: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
var choosing by rememberSaveable { mutableStateOf<BlockPicker?>(null) }
|
||||
fun options(transform: (BlockOptions) -> BlockOptions) = onChange { it.copy(options = transform(it.options)) }
|
||||
FullScreenPicker(
|
||||
title = stringResource(block.type.label),
|
||||
onDismiss = onDismiss,
|
||||
actions = {
|
||||
Button(onClick = onSave, modifier = Modifier.padding(end = 12.dp)) { Text(stringResource(R.string.save)) }
|
||||
},
|
||||
) {
|
||||
TitleSection(block, state, ::options)
|
||||
|
||||
if (block.type.takesSource) {
|
||||
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),
|
||||
position = Position.Alone,
|
||||
leading = { Icon(Icons.Rounded.FilterList, contentDescription = null) },
|
||||
trailing = { Icon(Icons.Rounded.ChevronRight, contentDescription = null) },
|
||||
onClick = onChooseSource,
|
||||
)
|
||||
}
|
||||
|
||||
TypeOptions(block, state, ::options, onPick = { choosing = it })
|
||||
|
||||
if (state.view.scope != null) {
|
||||
GroupedSectionHeader(stringResource(R.string.block_section_scope))
|
||||
GroupedSwitchRow(
|
||||
title = stringResource(R.string.block_ignore_scope),
|
||||
summary = stringResource(R.string.block_ignore_scope_hint, viewName(state.view.name, state.view.id)),
|
||||
checked = block.ignoreScope,
|
||||
onCheckedChange = { on -> onChange { it.copy(ignoreScope = on) } },
|
||||
position = Position.Alone,
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(Modifier.height(24.dp))
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.block_remove),
|
||||
position = Position.Alone,
|
||||
contentColor = MaterialTheme.colorScheme.error,
|
||||
leading = { Icon(Icons.Rounded.Delete, contentDescription = null) },
|
||||
onClick = onRemove,
|
||||
)
|
||||
Spacer(Modifier.height(24.dp))
|
||||
}
|
||||
|
||||
when (choosing) {
|
||||
BlockPicker.COLOR -> (block.options as? BlockOptions.CountTile)?.let { tile ->
|
||||
OptionPicker(
|
||||
title = stringResource(R.string.block_color),
|
||||
options = listOf<TileColor?>(null) + TileColor.entries,
|
||||
selected = tile.color,
|
||||
label = { stringResource(it?.label ?: R.string.block_automatic) },
|
||||
leading = { color ->
|
||||
val swatch = color?.let { tileColors(it).first } ?: MaterialTheme.colorScheme.surfaceContainerHighest
|
||||
Box(Modifier.size(24.dp).clip(CircleShape).background(swatch))
|
||||
},
|
||||
onSelect = { color -> options { (it as BlockOptions.CountTile).copy(color = color) } },
|
||||
onDismiss = { choosing = null },
|
||||
)
|
||||
}
|
||||
BlockPicker.ICON -> (block.options as? BlockOptions.CountTile)?.let { tile ->
|
||||
ViewIconPicker(
|
||||
current = tile.icon,
|
||||
onSelect = { icon -> options { (it as BlockOptions.CountTile).copy(icon = icon) } },
|
||||
onDismiss = { choosing = null },
|
||||
automatic = true,
|
||||
)
|
||||
}
|
||||
BlockPicker.SORT -> (block.options as? BlockOptions.TaskList)?.let { list ->
|
||||
OptionPicker(
|
||||
title = stringResource(R.string.sort_title),
|
||||
options = listOf<TaskSortOrder?>(null) + TaskSortOrder.entries,
|
||||
selected = list.sort,
|
||||
label = { stringResource(it?.let(::sortLabel) ?: R.string.block_sort_default) },
|
||||
onSelect = { sort -> options { (it as BlockOptions.TaskList).copy(sort = sort) } },
|
||||
onDismiss = { choosing = null },
|
||||
)
|
||||
}
|
||||
null -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
/** The pickers a block's settings open over themselves. */
|
||||
private enum class BlockPicker { COLOR, ICON, SORT }
|
||||
|
||||
/** A block's own title, a heading's text; nothing for the kinds that keep a fixed one. */
|
||||
@Composable
|
||||
private fun TitleSection(block: Block, state: ListsUiState.Content, options: ((BlockOptions) -> BlockOptions) -> Unit) {
|
||||
val current = when (val o = block.options) {
|
||||
is BlockOptions.Progress -> o.title
|
||||
is BlockOptions.CountTile -> o.title
|
||||
is BlockOptions.Preview -> o.title
|
||||
is BlockOptions.RecentlyCompleted -> o.title
|
||||
is BlockOptions.WeekStrip -> o.title
|
||||
is BlockOptions.SectionHeading -> o.text
|
||||
else -> return
|
||||
}
|
||||
val heading = block.type == BlockType.SECTION_HEADING
|
||||
// An empty title shows the default one, which the field offers as its placeholder.
|
||||
val fallback = if (heading) stringResource(R.string.block_heading_text_hint) else blockTitle(block.copy(options = BlockOptions.defaultFor(block.type)), state)
|
||||
GroupedSectionHeader(stringResource(if (heading) R.string.block_heading_text else R.string.block_title))
|
||||
NameField(
|
||||
name = current.orEmpty(),
|
||||
placeholder = fallback,
|
||||
autoFocus = heading && current.isNullOrEmpty(),
|
||||
onNameChange = { text ->
|
||||
val title = text.takeIf { it.isNotBlank() }
|
||||
options { o ->
|
||||
when (o) {
|
||||
is BlockOptions.Progress -> o.copy(title = title)
|
||||
is BlockOptions.CountTile -> o.copy(title = title)
|
||||
is BlockOptions.Preview -> o.copy(title = title)
|
||||
is BlockOptions.RecentlyCompleted -> o.copy(title = title)
|
||||
is BlockOptions.WeekStrip -> o.copy(title = title)
|
||||
is BlockOptions.SectionHeading -> o.copy(text = text)
|
||||
else -> o
|
||||
}
|
||||
}
|
||||
},
|
||||
onImeAction = {},
|
||||
)
|
||||
}
|
||||
|
||||
/** The options of the block's kind. */
|
||||
@Composable
|
||||
private fun TypeOptions(
|
||||
block: Block,
|
||||
state: ListsUiState.Content,
|
||||
options: ((BlockOptions) -> BlockOptions) -> Unit,
|
||||
onPick: (BlockPicker) -> Unit,
|
||||
) {
|
||||
when (val o = block.options) {
|
||||
is BlockOptions.Progress -> {
|
||||
GroupedSectionHeader(stringResource(R.string.block_section_options))
|
||||
GroupedSwitchRow(
|
||||
title = stringResource(R.string.block_wave),
|
||||
summary = stringResource(R.string.block_wave_hint),
|
||||
checked = o.wave,
|
||||
onCheckedChange = { on -> options { (it as BlockOptions.Progress).copy(wave = on) } },
|
||||
position = Position.Alone,
|
||||
)
|
||||
}
|
||||
is BlockOptions.CountTile -> {
|
||||
GroupedSectionHeader(stringResource(R.string.block_section_look))
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.block_color),
|
||||
summary = stringResource(o.color?.label ?: R.string.block_automatic),
|
||||
position = Position.Top,
|
||||
leading = { Icon(Icons.Rounded.Palette, contentDescription = null) },
|
||||
trailing = { Icon(Icons.Rounded.ChevronRight, contentDescription = null) },
|
||||
onClick = { onPick(BlockPicker.COLOR) },
|
||||
)
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.block_icon),
|
||||
summary = o.icon?.let { stringResource(it.label) } ?: stringResource(R.string.block_automatic),
|
||||
position = Position.Bottom,
|
||||
leading = { Icon(o.icon?.vector ?: Icons.Rounded.Apps, contentDescription = null) },
|
||||
trailing = { Icon(Icons.Rounded.ChevronRight, contentDescription = null) },
|
||||
onClick = { onPick(BlockPicker.ICON) },
|
||||
)
|
||||
}
|
||||
is BlockOptions.Preview -> {
|
||||
HowMany(o.count) { count -> options { (it as BlockOptions.Preview).copy(count = count) } }
|
||||
GroupedSectionHeader(stringResource(R.string.block_section_options))
|
||||
GroupedSwitchRow(
|
||||
title = stringResource(R.string.block_show_all),
|
||||
summary = stringResource(R.string.block_show_all_hint),
|
||||
checked = o.showAll,
|
||||
onCheckedChange = { on -> options { (it as BlockOptions.Preview).copy(showAll = on) } },
|
||||
position = Position.Top,
|
||||
)
|
||||
GroupedSwitchRow(
|
||||
title = stringResource(R.string.block_inline_done),
|
||||
summary = stringResource(R.string.block_inline_done_hint),
|
||||
checked = o.inlineDone,
|
||||
onCheckedChange = { on -> options { (it as BlockOptions.Preview).copy(inlineDone = on) } },
|
||||
position = Position.Bottom,
|
||||
)
|
||||
}
|
||||
is BlockOptions.RecentlyCompleted ->
|
||||
HowMany(o.count) { count -> options { (it as BlockOptions.RecentlyCompleted).copy(count = count) } }
|
||||
is BlockOptions.TaskList -> {
|
||||
GroupedSectionHeader(stringResource(R.string.block_section_options))
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.sort_title),
|
||||
summary = stringResource(o.sort?.let(::sortLabel) ?: R.string.block_sort_default),
|
||||
position = Position.Top,
|
||||
leading = { Icon(Icons.Rounded.Sort, contentDescription = null) },
|
||||
trailing = { Icon(Icons.Rounded.ChevronRight, contentDescription = null) },
|
||||
onClick = { onPick(BlockPicker.SORT) },
|
||||
)
|
||||
GroupedSwitchRow(
|
||||
title = stringResource(R.string.block_show_completed),
|
||||
summary = stringResource(R.string.block_show_completed_hint),
|
||||
checked = o.showCompleted,
|
||||
onCheckedChange = { on -> options { (it as BlockOptions.TaskList).copy(showCompleted = on) } },
|
||||
position = Position.Middle,
|
||||
)
|
||||
GroupedSwitchRow(
|
||||
title = stringResource(R.string.block_inline_done),
|
||||
summary = stringResource(R.string.block_inline_done_hint),
|
||||
checked = o.inlineDone,
|
||||
onCheckedChange = { on -> options { (it as BlockOptions.TaskList).copy(inlineDone = on) } },
|
||||
position = Position.Bottom,
|
||||
)
|
||||
}
|
||||
is BlockOptions.Lists -> ListsOptions(o, state, options)
|
||||
is BlockOptions.SectionHeading, is BlockOptions.WeekStrip, BlockOptions.Tags, BlockOptions.Filters -> Unit
|
||||
}
|
||||
}
|
||||
|
||||
/** How many tasks a preview shows, as an inline choice. */
|
||||
@Composable
|
||||
private fun HowMany(count: Int, onSelect: (Int) -> Unit) {
|
||||
GroupedSectionHeader(stringResource(R.string.block_how_many))
|
||||
ConnectedChoiceRow(
|
||||
options = BlockOptions.PREVIEW_COUNTS,
|
||||
selected = count,
|
||||
label = { it.toString() },
|
||||
onSelect = onSelect,
|
||||
)
|
||||
}
|
||||
|
||||
/** Which accounts' lists the lists block shows, and whether with their open counts. */
|
||||
@Composable
|
||||
private fun ListsOptions(o: BlockOptions.Lists, state: ListsUiState.Content, options: ((BlockOptions) -> BlockOptions) -> Unit) {
|
||||
val accounts = state.lists.map { it.accountName }.distinct().sortedBy { it.lowercase() }
|
||||
// An account no longer there stays listed while the block names it, so it can be unticked.
|
||||
val shown = (accounts + o.accounts.orEmpty()).distinct()
|
||||
if (shown.size > 1 || o.accounts != null) {
|
||||
GroupedSectionHeader(stringResource(R.string.block_accounts))
|
||||
val total = shown.size + 1
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.block_accounts_all),
|
||||
position = positionOf(0, total),
|
||||
selected = o.accounts == null,
|
||||
trailing = if (o.accounts == null) ({ SelectedCheck() }) else null,
|
||||
onClick = { options { (it as BlockOptions.Lists).copy(accounts = null) } },
|
||||
)
|
||||
shown.forEachIndexed { index, account ->
|
||||
val chosen = o.accounts?.contains(account) == true
|
||||
GroupedRow(
|
||||
title = account,
|
||||
position = positionOf(index + 1, total),
|
||||
selected = chosen,
|
||||
trailing = if (chosen) ({ SelectedCheck() }) else null,
|
||||
onClick = {
|
||||
options {
|
||||
val lists = it as BlockOptions.Lists
|
||||
val now = lists.accounts.orEmpty().let { set -> if (account in set) set - account else set + account }
|
||||
lists.copy(accounts = now.takeIf { set -> set.isNotEmpty() })
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
GroupedSectionHeader(stringResource(R.string.block_section_options))
|
||||
GroupedSwitchRow(
|
||||
title = stringResource(R.string.block_counts),
|
||||
summary = stringResource(R.string.block_counts_hint),
|
||||
checked = o.counts,
|
||||
onCheckedChange = { on -> options { (it as BlockOptions.Lists).copy(counts = on) } },
|
||||
position = Position.Alone,
|
||||
)
|
||||
}
|
||||
|
||||
/** A tile colour's name. */
|
||||
private val TileColor.label: Int
|
||||
get() = when (this) {
|
||||
TileColor.PRIMARY -> R.string.block_color_primary
|
||||
TileColor.SECONDARY -> R.string.block_color_secondary
|
||||
TileColor.TERTIARY -> R.string.block_color_tertiary
|
||||
TileColor.ERROR -> R.string.block_color_error
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -14,6 +14,16 @@ import de.jeanlucmakiola.agendula.domain.Block
|
||||
import de.jeanlucmakiola.agendula.domain.BlockOptions
|
||||
import de.jeanlucmakiola.agendula.domain.BlockSource
|
||||
import de.jeanlucmakiola.agendula.domain.BlockType
|
||||
import de.jeanlucmakiola.agendula.domain.BlockWidth
|
||||
import de.jeanlucmakiola.agendula.domain.dueCounts
|
||||
import de.jeanlucmakiola.agendula.domain.recentlyCompleted
|
||||
import de.jeanlucmakiola.agendula.domain.reordered
|
||||
import de.jeanlucmakiola.agendula.domain.replaced
|
||||
import de.jeanlucmakiola.agendula.domain.resized
|
||||
import de.jeanlucmakiola.agendula.domain.restored
|
||||
import de.jeanlucmakiola.agendula.domain.weekDays
|
||||
import de.jeanlucmakiola.agendula.domain.withBlock
|
||||
import de.jeanlucmakiola.agendula.domain.without
|
||||
import de.jeanlucmakiola.agendula.domain.RuleClock
|
||||
import de.jeanlucmakiola.agendula.domain.SavedFilter
|
||||
import de.jeanlucmakiola.agendula.domain.SmartList
|
||||
@@ -38,8 +48,11 @@ import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
import javax.inject.Inject
|
||||
import kotlin.time.Clock
|
||||
@@ -101,6 +114,15 @@ data class FilterOverview(val filter: SavedFilter, val openCount: Int)
|
||||
/** Done of total for a progress block. */
|
||||
data class BlockProgress(val done: Int, val total: Int)
|
||||
|
||||
/** A week strip's [days], which of them is [today], and how many open tasks are [due] on each. */
|
||||
data class WeekStripDays(val days: List<LocalDate>, val today: LocalDate, val due: Map<LocalDate, Int>)
|
||||
|
||||
/** A block just removed from view [viewId], from [index], until its undo lapses. */
|
||||
data class RemovedBlock(val viewId: Long, val block: Block, val index: Int)
|
||||
|
||||
/** Block [block] of view [viewId] as its settings screen changes it, until saved. */
|
||||
data class BlockDraft(val viewId: Long, val block: Block)
|
||||
|
||||
/** What the lists, tags and filters blocks show, read through one scope. */
|
||||
data class HomeSections(
|
||||
val groups: List<AccountGroup>,
|
||||
@@ -124,6 +146,10 @@ sealed interface ListsUiState {
|
||||
val counts: Map<Long, Int> = emptyMap(),
|
||||
/** What each preview block shows, by block id. */
|
||||
val previews: Map<Long, List<Task>> = emptyMap(),
|
||||
/** What each recently completed block shows, latest first, by block id. */
|
||||
val recent: Map<Long, List<Task>> = emptyMap(),
|
||||
/** Each week strip's days, by block id. */
|
||||
val weeks: Map<Long, WeekStripDays> = emptyMap(),
|
||||
/** The blocks whose list or saved filter was deleted. */
|
||||
val goneSources: Set<Long> = emptySet(),
|
||||
/** The view's scope names a list since deleted, so that part of it matches nothing. */
|
||||
@@ -187,16 +213,32 @@ internal fun homeContent(
|
||||
val progress = HashMap<Long, BlockProgress>()
|
||||
val counts = HashMap<Long, Int>()
|
||||
val previews = HashMap<Long, List<Task>>()
|
||||
val recent = HashMap<Long, List<Task>>()
|
||||
val weeks = HashMap<Long, WeekStripDays>()
|
||||
val gone = HashSet<Long>()
|
||||
view.blocks.forEach { block ->
|
||||
val within = scope.forBlock(block)
|
||||
// The smart lists leave out the hidden lists, but not one the scope names.
|
||||
val smartHidden = within.hiddenFromSmart(hidden)
|
||||
fun inView(task: Task) = task.listId !in smartHidden && within.admits(task, clock)
|
||||
when (block.type) {
|
||||
BlockType.RECENTLY_COMPLETED -> {
|
||||
val count = (block.options as BlockOptions.RecentlyCompleted).count
|
||||
recent[block.id] = recentlyCompleted(completedTasks.filter(::inView), count)
|
||||
return@forEach
|
||||
}
|
||||
BlockType.WEEK_STRIP -> {
|
||||
val days = weekDays(clock.today, clock.weekStart)
|
||||
weeks[block.id] = WeekStripDays(days, clock.today, dueCounts(openTasks.filter(::inView), days, clock.zone))
|
||||
return@forEach
|
||||
}
|
||||
else -> Unit
|
||||
}
|
||||
val source = block.source ?: return@forEach
|
||||
if (source.isGone(listIds, filterIds)) {
|
||||
gone += block.id
|
||||
return@forEach
|
||||
}
|
||||
val within = scope.forBlock(block)
|
||||
// The smart lists leave out the hidden lists, but not one the scope names.
|
||||
val smartHidden = within.hiddenFromSmart(hidden)
|
||||
fun shows(task: Task) = source.counts(task, context, smartHidden) && within.admits(task, clock)
|
||||
when (block.type) {
|
||||
BlockType.PROGRESS -> if (source == BlockSource.Smart(SmartList.TODAY)) {
|
||||
@@ -228,6 +270,8 @@ internal fun homeContent(
|
||||
progress = progress,
|
||||
counts = counts,
|
||||
previews = previews,
|
||||
recent = recent,
|
||||
weeks = weeks,
|
||||
goneSources = gone,
|
||||
scopeListsGone = scope.narrowedByGone,
|
||||
scopedSections = if (scope == AppliedScope.None) {
|
||||
@@ -368,18 +412,108 @@ class ListsViewModel @Inject constructor(
|
||||
val viewSaveFailed: StateFlow<Boolean> = _viewSaveFailed.asStateFlow()
|
||||
|
||||
/** Points the block [blockId] of view [viewId], whose source is gone, at [source] instead. */
|
||||
fun chooseSource(viewId: Long, blockId: Long, source: BlockSource) = viewModelScope.launch {
|
||||
// Read and written in one go, so nothing changed since the picker opened is lost.
|
||||
fun chooseSource(viewId: Long, blockId: Long, source: BlockSource) =
|
||||
editBlocks(viewId) { blocks -> blocks.map { if (it.id == blockId) it.copy(source = source) else it } }
|
||||
|
||||
/**
|
||||
* Changes the blocks of view [viewId] by [transform], read and written in one
|
||||
* go so nothing changed meanwhile is lost; says so when they can't be stored.
|
||||
*/
|
||||
private fun editBlocks(viewId: Long, transform: (List<Block>) -> List<Block>) = viewModelScope.launch {
|
||||
if (!settingsPrefs.updateView(viewId) { it.copy(blocks = transform(it.blocks)) }) flagSaveFailed()
|
||||
}
|
||||
|
||||
private suspend fun flagSaveFailed() {
|
||||
_viewSaveFailed.value = true
|
||||
delay(4_000)
|
||||
_viewSaveFailed.value = false
|
||||
}
|
||||
|
||||
/** Whether home shows the active view's blocks to rearrange. */
|
||||
val editingLayout: StateFlow<Boolean> = session.editingLayout
|
||||
|
||||
fun editLayout(viewId: Long) = session.editLayout(viewId)
|
||||
|
||||
/** Opens the layout of the view shown now; for a gesture that may outlive a switch of view. */
|
||||
fun editShownLayout() {
|
||||
(state.value as? ListsUiState.Content)?.view?.id?.let(session::editLayout)
|
||||
}
|
||||
|
||||
fun stopEditingLayout() {
|
||||
session.stopEditingLayout()
|
||||
_blockDraft.value = null
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a [type] block reading [source] to view [viewId], before its task list.
|
||||
* A section heading opens its settings straight away, to be given its text.
|
||||
*/
|
||||
fun addBlock(viewId: Long, type: BlockType, source: BlockSource?) = viewModelScope.launch {
|
||||
var added: Block? = null
|
||||
val written = settingsPrefs.updateView(viewId) { view ->
|
||||
view.copy(blocks = view.blocks.map { if (it.id == blockId) it.copy(source = source) else it })
|
||||
val blocks = view.blocks.withBlock(type, source)
|
||||
added = blocks.firstOrNull { block -> view.blocks.none { it.id == block.id } }
|
||||
view.copy(blocks = blocks)
|
||||
}
|
||||
if (!written) {
|
||||
_viewSaveFailed.value = true
|
||||
if (!written) return@launch flagSaveFailed()
|
||||
val block = added
|
||||
if (block != null && type == BlockType.SECTION_HEADING) _blockDraft.value = BlockDraft(viewId, block)
|
||||
}
|
||||
|
||||
/** Puts the blocks of view [viewId] in the order of [ids]. */
|
||||
fun moveBlocks(viewId: Long, ids: List<Long>) = editBlocks(viewId) { it.reordered(ids) }
|
||||
|
||||
fun resizeBlock(viewId: Long, blockId: Long, width: BlockWidth) = editBlocks(viewId) { it.resized(blockId, width) }
|
||||
|
||||
private val _removed = MutableStateFlow<RemovedBlock?>(null)
|
||||
|
||||
/** The block just removed, while its removal can be undone. */
|
||||
val removed: StateFlow<RemovedBlock?> = _removed.asStateFlow()
|
||||
private var removedTimer: Job? = null
|
||||
|
||||
/** Removes [block] from view [viewId], with a moment to undo it. */
|
||||
fun removeBlock(viewId: Long, block: Block) {
|
||||
val view = (state.value as? ListsUiState.Content)?.views?.firstOrNull { it.id == viewId } ?: return
|
||||
val index = view.blocks.indexOfFirst { it.id == block.id }.takeIf { it >= 0 } ?: return
|
||||
if (_blockDraft.value?.block?.id == block.id) _blockDraft.value = null
|
||||
editBlocks(viewId) { it.without(block.id) }
|
||||
_removed.value = RemovedBlock(viewId, block, index)
|
||||
removedTimer?.cancel()
|
||||
removedTimer = viewModelScope.launch {
|
||||
delay(4_000)
|
||||
_viewSaveFailed.value = false
|
||||
_removed.value = null
|
||||
}
|
||||
}
|
||||
|
||||
fun undoRemove() {
|
||||
val removed = _removed.value ?: return
|
||||
removedTimer?.cancel()
|
||||
_removed.value = null
|
||||
editBlocks(removed.viewId) { it.restored(removed.block, removed.index) }
|
||||
}
|
||||
|
||||
private val _blockDraft = MutableStateFlow<BlockDraft?>(null)
|
||||
|
||||
/** The block whose settings are open, as changed so far; `null` while none is. */
|
||||
val blockDraft: StateFlow<BlockDraft?> = _blockDraft.asStateFlow()
|
||||
|
||||
fun editBlock(viewId: Long, block: Block) {
|
||||
_blockDraft.value = BlockDraft(viewId, block)
|
||||
}
|
||||
|
||||
fun updateDraft(transform: (Block) -> Block) = _blockDraft.update { it?.copy(block = transform(it.block)) }
|
||||
|
||||
/** Stores the open block's settings over the block as it is stored now, and closes them. */
|
||||
fun saveDraft() {
|
||||
val draft = _blockDraft.value ?: return
|
||||
_blockDraft.value = null
|
||||
editBlocks(draft.viewId) { it.replaced(draft.block) }
|
||||
}
|
||||
|
||||
fun closeDraft() {
|
||||
_blockDraft.value = null
|
||||
}
|
||||
|
||||
private val _writeFailure = MutableStateFlow<ListWriteFailure?>(null)
|
||||
|
||||
/** Set when a list write is refused; the screen shows it and clears it. */
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package de.jeanlucmakiola.agendula.ui.lists
|
||||
|
||||
import androidx.compose.foundation.gestures.awaitEachGesture
|
||||
import androidx.compose.foundation.gestures.awaitFirstDown
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedback
|
||||
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
|
||||
import androidx.compose.ui.input.pointer.PointerEventPass
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
|
||||
/**
|
||||
* Calls [onLongPress] when the finger rests on this element for a long press,
|
||||
* whatever inside it takes taps: it watches before the content does, and once
|
||||
* it fires the rest of the press is its own, so nothing inside clicks or
|
||||
* scrolls. Moving past the touch slop first leaves the press to the content.
|
||||
*/
|
||||
internal fun Modifier.onLongPressOver(haptics: HapticFeedback, onLongPress: () -> Unit): Modifier =
|
||||
pointerInput(Unit) {
|
||||
awaitEachGesture {
|
||||
val down = awaitFirstDown(requireUnconsumed = false, pass = PointerEventPass.Initial)
|
||||
val slop = viewConfiguration.touchSlop
|
||||
val ended = withTimeoutOrNull(viewConfiguration.longPressTimeoutMillis) {
|
||||
var over = false
|
||||
while (!over) {
|
||||
val change = awaitPointerEvent(PointerEventPass.Initial).changes.firstOrNull { it.id == down.id }
|
||||
over = change == null || !change.pressed || change.isConsumed ||
|
||||
(change.position - down.position).getDistance() > slop
|
||||
}
|
||||
true
|
||||
}
|
||||
if (ended != null) return@awaitEachGesture
|
||||
haptics.performHapticFeedback(HapticFeedbackType.LongPress)
|
||||
onLongPress()
|
||||
do {
|
||||
val event = awaitPointerEvent(PointerEventPass.Initial)
|
||||
event.changes.forEach { it.consume() }
|
||||
} while (event.changes.any { it.pressed })
|
||||
}
|
||||
}
|
||||
@@ -145,7 +145,7 @@ fun EditViewScreen(
|
||||
if (choosingIcon && view != null) {
|
||||
ViewIconPicker(
|
||||
current = view.icon,
|
||||
onSelect = viewModel::setIcon,
|
||||
onSelect = { icon -> icon?.let(viewModel::setIcon) },
|
||||
onDismiss = { choosingIcon = false },
|
||||
)
|
||||
}
|
||||
@@ -170,11 +170,31 @@ fun EditViewScreen(
|
||||
/** How many icons lead the picker as suggestions. */
|
||||
private const val SUGGESTED_ICONS = 10
|
||||
|
||||
/** The curated view icons in a full-screen grid; picking one closes it. */
|
||||
/**
|
||||
* The curated view icons in a full-screen grid; picking one closes it. With
|
||||
* [automatic] a row on top picks none, for a tile that takes its source's icon.
|
||||
*/
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
private fun ViewIconPicker(current: ViewIcon, onSelect: (ViewIcon) -> Unit, onDismiss: () -> Unit) {
|
||||
internal fun ViewIconPicker(
|
||||
current: ViewIcon?,
|
||||
onSelect: (ViewIcon?) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
automatic: Boolean = false,
|
||||
) {
|
||||
FullScreenPicker(title = stringResource(R.string.view_icon_title), onDismiss = onDismiss) {
|
||||
if (automatic) {
|
||||
Spacer(Modifier.height(8.dp))
|
||||
GroupedRow(
|
||||
title = stringResource(R.string.block_automatic),
|
||||
position = Position.Alone,
|
||||
checked = current == null,
|
||||
onClick = {
|
||||
onSelect(null)
|
||||
onDismiss()
|
||||
},
|
||||
)
|
||||
}
|
||||
val (suggested, more) = ViewIcon.entries.withIndex().partition { it.index < SUGGESTED_ICONS }
|
||||
listOf(R.string.view_icon_suggested to suggested, R.string.view_icon_more to more).forEach { (header, icons) ->
|
||||
GroupedSectionHeader(stringResource(header))
|
||||
|
||||
@@ -44,6 +44,21 @@ class ViewSession @Inject constructor(
|
||||
appScope.launch { prefs.setActiveView(viewId) }
|
||||
}
|
||||
|
||||
private val _editingLayout = MutableStateFlow(false)
|
||||
|
||||
/** Home shows its blocks to rearrange, until [stopEditingLayout]. Held here so a rotation keeps it. */
|
||||
val editingLayout: StateFlow<Boolean> = _editingLayout.asStateFlow()
|
||||
|
||||
/** Shows view [viewId] with its layout open for editing. */
|
||||
fun editLayout(viewId: Long) {
|
||||
switchTo(viewId)
|
||||
_editingLayout.value = true
|
||||
}
|
||||
|
||||
fun stopEditingLayout() {
|
||||
_editingLayout.value = false
|
||||
}
|
||||
|
||||
private val _startPush = MutableStateFlow<TaskFilter?>(null)
|
||||
|
||||
/**
|
||||
|
||||
@@ -1188,6 +1188,89 @@
|
||||
<string name="view_icon_history">History</string>
|
||||
<string name="view_icon_grid">Grid</string>
|
||||
<string name="view_icon_tree">Tree</string>
|
||||
<!-- Editing a view's layout of blocks -->
|
||||
<string name="view_edit_layout">Edit layout</string>
|
||||
<string name="edit_layout_done">Done</string>
|
||||
<string name="block_add">Add block</string>
|
||||
<string name="block_settings">Block settings</string>
|
||||
<string name="block_drag">Drag to move</string>
|
||||
<string name="block_move_earlier">Move earlier</string>
|
||||
<string name="block_move_later">Move later</string>
|
||||
<string name="block_make_full">Make full width</string>
|
||||
<string name="block_make_half">Make half width</string>
|
||||
<string name="block_remove">Remove block</string>
|
||||
<string name="block_removed">Block removed</string>
|
||||
<string name="block_group_tasks">Tasks</string>
|
||||
<string name="block_group_browse">Browse</string>
|
||||
<string name="block_group_layout">Layout</string>
|
||||
<string name="block_progress">Progress</string>
|
||||
<string name="block_progress_hint">Ring with how much is done</string>
|
||||
<string name="block_count">Count tile</string>
|
||||
<string name="block_count_hint">One number, half or full width</string>
|
||||
<string name="block_preview">Preview</string>
|
||||
<string name="block_preview_hint">The next 3, 5 or 10 tasks</string>
|
||||
<string name="block_recent">Recently completed</string>
|
||||
<string name="block_recent_hint">What you finished, with undo</string>
|
||||
<string name="block_week">Week strip</string>
|
||||
<string name="block_week_hint">This week with due dots</string>
|
||||
<string name="block_task_list">Task list</string>
|
||||
<string name="block_task_list_hint">Every task, always at the bottom</string>
|
||||
<string name="block_task_list_taken">This view has one already</string>
|
||||
<string name="block_lists_hint">Your lists by account</string>
|
||||
<string name="block_tags_hint">Every tag with counts</string>
|
||||
<string name="block_filters_hint">Your saved filters</string>
|
||||
<string name="block_heading">Section heading</string>
|
||||
<string name="block_heading_hint">A title to group blocks</string>
|
||||
<string name="block_source_title">Show tasks from</string>
|
||||
<string name="block_source_rules">Custom rules</string>
|
||||
<string name="block_empty">Nothing to show right now</string>
|
||||
<string name="block_recent_empty">Nothing completed yet</string>
|
||||
<string name="block_heading_empty">No text yet</string>
|
||||
<!-- The task list block while the layout is edited; %1$s is its source, e.g. "All" -->
|
||||
<string name="block_task_list_summary">Tasks from %1$s</string>
|
||||
<string name="block_ignores_scope">Shows tasks outside this view</string>
|
||||
<string name="block_week_title">This week</string>
|
||||
<!-- A day in the week strip, for screen readers: %1$s is the day, %2$d the open tasks due -->
|
||||
<plurals name="block_week_day">
|
||||
<item quantity="one">%1$s, %2$d task due</item>
|
||||
<item quantity="other">%1$s, %2$d tasks due</item>
|
||||
</plurals>
|
||||
<!-- A recently completed task's time, e.g. "Done 10 minutes ago" -->
|
||||
<string name="block_recent_done_at">Done %1$s</string>
|
||||
<!-- A half-width progress tile: done of total -->
|
||||
<string name="block_progress_short">%1$d of %2$d</string>
|
||||
<string name="block_title">Title</string>
|
||||
<string name="block_heading_text">Text</string>
|
||||
<string name="block_heading_text_hint">Heading</string>
|
||||
<string name="block_section_tasks">Tasks</string>
|
||||
<string name="block_source">Source</string>
|
||||
<string name="block_section_options">Options</string>
|
||||
<string name="block_section_look">Look</string>
|
||||
<string name="block_section_scope">View scope</string>
|
||||
<string name="block_how_many">How many</string>
|
||||
<string name="block_show_all">“View all” link</string>
|
||||
<string name="block_show_all_hint">Opens the full list</string>
|
||||
<string name="block_inline_done">Check off here</string>
|
||||
<string name="block_inline_done_hint">Tap the box to complete a task</string>
|
||||
<string name="block_ignore_scope">Ignore view scope</string>
|
||||
<!-- %1$s is the view's name -->
|
||||
<string name="block_ignore_scope_hint">Also show tasks outside “%1$s”</string>
|
||||
<string name="block_wave">Moving wave</string>
|
||||
<string name="block_wave_hint">The ring’s wave moves, unless motion is reduced</string>
|
||||
<string name="block_color">Colour</string>
|
||||
<string name="block_icon">Icon</string>
|
||||
<string name="block_automatic">Automatic</string>
|
||||
<string name="block_color_primary">Primary</string>
|
||||
<string name="block_color_secondary">Secondary</string>
|
||||
<string name="block_color_tertiary">Tertiary</string>
|
||||
<string name="block_color_error">Alert</string>
|
||||
<string name="block_sort_default">As set for the app</string>
|
||||
<string name="block_show_completed">Completed tasks</string>
|
||||
<string name="block_show_completed_hint">In their own section at the end</string>
|
||||
<string name="block_accounts">Accounts</string>
|
||||
<string name="block_accounts_all">All accounts</string>
|
||||
<string name="block_counts">Counts</string>
|
||||
<string name="block_counts_hint">Open tasks next to each list</string>
|
||||
<!-- Where the app opens (#141) -->
|
||||
<string name="start_destination">Start screen</string>
|
||||
<string name="start_last_used">Last used view</string>
|
||||
|
||||
@@ -159,4 +159,37 @@ class HomePreviewsTest {
|
||||
assertThat(content(scoped(Rule.InList(setOf(1L, 2L)))).newTaskList).isNull()
|
||||
assertThat(content(scoped(Rule.Not(Rule.InList(setOf(9L))))).scopeListsGone).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `recently completed shows the view's completed tasks, latest first, unless it ignores the scope`() {
|
||||
fun done(id: Long, listId: Long, minutes: Long) = testTask(
|
||||
id = id,
|
||||
listId = listId,
|
||||
status = TaskStatus.COMPLETED,
|
||||
completedAt = startOfDay(today, zone) + kotlin.time.Duration.parse("${minutes}m"),
|
||||
)
|
||||
val completed = listOf(done(30, 1, 10), done(31, 2, 30), done(32, 1, 20), done(33, 1, 5))
|
||||
val blocks = listOf(
|
||||
Block(1, BlockType.RECENTLY_COMPLETED),
|
||||
Block(2, BlockType.RECENTLY_COMPLETED, ignoreScope = true, options = BlockOptions.RecentlyCompleted(count = 5)),
|
||||
)
|
||||
val state = homeContent(
|
||||
scoped(Rule.InList(setOf(1L)), blocks), listOf(View.home()), listOf(work, home),
|
||||
openTasks = emptyList(), completedTasks = completed, hidden = emptySet(),
|
||||
savedFilters = emptyList(), clock = clock, upcomingEnd = null,
|
||||
)
|
||||
assertThat(state.recent.getValue(1L).map { it.taskId }).containsExactly(32L, 30L, 33L).inOrder()
|
||||
assertThat(state.recent.getValue(2L).map { it.taskId }).containsExactly(31L, 32L, 30L, 33L).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the week strip counts the open tasks due on each day of the week, in the scope`() {
|
||||
val view = scoped(Rule.InList(setOf(1L)), listOf(Block(1, BlockType.WEEK_STRIP)))
|
||||
val week = content(view).weeks.getValue(1L)
|
||||
assertThat(week.today).isEqualTo(today)
|
||||
assertThat(week.days.first()).isEqualTo(LocalDate.of(2026, 11, 23))
|
||||
assertThat(week.days.last()).isEqualTo(LocalDate.of(2026, 11, 29))
|
||||
// Today's work task, then the even upcoming ones (list 1) due by Sunday.
|
||||
assertThat(week.due).containsExactly(today, 1, today.plusDays(2), 1)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user