From 1004356e75a5527ac647338a20dc3e4584957f10 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 19:24:57 +0100 Subject: [PATCH] Month widget: day totals from countByDay, test split bars (#491) --- .../calendula/widget/month/MonthGrid.kt | 2 +- .../calendula/widget/month/MonthGridViews.kt | 2 +- .../calendula/widget/month/MonthGridTest.kt | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthGrid.kt b/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthGrid.kt index 601f28c2..f893a110 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthGrid.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthGrid.kt @@ -72,7 +72,7 @@ internal class WeekLayout( /** The single lane of a [mixed] week, bars cut short where a day shows its count instead; null otherwise. */ val mixedLane: List>? = if (!mixed) null else mergeGaps(week.days.size) { col -> val day = seating[col] - if (day.hidden.isNotEmpty()) return@mergeGaps GridCell(LaneItem.Count(day.seated.size + day.hidden.size), 1) + if (day.hidden.isNotEmpty()) return@mergeGaps GridCell(LaneItem.Count(week.countByDay[week.days[col]] ?: day.hidden.size), 1) val seat = day.seated.firstOrNull() ?: return@mergeGaps null val spanEnd = if (seat.bar) week.spanAt(col, seat.lane)?.endCol ?: col else col val end = (col + 1..spanEnd).firstOrNull { seating[it].hidden.isNotEmpty() }?.minus(1) ?: spanEnd diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthGridViews.kt b/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthGridViews.kt index ce0a8d94..c7df3985 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthGridViews.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthGridViews.kt @@ -107,7 +107,7 @@ private fun weekViews( return week } layout.lanes.forEach { cells -> - val lane = laneViews(context, layout.compact) + val lane = laneViews(context) cells.forEach { cell -> val event = cell.item lane.addView(R.id.lane, if (event == null) gap(context, cell.cols) else bar(context, event, cell.cols, soften, mode)) diff --git a/app/src/test/java/de/jeanlucmakiola/calendula/widget/month/MonthGridTest.kt b/app/src/test/java/de/jeanlucmakiola/calendula/widget/month/MonthGridTest.kt index b1a647f2..5bd5058f 100644 --- a/app/src/test/java/de/jeanlucmakiola/calendula/widget/month/MonthGridTest.kt +++ b/app/src/test/java/de/jeanlucmakiola/calendula/widget/month/MonthGridTest.kt @@ -95,6 +95,19 @@ class MonthGridTest { ).inOrder() } + @Test + fun `a single lane cuts a multi-day bar around a busy day`() { + val trip = allDayEvent(monday, monday.plus(3, DateTimeUnit.DAY), id = 1, title = "Trip") + val busy = timedEvent(monday.plus(1, DateTimeUnit.DAY), 9, zone = zone, id = 2, title = "Busy") + val week = fitWeeks(weeks(listOf(trip, busy)), LaneFit(1))[1] + assertThat(week.mixedLane).containsExactly( + GridCell(LaneItem.Bar(trip), 1), + GridCell(LaneItem.Count(2), 1), + GridCell(LaneItem.Bar(trip), 2), + GridCell(null, 3), + ).inOrder() + } + @Test fun `lanes stop at the cap however tall the week`() { assertThat(lanesFitting(1000.dp, fontScale = 1f)).isEqualTo(LaneFit(MAX_LANES))