From 075940d29e98911cf2bd3e03a460de6896441c25 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Fri, 23 Oct 2026 18:29:25 +0200 Subject: [PATCH] Today list widget: today's events, then tomorrow's first ones once the day is done (#438) --- app/src/main/AndroidManifest.xml | 12 + .../calendula/widget/WidgetKind.kt | 9 + .../widget/config/WidgetConfigScreen.kt | 3 + .../widget/config/WidgetConfigViewModel.kt | 2 + .../calendula/widget/today/TodayWidget.kt | 243 ++++++++++++++++++ .../main/res/layout/widget_preview_today.xml | 31 +++ app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/appwidget_info_today.xml | 18 ++ .../calendula/widget/today/TodayRowsTest.kt | 57 ++++ 9 files changed, 377 insertions(+) create mode 100644 app/src/main/java/de/jeanlucmakiola/calendula/widget/today/TodayWidget.kt create mode 100644 app/src/main/res/layout/widget_preview_today.xml create mode 100644 app/src/main/res/xml/appwidget_info_today.xml create mode 100644 app/src/test/java/de/jeanlucmakiola/calendula/widget/today/TodayRowsTest.kt diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 06eb245e..2907953a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -400,6 +400,18 @@ android:resource="@xml/appwidget_info_upcoming" /> + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c1672e45..335accfb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -445,6 +445,8 @@ Calendula upcoming No upcoming events + Calendula today + Nothing left today Refresh New event Open Calendula to grant calendar access diff --git a/app/src/main/res/xml/appwidget_info_today.xml b/app/src/main/res/xml/appwidget_info_today.xml new file mode 100644 index 00000000..753674be --- /dev/null +++ b/app/src/main/res/xml/appwidget_info_today.xml @@ -0,0 +1,18 @@ + + diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/widget/today/TodayRowsTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/widget/today/TodayRowsTest.kt new file mode 100644 index 00000000..a0cb36c6 --- /dev/null +++ b/app/src/test/java/de/jeanlucmakiola/calendula/widget/today/TodayRowsTest.kt @@ -0,0 +1,57 @@ +package de.jeanlucmakiola.calendula.widget.today + +import com.google.common.truth.Truth.assertThat +import de.jeanlucmakiola.calendula.data.prefs.PastEventDisplay +import de.jeanlucmakiola.calendula.domain.EventInstance +import de.jeanlucmakiola.calendula.ui.agenda.AgendaDay +import de.jeanlucmakiola.calendula.ui.agenda.AgendaRange +import de.jeanlucmakiola.calendula.widget.AgendaWidgetOptions +import de.jeanlucmakiola.calendula.widget.DaysWidgetData +import de.jeanlucmakiola.calendula.widget.WidgetSize +import kotlinx.datetime.DayOfWeek +import kotlinx.datetime.LocalDate +import org.junit.jupiter.api.Test +import kotlin.time.Duration.Companion.hours +import kotlin.time.Instant + +class TodayRowsTest { + + private val now = Instant.parse("2026-10-21T12:00:00Z") + private val today = LocalDate(2026, 10, 21) + private val tomorrow = LocalDate(2026, 10, 22) + + private fun event(id: Long, start: Instant, end: Instant) = EventInstance( + instanceId = id, eventId = id, calendarId = 1, title = "e$id", + start = start, end = end, isAllDay = false, color = 0, location = null, + ) + + private fun data(past: PastEventDisplay, vararg days: AgendaDay) = DaysWidgetData.Ready( + today = today, + firstDay = today, + lastDay = tomorrow, + days = days.toList(), + weekStart = DayOfWeek.MONDAY, + is24Hour = true, + soften = true, + options = AgendaWidgetOptions(AgendaRange.Day, WidgetSize.SMALL, true, past), + now = now, + ) + + private val ended = event(1, now - 3.hours, now - 1.hours) + private val later = event(2, now + 1.hours, now + 2.hours) + private val next = event(3, now + 22.hours, now + 23.hours) + + @Test + fun `an event still to come lists today, finished ones as the past setting says`() { + val days = arrayOf(AgendaDay(today, listOf(ended, later)), AgendaDay(tomorrow, listOf(next))) + assertThat(todayRows(data(PastEventDisplay.DIM, *days))).isEqualTo(TodayRows.Today(listOf(ended, later))) + assertThat(todayRows(data(PastEventDisplay.HIDE, *days))).isEqualTo(TodayRows.Today(listOf(later))) + } + + @Test + fun `once today is over it looks ahead to tomorrow`() { + val over = data(PastEventDisplay.SHOW, AgendaDay(today, listOf(ended)), AgendaDay(tomorrow, listOf(next))) + assertThat(todayRows(over)).isEqualTo(TodayRows.NothingLeft(listOf(next))) + assertThat(todayRows(data(PastEventDisplay.SHOW))).isEqualTo(TodayRows.NothingLeft(emptyList())) + } +}