Skip to content

Commit

Permalink
Merge pull request #65 from opatry/64-crash-when-changing-sorting-on-…
Browse files Browse the repository at this point in the history
…android

Fix `DateRange` used directly as key in `stickyHeader`
  • Loading branch information
opatry authored Oct 15, 2024
2 parents b92ebd9 + 632212d commit 07766b2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ fun TasksColumn(

taskList.remainingTasks.forEach { (dateRange, tasks) ->
if (dateRange != null) {
stickyHeader(key = dateRange) {
stickyHeader(key = dateRange.key) {
Box(
Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 07766b2

Please sign in to comment.