Shorts slots on screen: one guide cell, slot details, 3 of 6, Tots Story Time
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m11s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m35s

Ported from release 0.108.45; screenshots of the guide and slot details in all six looks in design/shorts.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-06 04:45:56 +00:00
co-authored by Claude Opus 5.5
parent 59221e05f8
commit c606809250
9 changed files with 179 additions and 11 deletions
@@ -1120,7 +1120,17 @@ internal fun topUpPlan(existing: ChannelPlan?, aired: ScheduleCursor, pool: List
internal class ScheduledChannel(val loop: SampleChannel, plan: ChannelPlan) : SampleChannel(loop.lineup, loop.name, loop.number) {
@Volatile var plan: ChannelPlan = plan
private val parts by lazy { SmartChannels.firstOrNull { it.number == number }?.dayParts.orEmpty() }
private fun presented(entry: ScheduleEntry) = SampleBroadcast(entry.media, entry.startMs, presentationOf(entry, parts))
private fun presented(entry: ScheduleEntry) = SampleBroadcast(entry.media, entry.startMs, presentationOf(entry, parts), entry.group)
/** The shorts slot [show] belongs to, from the booked programmes around it, or null. */
fun slotOf(show: SampleBroadcast): ShortsBlock? {
if (show.group.isEmpty()) return null
val entries = plan.entries
val at = entries.indexOfFirst { it.startMs == show.startMs }.takeIf { it >= 0 } ?: return null
var first = at; var last = at
while (first > 0 && entries[first - 1].group == show.group && entries[first - 1].endMs == entries[first].startMs) first--
while (last < entries.lastIndex && entries[last + 1].group == show.group && entries[last].endMs == entries[last + 1].startMs) last++
return shortsBlocks(entries.subList(first, last + 1)).firstOrNull()?.takeIf { it.entries.size > 1 }
}
/** Runs over the plan for a while, as Wind Down Now does, leaving the plan itself as it was. */
@Volatile var stepIn: ChannelPlan? = null
fun seriesIdAt(startMs: Long) = (stepIn?.entries.orEmpty() + plan.entries).firstOrNull { it.startMs == startMs }?.seriesId
@@ -33,7 +33,11 @@ internal fun ClassicProgrammeStrip(item: SampleItem, playing: Boolean, modifier:
Row(verticalAlignment = Alignment.CenterVertically) {
val catching = scheduled?.catchingUp() == true
Text(if (catching) (if (playing) "FROM START" else "PAUSED") else if (playing || scheduled != null) "NOW" else "PAUSED", Modifier.width(70.dp), color = Yellow, fontWeight = FontWeight.Bold, fontSize = 14.sp)
Text(item.title, color = Ink, fontWeight = FontWeight.Bold, fontSize = 20.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
Text(item.title, Modifier.weight(1f, fill = false), color = Ink, fontWeight = FontWeight.Bold, fontSize = 20.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
// A short in a slot says where it sits: "Cartoon Shorts · 3 of 6" (Paul, 6 November 2026).
scheduled?.let { shortsLine(it.channel, it.programme) }?.let { line ->
Text(" $line", color = Muted, fontWeight = FontWeight.SemiBold, fontSize = 14.sp, maxLines = 1)
}
}
Row(verticalAlignment = Alignment.CenterVertically) {
if (scheduled != null && scheduled.catchingUp()) {
@@ -36,12 +36,12 @@ internal fun guideCells(channel: SampleChannel, windowStart: Long, windowEnd: Lo
require(windowEnd > windowStart)
val span = (windowEnd - windowStart).toFloat()
val cells = mutableListOf<GuideCell>()
var show = channel.at(windowStart)
var show = guideAt(channel, windowStart)
while (show.startMs < windowEnd) {
val from = maxOf(show.startMs, windowStart)
val to = minOf(show.endMs, windowEnd)
cells += GuideCell(show, (from - windowStart) / span, (to - from) / span)
show = channel.at(show.endMs)
show = guideAt(channel, show.endMs)
}
return cells
}
@@ -111,7 +111,7 @@ internal fun guideFirstRow(row: Int, first: Int, visible: Int, count: Int): Int
/** Cursor time after moving one programme along a channel, never earlier than [earliest]: now, or back into Catch Up. */
internal fun guideStep(channel: SampleChannel, cursorMs: Long, nowMs: Long, forward: Boolean, earliest: Long = nowMs): Long {
val show = channel.at(maxOf(cursorMs, earliest))
val show = guideAt(channel, maxOf(cursorMs, earliest))
return if (forward) show.endMs else maxOf(show.startMs - 1, earliest)
}
@@ -141,7 +141,11 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
val channel = channels[row.coerceIn(channels.indices)]
// Before now only where the channel's plan still holds what aired (Catch Up); otherwise the cursor stays at now.
val earliest = catchUpEarliest(channel, now)
val focused = channel.at(maxOf(cursor, earliest))
val focused = guideAt(channel, maxOf(cursor, earliest))
// OK on a shorts slot opens it: every short, each its own programme (Paul, 6 November 2026).
var openSlot by remember { mutableStateOf<Pair<ScheduledChannel, ShortsBlock>?>(null) }
openSlot?.let { (slotChannel, slot) -> ShortsSlotDetails(slotChannel, slot, now, onClose = { openSlot = null },
onCatchUp = { show -> openSlot = null; onCatchUp(catchUpEntry(slotChannel, show)) }, onWatch = { openSlot = null; onWatch(slotChannel.number, 0) }) }
val focusedPast = focused.endMs <= now && catchUpAvailable(channel, focused, now)
fun keepCursorInWindow(time: Long) {
cursor = time
@@ -162,7 +166,7 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(3.dp)) {
if (branding != null) Image(painterResource(branding.logo), branding.displayName, Modifier.logoPlate().width(96.dp).height(30.dp))
else Text(ChannelBrands.displayName(channel), color = Ink, fontSize = 16.sp)
val (focusedName, focusedDetail) = if (kidsAsleep(takeoverOf(channel.number, focused))) "Asleep till 6am" to "Back for Kids in the morning" else guideTitleParts(focused.media.item.title)
val (focusedName, focusedDetail) = if (kidsAsleep(takeoverOf(channel.number, focused))) "Asleep till 6am" to "Back for Kids in the morning" else guideTitle(channel.number, focused)
Text(focusedName, color = Ink, fontFamily = Anton, fontSize = 20.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
if (focusedDetail != null) Text(focusedDetail, color = Ink, fontSize = 15.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
Text("${guideDayPrefix(focused.startMs, now)}${clock(focused.startMs)} to ${clock(focused.endMs)} • ${channel.number} ${ChannelBrands.displayName(channel)}" +
@@ -205,7 +209,9 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
true
}
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> {
if (native.repeatCount == 0 && focusedPast) onCatchUp(catchUpEntry(channel, focused))
val slot = (channel as? ScheduledChannel)?.let { c -> c.slotOf(c.at(focused.startMs))?.let { c to it } }
if (native.repeatCount == 0 && slot != null) openSlot = slot
else if (native.repeatCount == 0 && focusedPast) onCatchUp(catchUpEntry(channel, focused))
else if (native.repeatCount == 0 && focused.startMs <= now) onWatch(channel.number, 0)
true
}
@@ -242,7 +248,8 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
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))
Text(if (cellWidth < GuideTitleMinWidth) "…" else if (asleep) "Asleep till 6am" else guideTitleParts(cell.show.media.item.title).first, Modifier.weight(1f, fill = false), color = ink, fontSize = 13.sp,
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 guideTitle(line.number, cell.show).first, 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() }
@@ -3,7 +3,9 @@ package tv.orbit.classic
internal data class ScheduledMedia(val item: SampleItem, val sourceId: String, val durationMs: Long)
internal data class SampleBroadcast(val media: ScheduledMedia, val startMs: Long,
/** The booked programme's block or event presentation key (see [presentationOf]), empty for ordinary programmes. */
val presentation: String = "") {
val presentation: String = "",
/** The shorts slot the programme was booked in ([ScheduleEntry.group]), or empty. */
val group: String = "") {
val endMs: Long get() = startMs + media.durationMs
fun offsetAt(timeMs: Long) = (timeMs - startMs).coerceIn(0, media.durationMs - 1)
}
@@ -74,9 +74,30 @@ internal val SHORTS_TAG = Regex("shorts\\|\\d{1,15}\\|[A-Za-z' ]{1,40}")
internal class ShortsBlock(val label: String, val startMs: Long, val endMs: Long, val entries: List<ScheduleEntry>) {
/** The shows in the slot, in the order they first air in it. */
val shows: List<String> get() = entries.map { guideTitleParts(it.media.item.title).first }.distinct()
val title get() = "$label: " + shows.take(3).joinToString(", ") + if (shows.size > 3) " and more" else ""
val title get() = "$label: " + shows.take(3).joinToString(", ") + if (shows.size > 3) " and ${shows.size - 3} more" else ""
/** The slot as one programme for the guide: its label, then what's in it, at its real start and length. */
fun asBroadcast(): SampleBroadcast {
val first = entries.first()
val span = endMs - startMs
val item = SampleItem("$label / " + shows.take(3).joinToString(", ") + (if (shows.size > 3) " and ${shows.size - 3} more" else "") + " / ${entries.size} shorts",
"Episode", span / 60_000, "", first.media.item.id, span)
return SampleBroadcast(ScheduledMedia(item, first.media.sourceId, span), startMs, first.presentation, first.group)
}
/** Which short of the slot [show] is, counted from one. */
fun position(show: SampleBroadcast) = entries.indexOfFirst { it.startMs == show.startMs } + 1
}
/** What the guide shows at [timeMs] on [channel]: a programme, or the whole shorts slot it belongs to. */
internal fun guideAt(channel: SampleChannel, timeMs: Long): SampleBroadcast {
val show = channel.at(timeMs)
return (channel as? ScheduledChannel)?.slotOf(show)?.asBroadcast() ?: show
}
/** Tots' bedtime stories in the evening carry Tots Story Time (Paul, 6 November 2026): one story is one programme. */
internal fun isStoryTime(channelNumber: Int, show: SampleBroadcast, zone: ZoneId = ZoneId.systemDefault()) =
channelNumber == TOTS_NUMBER && show.group.isEmpty() && guideTitleParts(show.media.item.title).first.contains("Bedtime Stories", ignoreCase = true) &&
Instant.ofEpochMilli(show.startMs).atZone(zone).hour.let { it >= 17 || it < 6 }
/** The shorts slots in [entries]: consecutive programmes sharing a tag. Anything without one isn't part of a slot. */
internal fun shortsBlocks(entries: List<ScheduleEntry>): List<ShortsBlock> = buildList {
var run = mutableListOf<ScheduleEntry>()
@@ -0,0 +1,96 @@
package tv.orbit.classic
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import androidx.tv.material3.Text
/**
* Shorts slots on screen (Paul, 6 November 2026, from the approved design/shorts): one guide cell for a slot, a list of its
* shorts on OK, "3 of 6" while one plays, and Tots Story Time on a single evening bedtime story. Everything shown is read
* from the booked programmes, so the title, times and shows always match what airs.
*/
/** What the guide calls [show]: a slot's label and contents, Tots Story Time for an evening story, or the programme's own name. */
internal fun guideTitle(channelNumber: Int, show: SampleBroadcast): Pair<String, String?> =
if (isStoryTime(channelNumber, show)) "Tots Story Time" to guideTitleParts(show.media.item.title).second
else guideTitleParts(show.media.item.title)
/** The small mark before a slot's title (three short bars) or a story's (Luna's moon). Nothing for anything else. */
@Composable
internal fun ShortsMark(show: SampleBroadcast, channelNumber: Int, modifier: Modifier = Modifier) {
val slot = show.group.isNotEmpty()
val story = !slot && isStoryTime(channelNumber, show)
if (!slot && !story) return
val bars = Yellow; val moon = Color(0xFFA77BFF); val behind = Panel
Canvas(modifier.size(12.dp)) {
if (slot) for (k in 0..2) drawRoundRect(bars, Offset(0f, k * size.height * .38f), Size(size.width * (1 - k * .18f), size.height * .24f), CornerRadius(2f))
else { drawCircle(moon, size.minDimension * .45f, center); drawCircle(behind, size.minDimension * .4f, center + Offset(size.width * .25f, -size.height * .12f)) }
}
}
/** While a short in a slot plays: "Cartoon Shorts · 3 of 6", or null. */
internal fun shortsLine(channel: SampleChannel, show: SampleBroadcast): String? =
(channel as? ScheduledChannel)?.slotOf(show)?.let { slot -> "${slot.label} · ${slot.position(show)} of ${slot.entries.size}" }
/** OK on a slot in the guide: each short with its time and length; what's aired can be caught up, what's on can be watched. */
@Composable
internal fun ShortsSlotDetails(channel: ScheduledChannel, slot: ShortsBlock, nowMs: Long, onClose: () -> Unit, onCatchUp: (SampleBroadcast) -> Unit, onWatch: () -> Unit) {
val first = remember { FocusRequester() }
LaunchedEffect(Unit) { runCatching { first.requestFocus() } }
Dialog(onDismissRequest = onClose, properties = DialogProperties(usePlatformDefaultWidth = false)) {
BackHandler(onBack = onClose)
val corner = RoundedCornerShape(12.dp)
Column(Modifier.width(620.dp).background(Deep, corner).border(1.dp, Blue, corner).padding(20.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) {
ShortsMark(slot.asBroadcast(), channel.number, Modifier.padding(end = 8.dp))
Text(slot.label.uppercase(), color = Ink, fontFamily = Anton, fontSize = 24.sp)
}
Text("${channel.number} ${ChannelBrands.displayName(channel)} · ${guideDayPrefix(slot.startMs, nowMs)}${clock(slot.startMs)} to ${clock(slot.endMs)} · " +
"${(slot.endMs - slot.startMs + 30_000) / 60_000} min · ${slot.entries.size} shorts", color = Muted, fontSize = 13.sp)
slot.entries.forEachIndexed { i, entry ->
val show = channel.at(entry.startMs)
val (name, detail) = guideTitleParts(entry.media.item.title)
val aired = entry.endMs <= nowMs; val on = entry.startMs <= nowMs && !aired
val watchable = (aired && catchUpAvailable(channel, show, nowMs)) || on
var focused by remember { mutableStateOf(false) }
Row(Modifier.fillMaxWidth().height(46.dp).then(if (i == 0) Modifier.focusRequester(first) else Modifier).onFocusChanged { focused = it.isFocused }
.background(if (focused) Navy else Panel, RoundedCornerShape(6.dp)).border(if (focused) 2.dp else 0.dp, if (focused) Yellow else Color.Transparent, RoundedCornerShape(6.dp))
.clickable { if (on) onWatch() else if (watchable) onCatchUp(show) }.padding(horizontal = 12.dp), verticalAlignment = Alignment.CenterVertically) {
Text(clock(entry.startMs), Modifier.width(56.dp), color = Yellow, fontFamily = BarlowCondensed, fontSize = 17.sp)
Column(Modifier.weight(1f)) {
Text(name, color = Ink, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis)
detail?.let { Text(it, color = Muted, fontSize = 11.sp, maxLines = 1, overflow = TextOverflow.Ellipsis) }
}
Text("${(entry.media.durationMs + 30_000) / 60_000} min", Modifier.padding(horizontal = 10.dp), color = Muted, fontSize = 13.sp)
when {
on -> Text("ON NOW", Modifier.background(Yellow, RoundedCornerShape(4.dp)).padding(horizontal = 8.dp, vertical = 2.dp), color = OnAccent, fontSize = 11.sp, fontWeight = FontWeight.SemiBold)
watchable -> Text("CATCH UP", Modifier.background(CatchUpGreen, RoundedCornerShape(4.dp)).padding(horizontal = 8.dp, vertical = 2.dp), color = OnAccent, fontSize = 11.sp, fontWeight = FontWeight.SemiBold)
}
}
}
Text("Each short is its own programme: Catch Up, where you've got to and Kids rules work short by short.", color = Muted, fontSize = 11.sp)
Text("OK Watch from this short ▲▼ Shorts Back Guide", color = Muted, fontSize = 11.sp)
}
}
}
@@ -57,4 +57,32 @@ class ShortsTest {
assertEquals(plan.entries.map { it.group }, back.entries.map { it.group })
assertEquals(plan.entries.size, back.entries.size)
}
@Test fun theGuideShowsASlotAsOneProgrammeAndTheShortsStayUnderneath() {
val pool = listOf(show("long", 22.0), show("a", 7.0), show("b", 6.0), show("c", 5.0))
val plan = extendSchedule(pool, ScheduleCursor(), at(9, 0), at(13, 0), finishTogether = true, shorts = ToonZShorts)
val loop = SampleChannel(plan.entries.take(3).map { it.media }, "ToonZ", 605)
val channel = ScheduledChannel(loop, plan)
val slot = shortsBlocks(plan.entries).first()
// The guide: one cell from the slot's first short to its last, titled for what's in it.
val cells = guideCells(channel, slot.startMs - 60_000, slot.endMs + 60_000)
val cell = cells.single { it.show.startMs == slot.startMs }
assertEquals(slot.endMs, cell.show.endMs)
assertEquals("Cartoon Shorts", guideTitle(605, cell.show).first)
assertTrue(guideTitle(605, cell.show).second!!.endsWith("${slot.entries.size} shorts"))
assertEquals(slot.endMs, guideStep(channel, slot.startMs + 60_000, slot.startMs, forward = true))
// Underneath, each short is still its own programme, and knows its place.
val second = channel.at(slot.entries[1].startMs)
assertEquals(slot.entries[1].media, second.media)
assertEquals("Cartoon Shorts · 2 of ${slot.entries.size}", shortsLine(channel, second))
assertNull(shortsLine(channel, channel.at(plan.entries.first { it.group.isEmpty() }.startMs)))
}
@Test fun anEveningBedtimeStoryOnTotsIsTotsStoryTime() {
val story = SampleBroadcast(ScheduledMedia(SampleItem("CBeebies Bedtime Stories / S2016 E25 / Tim Peake", "Episode", 5, "", "e1", 300_000), "s1", 300_000), at(18, 30))
assertTrue(isStoryTime(TOTS_NUMBER, story, zone))
assertEquals("Tots Story Time" to "S2016 E25 • Tim Peake", if (isStoryTime(TOTS_NUMBER, story, zone)) "Tots Story Time" to guideTitleParts(story.media.item.title).second else null)
assertFalse(isStoryTime(TOTS_NUMBER, story.copy(startMs = at(10, 0)), zone))
assertFalse(isStoryTime(605, story, zone))
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 850 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 525 KiB