From 590b580dd2708689906503339329507da9a3c15a Mon Sep 17 00:00:00 2001 From: Pauljd Date: Mon, 9 Nov 2026 19:17:43 +0000 Subject: [PATCH] Guide rows as their own skippable composable, with stable inputs Co-Authored-By: Claude Opus 5.5 --- .../main/java/tv/orbit/classic/GuideGrid.kt | 91 ++++++++++--------- 1 file changed, 50 insertions(+), 41 deletions(-) diff --git a/android/app/src/main/java/tv/orbit/classic/GuideGrid.kt b/android/app/src/main/java/tv/orbit/classic/GuideGrid.kt index 05ae0c68..421a344f 100644 --- a/android/app/src/main/java/tv/orbit/classic/GuideGrid.kt +++ b/android/app/src/main/java/tv/orbit/classic/GuideGrid.kt @@ -31,7 +31,9 @@ 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). */ +@androidx.compose.runtime.Immutable internal class GuideCellView(val cell: GuideCell, val label: String, val asleep: Boolean, val past: Boolean, val onNow: Boolean, val runsOn: Boolean) +@androidx.compose.runtime.Immutable internal class GuideRowView(val line: SampleChannel, val mark: ChannelBranding?, val takeover: Takeover?, val cells: List) /** A row's cells for the window, with their titles: the schedule lookups the guide used to repeat on every key press. */ @@ -288,48 +290,9 @@ internal fun GuideGrid(channels: List, selectedNumber: Int, modif // 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 = view.mark - // A takeover on at the guide's time wears its own mark (Paul, 6 November 2026). - 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) - } - 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 = 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 - Box(Modifier.offset(x = maxWidth * cell.startFraction).width(cellWidth.coerceAtLeast(1.dp)).fillMaxHeight() - .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 = 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 = cellView.asleep - if (!asleep && cellWidth >= GuideTitleMinWidth) ShortsMark(cell.show, line.number, Modifier.padding(end = 5.dp)) - 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() } - } - } - } - } - } + // Only the row the cursor leaves and the one it reaches change their inputs, so only they are redrawn. + GuideRowLine(view, index == row, if (gridFocused && index == row) focused.startMs else null, nowFraction, cellsWidth) } } } @@ -339,3 +302,49 @@ internal fun GuideGrid(channels: List, selectedNumber: Int, modif } } } + +/** One guide row (9 November 2026): skipped by Compose unless its own inputs change. */ +@Composable +private fun GuideRowLine(view: GuideRowView, selected: Boolean, focusStart: Long?, nowFraction: Float?, cellsWidth: androidx.compose.ui.unit.Dp) { + val line = view.line + Row(Modifier.fillMaxWidth().height(38.dp), horizontalArrangement = Arrangement.spacedBy(6.dp)) { + val mark = view.mark + // A takeover on at the guide's time wears its own mark (Paul, 6 November 2026). + val takeover = view.takeover + Row(Modifier.width(130.dp).fillMaxHeight().background(if (selected) 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) + } + Box(Modifier.width(cellsWidth).fillMaxHeight()) { + val maxWidth = cellsWidth + view.cells.forEach { cellView -> + val cell = cellView.cell + val isFocus = focusStart != null && cell.show.startMs == focusStart + 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 + Box(Modifier.offset(x = maxWidth * cell.startFraction).width(cellWidth.coerceAtLeast(1.dp)).fillMaxHeight() + .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 = 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 = cellView.asleep + if (!asleep && cellWidth >= GuideTitleMinWidth) ShortsMark(cell.show, line.number, Modifier.padding(end = 5.dp)) + 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() } + } + } + } + } + } +}