Today list widget: today's events, then tomorrow's first ones once the day is done (#438)
This commit is contained in:
1 parent
670cdb226a
commit
075940d29e
9 files changed
+377
No files matched your search
@@ -400,6 +400,18 @@
|
||||
android:resource="@xml/appwidget_info_upcoming" />
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".widget.today.TodayWidgetReceiver"
|
||||
android:label="@string/widget_today_label"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/appwidget_info_today" />
|
||||
</receiver>
|
||||
|
||||
<!-- Keeps both widgets fresh: the calendar provider broadcasts
|
||||
PROVIDER_CHANGED on any data change (external sync; the app's own
|
||||
writes redraw directly). The day boundary arrives as the app's own
|
||||
|
||||
@@ -18,6 +18,8 @@ import de.jeanlucmakiola.calendula.widget.week.WeekStripWidget
|
||||
import de.jeanlucmakiola.calendula.widget.week.WeekStripWidgetReceiver
|
||||
import de.jeanlucmakiola.calendula.widget.upcoming.UpcomingWidget
|
||||
import de.jeanlucmakiola.calendula.widget.upcoming.UpcomingWidgetReceiver
|
||||
import de.jeanlucmakiola.calendula.widget.today.TodayWidget
|
||||
import de.jeanlucmakiola.calendula.widget.today.TodayWidgetReceiver
|
||||
|
||||
/** A content option a widget's config screen offers, besides background and theme. */
|
||||
enum class WidgetOption { RANGE, TEXT_SIZE, PAST_DISPLAY, SHOW_TODAY, CALENDARS }
|
||||
@@ -69,6 +71,12 @@ enum class WidgetKind(
|
||||
setOf(WidgetOption.RANGE, WidgetOption.TEXT_SIZE, WidgetOption.CALENDARS),
|
||||
DpSize(180.dp, 180.dp),
|
||||
),
|
||||
TODAY(
|
||||
TodayWidgetReceiver::class.java,
|
||||
R.string.widget_today_label,
|
||||
setOf(WidgetOption.TEXT_SIZE, WidgetOption.PAST_DISPLAY, WidgetOption.CALENDARS),
|
||||
DpSize(300.dp, 100.dp),
|
||||
),
|
||||
;
|
||||
|
||||
fun widget(): GlanceAppWidget = when (this) {
|
||||
@@ -78,6 +86,7 @@ enum class WidgetKind(
|
||||
DATE -> DateWidget()
|
||||
WEEK_STRIP -> WeekStripWidget()
|
||||
UPCOMING -> UpcomingWidget()
|
||||
TODAY -> TodayWidget()
|
||||
}
|
||||
|
||||
/** Whether this kind stores [AgendaWidgetOptions] of its own. */
|
||||
|
||||
@@ -52,6 +52,7 @@ import de.jeanlucmakiola.calendula.widget.quickadd.QuickAddWidgetContent
|
||||
import de.jeanlucmakiola.calendula.widget.date.DateWidgetContent
|
||||
import de.jeanlucmakiola.calendula.widget.week.WeekStripWidgetContent
|
||||
import de.jeanlucmakiola.calendula.widget.upcoming.UpcomingWidgetContent
|
||||
import de.jeanlucmakiola.calendula.widget.today.TodayWidgetContent
|
||||
import de.jeanlucmakiola.calendula.widget.WidgetKind
|
||||
import de.jeanlucmakiola.floret.components.GroupedChoiceRow
|
||||
import de.jeanlucmakiola.floret.components.GroupedHint
|
||||
@@ -152,6 +153,8 @@ internal fun WidgetConfigScreen(
|
||||
is WidgetPreviewData.Month ->
|
||||
MonthWidgetContent(preview.source, preview.index, state.appearance, state.appTheme)
|
||||
is WidgetPreviewData.Days -> when (state.kind) {
|
||||
WidgetKind.TODAY ->
|
||||
TodayWidgetContent(preview.data, state.appearance, state.appTheme, preview = true)
|
||||
WidgetKind.UPCOMING -> UpcomingWidgetContent(preview.data, state.appearance, state.appTheme)
|
||||
else -> WeekStripWidgetContent(preview.data, state.appearance, state.appTheme)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import de.jeanlucmakiola.calendula.widget.WidgetSettings
|
||||
import de.jeanlucmakiola.calendula.widget.loadDays
|
||||
import de.jeanlucmakiola.calendula.widget.weekOf
|
||||
import de.jeanlucmakiola.calendula.widget.upcoming.loadUpcoming
|
||||
import de.jeanlucmakiola.calendula.widget.today.loadTodayList
|
||||
import de.jeanlucmakiola.calendula.widget.WidgetOption
|
||||
import de.jeanlucmakiola.calendula.widget.hiddenCalendars
|
||||
import de.jeanlucmakiola.calendula.widget.putHiddenCalendars
|
||||
@@ -239,6 +240,7 @@ class WidgetConfigViewModel @Inject constructor(
|
||||
}
|
||||
WidgetKind.QUICK_ADD, WidgetKind.DATE -> WidgetPreviewData.Today(today(systemZone()))
|
||||
WidgetKind.UPCOMING -> WidgetPreviewData.Days(context.loadUpcoming(draft.loadContext(settings)).content)
|
||||
WidgetKind.TODAY -> WidgetPreviewData.Days(context.loadTodayList(draft.loadContext(settings)).content)
|
||||
WidgetKind.WEEK_STRIP -> WidgetPreviewData.Days(context.loadDays(draft.loadContext(settings), ::weekOf).content)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
package de.jeanlucmakiola.calendula.widget.today
|
||||
|
||||
import android.content.Context
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.glance.GlanceId
|
||||
import androidx.glance.GlanceModifier
|
||||
import androidx.glance.GlanceTheme
|
||||
import androidx.glance.LocalContext
|
||||
import androidx.glance.LocalSize
|
||||
import androidx.glance.action.clickable
|
||||
import androidx.glance.appwidget.GlanceAppWidget
|
||||
import androidx.glance.appwidget.SizeMode
|
||||
import androidx.glance.appwidget.action.actionStartActivity
|
||||
import androidx.glance.appwidget.cornerRadius
|
||||
import androidx.glance.appwidget.lazy.LazyColumn
|
||||
import androidx.glance.appwidget.lazy.items
|
||||
import androidx.glance.appwidget.provideContent
|
||||
import androidx.glance.background
|
||||
import androidx.glance.currentState
|
||||
import androidx.glance.layout.Alignment
|
||||
import androidx.glance.layout.Box
|
||||
import androidx.glance.layout.Column
|
||||
import androidx.glance.layout.Row
|
||||
import androidx.glance.layout.Spacer
|
||||
import androidx.glance.layout.fillMaxHeight
|
||||
import androidx.glance.layout.fillMaxSize
|
||||
import androidx.glance.layout.fillMaxWidth
|
||||
import androidx.glance.layout.height
|
||||
import androidx.glance.layout.padding
|
||||
import androidx.glance.layout.width
|
||||
import androidx.glance.semantics.contentDescription
|
||||
import androidx.glance.semantics.semantics
|
||||
import androidx.glance.state.PreferencesGlanceStateDefinition
|
||||
import androidx.glance.text.FontWeight
|
||||
import androidx.glance.text.Text
|
||||
import androidx.glance.text.TextAlign
|
||||
import androidx.glance.text.TextStyle
|
||||
import de.jeanlucmakiola.calendula.MainActivity
|
||||
import de.jeanlucmakiola.calendula.R
|
||||
import de.jeanlucmakiola.calendula.data.prefs.PastEventDisplay
|
||||
import de.jeanlucmakiola.calendula.domain.EventInstance
|
||||
import de.jeanlucmakiola.calendula.domain.hasEnded
|
||||
import de.jeanlucmakiola.calendula.ui.common.CalendarView
|
||||
import de.jeanlucmakiola.calendula.widget.CalendulaWidgetReceiver
|
||||
import de.jeanlucmakiola.calendula.widget.CalendulaWidgetRoot
|
||||
import de.jeanlucmakiola.calendula.widget.DaysWidgetData
|
||||
import de.jeanlucmakiola.calendula.widget.EventRowMetrics
|
||||
import de.jeanlucmakiola.calendula.widget.WidgetAppearance
|
||||
import de.jeanlucmakiola.calendula.widget.WidgetEventRow
|
||||
import de.jeanlucmakiola.calendula.widget.WidgetLoadContext
|
||||
import de.jeanlucmakiola.calendula.widget.compactRowMetrics
|
||||
import de.jeanlucmakiola.calendula.widget.loadDays
|
||||
import de.jeanlucmakiola.calendula.widget.relativeDayLabel
|
||||
import de.jeanlucmakiola.calendula.widget.widgetAppearance
|
||||
import de.jeanlucmakiola.calendula.widget.widgetLocale
|
||||
import de.jeanlucmakiola.calendula.widget.widgetLoadContext
|
||||
import de.jeanlucmakiola.calendula.widget.widgetTimeLabel
|
||||
import de.jeanlucmakiola.floret.components.positionOf
|
||||
import de.jeanlucmakiola.floret.glance.LocalWidgetBackground
|
||||
import de.jeanlucmakiola.floret.glance.WidgetBackground
|
||||
import de.jeanlucmakiola.floret.glance.WidgetData
|
||||
import de.jeanlucmakiola.floret.glance.WidgetMessage
|
||||
import de.jeanlucmakiola.floret.glance.currentRefreshStamp
|
||||
import de.jeanlucmakiola.floret.glance.refreshStamp
|
||||
import de.jeanlucmakiola.floret.glance.wallpaperBacking
|
||||
import de.jeanlucmakiola.floret.locale.localizedDateFormatter
|
||||
import de.jeanlucmakiola.floret.prefs.ThemeMode
|
||||
import kotlinx.datetime.DateTimeUnit
|
||||
import kotlinx.datetime.LocalDate
|
||||
import kotlinx.datetime.plus
|
||||
import kotlinx.datetime.toJavaDayOfWeek
|
||||
import kotlinx.datetime.toJavaLocalDate
|
||||
import java.time.format.TextStyle as JavaTextStyle
|
||||
|
||||
/**
|
||||
* Today list (#438): only today's events beside today's date pill. Once
|
||||
* they're over, or with none at all, it says so and shows tomorrow's first
|
||||
* one or two events in a quieter style.
|
||||
*/
|
||||
class TodayWidget : GlanceAppWidget() {
|
||||
|
||||
override val stateDefinition = PreferencesGlanceStateDefinition
|
||||
|
||||
// Exact: whether one or two of tomorrow's events fit follows the height.
|
||||
override val sizeMode = SizeMode.Exact
|
||||
|
||||
override suspend fun provideGlance(context: Context, id: GlanceId) {
|
||||
val widgetData = WidgetData(context.loadTodayList(context.widgetLoadContext(id)), refreshStamp(context, id))
|
||||
provideContent {
|
||||
val loaded = widgetData.current(currentRefreshStamp()) { context.loadTodayList(context.widgetLoadContext(id)) }
|
||||
TodayWidgetContent(loaded.content, currentState<Preferences>().widgetAppearance, loaded.appTheme)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class TodayWidgetReceiver : CalendulaWidgetReceiver() {
|
||||
override val glanceAppWidget: GlanceAppWidget = TodayWidget()
|
||||
}
|
||||
|
||||
internal suspend fun Context.loadTodayList(load: WidgetLoadContext) = loadDays(load) { today, _ ->
|
||||
today..today.plus(1, DateTimeUnit.DAY)
|
||||
}
|
||||
|
||||
private val PillWidth = 44.dp
|
||||
private val RowGap = 2.dp
|
||||
|
||||
/** What the list side shows: today's events, or the look ahead once none are left. */
|
||||
internal sealed interface TodayRows {
|
||||
data class Today(val events: List<EventInstance>) : TodayRows
|
||||
data class NothingLeft(val tomorrow: List<EventInstance>) : TodayRows
|
||||
}
|
||||
|
||||
internal fun todayRows(data: DaysWidgetData.Ready): TodayRows {
|
||||
val today = data.eventsOn(data.today)
|
||||
if (today.none { !it.hasEnded(data.now) }) {
|
||||
return TodayRows.NothingLeft(data.eventsOn(data.today.plus(1, DateTimeUnit.DAY)))
|
||||
}
|
||||
val shown = if (data.options.pastDisplay == PastEventDisplay.HIDE) today.filterNot { it.hasEnded(data.now) } else today
|
||||
return TodayRows.Today(shown)
|
||||
}
|
||||
|
||||
/** The whole widget, shared with its config preview, which draws its list as a plain column. */
|
||||
@Composable
|
||||
internal fun TodayWidgetContent(
|
||||
data: DaysWidgetData,
|
||||
appearance: WidgetAppearance,
|
||||
appTheme: ThemeMode,
|
||||
preview: Boolean = false,
|
||||
) {
|
||||
CalendulaWidgetRoot(appearance, appTheme) {
|
||||
val context = LocalContext.current
|
||||
when (data) {
|
||||
DaysWidgetData.NeedsPermission -> WidgetMessage(context.getString(R.string.widget_needs_permission))
|
||||
is DaysWidgetData.Ready -> Row(modifier = GlanceModifier.fillMaxSize().padding(6.dp)) {
|
||||
TodayPill(data.today)
|
||||
Spacer(GlanceModifier.width(6.dp))
|
||||
val metrics = compactRowMetrics(data.options.textSize, context.resources.configuration.fontScale)
|
||||
Box(modifier = GlanceModifier.defaultWeight().fillMaxHeight()) {
|
||||
when (val rows = todayRows(data)) {
|
||||
is TodayRows.Today -> TodayList(rows.events, data, metrics, preview)
|
||||
is TodayRows.NothingLeft -> NothingLeft(rows.tomorrow, data, metrics)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TodayList(events: List<EventInstance>, data: DaysWidgetData.Ready, metrics: EventRowMetrics, preview: Boolean) {
|
||||
val context = LocalContext.current
|
||||
val row: @Composable (Int) -> Unit = { index ->
|
||||
val event = events[index]
|
||||
WidgetEventRow(
|
||||
event = event,
|
||||
secondary = widgetTimeLabel(context, event, data.today, data.is24Hour),
|
||||
soften = data.soften,
|
||||
metrics = metrics,
|
||||
position = positionOf(index, events.size),
|
||||
source = CalendarView.Day,
|
||||
dimmed = data.options.pastDisplay == PastEventDisplay.DIM && event.hasEnded(data.now),
|
||||
)
|
||||
}
|
||||
if (preview) {
|
||||
Column(modifier = GlanceModifier.fillMaxSize()) { repeat(minOf(events.size, 10)) { row(it) } }
|
||||
} else {
|
||||
LazyColumn(modifier = GlanceModifier.fillMaxSize()) { items(events.size) { row(it) } }
|
||||
}
|
||||
}
|
||||
|
||||
/** "Nothing left today", then as many of tomorrow's first two events as the height holds. */
|
||||
@Composable
|
||||
private fun NothingLeft(tomorrow: List<EventInstance>, data: DaysWidgetData.Ready, metrics: EventRowMetrics) {
|
||||
val context = LocalContext.current
|
||||
val fontScale = context.resources.configuration.fontScale
|
||||
val lineHeight = 20.dp * fontScale
|
||||
val room = LocalSize.current.height - 12.dp - lineHeight
|
||||
val fits = ((room + RowGap) / (metrics.rowHeight + RowGap)).toInt().coerceIn(0, 2)
|
||||
val ahead = tomorrow.take(fits)
|
||||
val backing = if (LocalWidgetBackground.current == WidgetBackground.TRANSPARENT) {
|
||||
GlanceModifier.wallpaperBacking(radius = 8.dp).padding(horizontal = 8.dp)
|
||||
} else {
|
||||
GlanceModifier.padding(horizontal = 4.dp)
|
||||
}
|
||||
Column(modifier = GlanceModifier.fillMaxSize(), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(
|
||||
text = context.getString(R.string.widget_nothing_left_today),
|
||||
maxLines = 1,
|
||||
style = TextStyle(color = GlanceTheme.colors.onSurfaceVariant, fontSize = metrics.title, fontWeight = FontWeight.Medium),
|
||||
modifier = backing.height(lineHeight),
|
||||
)
|
||||
val tomorrowDate = data.today.plus(1, DateTimeUnit.DAY)
|
||||
val tomorrowLabel = relativeDayLabel(context, tomorrowDate, data.today)
|
||||
ahead.forEachIndexed { index, event ->
|
||||
WidgetEventRow(
|
||||
event = event,
|
||||
secondary = "$tomorrowLabel · ${widgetTimeLabel(context, event, tomorrowDate, data.is24Hour)}",
|
||||
soften = data.soften,
|
||||
metrics = metrics,
|
||||
position = positionOf(index, ahead.size),
|
||||
source = CalendarView.Day,
|
||||
quiet = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Today's weekday and number, filled like the agenda's today pill; opens today. */
|
||||
@Composable
|
||||
private fun TodayPill(today: LocalDate) {
|
||||
val context = LocalContext.current
|
||||
val locale = widgetLocale()
|
||||
Column(
|
||||
modifier = GlanceModifier
|
||||
.width(PillWidth)
|
||||
.fillMaxHeight()
|
||||
.cornerRadius(PillWidth / 2)
|
||||
.background(GlanceTheme.colors.primary)
|
||||
.clickable(actionStartActivity(MainActivity.openDateIntent(context, today, CalendarView.Day)))
|
||||
.semantics { contentDescription = localizedDateFormatter(locale, "EEEEdMMMM").format(today.toJavaLocalDate()) },
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Text(
|
||||
text = today.dayOfWeek.toJavaDayOfWeek().getDisplayName(JavaTextStyle.SHORT, locale),
|
||||
maxLines = 1,
|
||||
style = TextStyle(color = GlanceTheme.colors.onPrimary, fontSize = 11.sp, textAlign = TextAlign.Center),
|
||||
)
|
||||
Text(
|
||||
text = today.day.toString(),
|
||||
maxLines = 1,
|
||||
style = TextStyle(
|
||||
color = GlanceTheme.colors.onPrimary,
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
textAlign = TextAlign.Center,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Static mock shown in the widget picker (android:previewLayout). -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/preview_widget_bg"
|
||||
android:orientation="horizontal"
|
||||
android:padding="6dp"
|
||||
tools:ignore="HardcodedText">
|
||||
|
||||
<TextView
|
||||
android:layout_width="44dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/preview_widget_today_bg"
|
||||
android:gravity="center"
|
||||
android:text="Wed\n7"
|
||||
android:textColor="@color/widget_preview_on_primary"
|
||||
android:textSize="13sp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="6dp"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView style="@style/WidgetPreviewEventRow" android:layout_marginTop="0dp" android:text="Stand-up\n9:30 – 9:45" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@@ -445,6 +445,8 @@
|
||||
</plurals>
|
||||
<string name="widget_upcoming_label">Calendula upcoming</string>
|
||||
<string name="widget_upcoming_empty">No upcoming events</string>
|
||||
<string name="widget_today_label">Calendula today</string>
|
||||
<string name="widget_nothing_left_today">Nothing left today</string>
|
||||
<string name="widget_refresh">Refresh</string>
|
||||
<string name="widget_new_event">New event</string>
|
||||
<string name="widget_needs_permission">Open Calendula to grant calendar access</string>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minWidth="250dp"
|
||||
android:minHeight="40dp"
|
||||
android:targetCellWidth="4"
|
||||
android:targetCellHeight="1"
|
||||
android:minResizeWidth="180dp"
|
||||
android:minResizeHeight="40dp"
|
||||
android:maxResizeWidth="420dp"
|
||||
android:maxResizeHeight="230dp"
|
||||
android:resizeMode="horizontal|vertical"
|
||||
android:widgetCategory="home_screen"
|
||||
android:configure="de.jeanlucmakiola.calendula.widget.config.WidgetConfigActivity"
|
||||
android:widgetFeatures="reconfigurable"
|
||||
android:description="@string/widget_today_label"
|
||||
android:updatePeriodMillis="1800000"
|
||||
android:previewLayout="@layout/widget_preview_today"
|
||||
android:initialLayout="@layout/glance_default_loading_layout" />
|
||||
@@ -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()))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user