diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/SettingsPrefs.kt b/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/SettingsPrefs.kt index e7b1f2e..990a03b 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/SettingsPrefs.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/SettingsPrefs.kt @@ -623,13 +623,14 @@ class SettingsPrefs @Inject constructor( } /** - * The views in order, with the list ids of the current store (see [listScope]), - * Home first (see [withHomeFirst]). + * The views in order, with the list ids of the current store, Home first (see + * [withHomeFirst]). Lists are qualified by the store alone, as the saved + * filters' are, since both share one rule grammar. */ val views: Flow> = - dataStore.data.map { p -> p[VIEWS] to scopeOf(p) } + dataStore.data.map { p -> p[VIEWS] to p[STORAGE_MODE] } .distinctUntilChanged() - .map { (raw, scope) -> ViewCodec.decode(raw, scope).withHomeFirst() } + .map { (raw, mode) -> ViewCodec.decode(raw, (storedMode(mode) ?: resolver.autoMode()).name).withHomeFirst() } .distinctUntilChanged() .flowOn(Dispatchers.Default) diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/ViewCodec.kt b/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/ViewCodec.kt index 34bc7ad..e7326e5 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/ViewCodec.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/data/prefs/ViewCodec.kt @@ -26,8 +26,10 @@ import java.net.URLEncoder * `list:OWN%3A3`, `tag:…`, `filter:4` or `rules:…`; options are `key=value` * pairs joined by `;`. Text is URL-encoded and booleans are `1` / `0`. * - * A writer has to keep the lines [decode] skips rather than encode only what it - * read, or a view from a newer version, or with a scope that doesn't parse, is lost. + * A later version that adds an option key or an enum value bumps [VERSION], so an + * older one reads none of its layout rather than a part of it. A writer has to + * keep the lines [decode] skips rather than encode only what it read, or a view + * from a newer version, or with a scope that doesn't parse, is lost. * * Fixed once released — don't change without a data migration. */ 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 b13461b..b856b76 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 @@ -296,16 +296,17 @@ private fun ListsContent( ) { // TODO(#59): apply the view's scope once views other than Home can have one. rows.forEach { row -> - // Tiles share a row, but a full progress tile stands alone like the Today hero always has. - val block = row.singleOrNull()?.takeIf { it.width == BlockWidth.FULL && it.type != BlockType.COUNT_TILE } - if (block == null) { - item { HalfRow(row, state, onOpenFilter) } + val block = row.first() + if (block.type in TILES) { + // A full progress tile stands alone, as the Today hero always has; other tiles share a row. + if (block.type == BlockType.PROGRESS && block.width == BlockWidth.FULL) { + item { Tile(block, state, onOpenFilter, Modifier.fillMaxWidth().padding(horizontal = 16.dp)) } + } else { + item { HalfRow(row, state, onOpenFilter) } + } return@forEach } when (block.type) { - BlockType.PROGRESS -> item { - Tile(block, state, onOpenFilter, Modifier.fillMaxWidth().padding(horizontal = 16.dp)) - } BlockType.PREVIEW -> previewSection(block, state, onOpenFilter, onOpenTask) BlockType.LISTS -> listsSection( key = "${block.id}", @@ -321,8 +322,8 @@ private fun ListsContent( BlockType.FILTERS -> if (state.groups.isNotEmpty()) { filtersSection("${block.id}", state.filters, onOpenFilter, onNewFilter) } - // Count tiles always go to a tile row above. - BlockType.COUNT_TILE -> Unit + // Rendered as tiles above. + BlockType.PROGRESS, BlockType.COUNT_TILE -> Unit // TODO(#59): the rest of the catalog renders from phase 3 on. BlockType.TASK_LIST, BlockType.SECTION_HEADING, @@ -334,6 +335,8 @@ private fun ListsContent( } } +private val TILES = setOf(BlockType.PROGRESS, BlockType.COUNT_TILE) + /** What a progress block shows: done of total for its source, or `null` for a source it can't show yet. */ private data class ProgressState(val done: Int, val total: Int, val filter: TaskFilter, val title: String?) @@ -341,7 +344,7 @@ private fun progressFor(block: Block, state: ListsUiState.Content): ProgressStat val source = block.source as? BlockSource.Smart ?: return null if (source.smart != SmartList.TODAY) return null val title = (block.options as BlockOptions.Progress).title - return ProgressState(state.todayDone, state.todayTotal, TaskFilter.Smart(SmartList.TODAY), title) + return ProgressState(state.todayDone, state.todayTotal, TaskFilter.Smart(source.smart), title) } /** The smart count a count tile shows; `null` for a source it can't show yet. */ @@ -373,7 +376,7 @@ private fun Tile( onOpenFilter: (TaskFilter) -> Unit, modifier: Modifier = Modifier, ) { - // TODO(#59): the wave switch and a tile's own title, colour and icon render from phase 3 on. + // TODO(#59): the wave switch, and a count tile's own title, colour and icon. when (block.type) { BlockType.PROGRESS -> progressFor(block, state)?.let { progress -> TodayHero(progress, onClick = { onOpenFilter(progress.filter) }, modifier = modifier) @@ -392,17 +395,17 @@ private fun LazyListScope.previewSection( onOpenFilter: (TaskFilter) -> Unit, onOpenTask: (Task) -> Unit, ) { - // TODO(#59): other sources once the preview block can take them. - if (block.source != BlockSource.Smart(SmartList.UPCOMING)) return + // TODO(#59): sources beyond the smart lists, and inline done. + val smart = (block.source as? BlockSource.Smart)?.smart ?: return val options = block.options as BlockOptions.Preview val tasks = state.previews[block.id].orEmpty() if (tasks.isEmpty()) return - item { SectionHeader(stringResource(R.string.smart_upcoming)) } + item { SectionHeader(stringResource(smartStyle(smart).labelRes)) } item { UpcomingPreview( tasks = tasks, onOpenTask = onOpenTask, - onViewAll = if (options.showAll) ({ onOpenFilter(TaskFilter.Smart(SmartList.UPCOMING)) }) else null, + onViewAll = if (options.showAll) ({ onOpenFilter(TaskFilter.Smart(smart)) }) else null, ) } } diff --git a/app/src/main/java/de/jeanlucmakiola/agendula/ui/lists/ListsViewModel.kt b/app/src/main/java/de/jeanlucmakiola/agendula/ui/lists/ListsViewModel.kt index 160b1d8..170d551 100644 --- a/app/src/main/java/de/jeanlucmakiola/agendula/ui/lists/ListsViewModel.kt +++ b/app/src/main/java/de/jeanlucmakiola/agendula/ui/lists/ListsViewModel.kt @@ -116,9 +116,13 @@ sealed interface ListsUiState { * The tasks each preview block of this view shows, by block id: the first of * [upcoming] for a preview of Upcoming. Other sources show nothing yet. */ -internal fun View.previews(upcoming: Sequence): Map> = blocks - .filter { it.type == BlockType.PREVIEW && it.source == BlockSource.Smart(SmartList.UPCOMING) } - .associate { it.id to upcoming.take((it.options as BlockOptions.Preview).count).toList() } +internal fun View.previews(upcoming: Sequence): Map> { + val counts = blocks + .filter { it.type == BlockType.PREVIEW && it.source == BlockSource.Smart(SmartList.UPCOMING) } + .associate { it.id to (it.options as BlockOptions.Preview).count } + val next = upcoming.take(counts.values.maxOrNull() ?: 0).toList() + return counts.mapValues { (_, count) -> next.take(count) } +} /** The home overview: smart lists with live counts, then user lists by account. */ @HiltViewModel diff --git a/app/src/test/java/de/jeanlucmakiola/agendula/data/prefs/ViewCodecTest.kt b/app/src/test/java/de/jeanlucmakiola/agendula/data/prefs/ViewCodecTest.kt index 137f0bf..095611f 100644 --- a/app/src/test/java/de/jeanlucmakiola/agendula/data/prefs/ViewCodecTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/agendula/data/prefs/ViewCodecTest.kt @@ -97,15 +97,6 @@ class ViewCodecTest { assertThat(odd.blocks.single().source).isEqualTo(BlockSource.ListElsewhere("OWN:abc")) } - @Test - fun `an external provider's lists are its own`() { - val view = View(1, "x", ViewIcon.HOME, null, listOf(Block(1, BlockType.COUNT_TILE, BlockSource.List(5)))) - val raw = ViewCodec.encode(listOf(view), "EXTERNAL@org.tasks.opentasks") - assertThat(ViewCodec.decode(raw, "EXTERNAL@org.tasks.opentasks")).containsExactly(view) - assertThat(ViewCodec.decode(raw, "EXTERNAL").single().blocks.single().source) - .isEqualTo(BlockSource.ListElsewhere("EXTERNAL@org.tasks.opentasks:5")) - } - @Test fun `nothing stored, or another version, reads as no views`() { assertThat(ViewCodec.decode(null, "OWN")).isEmpty()