From 632212dd89a3585004cdc4322a101196845b966c Mon Sep 17 00:00:00 2001 From: Olivier Patry Date: Tue, 15 Oct 2024 19:48:16 +0200 Subject: [PATCH] Fix DateRange used directly as key in stickyHeader --- .../net/opatry/tasks/app/ui/TaskListsViewModel.kt | 2 +- .../net/opatry/tasks/app/ui/screen/tasksPane.kt | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tasks-app-shared/src/commonMain/kotlin/net/opatry/tasks/app/ui/TaskListsViewModel.kt b/tasks-app-shared/src/commonMain/kotlin/net/opatry/tasks/app/ui/TaskListsViewModel.kt index 0cb54278..c8d7b01a 100644 --- a/tasks-app-shared/src/commonMain/kotlin/net/opatry/tasks/app/ui/TaskListsViewModel.kt +++ b/tasks-app-shared/src/commonMain/kotlin/net/opatry/tasks/app/ui/TaskListsViewModel.kt @@ -59,7 +59,7 @@ private fun TaskListDataModel.asTaskListUIModel(): TaskListUIModel { .groupBy { task -> when (task.dateRange) { // merge all overdue tasks to the same range - is DateRange.Overdue -> DateRange.Overdue(LocalDate.fromEpochDays(-1), 1) + is DateRange.Overdue -> DateRange.Overdue(LocalDate.fromEpochDays(0), -1) else -> task.dateRange } } diff --git a/tasks-app-shared/src/commonMain/kotlin/net/opatry/tasks/app/ui/screen/tasksPane.kt b/tasks-app-shared/src/commonMain/kotlin/net/opatry/tasks/app/ui/screen/tasksPane.kt index 70bb570d..60fefedf 100644 --- a/tasks-app-shared/src/commonMain/kotlin/net/opatry/tasks/app/ui/screen/tasksPane.kt +++ b/tasks-app-shared/src/commonMain/kotlin/net/opatry/tasks/app/ui/screen/tasksPane.kt @@ -606,7 +606,7 @@ fun TasksColumn( taskList.remainingTasks.forEach { (dateRange, tasks) -> if (dateRange != null) { - stickyHeader(key = dateRange) { + stickyHeader(key = dateRange.key) { Box( Modifier .fillMaxWidth() @@ -689,8 +689,16 @@ fun TasksColumn( } } +private val DateRange.key: String + get() = when (this) { + is DateRange.Overdue -> "overdue${numberOfDays}" + is DateRange.Today -> "today" + is DateRange.Later -> "later${numberOfDays}" + DateRange.None -> "none" + } + @Composable -fun DateRange?.toColor(): Color = when (this) { +private fun DateRange?.toColor(): Color = when (this) { is DateRange.Overdue -> MaterialTheme.colorScheme.error is DateRange.Today -> MaterialTheme.colorScheme.primary is DateRange.Later, @@ -699,7 +707,7 @@ fun DateRange?.toColor(): Color = when (this) { } @Composable -fun DateRange.toLabel(sectionLabel: Boolean = false): String = when (this) { +private fun DateRange.toLabel(sectionLabel: Boolean = false): String = when (this) { is DateRange.Overdue -> { val numberOfDays = abs(numberOfDays) when {