Guide: each visible row's cells and titles worked out once per window and minute, not per key press
The cursor only changes focus now, and the rows no longer measure themselves (no BoxWithConstraints per row). Measured upstairs before: 75 ms a press up/down. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,21 @@ private const val GUIDE_MAX_SLOTS_AHEAD = 7 * 48
|
||||
|
||||
internal data class GuideCell(val show: SampleBroadcast, val startFraction: Float, val widthFraction: Float)
|
||||
|
||||
/** One guide cell ready to draw: everything that doesn't depend on where the cursor is (9 November 2026). */
|
||||
internal class GuideCellView(val cell: GuideCell, val label: String, val asleep: Boolean, val past: Boolean, val onNow: Boolean, val runsOn: Boolean)
|
||||
internal class GuideRowView(val line: SampleChannel, val mark: ChannelBranding?, val takeover: Takeover?, val cells: List<GuideCellView>)
|
||||
|
||||
/** A row's cells for the window, with their titles: the schedule lookups the guide used to repeat on every key press. */
|
||||
internal fun guideRowView(line: SampleChannel, windowStart: Long, windowEnd: Long, now: Long): GuideRowView =
|
||||
GuideRowView(line, ChannelBrands.forNumber(line.number), takeoverOf(line.number, line.at(maxOf(windowStart, now))),
|
||||
guideWatchableCells(guideCells(line, windowStart, windowEnd), now, now).map { cell ->
|
||||
val past = cell.show.endMs <= now
|
||||
val asleep = kidsAsleep(takeoverOf(line.number, cell.show))
|
||||
val offAir = offAirUntil(line.number, cell.show.startMs)
|
||||
GuideCellView(cell, if (asleep) "Asleep till 6am" else if (offAir != null) "Off air · ${offAir.lowercase().replaceFirstChar { it.uppercase() }}" else guideTitle(line.number, cell.show).first,
|
||||
asleep, past, cell.show.startMs <= now && !past, cell.show.endMs > windowEnd)
|
||||
})
|
||||
|
||||
/** The programmes a channel airs inside a window, clipped to it. The channel's own clock decides everything. */
|
||||
internal fun guideCells(channel: SampleChannel, windowStart: Long, windowEnd: Long): List<GuideCell> {
|
||||
require(windowEnd > windowStart)
|
||||
@@ -233,6 +248,7 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
|
||||
}
|
||||
BoxWithConstraints(Modifier.fillMaxWidth().weight(1f)) {
|
||||
val visibleRows = ((maxHeight + 3.dp) / 41.dp).toInt().coerceAtLeast(1)
|
||||
val gridWidth = maxWidth
|
||||
firstRow = guideFirstRow(row, firstRow, visibleRows, channels.size)
|
||||
rowsShown = minOf(visibleRows, channels.size)
|
||||
// The rows step at once (Paul, 6 November 2026: easing them stuttered and seemed to jump back and forth).
|
||||
@@ -264,23 +280,33 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
|
||||
else -> false
|
||||
}
|
||||
}, verticalArrangement = Arrangement.spacedBy(3.dp)) {
|
||||
channels.subList(firstRow, minOf(firstRow + visibleRows, channels.size)).forEachIndexed { offset, line ->
|
||||
// Each visible row's cells, titles and marks, worked out once for this window and minute rather than on every key
|
||||
// press (9 November 2026: a press cost ~22 ms on the main thread rebuilding them all). The cursor only changes focus.
|
||||
val rowViews = remember(channels, firstRow, visibleRows, windowStart, windowEnd, now) {
|
||||
channels.subList(firstRow, minOf(firstRow + visibleRows, channels.size)).map { line -> guideRowView(line, windowStart, windowEnd, now) }
|
||||
}
|
||||
// The programme cells' width, known here, so no row needs its own measuring pass.
|
||||
val cellsWidth = (gridWidth - 136.dp).coerceAtLeast(1.dp)
|
||||
rowViews.forEachIndexed { offset, view ->
|
||||
val line = view.line
|
||||
val index = firstRow + offset
|
||||
Row(Modifier.fillMaxWidth().height(38.dp), horizontalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
val mark = ChannelBrands.forNumber(line.number)
|
||||
val mark = view.mark
|
||||
// A takeover on at the guide's time wears its own mark (Paul, 6 November 2026).
|
||||
val takeover = takeoverOf(line.number, line.at(maxOf(windowStart, now)))
|
||||
val takeover = view.takeover
|
||||
Row(Modifier.width(130.dp).fillMaxHeight().background(if (index == row) Blue else Panel, androidx.compose.foundation.shape.RoundedCornerShape(4.dp)).padding(start = 6.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
Text(line.number.toString(), Modifier.width(30.dp), color = Yellow, fontFamily = BarlowCondensed, fontSize = 13.sp)
|
||||
if (takeover != null) TakeoverMark(takeover, Modifier.width(92.dp), height = 18.dp, textSize = 13.sp)
|
||||
else if (mark != null) Image(cachedPainter(mark.logo), mark.displayName, Modifier.logoPlate().width(88.dp).height(28.dp))
|
||||
else Text(ChannelBrands.displayName(line), color = Ink, fontSize = 13.sp, maxLines = 1)
|
||||
}
|
||||
BoxWithConstraints(Modifier.weight(1f).fillMaxHeight()) {
|
||||
guideWatchableCells(guideCells(line, windowStart, windowEnd), now, now).forEach { cell ->
|
||||
Box(Modifier.width(cellsWidth).fillMaxHeight()) {
|
||||
val maxWidth = cellsWidth
|
||||
view.cells.forEach { cellView ->
|
||||
val cell = cellView.cell
|
||||
val isFocus = gridFocused && index == row && cell.show.startMs == focused.startMs
|
||||
val past = cell.show.endMs <= now
|
||||
val onNow = cell.show.startMs <= now && !past
|
||||
val past = cellView.past
|
||||
val onNow = cellView.onNow
|
||||
val cellWidth = maxWidth * cell.widthFraction - 3.dp
|
||||
// Runs along the foot of what's on now, so the time reads down the rows without crossing a title.
|
||||
val elapsed = if (onNow && nowFraction != null) (maxWidth * (nowFraction - cell.startFraction)).coerceIn(0.dp, cellWidth.coerceAtLeast(0.dp)) else 0.dp
|
||||
@@ -288,15 +314,14 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
|
||||
.background(if (isFocus) Navy else if (past) catchUpDim() else if (onNow) Panel else GuideLater, androidx.compose.foundation.shape.RoundedCornerShape(4.dp))
|
||||
// Focused as on What's On: navy inside a gold ring, the title crisp in white.
|
||||
.border(if (isFocus) 2.dp else 0.dp, if (isFocus) Yellow else Color.Transparent, androidx.compose.foundation.shape.RoundedCornerShape(4.dp)), contentAlignment = Alignment.CenterStart) {
|
||||
val runsOn = cell.show.endMs > windowEnd
|
||||
val runsOn = cellView.runsOn
|
||||
val ink = if (isFocus) Ink else if (past) Muted else Ink
|
||||
if (elapsed > 0.dp) Box(Modifier.align(Alignment.BottomStart).width(elapsed).height(3.dp).background(Yellow))
|
||||
Row(Modifier.padding(horizontal = 6.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||
// Kids never sees what a grown-up takeover is showing.
|
||||
val asleep = kidsAsleep(takeoverOf(line.number, cell.show))
|
||||
val offAir = offAirUntil(line.number, cell.show.startMs)
|
||||
val asleep = cellView.asleep
|
||||
if (!asleep && cellWidth >= GuideTitleMinWidth) ShortsMark(cell.show, line.number, Modifier.padding(end = 5.dp))
|
||||
Text(if (cellWidth < GuideTitleMinWidth) "…" else if (asleep) "Asleep till 6am" else if (offAir != null) "Off air · ${offAir.lowercase().replaceFirstChar { it.uppercase() }}" else guideTitle(line.number, cell.show).first, Modifier.weight(1f, fill = false), color = ink, fontSize = 13.sp,
|
||||
Text(if (cellWidth < GuideTitleMinWidth) "…" else cellView.label, Modifier.weight(1f, fill = false), color = ink, fontSize = 13.sp,
|
||||
fontWeight = if (isFocus || onNow) FontWeight.SemiBold else FontWeight.Normal, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
if (runsOn && cellWidth >= GuideTitleMinWidth) Text(" ►", color = ink, fontSize = 9.sp)
|
||||
if (past && cellWidth >= GuideTitleMinWidth + 14.dp) { Spacer(Modifier.width(4.dp)); CatchUpMark() }
|
||||
|
||||
Reference in New Issue
Block a user