Group overdue tasks together

pull/1723/head
Alex Baker 3 years ago
parent 3d7e4c1993
commit 58a2b16662

@ -18,7 +18,7 @@ data class AdapterSection(
) {
fun headerColor(context: Context, sortMode: Int, textColor: Int = R.color.text_secondary) =
ContextCompat.getColor(context, if ((sortMode == SORT_DUE || sortMode == SORT_START)
&& value > 0
&& (value > 0 || value == -1L)
&& value.toDateTime().plusDays(1).startOfDay().isBeforeNow) {
R.color.overdue
} else {
@ -35,6 +35,7 @@ data class AdapterSection(
): String =
when {
sortMode == SORT_IMPORTANCE -> context.getString(priorityToString())
value == -1L -> context.getString(R.string.filter_overdue)
value == 0L -> context.getString(when (sortMode) {
SORT_DUE -> R.string.no_due_date
SORT_START -> R.string.no_start_date

@ -2,9 +2,9 @@ package org.tasks.tasklist
import android.util.SparseArray
import androidx.core.util.forEach
import com.todoroo.andlib.utility.DateUtilities.now
import com.todoroo.astrid.core.SortHelper
import org.tasks.data.TaskContainer
import org.tasks.date.DateTimeUtils
import org.tasks.time.DateTimeUtils.startOfDay
import java.util.*
@ -58,11 +58,18 @@ class SectionedDataSource constructor(
private fun getSections(): SparseArray<AdapterSection> {
val sections = ArrayList<AdapterSection>()
val startOfToday = now().startOfDay()
for (i in tasks.indices) {
val task = tasks[i]
val sortGroup = task.sortGroup ?: continue
val header = if (sortMode == SortHelper.SORT_IMPORTANCE || sortGroup == 0L) {
sortGroup
} else if (sortMode == SortHelper.SORT_DUE) {
when {
sortGroup == 0L -> 0
sortGroup < startOfToday -> -1
else -> sortGroup.startOfDay()
}
} else {
sortGroup.startOfDay()
}
@ -75,7 +82,17 @@ class SectionedDataSource constructor(
SortHelper.SORT_IMPORTANCE -> if (header != previous) {
sections.add(AdapterSection(i, header, 0, isCollapsed))
}
else -> if (previous > 0 && header != DateTimeUtils.newDateTime(previous).startOfDay().millis) {
SortHelper.SORT_DUE -> {
val previousOverdue = previous < startOfToday
val currentOverdue = header == -1L
if (previous > 0 &&
((currentOverdue != previousOverdue) ||
(!currentOverdue && header != previous.startOfDay()))
) {
sections.add(AdapterSection(i, header, 0, isCollapsed))
}
}
else -> if (previous > 0 && header != previous.startOfDay()) {
sections.add(AdapterSection(i, header, 0, isCollapsed))
}
}

@ -10,6 +10,7 @@ import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.chip.ChipGroup
import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.andlib.utility.DateUtilities.now
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.core.SortHelper.SORT_DUE
import com.todoroo.astrid.core.SortHelper.SORT_START
@ -193,8 +194,9 @@ class TaskViewHolder internal constructor(
dueDate.setTextColor(textColorSecondary)
}
val dateValue: String? = if (sortByDueDate
&& task.sortGroup?.startOfDay() == task.dueDate.startOfDay()
&& preferences.showGroupHeaders()) {
&& task.sortGroup >= now().startOfDay()
&& preferences.showGroupHeaders()
) {
task.takeIf { it.hasDueTime() }?.let {
DateUtilities.getTimeString(context, newDateTime(task.dueDate))
}

Loading…
Cancel
Save