Month widget: keep a lane in short week rows (#491)
This commit is contained in:
1 parent
9ccc303a2a
commit
f574f039f5
5 files changed
+48
-14
No files matched your search
@@ -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
|
||||
@@ -46,6 +46,7 @@ internal data class GridColors(
|
||||
internal fun monthGridViews(
|
||||
context: Context,
|
||||
layouts: List<WeekLayout>,
|
||||
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])
|
||||
|
||||
|
||||
@@ -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(),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user