From 506ebdb0925d9adb5bdcfbfe1aa9b2107aaf391c Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 18:21:56 +0100 Subject: [PATCH 01/12] Number week rows by their Thursday (#493) --- .../java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt | 4 ++-- .../java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt | 4 ++-- floret-kit | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt index 2115f573..b28aab57 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt @@ -187,7 +187,7 @@ import de.jeanlucmakiola.floret.identity.itemEnter import de.jeanlucmakiola.floret.identity.rememberReduceMotion import de.jeanlucmakiola.floret.locale.currentLocale import de.jeanlucmakiola.calendula.ui.common.next -import de.jeanlucmakiola.floret.time.isoWeekNumber +import de.jeanlucmakiola.floret.time.rowWeekNumber import kotlinx.coroutines.delay import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filterNotNull @@ -2707,7 +2707,7 @@ private fun monthChipDragModifier( */ @Composable private fun WeekNumberGutter(weekStart: LocalDate, modifier: Modifier = Modifier) { - val weekNumber = remember(weekStart) { weekStart.toJavaLocalDate().isoWeekNumber() } + val weekNumber = remember(weekStart) { weekStart.toJavaLocalDate().rowWeekNumber() } val label = stringResource(R.string.week_number_label) val openLabel = stringResource(R.string.month_open_week, weekNumber) val onOpenWeek = LocalOpenWeek.current diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt index 72c09998..6c2b82d6 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt @@ -209,7 +209,7 @@ import de.jeanlucmakiola.calendula.ui.common.TIMELINE_CONTENT_END_INSET import de.jeanlucmakiola.calendula.ui.common.hourCellBlockInset import de.jeanlucmakiola.calendula.ui.common.hourGridCells import de.jeanlucmakiola.calendula.ui.common.tappedMinuteOfDay -import de.jeanlucmakiola.floret.time.isoWeekNumber +import de.jeanlucmakiola.floret.time.rowWeekNumber import kotlinx.coroutines.launch import kotlinx.datetime.DateTimeUnit import kotlinx.datetime.LocalDate @@ -1137,7 +1137,7 @@ private fun WeekDayHeader( */ @Composable private fun WeekNumberCell(weekStart: LocalDate, showBadge: Boolean, modifier: Modifier = Modifier) { - val weekNumber = remember(weekStart) { weekStart.toJavaLocalDate().isoWeekNumber() } + val weekNumber = remember(weekStart) { weekStart.toJavaLocalDate().rowWeekNumber() } Column( modifier = modifier .fillMaxWidth() diff --git a/floret-kit b/floret-kit index 1ff6702f..8b850b5b 160000 --- a/floret-kit +++ b/floret-kit @@ -1 +1 @@ -Subproject commit 1ff6702fe6ff1ab695157e6559ec3761ba9f01b9 +Subproject commit 8b850b5b756689b6c86ad6e77ec7fda2ad0765a2 From f574f039f53377b187bf1ab64bd7833a98c38547 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 18:24:44 +0100 Subject: [PATCH 02/12] Month widget: keep a lane in short week rows (#491) --- .../calendula/widget/month/MonthGrid.kt | 16 ++++++++++++--- .../calendula/widget/month/MonthGridViews.kt | 13 +++++++----- .../calendula/widget/month/MonthWidget.kt | 5 +++-- .../res/layout/widget_month_lane_compact.xml | 8 ++++++++ .../calendula/widget/month/MonthGridTest.kt | 20 +++++++++++++++---- 5 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 app/src/main/res/layout/widget_month_lane_compact.xml 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 e43d95c6..b6b007a0 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 @@ -62,12 +62,20 @@ internal class WeekLayout(val week: MonthWeek, val laneCap: Int, val showsOverfl } } +/** How many lanes a week row holds, and whether they're the [compact] height. */ +internal data class LaneFit(val lanes: Int, val compact: Boolean = false) + /** * Event lanes a week row [weekHeight] tall holds under its day number, held to - * [MAX_LANES] so a tall widget's payload stays bounded (#214). + * [MAX_LANES] so a tall widget's payload stays bounded (#214). The last lane's + * bottom gap may be cut off, and a row too short for one full lane still gets + * one compact lane when that fits (#491). */ -internal fun lanesFitting(weekHeight: Dp): Int = - ((weekHeight.value - DAY_ROW_DP - LANES_TOP_DP) / LANE_ROW_DP).toInt().coerceIn(0, MAX_LANES) +internal fun lanesFitting(weekHeight: Dp): LaneFit { + val room = weekHeight.value - DAY_ROW_DP - LANES_TOP_DP + LANE_GAP_DP + val full = (room / LANE_ROW_DP).toInt().coerceIn(0, MAX_LANES) + return if (full == 0 && room >= COMPACT_LANE_ROW_DP) LaneFit(1, compact = true) else LaneFit(full) +} /** * Seats each week in [lanes] lanes. A week whose events need more gives its @@ -85,4 +93,6 @@ internal const val MAX_LANES = 8 private const val DAY_ROW_DP = 18f private const val LANES_TOP_DP = 2f private const val LANE_ROW_DP = 15f +private const val COMPACT_LANE_ROW_DP = 12f +private const val LANE_GAP_DP = 1f private const val UNCAPPED_LANES = 64 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 f5854d29..82566f49 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 @@ -46,6 +46,7 @@ internal data class GridColors( internal fun monthGridViews( context: Context, layouts: List, + compact: Boolean, currentMonth: Month, today: LocalDate, soften: Boolean, @@ -54,13 +55,14 @@ internal fun monthGridViews( ): RemoteViews { val grid = RemoteViews(context.packageName, R.layout.widget_month_grid) grid.removeAllViews(R.id.month_grid) - layouts.forEach { grid.addView(R.id.month_grid, weekViews(context, it, currentMonth, today, soften, colors, mode)) } + layouts.forEach { grid.addView(R.id.month_grid, weekViews(context, it, compact, currentMonth, today, soften, colors, mode)) } return grid } private fun weekViews( context: Context, layout: WeekLayout, + compact: Boolean, currentMonth: Month, today: LocalDate, soften: Boolean, @@ -92,7 +94,7 @@ private fun weekViews( if (isToday) week.setImageTint(context, TODAY_IDS[col], colors.primary) } layout.lanes.forEach { cells -> - val lane = laneViews(context) + val lane = laneViews(context, compact) 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)) @@ -100,7 +102,7 @@ private fun weekViews( week.addView(R.id.week_lanes, lane) } if (layout.showsOverflow && layout.overflow.isNotEmpty()) { - val lane = laneViews(context) + val lane = laneViews(context, compact) layout.overflow.forEach { cell -> val count = cell.item if (count == null) { @@ -117,8 +119,9 @@ private fun weekViews( return week } -private fun laneViews(context: Context) = - RemoteViews(context.packageName, R.layout.widget_month_lane).apply { removeAllViews(R.id.lane) } +private fun laneViews(context: Context, compact: Boolean) = + RemoteViews(context.packageName, if (compact) R.layout.widget_month_lane_compact else R.layout.widget_month_lane) + .apply { removeAllViews(R.id.lane) } private fun gap(context: Context, cols: Int) = RemoteViews(context.packageName, GAP_LAYOUTS[cols - 1]) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthWidget.kt b/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthWidget.kt index 227405c3..49388525 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthWidget.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthWidget.kt @@ -254,7 +254,8 @@ private fun MonthWidgetBody(source: MonthWidgetSource, index: Int) { val context = LocalContext.current val fontScale = context.resources.configuration.fontScale val weekHeight = (LocalSize.current.height - gridChromeHeight(fontScale)) / weeks.size - val layouts = fitWeeks(weeks, lanesFitting(weekHeight)) + val fit = lanesFitting(weekHeight) + val layouts = fitWeeks(weeks, fit.lanes) val mode = LocalWidgetThemeMode.current val colors = GridColors( onSurface = remoteColor(WidgetColorRole.ON_SURFACE), @@ -272,7 +273,7 @@ private fun MonthWidgetBody(source: MonthWidgetSource, index: Int) { Column(modifier = GlanceModifier.fillMaxWidth().defaultWeight()) { WeekdayHeader(weekStart = source.weekStart) AndroidRemoteViews( - remoteViews = monthGridViews(context, layouts, ym.month, source.today, source.soften, colors, mode), + remoteViews = monthGridViews(context, layouts, fit.compact, ym.month, source.today, source.soften, colors, mode), modifier = GlanceModifier.fillMaxWidth().defaultWeight(), ) } diff --git a/app/src/main/res/layout/widget_month_lane_compact.xml b/app/src/main/res/layout/widget_month_lane_compact.xml new file mode 100644 index 00000000..71010c26 --- /dev/null +++ b/app/src/main/res/layout/widget_month_lane_compact.xml @@ -0,0 +1,8 @@ + + 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 fa69afcf..9223f521 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 @@ -56,14 +56,26 @@ class MonthGridTest { @Test fun `a taller week fits more lanes`() { - assertThat(lanesFitting(19.dp)).isEqualTo(0) - assertThat(lanesFitting(50.dp)).isEqualTo(2) - assertThat(lanesFitting(100.dp)).isEqualTo(5) + assertThat(lanesFitting(19.dp)).isEqualTo(LaneFit(0)) + assertThat(lanesFitting(50.dp)).isEqualTo(LaneFit(2)) + assertThat(lanesFitting(100.dp)).isEqualTo(LaneFit(5)) + } + + @Test + fun `the last lane may lose its bottom gap`() { + assertThat(lanesFitting(34.dp)).isEqualTo(LaneFit(1)) + assertThat(lanesFitting(49.dp)).isEqualTo(LaneFit(2)) + } + + @Test + fun `a row too short for a full lane gets a compact one`() { + assertThat(lanesFitting(31.dp)).isEqualTo(LaneFit(1, compact = true)) + assertThat(lanesFitting(30.dp)).isEqualTo(LaneFit(0)) } @Test fun `lanes stop at the cap however tall the week`() { - assertThat(lanesFitting(1000.dp)).isEqualTo(MAX_LANES) + assertThat(lanesFitting(1000.dp)).isEqualTo(LaneFit(MAX_LANES)) } @Test From f267744c1c8891b779efc29043fa7727adcc284a Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 18:40:30 +0100 Subject: [PATCH 03/12] Month widget: keep the single lane's bars, compact lane only at normal font scale (#491) --- .../calendula/widget/month/MonthGrid.kt | 37 ++++++++++++------- .../calendula/widget/month/MonthGridViews.kt | 8 ++-- .../calendula/widget/month/MonthWidget.kt | 5 +-- .../calendula/widget/month/MonthGridTest.kt | 26 ++++++++----- 4 files changed, 45 insertions(+), 31 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 b6b007a0..2a60fe14 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 @@ -37,10 +37,16 @@ internal fun mergeGaps(columns: Int, cellAt: (Int) -> GridCell?): L } /** - * One week of the grid seated with [laneCap] lanes. [showsOverflow] is off when - * the week has no room for even the "+N" row. + * One week of the grid seated with [laneCap] lanes, drawn [compact] when the + * row is too short for a full one. [showsOverflow] is off when the week has no + * room for the "+N" row. */ -internal class WeekLayout(val week: MonthWeek, val laneCap: Int, val showsOverflow: Boolean = true) { +internal class WeekLayout( + val week: MonthWeek, + val laneCap: Int, + val showsOverflow: Boolean = true, + val compact: Boolean = false, +) { private val seating: List = week.days.indices.map { week.seating(it, laneCap) } /** Lanes filled from the top; empty lanes below are not drawn. */ @@ -67,22 +73,24 @@ internal data class LaneFit(val lanes: Int, val compact: Boolean = false) /** * Event lanes a week row [weekHeight] tall holds under its day number, held to - * [MAX_LANES] so a tall widget's payload stays bounded (#214). The last lane's - * bottom gap may be cut off, and a row too short for one full lane still gets - * one compact lane when that fits (#491). + * [MAX_LANES] so a tall widget's payload stays bounded (#214). A row too short + * for one full lane still gets a compact one when its text fits at [fontScale] (#491). */ -internal fun lanesFitting(weekHeight: Dp): LaneFit { - val room = weekHeight.value - DAY_ROW_DP - LANES_TOP_DP + LANE_GAP_DP +internal fun lanesFitting(weekHeight: Dp, fontScale: Float = 1f): LaneFit { + val room = weekHeight.value - DAY_ROW_DP - LANES_TOP_DP val full = (room / LANE_ROW_DP).toInt().coerceIn(0, MAX_LANES) - return if (full == 0 && room >= COMPACT_LANE_ROW_DP) LaneFit(1, compact = true) else LaneFit(full) + val compactFits = room >= COMPACT_LANE_ROW_DP && fontScale <= COMPACT_MAX_FONT_SCALE + return if (full == 0 && compactFits) LaneFit(1, compact = true) else LaneFit(full) } /** - * Seats each week in [lanes] lanes. A week whose events need more gives its - * last lane to the "+N" row instead. + * Seats each week in [fit]'s lanes. A week whose events need more gives its + * last lane to the "+N" row instead, unless that would leave it no lane at all: + * a single lane keeps its bars and drops the count (#491). */ -internal fun fitWeeks(weeks: List, lanes: Int): List = weeks.map { week -> - if (lanes == 0) return@map WeekLayout(week, laneCap = 0, showsOverflow = false) +internal fun fitWeeks(weeks: List, fit: LaneFit): List = weeks.map { week -> + val lanes = fit.lanes + if (lanes <= 1) return@map WeekLayout(week, laneCap = lanes, showsOverflow = false, compact = fit.compact) val needed = WeekLayout(week, UNCAPPED_LANES).usedLanes WeekLayout(week, if (needed <= lanes) lanes else lanes - 1) } @@ -93,6 +101,7 @@ internal const val MAX_LANES = 8 private const val DAY_ROW_DP = 18f private const val LANES_TOP_DP = 2f private const val LANE_ROW_DP = 15f +/** Matches `widget_month_lane_compact`'s height; its 9sp text clips past [COMPACT_MAX_FONT_SCALE]. */ private const val COMPACT_LANE_ROW_DP = 12f -private const val LANE_GAP_DP = 1f +private const val COMPACT_MAX_FONT_SCALE = 1.1f private const val UNCAPPED_LANES = 64 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 82566f49..bbd280ba 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 @@ -46,7 +46,6 @@ internal data class GridColors( internal fun monthGridViews( context: Context, layouts: List, - compact: Boolean, currentMonth: Month, today: LocalDate, soften: Boolean, @@ -55,14 +54,13 @@ internal fun monthGridViews( ): RemoteViews { val grid = RemoteViews(context.packageName, R.layout.widget_month_grid) grid.removeAllViews(R.id.month_grid) - layouts.forEach { grid.addView(R.id.month_grid, weekViews(context, it, compact, currentMonth, today, soften, colors, mode)) } + layouts.forEach { grid.addView(R.id.month_grid, weekViews(context, it, currentMonth, today, soften, colors, mode)) } return grid } private fun weekViews( context: Context, layout: WeekLayout, - compact: Boolean, currentMonth: Month, today: LocalDate, soften: Boolean, @@ -94,7 +92,7 @@ private fun weekViews( if (isToday) week.setImageTint(context, TODAY_IDS[col], colors.primary) } layout.lanes.forEach { cells -> - val lane = laneViews(context, compact) + val lane = laneViews(context, layout.compact) 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)) @@ -102,7 +100,7 @@ private fun weekViews( week.addView(R.id.week_lanes, lane) } if (layout.showsOverflow && layout.overflow.isNotEmpty()) { - val lane = laneViews(context, compact) + val lane = laneViews(context, layout.compact) layout.overflow.forEach { cell -> val count = cell.item if (count == null) { diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthWidget.kt b/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthWidget.kt index 49388525..abe674b5 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthWidget.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/widget/month/MonthWidget.kt @@ -254,8 +254,7 @@ private fun MonthWidgetBody(source: MonthWidgetSource, index: Int) { val context = LocalContext.current val fontScale = context.resources.configuration.fontScale val weekHeight = (LocalSize.current.height - gridChromeHeight(fontScale)) / weeks.size - val fit = lanesFitting(weekHeight) - val layouts = fitWeeks(weeks, fit.lanes) + val layouts = fitWeeks(weeks, lanesFitting(weekHeight, fontScale)) val mode = LocalWidgetThemeMode.current val colors = GridColors( onSurface = remoteColor(WidgetColorRole.ON_SURFACE), @@ -273,7 +272,7 @@ private fun MonthWidgetBody(source: MonthWidgetSource, index: Int) { Column(modifier = GlanceModifier.fillMaxWidth().defaultWeight()) { WeekdayHeader(weekStart = source.weekStart) AndroidRemoteViews( - remoteViews = monthGridViews(context, layouts, fit.compact, ym.month, source.today, source.soften, colors, mode), + remoteViews = monthGridViews(context, layouts, ym.month, source.today, source.soften, colors, mode), modifier = GlanceModifier.fillMaxWidth().defaultWeight(), ) } 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 9223f521..946af7c8 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 @@ -42,14 +42,14 @@ class MonthGridTest { @Test fun `a week that fits keeps every lane`() { - val layouts = fitWeeks(busyWeeks(perDay = 2), lanes = 3) + val layouts = fitWeeks(busyWeeks(perDay = 2), LaneFit(3)) assertThat(layouts.map { it.laneCap }.distinct()).containsExactly(3) assertThat(layouts.all { it.overflow.isEmpty() }).isTrue() } @Test fun `a week that doesn't fit gives its last lane to the overflow`() { - val layouts = fitWeeks(busyWeeks(perDay = 5), lanes = 3) + val layouts = fitWeeks(busyWeeks(perDay = 5), LaneFit(3)) assertThat(layouts.map { it.laneCap }.distinct()).containsExactly(2) assertThat(layouts.all { it.overflow.isNotEmpty() }).isTrue() } @@ -62,15 +62,23 @@ class MonthGridTest { } @Test - fun `the last lane may lose its bottom gap`() { - assertThat(lanesFitting(34.dp)).isEqualTo(LaneFit(1)) - assertThat(lanesFitting(49.dp)).isEqualTo(LaneFit(2)) + fun `a row too short for a full lane gets a compact one`() { + assertThat(lanesFitting(34.dp)).isEqualTo(LaneFit(1, compact = true)) + assertThat(lanesFitting(32.dp)).isEqualTo(LaneFit(1, compact = true)) + assertThat(lanesFitting(31.dp)).isEqualTo(LaneFit(0)) + assertThat(lanesFitting(35.dp)).isEqualTo(LaneFit(1)) } @Test - fun `a row too short for a full lane gets a compact one`() { - assertThat(lanesFitting(31.dp)).isEqualTo(LaneFit(1, compact = true)) - assertThat(lanesFitting(30.dp)).isEqualTo(LaneFit(0)) + fun `no compact lane at a large font scale`() { + assertThat(lanesFitting(34.dp, fontScale = 1.3f)).isEqualTo(LaneFit(0)) + } + + @Test + fun `a single lane keeps its bars in a busy week`() { + val layouts = fitWeeks(busyWeeks(perDay = 5), LaneFit(1, compact = true)) + assertThat(layouts.all { it.laneCap == 1 && it.lanes.size == 1 && it.compact }).isTrue() + assertThat(layouts.none { it.showsOverflow }).isTrue() } @Test @@ -80,7 +88,7 @@ class MonthGridTest { @Test fun `a week with no room for a lane draws no overflow row either`() { - val layouts = fitWeeks(busyWeeks(perDay = 5), lanes = 0) + val layouts = fitWeeks(busyWeeks(perDay = 5), LaneFit(0)) assertThat(layouts.none { it.showsOverflow }).isTrue() assertThat(layouts.all { it.lanes.isEmpty() }).isTrue() } From bd3b4605cb7220ff2cbcc87973b2c6b85defe510 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 18:41:40 +0100 Subject: [PATCH 04/12] Fix week number gutter KDoc (#493) --- .../java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt | 4 ++-- floret-kit | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt index b28aab57..9eab737f 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt @@ -2702,8 +2702,8 @@ private fun monthChipDragModifier( * Left-gutter calendar-week cell (#25): a full-height tonal pill mirroring the * day cells' geometry, set apart by the secondaryContainer tint (matching the * Week view's badge), with the ISO week number centred like a day number. The - * week is computed on the row's first day — the same basis as the Week view — so - * the two agree. + * number comes from the row's Thursday, as in the Week view, so it is right for + * any first weekday (#493). */ @Composable private fun WeekNumberGutter(weekStart: LocalDate, modifier: Modifier = Modifier) { diff --git a/floret-kit b/floret-kit index 8b850b5b..968d6303 160000 --- a/floret-kit +++ b/floret-kit @@ -1 +1 @@ -Subproject commit 8b850b5b756689b6c86ad6e77ec7fda2ad0765a2 +Subproject commit 968d63034f0c78450dc04927c47d84aadbb3479e From fb434f3f152a29507179defe22c49908cc1214be Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 18:48:14 +0100 Subject: [PATCH 05/12] Month widget: compact-only bar fallback, no compact lane above default font scale (#491) --- .../jeanlucmakiola/calendula/widget/month/MonthGrid.kt | 9 +++++---- .../calendula/widget/month/MonthGridViews.kt | 4 ++-- .../calendula/widget/month/MonthGridTest.kt | 10 ++++++++-- 3 files changed, 15 insertions(+), 8 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 2a60fe14..80acdbe1 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 @@ -85,12 +85,13 @@ internal fun lanesFitting(weekHeight: Dp, fontScale: Float = 1f): LaneFit { /** * Seats each week in [fit]'s lanes. A week whose events need more gives its - * last lane to the "+N" row instead, unless that would leave it no lane at all: - * a single lane keeps its bars and drops the count (#491). + * last lane to the "+N" row instead. A compact lane has no room for that row, + * so it keeps its bars (#491). */ internal fun fitWeeks(weeks: List, fit: LaneFit): List = weeks.map { week -> val lanes = fit.lanes - if (lanes <= 1) return@map WeekLayout(week, laneCap = lanes, showsOverflow = false, compact = fit.compact) + if (lanes == 0) return@map WeekLayout(week, laneCap = 0, showsOverflow = false) + if (fit.compact) return@map WeekLayout(week, laneCap = lanes, showsOverflow = false, compact = true) val needed = WeekLayout(week, UNCAPPED_LANES).usedLanes WeekLayout(week, if (needed <= lanes) lanes else lanes - 1) } @@ -103,5 +104,5 @@ private const val LANES_TOP_DP = 2f private const val LANE_ROW_DP = 15f /** Matches `widget_month_lane_compact`'s height; its 9sp text clips past [COMPACT_MAX_FONT_SCALE]. */ private const val COMPACT_LANE_ROW_DP = 12f -private const val COMPACT_MAX_FONT_SCALE = 1.1f +private const val COMPACT_MAX_FONT_SCALE = 1f private const val UNCAPPED_LANES = 64 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 bbd280ba..2ac5145a 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 @@ -100,7 +100,7 @@ private fun weekViews( week.addView(R.id.week_lanes, lane) } if (layout.showsOverflow && layout.overflow.isNotEmpty()) { - val lane = laneViews(context, layout.compact) + val lane = laneViews(context) layout.overflow.forEach { cell -> val count = cell.item if (count == null) { @@ -117,7 +117,7 @@ private fun weekViews( return week } -private fun laneViews(context: Context, compact: Boolean) = +private fun laneViews(context: Context, compact: Boolean = false) = RemoteViews(context.packageName, if (compact) R.layout.widget_month_lane_compact else R.layout.widget_month_lane) .apply { removeAllViews(R.id.lane) } 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 946af7c8..d8617694 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 @@ -71,11 +71,17 @@ class MonthGridTest { @Test fun `no compact lane at a large font scale`() { - assertThat(lanesFitting(34.dp, fontScale = 1.3f)).isEqualTo(LaneFit(0)) + assertThat(lanesFitting(34.dp, fontScale = 1.1f)).isEqualTo(LaneFit(0)) } @Test - fun `a single lane keeps its bars in a busy week`() { + fun `a single full lane still folds a busy week into the count`() { + val layouts = fitWeeks(busyWeeks(perDay = 5), LaneFit(1)) + assertThat(layouts.all { it.laneCap == 0 && it.showsOverflow && it.overflow.isNotEmpty() }).isTrue() + } + + @Test + fun `a compact lane keeps its bars in a busy week`() { val layouts = fitWeeks(busyWeeks(perDay = 5), LaneFit(1, compact = true)) assertThat(layouts.all { it.laneCap == 1 && it.lanes.size == 1 && it.compact }).isTrue() assertThat(layouts.none { it.showsOverflow }).isTrue() From 726dbbbaf3f5f293d8048b54cb757062fa8866c9 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 18:51:00 +0100 Subject: [PATCH 06/12] Month widget: require font scale for lane fitting (#491) --- .../calendula/widget/month/MonthGrid.kt | 5 ++--- .../calendula/widget/month/MonthGridTest.kt | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 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 80acdbe1..23783c15 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 @@ -76,7 +76,7 @@ internal data class LaneFit(val lanes: Int, val compact: Boolean = false) * [MAX_LANES] so a tall widget's payload stays bounded (#214). A row too short * for one full lane still gets a compact one when its text fits at [fontScale] (#491). */ -internal fun lanesFitting(weekHeight: Dp, fontScale: Float = 1f): LaneFit { +internal fun lanesFitting(weekHeight: Dp, fontScale: Float): LaneFit { val room = weekHeight.value - DAY_ROW_DP - LANES_TOP_DP val full = (room / LANE_ROW_DP).toInt().coerceIn(0, MAX_LANES) val compactFits = room >= COMPACT_LANE_ROW_DP && fontScale <= COMPACT_MAX_FONT_SCALE @@ -90,8 +90,7 @@ internal fun lanesFitting(weekHeight: Dp, fontScale: Float = 1f): LaneFit { */ internal fun fitWeeks(weeks: List, fit: LaneFit): List = weeks.map { week -> val lanes = fit.lanes - if (lanes == 0) return@map WeekLayout(week, laneCap = 0, showsOverflow = false) - if (fit.compact) return@map WeekLayout(week, laneCap = lanes, showsOverflow = false, compact = true) + if (lanes == 0 || fit.compact) return@map WeekLayout(week, laneCap = lanes, showsOverflow = false, compact = fit.compact) val needed = WeekLayout(week, UNCAPPED_LANES).usedLanes WeekLayout(week, if (needed <= lanes) lanes else lanes - 1) } 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 d8617694..c336b508 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 @@ -56,17 +56,17 @@ class MonthGridTest { @Test fun `a taller week fits more lanes`() { - assertThat(lanesFitting(19.dp)).isEqualTo(LaneFit(0)) - assertThat(lanesFitting(50.dp)).isEqualTo(LaneFit(2)) - assertThat(lanesFitting(100.dp)).isEqualTo(LaneFit(5)) + assertThat(lanesFitting(19.dp, fontScale = 1f)).isEqualTo(LaneFit(0)) + assertThat(lanesFitting(50.dp, fontScale = 1f)).isEqualTo(LaneFit(2)) + assertThat(lanesFitting(100.dp, fontScale = 1f)).isEqualTo(LaneFit(5)) } @Test fun `a row too short for a full lane gets a compact one`() { - assertThat(lanesFitting(34.dp)).isEqualTo(LaneFit(1, compact = true)) - assertThat(lanesFitting(32.dp)).isEqualTo(LaneFit(1, compact = true)) - assertThat(lanesFitting(31.dp)).isEqualTo(LaneFit(0)) - assertThat(lanesFitting(35.dp)).isEqualTo(LaneFit(1)) + assertThat(lanesFitting(34.dp, fontScale = 1f)).isEqualTo(LaneFit(1, compact = true)) + assertThat(lanesFitting(32.dp, fontScale = 1f)).isEqualTo(LaneFit(1, compact = true)) + assertThat(lanesFitting(31.dp, fontScale = 1f)).isEqualTo(LaneFit(0)) + assertThat(lanesFitting(35.dp, fontScale = 1f)).isEqualTo(LaneFit(1)) } @Test @@ -89,7 +89,7 @@ class MonthGridTest { @Test fun `lanes stop at the cap however tall the week`() { - assertThat(lanesFitting(1000.dp)).isEqualTo(LaneFit(MAX_LANES)) + assertThat(lanesFitting(1000.dp, fontScale = 1f)).isEqualTo(LaneFit(MAX_LANES)) } @Test From 76314aebbd91393cb75235d5bfaf1dc05774af7e Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 19:15:00 +0100 Subject: [PATCH 07/12] Number weeks by the locale's rules (#493) --- .../jeanlucmakiola/calendula/ui/month/MonthScreen.kt | 10 ++++++---- .../de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt | 4 +++- floret-kit | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt index 9eab737f..a4dc9183 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt @@ -205,6 +205,7 @@ import java.time.format.TextStyle as JavaTextStyle import java.util.Locale import kotlinx.datetime.toJavaMonth import kotlinx.datetime.yearMonth +import java.time.temporal.WeekFields private val LocalTodayPulse = staticCompositionLocalOf { 0 } @@ -2701,13 +2702,14 @@ private fun monthChipDragModifier( /** * Left-gutter calendar-week cell (#25): a full-height tonal pill mirroring the * day cells' geometry, set apart by the secondaryContainer tint (matching the - * Week view's badge), with the ISO week number centred like a day number. The - * number comes from the row's Thursday, as in the Week view, so it is right for - * any first weekday (#493). + * Week view's badge), with the week number centred like a day number. It is + * numbered the locale's way from the row's mid-week day, as in the Week view, + * so it is right for any first weekday (#493). */ @Composable private fun WeekNumberGutter(weekStart: LocalDate, modifier: Modifier = Modifier) { - val weekNumber = remember(weekStart) { weekStart.toJavaLocalDate().rowWeekNumber() } + val locale = currentLocale() + val weekNumber = remember(weekStart, locale) { weekStart.toJavaLocalDate().rowWeekNumber(WeekFields.of(locale)) } val label = stringResource(R.string.week_number_label) val openLabel = stringResource(R.string.month_open_week, weekNumber) val onOpenWeek = LocalOpenWeek.current diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt index 6c2b82d6..6a2cc629 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt @@ -221,6 +221,7 @@ import kotlinx.datetime.toLocalDateTime import java.time.format.TextStyle as JavaTextStyle import java.util.Locale import kotlinx.datetime.yearMonth +import java.time.temporal.WeekFields /** One lane of the all-day strip, sized to a trimmed bar line (#190). */ private val ALL_DAY_ROW_HEIGHT = 20.dp @@ -1137,7 +1138,8 @@ private fun WeekDayHeader( */ @Composable private fun WeekNumberCell(weekStart: LocalDate, showBadge: Boolean, modifier: Modifier = Modifier) { - val weekNumber = remember(weekStart) { weekStart.toJavaLocalDate().rowWeekNumber() } + val locale = currentLocale() + val weekNumber = remember(weekStart, locale) { weekStart.toJavaLocalDate().rowWeekNumber(WeekFields.of(locale)) } Column( modifier = modifier .fillMaxWidth() diff --git a/floret-kit b/floret-kit index 968d6303..003eca33 160000 --- a/floret-kit +++ b/floret-kit @@ -1 +1 @@ -Subproject commit 968d63034f0c78450dc04927c47d84aadbb3479e +Subproject commit 003eca337a124cf52e236479eafe5cd98465aa4c From dec2d1cb05501e55386c85fcb4afe77f214960f6 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 19:17:57 +0100 Subject: [PATCH 08/12] Month widget: one lane shows bars and per-day counts (#491) --- .../calendula/widget/month/MonthGrid.kt | 28 ++++++++++++++++--- .../calendula/widget/month/MonthGridViews.kt | 26 ++++++++++++++--- .../calendula/widget/month/MonthGridTest.kt | 20 +++++++++---- 3 files changed, 60 insertions(+), 14 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 23783c15..601f28c2 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 @@ -36,16 +36,24 @@ internal fun mergeGaps(columns: Int, cellAt: (Int) -> GridCell?): L return cells } +/** What a cell of the single mixed lane shows: an event's bar, or a day's event count. */ +internal sealed interface LaneItem { + data class Bar(val event: EventInstance) : LaneItem + data class Count(val count: Int) : LaneItem +} + /** * One week of the grid seated with [laneCap] lanes, drawn [compact] when the * row is too short for a full one. [showsOverflow] is off when the week has no - * room for the "+N" row. + * room for the "+N" row; a [mixed] single lane then shows each day's count in + * place of its bar where the day has more than fits (#491). */ internal class WeekLayout( val week: MonthWeek, val laneCap: Int, val showsOverflow: Boolean = true, val compact: Boolean = false, + val mixed: Boolean = false, ) { private val seating: List = week.days.indices.map { week.seating(it, laneCap) } @@ -61,6 +69,16 @@ 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) + 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 + GridCell(LaneItem.Bar(seat.event), end - col + 1) + } + /** The "+N" row as counts and merged gaps; empty when everything fits. */ val overflow: List> = seating.map { it.hidden.size }.let { hidden -> if (hidden.none { it > 0 }) emptyList() @@ -85,12 +103,14 @@ internal fun lanesFitting(weekHeight: Dp, fontScale: Float): LaneFit { /** * Seats each week in [fit]'s lanes. A week whose events need more gives its - * last lane to the "+N" row instead. A compact lane has no room for that row, - * so it keeps its bars (#491). + * last lane to the "+N" row instead. A single lane has no room for that row, + * so it mixes bars and per-day counts (#491). */ internal fun fitWeeks(weeks: List, fit: LaneFit): List = weeks.map { week -> val lanes = fit.lanes - if (lanes == 0 || fit.compact) return@map WeekLayout(week, laneCap = lanes, showsOverflow = false, compact = fit.compact) + if (lanes <= 1) { + return@map WeekLayout(week, laneCap = lanes, showsOverflow = false, compact = fit.compact, mixed = lanes == 1) + } val needed = WeekLayout(week, UNCAPPED_LANES).usedLanes WeekLayout(week, if (needed <= lanes) lanes else lanes - 1) } 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 2ac5145a..ce0a8d94 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 @@ -91,6 +91,21 @@ private fun weekViews( week.setViewVisibility(TODAY_IDS[col], if (isToday) View.VISIBLE else View.GONE) if (isToday) week.setImageTint(context, TODAY_IDS[col], colors.primary) } + layout.mixedLane?.let { cells -> + val lane = laneViews(context, layout.compact) + cells.forEach { cell -> + lane.addView( + R.id.lane, + when (val item = cell.item) { + null -> gap(context, cell.cols) + is LaneItem.Bar -> bar(context, item.event, cell.cols, soften, mode) + is LaneItem.Count -> more(context, item.count, colors) + }, + ) + } + week.addView(R.id.week_lanes, lane) + return week + } layout.lanes.forEach { cells -> val lane = laneViews(context, layout.compact) cells.forEach { cell -> @@ -106,10 +121,7 @@ private fun weekViews( if (count == null) { lane.addView(R.id.lane, gap(context, cell.cols)) } else { - val more = RemoteViews(context.packageName, R.layout.widget_month_more) - more.setTextViewText(R.id.more, "+$count") - more.setTextColor(context, R.id.more, colors.onSurfaceVariant) - lane.addView(R.id.lane, more) + lane.addView(R.id.lane, more(context, count, colors)) } } week.addView(R.id.week_lanes, lane) @@ -117,6 +129,12 @@ private fun weekViews( return week } +private fun more(context: Context, count: Int, colors: GridColors) = + RemoteViews(context.packageName, R.layout.widget_month_more).apply { + setTextViewText(R.id.more, "+$count") + setTextColor(context, R.id.more, colors.onSurfaceVariant) + } + private fun laneViews(context: Context, compact: Boolean = false) = RemoteViews(context.packageName, if (compact) R.layout.widget_month_lane_compact else R.layout.widget_month_lane) .apply { removeAllViews(R.id.lane) } 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 c336b508..b1a647f2 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 @@ -75,16 +75,24 @@ class MonthGridTest { } @Test - fun `a single full lane still folds a busy week into the count`() { + fun `a single lane shows counts on busy days`() { val layouts = fitWeeks(busyWeeks(perDay = 5), LaneFit(1)) - assertThat(layouts.all { it.laneCap == 0 && it.showsOverflow && it.overflow.isNotEmpty() }).isTrue() + assertThat(layouts.all { it.mixedLane == List(7) { GridCell(LaneItem.Count(5), 1) } }).isTrue() } @Test - fun `a compact lane keeps its bars in a busy week`() { - val layouts = fitWeeks(busyWeeks(perDay = 5), LaneFit(1, compact = true)) - assertThat(layouts.all { it.laneCap == 1 && it.lanes.size == 1 && it.compact }).isTrue() - assertThat(layouts.none { it.showsOverflow }).isTrue() + fun `a single lane keeps bars on days that fit`() { + val lone = timedEvent(monday.plus(1, DateTimeUnit.DAY), 9, zone = zone, id = 1, title = "Lone") + val busy = (2L..4L).map { timedEvent(monday.plus(3, DateTimeUnit.DAY), it.toInt() + 8, zone = zone, id = it, title = "B$it") } + val week = fitWeeks(weeks(listOf(lone) + busy), LaneFit(1, compact = true))[1] + assertThat(week.compact).isTrue() + assertThat(week.mixedLane).containsExactly( + GridCell(null, 1), + GridCell(LaneItem.Bar(lone), 1), + GridCell(null, 1), + GridCell(LaneItem.Count(3), 1), + GridCell(null, 3), + ).inOrder() } @Test From 77b0c6db09933109740ead9cee5291d833f72221 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 19:22:55 +0100 Subject: [PATCH 09/12] Week numbers follow the device region, shared helper (#493) --- .../calendula/ui/common/WeekNumber.kt | 21 +++++++++++++++++++ .../calendula/ui/month/MonthScreen.kt | 10 ++++----- .../calendula/ui/week/WeekScreen.kt | 6 ++---- 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 app/src/main/java/de/jeanlucmakiola/calendula/ui/common/WeekNumber.kt diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/WeekNumber.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/WeekNumber.kt new file mode 100644 index 00000000..6b34b62c --- /dev/null +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/common/WeekNumber.kt @@ -0,0 +1,21 @@ +package de.jeanlucmakiola.calendula.ui.common + +import android.content.res.Resources +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import de.jeanlucmakiola.floret.time.rowWeekNumber +import kotlinx.datetime.LocalDate +import kotlinx.datetime.toJavaLocalDate +import java.time.temporal.WeekFields + +/** + * The week number of the grid row starting on [rowStart], numbered by the + * device region's rules (#493). The region, not the app language: an English + * UI in the Netherlands still numbers weeks the ISO way. Shared by the Month + * gutter and the Week badge so the two always agree. + */ +@Composable +internal fun rememberRowWeekNumber(rowStart: LocalDate): Int { + val fields = remember { WeekFields.of(Resources.getSystem().configuration.locales[0]) } + return remember(rowStart, fields) { rowStart.toJavaLocalDate().rowWeekNumber(fields) } +} diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt index a4dc9183..83001dfb 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/month/MonthScreen.kt @@ -187,7 +187,6 @@ import de.jeanlucmakiola.floret.identity.itemEnter import de.jeanlucmakiola.floret.identity.rememberReduceMotion import de.jeanlucmakiola.floret.locale.currentLocale import de.jeanlucmakiola.calendula.ui.common.next -import de.jeanlucmakiola.floret.time.rowWeekNumber import kotlinx.coroutines.delay import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filterNotNull @@ -205,7 +204,7 @@ import java.time.format.TextStyle as JavaTextStyle import java.util.Locale import kotlinx.datetime.toJavaMonth import kotlinx.datetime.yearMonth -import java.time.temporal.WeekFields +import de.jeanlucmakiola.calendula.ui.common.rememberRowWeekNumber private val LocalTodayPulse = staticCompositionLocalOf { 0 } @@ -2703,13 +2702,12 @@ private fun monthChipDragModifier( * Left-gutter calendar-week cell (#25): a full-height tonal pill mirroring the * day cells' geometry, set apart by the secondaryContainer tint (matching the * Week view's badge), with the week number centred like a day number. It is - * numbered the locale's way from the row's mid-week day, as in the Week view, - * so it is right for any first weekday (#493). + * numbered by the device region from the row's mid-week day, as in the Week + * view, so it is right for any first weekday (#493). */ @Composable private fun WeekNumberGutter(weekStart: LocalDate, modifier: Modifier = Modifier) { - val locale = currentLocale() - val weekNumber = remember(weekStart, locale) { weekStart.toJavaLocalDate().rowWeekNumber(WeekFields.of(locale)) } + val weekNumber = rememberRowWeekNumber(weekStart) val label = stringResource(R.string.week_number_label) val openLabel = stringResource(R.string.month_open_week, weekNumber) val onOpenWeek = LocalOpenWeek.current diff --git a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt index 6a2cc629..f05c0fc8 100644 --- a/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt +++ b/app/src/main/java/de/jeanlucmakiola/calendula/ui/week/WeekScreen.kt @@ -209,7 +209,6 @@ import de.jeanlucmakiola.calendula.ui.common.TIMELINE_CONTENT_END_INSET import de.jeanlucmakiola.calendula.ui.common.hourCellBlockInset import de.jeanlucmakiola.calendula.ui.common.hourGridCells import de.jeanlucmakiola.calendula.ui.common.tappedMinuteOfDay -import de.jeanlucmakiola.floret.time.rowWeekNumber import kotlinx.coroutines.launch import kotlinx.datetime.DateTimeUnit import kotlinx.datetime.LocalDate @@ -221,7 +220,7 @@ import kotlinx.datetime.toLocalDateTime import java.time.format.TextStyle as JavaTextStyle import java.util.Locale import kotlinx.datetime.yearMonth -import java.time.temporal.WeekFields +import de.jeanlucmakiola.calendula.ui.common.rememberRowWeekNumber /** One lane of the all-day strip, sized to a trimmed bar line (#190). */ private val ALL_DAY_ROW_HEIGHT = 20.dp @@ -1138,8 +1137,7 @@ private fun WeekDayHeader( */ @Composable private fun WeekNumberCell(weekStart: LocalDate, showBadge: Boolean, modifier: Modifier = Modifier) { - val locale = currentLocale() - val weekNumber = remember(weekStart, locale) { weekStart.toJavaLocalDate().rowWeekNumber(WeekFields.of(locale)) } + val weekNumber = rememberRowWeekNumber(weekStart) Column( modifier = modifier .fillMaxWidth() From 1004356e75a5527ac647338a20dc3e4584957f10 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 19:24:57 +0100 Subject: [PATCH 10/12] 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)) From 9387bdc1eeca9831e2d53cc66142a8fb4aa76c56 Mon Sep 17 00:00:00 2001 From: Jean-Luc Makiola Date: Mon, 9 Nov 2026 20:32:00 +0100 Subject: [PATCH 11/12] Drop unused WorkManager permissions (#448) --- app/src/main/AndroidManifest.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 24e5c3e8..b272d8e9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -41,6 +41,11 @@ --> + + + + +