From 7f3807c8fdc9454e0158fd7decbe2e844aadd334 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Fri, 27 Nov 2026 14:46:32 +0100 Subject: [PATCH] Tiles and previews show custom rules; only they offer them as a source (#59, #172) --- .../agendula/ui/lists/ListsScreen.kt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/ui/lists/ListsScreen.kt b/app/src/main/java/de/jeanlucmakiola/agendula/ui/lists/ListsScreen.kt index 4c4ad48..cab8856 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/ui/lists/ListsScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/ui/lists/ListsScreen.kt @@ -347,11 +347,15 @@ fun ListsScreen( todayOnly = choosingBlock.type == BlockType.PROGRESS, onPick = { source -> viewModel.chooseSource(content.view.id, choosingBlock.id, source) }, onDismiss = { choosingSourceFor = null }, - onCustomRules = if (choosingBlock.type == BlockType.PROGRESS) null else ({ onEditBlockRules(content.view.id, choosingBlock.id) }), + // Only a tile and a preview can show custom rules so far. + onCustomRules = if (choosingBlock.type in CUSTOM_RULE_BLOCKS) ({ onEditBlockRules(content.view.id, choosingBlock.id) }) else null, ) } } +/** The blocks that can show a [BlockSource.Rules] source. */ +private val CUSTOM_RULE_BLOCKS = setOf(BlockType.COUNT_TILE, BlockType.PREVIEW) + /** * Wording for a refused list write. * @@ -543,12 +547,13 @@ private fun Tile( modifier = modifier, ) } - BlockType.COUNT_TILE -> state.counts[block.id]?.takeIf { filter != null }?.let { count -> + // Custom rules have no screen of their own to open, so their tile only counts. + BlockType.COUNT_TILE -> state.counts[block.id]?.takeIf { filter != null || source is BlockSource.Rules }?.let { count -> CountCard( style = tileStyle(source!!, state), count = count, modifier = modifier, - onClick = { onOpenFilter(filter!!, scopeFor(block)) }, + onClick = { filter?.let { onOpenFilter(it, scopeFor(block)) } }, ) } else -> null @@ -588,7 +593,8 @@ private fun LazyListScope.previewSection( ) { // TODO(#59): inline done. val source = block.source ?: return - val filter = source.taskFilter ?: return + val filter = source.taskFilter + if (filter == null && source !is BlockSource.Rules) return val options = block.options as BlockOptions.Preview val tasks = state.previews[block.id].orEmpty() if (tasks.isEmpty()) return @@ -597,7 +603,7 @@ private fun LazyListScope.previewSection( UpcomingPreview( tasks = tasks, onOpenTask = onOpenTask, - onViewAll = if (options.showAll) ({ onOpenFilter(filter) }) else null, + onViewAll = if (options.showAll && filter != null) ({ onOpenFilter(filter) }) else null, ) } }