Refresh widgets on range change, cap Up next, flag a limited Upcoming (#128)
This commit is contained in:
1 parent
867ba6c109
commit
dd9911e7dd
8 files changed
+70
-13
No files matched your search
+2
-2
@@ -10,8 +10,8 @@ All notable changes to this project are documented here. The format follows
|
||||
### Added
|
||||
- Upcoming can be limited to tasks due within the next week, two weeks,
|
||||
month, three months or year, from its view options. The home count and
|
||||
preview and Upcoming widgets follow; tasks due further ahead stay in All
|
||||
(#128).
|
||||
preview, Upcoming widgets and the Up next widget follow; tasks due further
|
||||
ahead stay in All (#128).
|
||||
|
||||
## [1.3.2] - 2026-11-13
|
||||
|
||||
|
||||
@@ -167,8 +167,9 @@ class ListsViewModel @Inject constructor(
|
||||
// The smart counts leave out the hidden lists; each list's own count does not.
|
||||
val smartTopLevel = topLevel.filter { it.listId !in hidden }
|
||||
val upcomingEnd = upcomingRange.end(now, zone)
|
||||
val smartFilters = SmartList.entries.associateWith { TaskFilter.Smart(it) }
|
||||
fun inSmart(task: Task, smart: SmartList) =
|
||||
TaskFiltering.matches(task, TaskFilter.Smart(smart), todayStart, todayEnd, upcomingEnd = upcomingEnd)
|
||||
TaskFiltering.matches(task, smartFilters.getValue(smart), todayStart, todayEnd, upcomingEnd = upcomingEnd)
|
||||
fun count(smart: SmartList) = smartTopLevel.count { inSmart(it, smart) }
|
||||
|
||||
val smartCounts = listOf(
|
||||
|
||||
@@ -209,7 +209,8 @@ fun TaskListScreen(
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = { showSort = true }, enabled = content != null) {
|
||||
BadgedBox(badge = { if (content?.selectedTags?.isNotEmpty() == true) Badge() }) {
|
||||
val narrowed = content?.selectedTags?.isNotEmpty() == true || content?.upcomingLimited == true
|
||||
BadgedBox(badge = { if (narrowed) Badge() }) {
|
||||
Icon(Icons.Rounded.Tune, contentDescription = stringResource(R.string.view_options_title))
|
||||
}
|
||||
}
|
||||
@@ -436,7 +437,8 @@ private fun TaskListBody(
|
||||
),
|
||||
) {
|
||||
if (state.tasks.isEmpty()) {
|
||||
item(key = "empty") { EmptyState(stringResource(R.string.task_list_empty)) }
|
||||
val empty = if (state.upcomingLimited) R.string.upcoming_range_empty else R.string.task_list_empty
|
||||
item(key = "empty") { EmptyState(stringResource(empty)) }
|
||||
}
|
||||
|
||||
sections.forEach { section ->
|
||||
|
||||
@@ -9,6 +9,7 @@ import de.jeanlucmakiola.agendula.data.sync.RemoteLists
|
||||
import de.jeanlucmakiola.agendula.data.tasks.TasksRepository
|
||||
import de.jeanlucmakiola.agendula.data.tasks.recoveringFromProviderFailure
|
||||
import de.jeanlucmakiola.agendula.domain.SavedFilter
|
||||
import de.jeanlucmakiola.agendula.domain.SmartList
|
||||
import de.jeanlucmakiola.agendula.domain.Task
|
||||
import de.jeanlucmakiola.agendula.domain.TaskFilter
|
||||
import de.jeanlucmakiola.agendula.domain.TaskFiltering
|
||||
@@ -18,6 +19,7 @@ import de.jeanlucmakiola.agendula.domain.TaskList
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSection
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSortOrder
|
||||
import de.jeanlucmakiola.agendula.domain.UpcomingRange
|
||||
import de.jeanlucmakiola.agendula.widget.TaskWidgetUpdater
|
||||
import de.jeanlucmakiola.agendula.domain.comparator
|
||||
import de.jeanlucmakiola.agendula.ui.lists.ListWriteFailure
|
||||
import de.jeanlucmakiola.agendula.ui.lists.asFailure
|
||||
@@ -73,7 +75,11 @@ sealed interface TaskListUiState {
|
||||
val savedFilter: SavedFilter? = null,
|
||||
/** The filter this content was built for; a reused screen briefly holds the previous one's. */
|
||||
val filter: TaskFilter? = null,
|
||||
) : TaskListUiState
|
||||
) : TaskListUiState {
|
||||
/** Upcoming, narrowed to a time frame the user picked. */
|
||||
val upcomingLimited: Boolean
|
||||
get() = filter == TaskFilter.Smart(SmartList.UPCOMING) && upcomingRange != UpcomingRange.ALL
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,6 +103,7 @@ class TaskListViewModel @Inject constructor(
|
||||
private val settingsPrefs: SettingsPrefs,
|
||||
private val remoteLists: RemoteLists,
|
||||
private val manualSync: ManualSync,
|
||||
private val widgetUpdater: TaskWidgetUpdater,
|
||||
@ApplicationScope private val appScope: CoroutineScope,
|
||||
) : ViewModel() {
|
||||
|
||||
@@ -299,7 +306,10 @@ class TaskListViewModel @Inject constructor(
|
||||
|
||||
fun setSortOrder(order: TaskSortOrder) = viewModelScope.launch { settingsPrefs.setSortOrder(order) }
|
||||
|
||||
fun setUpcomingRange(range: UpcomingRange) = viewModelScope.launch { settingsPrefs.setUpcomingRange(range) }
|
||||
fun setUpcomingRange(range: UpcomingRange) = viewModelScope.launch {
|
||||
settingsPrefs.setUpcomingRange(range)
|
||||
widgetUpdater.requestRefresh()
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes every completed task in [listId]. A completed occurrence goes on its
|
||||
|
||||
@@ -11,6 +11,7 @@ import de.jeanlucmakiola.agendula.domain.TaskFiltering
|
||||
import de.jeanlucmakiola.agendula.domain.TaskList
|
||||
import de.jeanlucmakiola.agendula.domain.calendarDate
|
||||
import de.jeanlucmakiola.agendula.domain.comparator
|
||||
import de.jeanlucmakiola.agendula.domain.wallClock
|
||||
import de.jeanlucmakiola.floret.time.DayWindow
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.catch
|
||||
@@ -71,9 +72,21 @@ internal fun todayProgress(
|
||||
return Triple(done, remaining.size, remaining.take(MAX_TODAY_ROWS).map { it.toWidgetRow(now, today, zone) })
|
||||
}
|
||||
|
||||
/** Open dated tasks by earliest due moment, overdue included; undated tasks are skipped. */
|
||||
internal fun upcoming(open: List<Task>, now: Instant, today: LocalDate, zone: ZoneId): List<WidgetTaskRow> =
|
||||
open.filter { it.due != null }.sortedBy { it.due!! }.take(MAX_UPCOMING_ROWS).map { it.toWidgetRow(now, today, zone) }
|
||||
/**
|
||||
* Open dated tasks by earliest due moment, overdue included; undated tasks are
|
||||
* skipped, and so are those due from [end] on (see [de.jeanlucmakiola.agendula.domain.UpcomingRange.end]).
|
||||
*/
|
||||
internal fun upcoming(
|
||||
open: List<Task>,
|
||||
now: Instant,
|
||||
today: LocalDate,
|
||||
zone: ZoneId,
|
||||
end: Instant? = null,
|
||||
): List<WidgetTaskRow> =
|
||||
open.filter { task -> task.wallClock(task.due, zone)?.let { end == null || it < end } ?: false }
|
||||
.sortedBy { it.due!! }
|
||||
.take(MAX_UPCOMING_ROWS)
|
||||
.map { it.toWidgetRow(now, today, zone) }
|
||||
|
||||
private const val MAX_UPCOMING_ROWS = 200
|
||||
|
||||
@@ -141,7 +154,7 @@ internal fun Context.widgetStats(): Flow<WidgetStatsData> {
|
||||
todayDone = done,
|
||||
todayRemaining = remaining,
|
||||
todayTasks = todayTasks,
|
||||
upcoming = upcoming(open, now, today, zone),
|
||||
upcoming = upcoming(open, now, today, zone, settings.upcomingRange.end(now, zone)),
|
||||
week = weekDays(open, comparator, now, today, zone),
|
||||
lists = listTiles(open, lists),
|
||||
dynamicColor = settings.dynamicColor,
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
<string name="upcoming_range_month">The next month</string>
|
||||
<string name="upcoming_range_three_months">The next 3 months</string>
|
||||
<string name="upcoming_range_year">The next year</string>
|
||||
<string name="upcoming_range_empty">Nothing due in this time frame. Widen it in the view options.</string>
|
||||
<string name="view_filter_clear">Clear filter</string>
|
||||
<string name="sort_due">Due date</string>
|
||||
<string name="sort_priority">Priority</string>
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package de.jeanlucmakiola.agendula.domain
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.floret.time.DayWindow
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
import kotlin.time.Instant
|
||||
|
||||
class TaskFilteringTest {
|
||||
@@ -43,8 +46,24 @@ class TaskFilteringTest {
|
||||
TaskFiltering.matches(task, TaskFilter.Smart(SmartList.UPCOMING), todayStart, todayEnd, upcomingEnd = end)
|
||||
assertThat(inUpcoming(testTask(due = at(1015 * dayMs - 1)))).isTrue()
|
||||
assertThat(inUpcoming(testTask(due = at(1015 * dayMs)))).isFalse()
|
||||
assertThat(TaskFiltering.matches(testTask(due = at(1100 * dayMs)), TaskFilter.Smart(SmartList.ALL), todayStart, todayEnd, upcomingEnd = end))
|
||||
.isTrue()
|
||||
val farOff = testTask(due = at(1100 * dayMs))
|
||||
assertThat(TaskFiltering.matches(farOff, TaskFilter.Smart(SmartList.ALL), todayStart, todayEnd, upcomingEnd = end)).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an all-day due on the range's last day stays in upcoming`() {
|
||||
val zone = ZoneId.systemDefault()
|
||||
val today = LocalDate.of(2026, 3, 10)
|
||||
val (start, end) = DayWindow.today(
|
||||
Instant.fromEpochMilliseconds(today.atTime(9, 0).atZone(zone).toInstant().toEpochMilli()),
|
||||
zone,
|
||||
)
|
||||
val upcomingEnd = UpcomingRange.WEEK.end(start, zone)
|
||||
fun dueOn(date: LocalDate) = testTask(due = allDayInstantOf(date), isAllDay = true)
|
||||
fun inUpcoming(task: Task) =
|
||||
TaskFiltering.matches(task, TaskFilter.Smart(SmartList.UPCOMING), start, end, upcomingEnd = upcomingEnd)
|
||||
assertThat(inUpcoming(dueOn(today.plusDays(7)))).isTrue()
|
||||
assertThat(inUpcoming(dueOn(today.plusDays(8)))).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.truth.Truth.assertThat
|
||||
import de.jeanlucmakiola.agendula.domain.TaskList
|
||||
import de.jeanlucmakiola.agendula.domain.TaskSortOrder
|
||||
import de.jeanlucmakiola.agendula.domain.TaskStatus
|
||||
import de.jeanlucmakiola.agendula.domain.UpcomingRange
|
||||
import de.jeanlucmakiola.agendula.domain.allDayInstantOf
|
||||
import de.jeanlucmakiola.agendula.domain.comparator
|
||||
import de.jeanlucmakiola.agendula.domain.testTask
|
||||
@@ -100,6 +101,16 @@ class WidgetStatsTest {
|
||||
assertThat(upcoming(open, now, today, newYork).map { it.taskId }).containsExactly(3L, 2L).inOrder()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `upcoming stops at the range end`() {
|
||||
val open = listOf(
|
||||
testTask(id = 1, due = at("2026-07-27T23:00:00")),
|
||||
testTask(id = 2, due = at("2026-07-28T00:00:00")),
|
||||
)
|
||||
val end = UpcomingRange.WEEK.end(now, newYork)
|
||||
assertThat(upcoming(open, now, today, newYork, end).map { it.taskId }).containsExactly(1L)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `upcoming is empty when nothing is dated`() {
|
||||
assertThat(upcoming(listOf(testTask(due = null)), now, today, newYork)).isEmpty()
|
||||
|
||||
Reference in new issue
Block a user