1 parent
9b178fc80b
commit
dd1a801560
8 files changed
+67
-15
No files matched your search
@@ -30,7 +30,7 @@ import de.jeanlucmakiola.agendula.domain.asReminderLead
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSortOrder
|
||||
import de.jeanlucmakiola.agendula.domain.SmartList
|
||||
import de.jeanlucmakiola.agendula.domain.UpcomingRange
|
||||
import de.jeanlucmakiola.agendula.domain.dueBefore
|
||||
import de.jeanlucmakiola.agendula.domain.withinUpcoming
|
||||
import de.jeanlucmakiola.floret.reminders.ReminderLead
|
||||
import de.jeanlucmakiola.floret.reminders.ReminderOverride
|
||||
import de.jeanlucmakiola.floret.reminders.ReminderOverrideCodec
|
||||
@@ -70,6 +70,9 @@ fun TimeFormatPref.is24Hour(systemIs24Hour: Boolean): Boolean = when (this) {
|
||||
TimeFormatPref.TWENTY_FOUR_HOUR -> true
|
||||
}
|
||||
|
||||
/** What [Settings.viewOf] shows of a view's tasks, and whether the Upcoming range left some out. */
|
||||
data class SmartView(val tasks: List<Task>, val hiddenByRange: Boolean)
|
||||
|
||||
/** A list's own take on [Settings.persistentReminders]; [INHERIT] follows the app setting. */
|
||||
enum class ListPersistence { INHERIT, ALWAYS, NEVER }
|
||||
|
||||
@@ -170,11 +173,24 @@ data class Settings(
|
||||
tasks: List<Task>,
|
||||
now: Instant = Clock.System.now(),
|
||||
zone: ZoneId = ZoneId.systemDefault(),
|
||||
): List<Task> {
|
||||
if (filter !is TaskFilter.Smart) return tasks
|
||||
): List<Task> = viewOf(filter, tasks, now, zone).tasks
|
||||
|
||||
/** [visibleIn], and whether [upcomingRange] kept any of [tasks] out, in one pass. */
|
||||
fun viewOf(
|
||||
filter: TaskFilter,
|
||||
tasks: List<Task>,
|
||||
now: Instant = Clock.System.now(),
|
||||
zone: ZoneId = ZoneId.systemDefault(),
|
||||
): SmartView {
|
||||
if (filter !is TaskFilter.Smart) return SmartView(tasks, hiddenByRange = false)
|
||||
val end = if (filter.list == SmartList.UPCOMING) upcomingRange.end(now, zone) else null
|
||||
if (hiddenFromSmartLists.isEmpty() && end == null) return tasks
|
||||
return tasks.filter { it.listId !in hiddenFromSmartLists && (end == null || dueBefore(it, end, zone)) }
|
||||
if (hiddenFromSmartLists.isEmpty() && end == null) return SmartView(tasks, hiddenByRange = false)
|
||||
var hiddenByRange = false
|
||||
val kept = tasks.filter { task ->
|
||||
if (task.listId in hiddenFromSmartLists) return@filter false
|
||||
withinUpcoming(task, end, zone).also { if (!it) hiddenByRange = true }
|
||||
}
|
||||
return SmartView(kept, hiddenByRange)
|
||||
}
|
||||
|
||||
/** The lead times for a task in [listId]: its override if set, else the global default. */
|
||||
|
||||
@@ -69,19 +69,21 @@ fun newTaskDates(
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether an open task with these dates shows in [smartList], or passes
|
||||
* [savedFilter]'s due windows; with neither it shows anywhere.
|
||||
* Whether an open task with these dates shows in [smartList], Upcoming reaching
|
||||
* up to [upcomingEnd], or passes [savedFilter]'s due windows; with neither it
|
||||
* shows anywhere.
|
||||
*/
|
||||
fun NewTaskDates.showsIn(
|
||||
smartList: SmartList?,
|
||||
savedFilter: SavedFilter?,
|
||||
todayStart: Instant,
|
||||
todayEnd: Instant,
|
||||
upcomingEnd: Instant? = null,
|
||||
): Boolean {
|
||||
val probe = openTaskDated(start, due, isAllDay)
|
||||
return when {
|
||||
savedFilter != null -> savedFilter.due.isEmpty() || dueWindowOf(probe, todayStart, todayEnd) in savedFilter.due
|
||||
smartList != null -> TaskFiltering.matches(probe, TaskFilter.Smart(smartList), todayStart, todayEnd)
|
||||
smartList != null -> TaskFiltering.matches(probe, TaskFilter.Smart(smartList), todayStart, todayEnd, upcomingEnd = upcomingEnd)
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,6 @@ object TaskFiltering {
|
||||
SmartList.OVERDUE -> !task.isClosed && dueWindowOf(task, todayStart, todayEnd) == DueWindow.OVERDUE
|
||||
SmartList.TODAY -> isToday(task, todayStart, todayEnd)
|
||||
SmartList.UPCOMING -> !task.isClosed && dueWindowOf(task, todayStart, todayEnd) == DueWindow.UPCOMING &&
|
||||
(upcomingEnd == null || dueBefore(task, upcomingEnd))
|
||||
withinUpcoming(task, upcomingEnd)
|
||||
}
|
||||
}
|
||||
@@ -29,3 +29,10 @@ enum class UpcomingRange {
|
||||
/** Whether [task] is due before [end]; an undated task never is. */
|
||||
fun dueBefore(task: Task, end: Instant, zone: ZoneId = ZoneId.systemDefault()): Boolean =
|
||||
task.wallClock(TaskEnd.DUE, zone)?.let { it < end } ?: false
|
||||
|
||||
/**
|
||||
* Whether [task] is within the reach of Upcoming that ends at [end] (see
|
||||
* [UpcomingRange.end]); `null` is no limit. The one place the range applies.
|
||||
*/
|
||||
fun withinUpcoming(task: Task, end: Instant?, zone: ZoneId = ZoneId.systemDefault()): Boolean =
|
||||
end == null || dueBefore(task, end, zone)
|
||||
@@ -247,10 +247,12 @@ class TaskEditViewModel @Inject constructor(
|
||||
val now = Clock.System.now()
|
||||
val today = now.calendarDate(allDay = false)
|
||||
val preset = filter?.newTaskPreset(today)
|
||||
val (todayStart, todayEnd) = DayWindow.today(now, ZoneId.systemDefault())
|
||||
val zone = ZoneId.systemDefault()
|
||||
val (todayStart, todayEnd) = DayWindow.today(now, zone)
|
||||
val upcomingEnd = settings.upcomingRange.end(now, zone)
|
||||
val presetDue = preset?.dueDate ?: presetSmartList?.dueWindows?.presetDue(today)
|
||||
val dates = settings.defaultNewTaskDates(today, now, presetDue, subtask = parentId != null) {
|
||||
it.showsIn(presetSmartList, filter, todayStart, todayEnd)
|
||||
it.showsIn(presetSmartList, filter, todayStart, todayEnd, upcomingEnd)
|
||||
}
|
||||
startFollowsDue = settings.defaultStartDate.takeIf { dates.start != null && dates.due != null }
|
||||
// A read-only or vanished default — or a widget's preset list, if it was
|
||||
|
||||
@@ -50,7 +50,6 @@ import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
@@ -212,9 +211,7 @@ class TaskListViewModel @Inject constructor(
|
||||
combine(content, pendingDeletes, settingsPrefs.settings, tagFilter) { st, pending, settings, tags ->
|
||||
if (st is TaskListUiState.Content) {
|
||||
val now = Clock.System.now()
|
||||
val inView = settings.visibleIn(f, st.tasks, now)
|
||||
val hiddenByRange = settings.upcomingRange != UpcomingRange.ALL &&
|
||||
settings.copy(upcomingRange = UpcomingRange.ALL).visibleIn(f, st.tasks, now).size > inView.size
|
||||
val (inView, hiddenByRange) = settings.viewOf(f, st.tasks, now)
|
||||
val visible = inView.filter { it.occurrenceKey !in pending }
|
||||
val available = tagsInUse(visible) - setOfNotNull((f as? TaskFilter.Tagged)?.tag)
|
||||
// A tag that vanished can no longer be unticked, so it is dropped
|
||||
|
||||
@@ -35,5 +35,18 @@ class SettingsVisibilityTest {
|
||||
val upcoming = limited.visibleIn(TaskFilter.Smart(SmartList.UPCOMING), listOf(near, far), now, zone)
|
||||
assertThat(upcoming.map { it.taskId }).containsExactly(1L)
|
||||
assertThat(limited.visibleIn(TaskFilter.Smart(SmartList.ALL), listOf(near, far), now, zone)).hasSize(2)
|
||||
assertThat(limited.viewOf(TaskFilter.Smart(SmartList.UPCOMING), listOf(near, far), now, zone).hiddenByRange).isTrue()
|
||||
assertThat(limited.viewOf(TaskFilter.Smart(SmartList.UPCOMING), listOf(near), now, zone).hiddenByRange).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a hidden list is not counted as kept out by the range`() {
|
||||
val zone = ZoneId.of("UTC")
|
||||
val now = Instant.fromEpochMilliseconds(1000 * 86_400_000L)
|
||||
val hiddenFar = testTask(id = 2, listId = 2, due = Instant.fromEpochMilliseconds(1100 * 86_400_000L))
|
||||
val limited = settings.copy(upcomingRange = UpcomingRange.WEEK)
|
||||
val view = limited.viewOf(TaskFilter.Smart(SmartList.UPCOMING), listOf(hiddenFar), now, zone)
|
||||
assertThat(view.tasks).isEmpty()
|
||||
assertThat(view.hiddenByRange).isFalse()
|
||||
}
|
||||
}
|
||||
@@ -57,6 +57,21 @@ class NewTaskDefaultsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `a default due past a limited Upcoming gives way to the preset (#128)`() {
|
||||
val (start, end) = DayWindow.today(now, zone)
|
||||
val upcomingEnd = UpcomingRange.WEEK.end(now, zone)
|
||||
val preset = SmartList.UPCOMING.dueWindows.presetDue(localToday)
|
||||
val dates = newTaskDates(DefaultDueDate.NEXT_MONTH, DefaultStartDate.NONE, preset, localToday, now) {
|
||||
it.showsIn(SmartList.UPCOMING, null, start, end, upcomingEnd)
|
||||
}
|
||||
assertThat(dates.due).isEqualTo(allDayInstantOf(localToday.plusDays(1)))
|
||||
val unlimited = newTaskDates(DefaultDueDate.NEXT_MONTH, DefaultStartDate.NONE, preset, localToday, now) {
|
||||
it.showsIn(SmartList.UPCOMING, null, start, end)
|
||||
}
|
||||
assertThat(unlimited.due).isEqualTo(allDayInstantOf(localToday.plusMonths(1)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the default due applies where the view still shows the task, else its preset`() {
|
||||
val (start, end) = DayWindow.today(now, zone)
|
||||
|
||||
Reference in new issue
Block a user