0.100.0: v2 interface: one top bar (Home, What's On, TV Guide, Drive-In, Arcade), Home category menu, What's On screen with pop-up and reminders, one-screen Drive-In, restyled TV Guide
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 2m15s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m33s

What's On reads confirmed bookings only (WhatsOnPage, 6 tests). Scheduling untouched: booking fingerprints identical to 0.99.17.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-04 17:24:37 +00:00
co-authored by Claude Opus 5.5
parent 7bb600fb76
commit 2264361b5c
16 changed files with 599 additions and 280 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ android {
applicationId = "tv.orbit.classic"
minSdk = 26
targetSdk = 36
versionCode = 147
versionName = "0.99.17-beerus-premiere"
versionCode = 148
versionName = "0.100.0-whats-on"
}
buildFeatures { compose = true }
compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 }
@@ -2,13 +2,8 @@ package tv.orbit.classic
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Matrix
import android.graphics.Paint
import android.graphics.Path
import android.graphics.RectF
import android.view.KeyEvent
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
@@ -23,9 +18,7 @@ import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.drawIntoCanvas
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.nativeCanvas
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.input.key.onPreviewKeyEvent
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
@@ -34,9 +27,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
@@ -213,8 +204,6 @@ internal fun driveInReminderDue(bills: List<DriveInBill>, tickets: Map<Long, Int
internal fun liveTickets(tickets: Map<Long, Int>, nowMs: Long) = tickets.filterKeys { it > nowMs - 24 * 60 * 60_000L }
private val Marquee = FontFamily(Font(R.font.anton_regular))
private val BoardInk = Color(0xFF2A1238)
private val BoardPink = Color(0xFFC2358F)
private val Gold = Color(0xFFF2C14E)
@Composable
@@ -231,89 +220,6 @@ internal fun rememberFilmPicture(session: EmbySampleSession, itemId: String?): B
return picture
}
/** One line on a board. Its height is fixed, whatever the font asks for, so the lines land where they're measured to. */
@Composable
private fun BoardLine(height: Float, content: @Composable () -> Unit) {
Box(Modifier.fillMaxWidth().height(height.dp), contentAlignment = Alignment.Center) { content() }
}
/** Tonight's bill in the board's own letters. The board stays the same size, so long titles get smaller. */
@Composable
private fun MarqueeBoard(bill: DriveInBill?, nowMs: Long, x: Dp, y: Dp, width: Dp, height: Dp, big: Float, tilt: Float = 0f) {
val lineUp = Modifier.wrapContentHeight(unbounded = true)
Box(Modifier.offset(x, y).size(width, height).graphicsLayer(rotationZ = tilt), contentAlignment = Alignment.Center) {
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy((big * .1f).dp)) {
val head = bill?.let { driveInDay(it, nowMs).uppercase(java.util.Locale.UK) } ?: "COMING SOON"
BoardLine(big * 1.2f) { Text(if (bill != null) "$head AT THE DRIVE-IN" else head, lineUp, color = BoardInk, fontFamily = Marquee, fontSize = big.sp, maxLines = 1, softWrap = false) }
if (bill != null) {
BoardLine(big * .72f) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
Box(Modifier.size((big * 1.4f).dp, 2.dp).background(BoardPink))
Text(bill.kind.label.uppercase(java.util.Locale.UK), lineUp, color = BoardInk, fontFamily = Barlow, fontWeight = FontWeight.SemiBold, fontSize = (big * .6f).sp, letterSpacing = 1.sp, maxLines = 1, softWrap = false)
Box(Modifier.size((big * 1.4f).dp, 2.dp).background(BoardPink))
}
}
val title = bill.title.uppercase(java.util.Locale.UK)
val fit = when { title.length > 44 -> .42f; title.length > 32 -> .5f; else -> .62f }
BoardLine(big * .72f) { Text(title, lineUp.fillMaxWidth(), color = BoardInk, fontFamily = Barlow, fontWeight = FontWeight.SemiBold, fontSize = (big * fit).sp, textAlign = TextAlign.Center, maxLines = 1, overflow = TextOverflow.Ellipsis) }
}
}
}
}
@Composable
private fun EventTile(bill: DriveInBill, nowMs: Long, selected: Boolean, ticketed: Boolean, modifier: Modifier) {
val corner = RoundedCornerShape(5.dp)
val ink = if (selected) Navy else Color.White
Row((if (selected) modifier.background(Yellow, corner) else modifier.background(Color(0xFF0E2147), corner).border(1.dp, Color(0xFFC98A1E), corner)).padding(horizontal = 10.dp),
verticalAlignment = Alignment.CenterVertically) {
Column(Modifier.weight(1f)) {
Text(driveInDay(bill, nowMs).uppercase(java.util.Locale.UK) + if (ticketed) " • TICKET" else "", color = if (selected) Navy else Gold, fontFamily = Barlow, fontWeight = FontWeight.SemiBold, fontSize = 10.sp, letterSpacing = 1.sp, maxLines = 1)
Text(bill.kind.label, color = ink, fontFamily = Barlow, fontWeight = FontWeight.SemiBold, fontSize = 15.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
Text(clock(bill.startMs), color = ink, fontFamily = Barlow, fontSize = 16.sp, maxLines = 1)
}
}
/** Over the lot's big screen, which leans away from the viewer. Corners are in the 1920-wide scene. */
@Composable
private fun PictureOnBigScreen(picture: Bitmap?) {
if (picture == null) return
Canvas(Modifier.fillMaxSize()) {
val s = size.width / 1920f
val to = floatArrayOf(1321f, 340f, 1860f, 262f, 1866f, 591f, 1321f, 597f).map { it * s }.toFloatArray()
val from = floatArrayOf(0f, 0f, picture.width.toFloat(), 0f, picture.width.toFloat(), picture.height.toFloat(), 0f, picture.height.toFloat())
val matrix = Matrix().apply { setPolyToPoly(from, 0, to, 0, 4) }
drawIntoCanvas { it.nativeCanvas.drawBitmap(picture, matrix, Paint(Paint.FILTER_BITMAP_FLAG)) }
}
}
/** On the CRT's curved glass, cropped to its old shape, with faint scan lines. */
@Composable
private fun PictureOnTube(picture: Bitmap?) {
Canvas(Modifier.fillMaxSize()) {
val s = size.width / 1920f
val glass = Path().apply {
moveTo(160 * s, 152 * s); cubicTo(340 * s, 132 * s, 680 * s, 132 * s, 860 * s, 152 * s); cubicTo(884 * s, 300 * s, 884 * s, 640 * s, 860 * s, 788 * s)
cubicTo(680 * s, 808 * s, 340 * s, 808 * s, 160 * s, 788 * s); cubicTo(136 * s, 640 * s, 136 * s, 300 * s, 160 * s, 152 * s); close()
}
val area = RectF(136 * s, 136 * s, 884 * s, 804 * s)
drawIntoCanvas { canvas ->
val native = canvas.nativeCanvas
native.save(); native.clipPath(glass)
if (picture != null) {
val scale = maxOf(area.width() / picture.width, area.height() / picture.height)
val matrix = Matrix().apply { postTranslate(-picture.width / 2f, -picture.height / 2f); postScale(scale, scale); postTranslate(area.centerX(), area.centerY()) }
native.drawBitmap(picture, matrix, Paint(Paint.FILTER_BITMAP_FLAG))
}
val line = Paint().apply { color = android.graphics.Color.argb(40, 0, 0, 0); strokeWidth = 2 * s }
var y = area.top
while (y < area.bottom) { native.drawLine(area.left, y, area.right, y, line); y += 6 * s }
native.restore()
}
}
}
/** Picking a later show asks first. With a ticket, the same place shows it, and it can be handed back. */
@Composable
private fun DriveInTicket(bill: DriveInBill, nowMs: Long, ticketed: Boolean, onTicket: () -> Unit, onHandBack: () -> Unit, onClose: () -> Unit) {
@@ -374,33 +280,34 @@ internal fun DriveInReminderCard(reminder: DriveInReminder, nowMs: Long, onGo: (
}
}
/** Three scenes take turns, a new one each visit: the theatre, the lot and the old set. */
/**
* The Drive-In on one screen (Paul's v2 design, 4 November 2026): the chosen bill large on the left over its own film
* artwork, blended into deep navy, with its ticket; this week's bills down the right. Up and down choose a bill, OK
* watches what's showing now or opens its ticket. The bills come from the Drive-In's own booked plan, untouched.
*/
@Composable
internal fun DriveInScreen(session: EmbySampleSession, plan: ChannelPlan?, visit: Int, modifier: Modifier, active: Boolean, tickets: Map<Long, Int>,
onTicket: (DriveInBill) -> Unit, onHandBack: (DriveInBill) -> Unit, onWatch: () -> Unit) {
var now by remember { mutableLongStateOf(System.currentTimeMillis()) }
LaunchedEffect(Unit) { while (true) { delay(1000); if (!FullScreen.active) now = System.currentTimeMillis() } }
val minute = now / 60_000
val lineup = remember(plan, minute) { plan?.let { driveInLineup(driveInBills(it), now) }.orEmpty() }
var chosenKind by remember { mutableStateOf<DriveInKind?>(null) }
val soonest = lineup.minByOrNull { it.startMs }
val selected = lineup.firstOrNull { it.kind == chosenKind } ?: soonest
val index = lineup.indexOf(selected)
val bills = remember(plan, minute) { plan?.let { driveInBills(it).filter { bill -> bill.endMs > now } }.orEmpty().take(DRIVE_IN_LISTED) }
var chosen by remember(visit) { mutableStateOf<Long?>(null) }
val selected = bills.firstOrNull { it.startMs == chosen } ?: bills.firstOrNull()
val index = bills.indexOf(selected)
var ticket by remember { mutableStateOf<DriveInBill?>(null) }
val ownFocus = remember { FocusRequester() }
val focus = LocalDriveInFocus.current ?: ownFocus
LaunchedEffect(active, ticket) { if (active && ticket == null) focus.requestFocus() }
val scene = Math.floorMod(visit, DRIVE_IN_SCENES)
val nav = LocalNavFocus.current
Box(modifier.fillMaxSize().background(Navy).focusRequester(focus).focusProperties { if (nav != null) up = nav }.focusable().onPreviewKeyEvent { event ->
val native = event.nativeKeyEvent
// With the ticket open, the keys are for its buttons.
if (native.action != KeyEvent.ACTION_DOWN || lineup.isEmpty() || ticket != null) return@onPreviewKeyEvent false
if (native.action != KeyEvent.ACTION_DOWN || bills.isEmpty() || ticket != null) return@onPreviewKeyEvent false
when (native.keyCode) {
// The list runs across the bottom, or down the side on the CRT. Up off the top goes to the bar.
KeyEvent.KEYCODE_DPAD_UP -> if (scene == 2 && index > 0) { chosenKind = lineup[index - 1].kind; true } else false
KeyEvent.KEYCODE_DPAD_LEFT -> { chosenKind = lineup[Math.floorMod(index - 1, lineup.size)].kind; true }
KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.KEYCODE_DPAD_DOWN -> { chosenKind = lineup[Math.floorMod(index + 1, lineup.size)].kind; true }
// Up off the first bill goes to the top bar.
KeyEvent.KEYCODE_DPAD_UP -> if (index > 0) { chosen = bills[index - 1].startMs; true } else false
KeyEvent.KEYCODE_DPAD_DOWN -> { if (index < bills.lastIndex) chosen = bills[index + 1].startMs; true }
KeyEvent.KEYCODE_DPAD_CENTER, KeyEvent.KEYCODE_ENTER -> {
if (native.repeatCount == 0) selected?.let { if (it.startMs <= now) onWatch() else ticket = it }
true
@@ -408,42 +315,59 @@ internal fun DriveInScreen(session: EmbySampleSession, plan: ChannelPlan?, visit
else -> false
}
}) {
val backdrop = when (scene) { 0 -> R.drawable.drive_in_theatre; 1 -> R.drawable.drive_in_lot; else -> R.drawable.drive_in_crt }
Image(painterResource(backdrop), null, Modifier.fillMaxSize(), contentScale = ContentScale.FillBounds)
// Only the two scenes with a screen need the film's picture.
val picture = rememberFilmPicture(session, selected?.entries?.first()?.media?.item?.id.takeIf { scene != 0 })
when (scene) {
0 -> MarqueeBoard(selected, now, 270.dp, 192.dp, 430.dp, 90.dp, 29f)
1 -> {
PictureOnBigScreen(picture)
MarqueeBoard(selected, now, 217.dp, 183.dp, 300.dp, 82.dp, 24f, tilt = 1.5f)
val picture = rememberFilmPicture(session, selected?.entries?.first()?.media?.item?.id)
if (picture != null) Image(picture.asImageBitmap(), null, Modifier.fillMaxSize(), contentScale = ContentScale.Crop)
else Image(painterResource(R.drawable.drive_in_lot), null, Modifier.fillMaxSize(), contentScale = ContentScale.Crop)
// Deep navy over the art, so it sits inside Orbit and the words read: strongest on the left, top and bottom.
Box(Modifier.fillMaxSize().background(Brush.horizontalGradient(0f to Navy.copy(alpha = .96f), .42f to Navy.copy(alpha = .9f), .62f to Navy.copy(alpha = .55f), 1f to Navy.copy(alpha = .35f))))
Box(Modifier.fillMaxSize().background(Brush.verticalGradient(0f to Navy.copy(alpha = .9f), .2f to Navy.copy(alpha = .2f), .75f to Navy.copy(alpha = .25f), 1f to Navy.copy(alpha = .95f))))
Column(Modifier.padding(start = 36.dp, top = 78.dp).width(540.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
Image(painterResource(R.drawable.orbit_drive_in_epg), "Orbit Drive-In", Modifier.width(110.dp).height(34.dp), alignment = Alignment.CenterStart)
if (selected == null) {
Text("Tonight's bill is on its way.", color = Color.White, fontFamily = Barlow, fontSize = 20.sp)
return@Column
}
else -> {
PictureOnTube(picture)
if (selected != null) Column(Modifier.offset(68.dp, 318.dp).size(374.dp, 84.dp).background(Color(0xCC03081A)).padding(horizontal = 14.dp, vertical = 8.dp)) {
Text("${driveInDay(selected, now).uppercase(java.util.Locale.UK)} • ${selected.kind.label.uppercase(java.util.Locale.UK)}", color = Gold, fontFamily = Barlow, fontWeight = FontWeight.SemiBold, fontSize = 12.sp, letterSpacing = 1.sp, maxLines = 1)
Text(selected.title.uppercase(java.util.Locale.UK), color = Color.White, fontFamily = Marquee, fontSize = if (selected.title.length > 32) 18.sp else 24.sp, maxLines = 2, overflow = TextOverflow.Ellipsis)
Text("${driveInDay(selected, now).uppercase(java.util.Locale.UK)} · ${selected.kind.label.uppercase(java.util.Locale.UK)}",
Modifier.background(Yellow, RoundedCornerShape(3.dp)).padding(horizontal = 8.dp, vertical = 3.dp), color = Navy, fontFamily = Barlow, fontWeight = FontWeight.SemiBold, fontSize = 12.sp, letterSpacing = .5.sp, maxLines = 1)
Text(if (selected.startMs <= now) "Now showing" else "Gates ${clock(selected.startMs - 5 * 60_000)} · Feature ${clock(selected.startMs)}", color = Yellow, fontFamily = BarlowCondensed, fontSize = 22.sp)
Text(selected.title.uppercase(java.util.Locale.UK), color = Color.White, fontFamily = Marquee, fontSize = if (selected.title.length > 28) 30.sp else 42.sp, lineHeight = 46.sp, maxLines = 2, overflow = TextOverflow.Ellipsis)
Text((if (selected.films.size > 1) selected.films.joinToString(" · ") + " · " else "") + "${(selected.endMs - selected.startMs) / 60_000} min", color = Color(0xFFE4ECF8), fontFamily = Barlow, fontSize = 14.sp, maxLines = 2, overflow = TextOverflow.Ellipsis)
Spacer(Modifier.height(10.dp))
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Image(painterResource(R.drawable.orbit_drive_in_ticket), "Ticket", Modifier.width(150.dp).height(47.dp))
val held = selected.startMs in tickets
Column {
Text(when { selected.startMs <= now -> "Showing now"; held -> "Ticket held"; else -> "No ticket yet" }, color = if (held || selected.startMs <= now) Mint else Color.White, fontFamily = Barlow, fontWeight = FontWeight.SemiBold, fontSize = 15.sp)
Text(when { selected.startMs <= now -> "OK to watch"; held -> "Reminder 5 minutes before, and at the start. OK to see it"; else -> "OK to get your ticket" }, color = Muted, fontFamily = Barlow, fontSize = 11.sp)
}
}
}
if (scene == 2) {
Column(Modifier.offset(607.dp, 200.dp).width(330.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) {
lineup.forEach { EventTile(it, now, it === selected, it.startMs in tickets, Modifier.fillMaxWidth().height(50.dp)) }
if (lineup.isEmpty()) Text("Tonight's bill is on its way.", color = Color.White, fontFamily = Barlow, fontSize = 16.sp)
}
} else {
Box(Modifier.align(Alignment.BottomCenter).fillMaxWidth().height(100.dp).background(Brush.verticalGradient(listOf(Color.Transparent, Color(0xEB03081A)))))
Row(Modifier.align(Alignment.BottomCenter).padding(start = 20.dp, end = 20.dp, bottom = 26.dp).fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(10.dp)) {
lineup.forEach { EventTile(it, now, it === selected, it.startMs in tickets, Modifier.weight(1f).height(42.dp)) }
if (lineup.isEmpty()) Text("Tonight's bill is on its way.", color = Color.White, fontFamily = Barlow, fontSize = 16.sp)
}
Column(Modifier.align(Alignment.TopEnd).padding(top = 78.dp, end = 36.dp).width(300.dp).background(Navy.copy(alpha = .86f), RoundedCornerShape(8.dp)).padding(10.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
Text("THIS WEEK'S BILLS", color = Color.White, fontFamily = Marquee, fontSize = 16.sp)
bills.forEach { bill -> BillRow(bill, now, bill === selected, bill.startMs in tickets) }
if (bills.isEmpty()) Text("Nothing booked yet.", color = Muted, fontFamily = Barlow, fontSize = 13.sp)
}
val hint = when {
selected != null && selected.startMs <= now -> "OK Watch"
selected != null && selected.startMs in tickets -> "OK Your ticket"
else -> "OK Get your ticket"
}
Text("$hint ◄► Choose an event Back Leave", Modifier.align(Alignment.BottomStart).padding(start = 20.dp, bottom = 6.dp), color = Color(0xFFD5DCEA), fontFamily = Barlow, fontSize = 11.sp)
Text("OK Watch or ticket ▲▼ Choose a bill ▲ at the top: the top bar Back Home", Modifier.align(Alignment.BottomStart).padding(start = 36.dp, bottom = 10.dp),
color = Muted, fontFamily = Barlow, fontSize = 10.sp)
ticket?.let { bill -> DriveInTicket(bill, now, bill.startMs in tickets, onTicket = { onTicket(bill) }, onHandBack = { onHandBack(bill); ticket = null }, onClose = { ticket = null }) }
}
}
/** How many of the week's bills the list shows. */
private const val DRIVE_IN_LISTED = 5
@Composable
private fun BillRow(bill: DriveInBill, nowMs: Long, selected: Boolean, ticketed: Boolean) {
val shape = RoundedCornerShape(6.dp)
val ink = if (selected) Navy else Color.White
Row(Modifier.fillMaxWidth().height(52.dp).background(if (selected) Yellow else Panel, shape).padding(horizontal = 10.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
Column(Modifier.width(52.dp)) {
Text(driveInDay(bill, nowMs).take(3).uppercase(java.util.Locale.UK), color = if (selected) Navy else Muted, fontFamily = Barlow, fontWeight = FontWeight.SemiBold, fontSize = 10.sp)
Text(clock(bill.startMs), color = if (selected) Navy else Yellow, fontFamily = BarlowCondensed, fontSize = 18.sp)
}
Column(Modifier.weight(1f)) {
Text(bill.kind.label.uppercase(java.util.Locale.UK) + if (ticketed) " · TICKET HELD" else "", color = if (selected) Navy else if (ticketed) Mint else Yellow, fontFamily = Barlow, fontWeight = FontWeight.SemiBold, fontSize = 9.sp, letterSpacing = .5.sp, maxLines = 1)
Text(bill.title, color = ink, fontFamily = Barlow, fontWeight = FontWeight.SemiBold, fontSize = 13.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
}
@@ -66,7 +66,7 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI
connection.connectTimeout = 10_000
connection.readTimeout = request.readTimeoutMs ?: if (request.path == "/Sessions/Logout") 5_000 else 15_000
connection.setRequestProperty("Accept", "application/json")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.99.17\"")
connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.100.0\"")
request.token?.let { connection.setRequestProperty("X-Emby-Token", it) }
if (request.method == "POST") {
val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8)
@@ -54,7 +54,7 @@ private const val RESTORE_QUIET_TRIES = 4
@Composable
internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolean,
mainGuide: Boolean, mainHome: Boolean = false, mainDriveIn: Boolean = false, onChannelAvailable: (Boolean) -> Unit, onRestoreChecked: () -> Unit = {}, onGuide: () -> Unit,
mainGuide: Boolean, mainHome: Boolean = false, mainDriveIn: Boolean = false, mainWhatsOn: Boolean = false, onChannelAvailable: (Boolean) -> Unit, onRestoreChecked: () -> Unit = {}, onGuide: () -> Unit,
onHome: () -> Unit = {}, onDriveIn: () -> Unit = {}) {
val appContext = androidx.compose.ui.platform.LocalContext.current.applicationContext
val savedStore = remember { RememberedConnectionStore.get(appContext) }
@@ -88,6 +88,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
var tickets by remember { mutableStateOf<Map<Long, Int>>(emptyMap()) }
var pendingDriveInWatch by remember { mutableStateOf(false) }
var reminder by remember { mutableStateOf<DriveInReminder?>(null) }
var reminders by remember { mutableStateOf<List<ProgrammeReminder>>(emptyList()) }
var programmeReminder by remember { mutableStateOf<ProgrammeReminder?>(null) }
var windingDown by remember { mutableStateOf(false) }
// Each visit opens on the next of the three scenes.
var driveInVisits by remember { mutableIntStateOf((System.currentTimeMillis() / 60_000 % DRIVE_IN_SCENES).toInt()) }
@@ -138,7 +140,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
try { catalogue.clear() }
catch (_: Exception) { message = "The library data could not be removed. Clear Orbit TV app data in Android Settings before leaving this device." }
}
driveInPlan = null; tickets = emptyMap(); reminder = null
driveInPlan = null; tickets = emptyMap(); reminder = null; reminders = emptyList(); programmeReminder = null
seriesMatches = null; episodeSamples = null; approvedSeries = emptySet()
darkMovies = emptyList(); approvedDark = emptySet(); afterDarkChannel = null
lastNumber = null
@@ -243,7 +245,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
LaunchedEffect(session, extraChannels, channel, afterDarkChannel, toonamiChannel) {
val active = session ?: return@LaunchedEffect
// What's booked shows straight away. The rounds below take a while with this many channels.
try { withContext(Dispatchers.IO) { driveInPlan = scheduleStore.loadPlan(active.accountId, DRIVE_IN_NUMBER); tickets = liveTickets(scheduleStore.loadTickets(active.accountId), System.currentTimeMillis()) } }
try { withContext(Dispatchers.IO) { driveInPlan = scheduleStore.loadPlan(active.accountId, DRIVE_IN_NUMBER); tickets = liveTickets(scheduleStore.loadTickets(active.accountId), System.currentTimeMillis())
reminders = liveReminders(scheduleStore.loadReminders(active.accountId), System.currentTimeMillis()) } }
catch (cancelled: CancellationException) { throw cancelled }
catch (_: Exception) { /* The round below tries again. */ }
while (true) {
@@ -278,8 +281,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
}
}
}
LaunchedEffect(mainGuide, mainHome) {
if (!mainGuide && !mainHome) { watchingChannel = false; channelClockOffset = 0 }
LaunchedEffect(mainGuide, mainHome, mainWhatsOn) {
if (!mainGuide && !mainHome && !mainWhatsOn) { watchingChannel = false; channelClockOffset = 0 }
}
LaunchedEffect(mainDriveIn) {
if (mainDriveIn) { driveInVisits++; if (pendingDriveInWatch) { pendingDriveInWatch = false; watchingDriveIn = true } } else watchingDriveIn = false
@@ -301,6 +304,28 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
delay(5_000)
}
}
fun saveReminders(changed: List<ProgrammeReminder>) {
reminders = changed
val active = session ?: return
scope.launch(Dispatchers.IO) { runCatching { scheduleStore.saveReminders(active.accountId, changed) } }
}
// What's On's reminders, checked wherever the viewer is, as the Drive-In's are.
LaunchedEffect(reminders) {
while (reminders.isNotEmpty()) {
val due = programmeReminderDue(reminders, System.currentTimeMillis())
if (due?.stage != programmeReminder?.stage || due?.startMs != programmeReminder?.startMs) programmeReminder = due
delay(5_000)
}
}
programmeReminder?.let { due ->
fun answered() { saveReminders(reminders.map { if (it.channel == due.channel && it.startMs == due.startMs) it.copy(stage = due.stage) else it }); programmeReminder = null }
ProgrammeReminderCard(due, System.currentTimeMillis(), onDismiss = ::answered, onWatch = {
answered()
if (selectedNumber != due.channel) { lastNumber = selectedNumber; selectedNumber = due.channel }
channelClockOffset = 0; watchingChannel = true
if (!mainGuide && !mainHome && !mainWhatsOn) onGuide()
})
}
reminder?.let { due ->
fun answered() { saveTickets(tickets + (due.bill.startMs to due.stage)); reminder = null }
DriveInReminderCard(due, System.currentTimeMillis(), onDismiss = ::answered, onGo = {
@@ -330,7 +355,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
onTicket = { saveTickets(tickets + (it.startMs to 0)) }, onHandBack = { saveTickets(tickets - it.startMs) }, onWatch = { watchingDriveIn = true })
return
}
if ((mainGuide || mainHome) && liveSession != null && liveChannel != null) {
if ((mainGuide || mainHome || mainWhatsOn) && liveSession != null && liveChannel != null) {
if (watchingChannel) ScheduledChannelPlayer(liveSession, liveChannel, channelClockOffset,
intro = remember { CurtainIntro.takeIf { IntroTrial.take() } },
onClose = { watchingChannel = false; channelClockOffset = 0 },
@@ -353,10 +378,14 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
channelClockOffset = offset; watchingChannel = true
}
val picture = @Composable { GuidePicture(liveSession, liveChannel, live = !watchingChannel, handoff = liveHandoff, onUnplayable = ::rememberUnplayable) }
if (mainHome) HomeScreen(liveSession, availableChannels, liveChannel, modifier, picture,
onCategory = { guideCategory = it; onGuide() }, onWatch = { tune(it, 0) }, onDriveIn = onDriveIn, driveInPlan = driveInPlan)
else GuideGrid(channelsIn(guideCategory, availableChannels).ifEmpty { availableChannels }, selectedNumber, modifier, guideCategory.label, picture,
onWatch = ::tune, onBack = { guideCategory = ChannelCategory.All; onHome() })
when {
mainHome -> HomeScreen(availableChannels, modifier, onCategory = { guideCategory = it; onGuide() })
mainWhatsOn -> WhatsOnScreen(liveSession, scheduledChannels.mapValues { it.value.plan }, driveInPlan, modifier, reminders,
onWatch = { tune(it, 0) }, onDriveIn = onDriveIn, onBack = onHome,
onRemind = { item -> saveReminders(liveReminders(reminders, System.currentTimeMillis()) + ProgrammeReminder(item.channel, item.startMs, item.title)) })
else -> GuideGrid(channelsIn(guideCategory, availableChannels).ifEmpty { availableChannels }, selectedNumber, modifier, guideCategory, homeCategories(availableChannels.map { it.number }), picture,
onCategory = { guideCategory = it }, onWatch = ::tune, onBack = { guideCategory = ChannelCategory.All; onHome() })
}
return
}
if (!visible) return
@@ -4,12 +4,15 @@ import android.view.KeyEvent
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.*
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.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
@@ -78,7 +81,20 @@ internal fun guideNowFraction(nowMs: Long, windowStart: Long, windowEnd: Long):
/** Below this a title can't fit, so the block shows it's cut short rather than sitting empty. */
private val GuideTitleMinWidth = 34.dp
private val GuideChannelColumn = Color(0xFF0A1B3C)
/** Programmes later than now: a shade darker than what's on, so now stands out down the rows. */
private val GuideLater = Color(0xFF0F2C5C)
/** One category along the top of the guide. Down goes straight to the grid. */
@Composable
private fun CategoryChip(category: ChannelCategory, current: Boolean, grid: FocusRequester, onClick: () -> Unit) {
var focused by remember { mutableStateOf(false) }
val shape = androidx.compose.foundation.shape.RoundedCornerShape(12.dp)
Box(Modifier.focusProperties { down = grid }.onFocusChanged { focused = it.isFocused }
.background(if (current || focused) Yellow else Panel, shape).then(if (focused) Modifier.border(2.dp, Color.White, shape) else Modifier)
.clickable(onClick = onClick).padding(horizontal = 12.dp, vertical = 4.dp)) {
Text(category.label, color = if (current || focused) Navy else Color.White, fontSize = 12.sp, fontWeight = FontWeight.SemiBold, maxLines = 1)
}
}
/** The first row to draw. It moves a row before the edge, so there's always a sign of the next channel. */
internal fun guideFirstRow(row: Int, first: Int, visible: Int, count: Int): Int {
@@ -98,10 +114,12 @@ internal fun guideStep(channel: SampleChannel, cursorMs: Long, nowMs: Long, forw
}
@Composable
internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modifier: Modifier = Modifier, title: String = "All Channels", picture: @Composable () -> Unit = {}, onWatch: (Int, Long) -> Unit, onBack: () -> Unit) {
internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modifier: Modifier = Modifier, category: ChannelCategory = ChannelCategory.All,
categories: List<ChannelCategory> = listOf(ChannelCategory.All), picture: @Composable () -> Unit = {}, onCategory: (ChannelCategory) -> Unit = {}, onWatch: (Int, Long) -> Unit, onBack: () -> Unit) {
val title = category.label
var now by remember { mutableLongStateOf(System.currentTimeMillis()) }
LaunchedEffect(Unit) { while (true) { delay(1000); if (!FullScreen.active) now = System.currentTimeMillis() } }
var row by remember { mutableIntStateOf(channels.indexOfFirst { it.number == selectedNumber }.coerceAtLeast(0)) }
var row by remember(category) { mutableIntStateOf(channels.indexOfFirst { it.number == selectedNumber }.coerceAtLeast(0)) }
var cursor by remember { mutableLongStateOf(now) }
var slotsAhead by remember { mutableIntStateOf(0) }
var firstRow by remember { mutableIntStateOf(0) }
@@ -124,28 +142,32 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
slotsAhead = ahead
}
Column(modifier.fillMaxWidth().background(Navy).padding(horizontal = 14.dp, vertical = 8.dp), verticalArrangement = Arrangement.spacedBy(5.dp)) {
Row(Modifier.fillMaxWidth().height(135.dp), horizontalArrangement = Arrangement.spacedBy(14.dp)) {
// The categories along the top, as Home lists them: the current one gold, the focused one ringed.
Row(horizontalArrangement = Arrangement.spacedBy(5.dp)) {
categories.forEach { option -> CategoryChip(option, option == category, gridFocus) { onCategory(option) } }
}
Row(Modifier.fillMaxWidth().height(118.dp).background(Deep, androidx.compose.foundation.shape.RoundedCornerShape(6.dp)).padding(8.dp), horizontalArrangement = Arrangement.spacedBy(14.dp)) {
val branding = ChannelBrands.forNumber(channel.number)
// The picture stays on the tuned channel while the cursor browses, so moving rows never re-tunes.
Box(Modifier.width(240.dp).fillMaxHeight().background(Panel)) {
picture()
}
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
if (branding != null) Image(painterResource(branding.logo), branding.displayName, Modifier.width(115.dp).height(36.dp))
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(3.dp)) {
if (branding != null) Image(painterResource(branding.logo), branding.displayName, Modifier.width(96.dp).height(30.dp))
else Text(ChannelBrands.displayName(channel), color = Color.White, fontSize = 16.sp)
val (focusedName, focusedDetail) = guideTitleParts(focused.media.item.title)
Text(focusedName, color = Color.White, fontSize = 21.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis)
Text(focusedName, color = Color.White, fontFamily = Anton, fontSize = 20.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
if (focusedDetail != null) Text(focusedDetail, color = Color.White, 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)}", color = Muted, fontSize = 13.sp, maxLines = 1)
}
Box(Modifier.width(180.dp).fillMaxHeight().background(Panel)) {
picture()
}
}
Row(Modifier.fillMaxWidth().height(20.dp).background(Panel), verticalAlignment = Alignment.CenterVertically) {
Row(Modifier.fillMaxWidth().height(20.dp).background(Blue, androidx.compose.foundation.shape.RoundedCornerShape(3.dp)), verticalAlignment = Alignment.CenterVertically) {
Text(guideDayPrefix(windowStart, now).trim().ifEmpty { "$title, today" }, Modifier.width(136.dp).padding(start = 8.dp), color = Color.White, fontSize = 12.sp, fontWeight = FontWeight.SemiBold)
BoxWithConstraints(Modifier.weight(1f).fillMaxHeight()) {
Row(Modifier.fillMaxSize(), verticalAlignment = Alignment.CenterVertically) {
repeat(GUIDE_SLOTS) { Text(clock(windowStart + it * GUIDE_SLOT_MS), Modifier.weight(1f).padding(start = 4.dp), color = Color.White, fontSize = 12.sp, fontWeight = FontWeight.SemiBold) }
}
if (nowFraction != null) Box(Modifier.align(Alignment.BottomStart).offset(x = maxWidth * nowFraction - 1.dp).size(2.dp, 5.dp).background(Color.White))
if (nowFraction != null) Box(Modifier.align(Alignment.BottomStart).offset(x = maxWidth * nowFraction - 3.dp).size(6.dp, 6.dp).background(Yellow))
}
}
BoxWithConstraints(Modifier.fillMaxWidth().weight(1f)) {
@@ -178,8 +200,8 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
val index = firstRow + offset
Row(Modifier.fillMaxWidth().height(38.dp), horizontalArrangement = Arrangement.spacedBy(6.dp)) {
val mark = ChannelBrands.forNumber(line.number)
Row(Modifier.width(130.dp).fillMaxHeight().background(if (index == row) Blue else GuideChannelColumn).padding(start = 6.dp), verticalAlignment = Alignment.CenterVertically) {
Text(line.number.toString(), Modifier.width(30.dp), color = Muted, fontSize = 12.sp, fontWeight = FontWeight.SemiBold)
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 (mark != null) Image(painterResource(mark.logo), mark.displayName, Modifier.width(88.dp).height(28.dp))
else Text(ChannelBrands.displayName(line), color = Color.White, fontSize = 13.sp, maxLines = 1)
}
@@ -191,10 +213,10 @@ internal fun GuideGrid(channels: List<SampleChannel>, selectedNumber: Int, modif
// 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) Yellow else if (onNow) Blue else Panel), contentAlignment = Alignment.CenterStart) {
.background(if (isFocus) Yellow else if (onNow) Panel else GuideLater, androidx.compose.foundation.shape.RoundedCornerShape(4.dp)), contentAlignment = Alignment.CenterStart) {
val runsOn = cell.show.endMs > windowEnd
val ink = if (isFocus) Navy else Color.White
if (elapsed > 0.dp) Box(Modifier.align(Alignment.BottomStart).width(elapsed).height(3.dp).background(ink))
if (elapsed > 0.dp) Box(Modifier.align(Alignment.BottomStart).width(elapsed).height(3.dp).background(if (isFocus) Navy else Yellow))
Row(Modifier.padding(horizontal = 6.dp), verticalAlignment = Alignment.CenterVertically) {
Text(if (cellWidth >= GuideTitleMinWidth) guideTitleParts(cell.show.media.item.title).first else "…", Modifier.weight(1f, fill = false), color = ink, fontSize = 13.sp,
fontWeight = if (isFocus || onNow) FontWeight.SemiBold else FontWeight.Normal, maxLines = 1, overflow = TextOverflow.Ellipsis)
@@ -14,17 +14,12 @@ import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
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.tv.material3.Text
import kotlinx.coroutines.delay
internal enum class ChannelCategory(val label: String, val icon: Int) {
All("All Channels", R.drawable.orbit_icon_all),
@@ -51,7 +46,6 @@ internal fun programmeProgress(startMs: Long, endMs: Long, nowMs: Long): Float =
if (endMs <= startMs) 0f else ((nowMs - startMs).toFloat() / (endMs - startMs)).coerceIn(0f, 1f)
private val HomeCorner = RoundedCornerShape(6.dp)
private const val HOME_SHUFFLE_MS = 30 * 60_000L
/** A few other channels, a different mix each half hour, so the choice doesn't shuffle under the cursor. */
internal fun homeOnNow(channels: List<SampleChannel>, tunedNumber: Int, count: Int, seed: Long): List<SampleChannel> =
@@ -66,109 +60,33 @@ internal fun HomeCard(modifier: Modifier = Modifier, focusRequester: FocusReques
}
}
/**
* Home is the category menu and nothing else (Paul's v2 design, 4 November 2026): a stacked list in the middle of the
* screen, after the old satellite guide's, each row an icon and a name, the focused row filled gold. OK opens the TV
* Guide on that category. What's On holds the evening's highlights.
*/
@Composable
private fun ProgressBar(fraction: Float, modifier: Modifier = Modifier, focused: Boolean = false) {
Box(modifier.height(4.dp).clip(RoundedCornerShape(2.dp)).background(if (focused) Navy.copy(alpha = .25f) else Navy)) {
Box(Modifier.fillMaxWidth(fraction).fillMaxHeight().background(if (focused) Navy else Color.White))
}
}
/** What's on, written over the live picture so the picture itself never has to move or restart. */
@Composable
private fun WhatsOn(tuned: SampleChannel, now: Long, modifier: Modifier) {
val show = tuned.at(now)
val next = tuned.at(show.endMs)
val branding = ChannelBrands.forNumber(tuned.number)
val (name, detail) = guideTitleParts(show.media.item.title)
Row(modifier.background(Brush.verticalGradient(listOf(Color.Transparent, Color(0xE603081A), Color(0xF003081A)))).padding(start = 10.dp, end = 10.dp, top = 22.dp, bottom = 8.dp),
horizontalArrangement = Arrangement.spacedBy(10.dp), verticalAlignment = Alignment.Bottom) {
if (branding != null) Image(painterResource(branding.logo), branding.displayName, Modifier.width(84.dp).height(28.dp))
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
Text("${tuned.number} • NOW ${clock(show.startMs)} to ${clock(show.endMs)}", color = Color(0xFFD5DCEA), fontSize = 11.sp, fontWeight = FontWeight.SemiBold, maxLines = 1)
Text(name, color = Color.White, fontSize = 17.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis)
if (detail != null) Text(detail, color = Color.White, fontSize = 12.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
ProgressBar(programmeProgress(show.startMs, show.endMs, now), Modifier.fillMaxWidth().padding(vertical = 2.dp))
Text("NEXT ${clock(next.startMs)} ${guideTitleParts(next.media.item.title).first}", color = Color(0xFFD5DCEA), fontSize = 11.sp, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
}
/** The ticket, then the next bill over its own artwork from the library, then what follows. */
@Composable
private fun DriveInCard(session: EmbySampleSession, plan: ChannelPlan?, now: Long, modifier: Modifier, onClick: () -> Unit) {
val minute = now / 60_000
val coming = remember(plan, minute) { plan?.let { driveInBills(it).filter { bill -> bill.endMs > now } }.orEmpty() }
val first = coming.firstOrNull()
val picture = rememberFilmPicture(session, first?.entries?.first()?.media?.item?.id)
HomeCard(modifier, onClick = onClick) { focused ->
Column(Modifier.fillMaxSize().padding(3.dp), verticalArrangement = Arrangement.spacedBy(5.dp)) {
Image(painterResource(R.drawable.orbit_drive_in_ticket), "Orbit Drive-In", Modifier.fillMaxWidth().aspectRatio(500f / 155f), contentScale = ContentScale.FillBounds)
Box(Modifier.fillMaxWidth().weight(1f).clip(HomeCorner).background(Navy)) {
picture?.let { Image(it.asImageBitmap(), null, Modifier.matchParentSize(), contentScale = ContentScale.Crop) }
Column(Modifier.align(Alignment.BottomStart).fillMaxWidth().background(Brush.verticalGradient(listOf(Color.Transparent, Color(0xE603081A), Color(0xF003081A)))).padding(start = 10.dp, end = 10.dp, top = 24.dp, bottom = 8.dp),
verticalArrangement = Arrangement.spacedBy(2.dp)) {
if (first != null) {
Text("${driveInDay(first, now).uppercase(java.util.Locale.UK)}${if (first.startMs > now) " • ${clock(first.startMs)}" else ""}", color = Color(0xFFF2C14E), fontSize = 11.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.sp, maxLines = 1)
Text(first.title, color = Color.White, fontSize = 17.sp, fontWeight = FontWeight.SemiBold, maxLines = 2, overflow = TextOverflow.Ellipsis)
Text(first.kind.label, color = Color(0xFFD5DCEA), fontSize = 11.sp, maxLines = 1)
} else Text("Tonight's bill is on its way", color = Color.White, fontSize = 15.sp, fontWeight = FontWeight.SemiBold)
}
}
coming.drop(1).take(2).forEach { bill ->
Text("${driveInDay(bill, now)} at ${clock(bill.startMs)} - ${bill.title}", Modifier.padding(horizontal = 7.dp), color = if (focused) Navy else Color.White, fontSize = 11.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
}
}
/** Home opens onto the tuned channel playing, one press from anything else. */
@Composable
internal fun HomeScreen(session: EmbySampleSession, channels: List<SampleChannel>, tuned: SampleChannel, modifier: Modifier = Modifier,
picture: @Composable () -> Unit, onCategory: (ChannelCategory) -> Unit, onWatch: (Int) -> Unit, onDriveIn: () -> Unit, driveInPlan: ChannelPlan? = null) {
var now by remember { mutableLongStateOf(System.currentTimeMillis()) }
LaunchedEffect(Unit) { while (true) { delay(1000); if (!FullScreen.active) now = System.currentTimeMillis() } }
internal fun HomeScreen(channels: List<SampleChannel>, modifier: Modifier = Modifier, onCategory: (ChannelCategory) -> Unit) {
val firstFocus = remember { FocusRequester() }
val gear = LocalNavFocus.current
LaunchedEffect(Unit) { firstFocus.requestFocus() }
Column(modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(8.dp)) {
Row(Modifier.fillMaxWidth().weight(1f), horizontalArrangement = Arrangement.spacedBy(14.dp)) {
Column(Modifier.width(176.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(6.dp)) {
homeCategories(channels.map { it.number }).forEachIndexed { index, category ->
HomeCard(Modifier.fillMaxWidth().weight(1f).focusProperties { if (index == 0 && gear != null) up = gear }, if (index == 0) firstFocus else null, onClick = { onCategory(category) }) { focused ->
Row(Modifier.fillMaxSize().padding(horizontal = 10.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
Image(painterResource(category.icon), null, Modifier.size(26.dp), colorFilter = if (focused) ColorFilter.tint(Navy) else null)
Text(category.label, color = if (focused) Navy else Color.White, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, maxLines = 1)
}
val nav = LocalNavFocus.current
LaunchedEffect(Unit) { runCatching { firstFocus.requestFocus() } }
Column(modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally) {
Spacer(Modifier.weight(.6f))
Text("What would you like to watch?", color = Color.White, fontFamily = Anton, fontSize = 22.sp)
Spacer(Modifier.height(16.dp))
Column(Modifier.width(400.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
homeCategories(channels.map { it.number }).forEachIndexed { index, category ->
HomeCard(Modifier.fillMaxWidth().height(31.dp).focusProperties { if (index == 0 && nav != null) up = nav }, if (index == 0) firstFocus else null, onClick = { onCategory(category) }) { focused ->
Row(Modifier.fillMaxSize().padding(horizontal = 16.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Image(painterResource(category.icon), null, Modifier.size(18.dp), colorFilter = if (focused) ColorFilter.tint(Navy) else null)
Text(category.label.uppercase(java.util.Locale.UK), color = if (focused) Navy else Color.White, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, letterSpacing = .5.sp, maxLines = 1)
}
}
}
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(6.dp)) {
HomeCard(Modifier.fillMaxWidth().aspectRatio(16f / 9f), onClick = { onWatch(tuned.number) }) {
Box(Modifier.fillMaxSize().padding(3.dp)) {
picture()
WhatsOn(tuned, now, Modifier.align(Alignment.BottomStart).fillMaxWidth())
}
}
Text("On now", color = Color.White, fontSize = 14.sp, fontWeight = FontWeight.SemiBold)
val seed = now / HOME_SHUFFLE_MS
val others = remember(seed, tuned.number, channels.size) { homeOnNow(channels, tuned.number, 3, seed) }
others.forEach { line ->
val show = line.at(now)
val mark = ChannelBrands.forNumber(line.number)
HomeCard(Modifier.fillMaxWidth().weight(1f), onClick = { onWatch(line.number) }) { focused ->
Row(Modifier.fillMaxSize().padding(horizontal = 8.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(8.dp)) {
if (mark != null) Image(painterResource(mark.logo), mark.displayName, Modifier.width(84.dp).height(28.dp))
else Text(ChannelBrands.displayName(line), Modifier.width(84.dp), color = if (focused) Navy else Color.White, fontSize = 12.sp, maxLines = 1)
Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text(guideTitleParts(show.media.item.title).first, color = if (focused) Navy else Color.White, fontSize = 13.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis)
ProgressBar(programmeProgress(show.startMs, show.endMs, now), Modifier.fillMaxWidth(), focused)
}
}
}
}
}
DriveInCard(session, driveInPlan, now, Modifier.width(250.dp).fillMaxHeight(), onDriveIn)
}
Text("▲▼ Move OK Select ► Picture and events Back Close", color = Muted, fontSize = 11.sp)
Spacer(Modifier.height(14.dp))
Text("Tonight's Pick and the evening's highlights are in What's On", color = Muted, fontSize = 11.sp)
Spacer(Modifier.weight(1f))
Text("OK Open the category ▲▼ Move ▲ at the top: the top bar Back Close Orbit", Modifier.align(Alignment.Start), color = Muted, fontSize = 10.sp)
}
}
@@ -74,14 +74,18 @@ internal fun OrbitButton(label: String, modifier: Modifier = Modifier, selected:
}
}
/** One place along the top, always a press away. */
/**
* One place along the top, always a press away (v2 design): the screen you're on is white with a gold underline, the
* focused place is filled gold.
*/
@Composable
private fun NavItem(label: String, selected: Boolean, focus: FocusRequester?, below: FocusRequester?, onClick: () -> Unit) {
var focused by remember { mutableStateOf(false) }
val corner = androidx.compose.foundation.shape.RoundedCornerShape(5.dp)
Box((if (focus != null) Modifier.focusRequester(focus) else Modifier).focusProperties { if (below != null) down = below }.height(32.dp).onFocusChanged { focused = it.isFocused }
.background(if (focused) Yellow else if (selected) Blue else Navy.copy(alpha = .72f), corner).clickable(onClick = onClick).padding(horizontal = 14.dp), contentAlignment = Alignment.Center) {
Text(label, color = if (focused) Navy else Color.White, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, maxLines = 1)
Column((if (focus != null) Modifier.focusRequester(focus) else Modifier).focusProperties { if (below != null) down = below }.height(32.dp).onFocusChanged { focused = it.isFocused }
.background(if (focused) Yellow else Color.Transparent, corner).clickable(onClick = onClick).padding(horizontal = 12.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
Text(label, color = if (focused) Navy else if (selected) Color.White else Muted, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, maxLines = 1)
Box(Modifier.padding(top = 2.dp).width(28.dp).height(2.dp).background(if (selected && !focused) Yellow else Color.Transparent))
}
}
@@ -105,7 +109,7 @@ private fun OrbitApp() {
onDispose { lifecycle.removeObserver(observer) }
}
// Back on the main menu closes the app.
BackHandler(realChannelAvailable && section != "TV Guide" && section != "Home") { section = "Home" }
BackHandler(realChannelAvailable && section != "TV Guide" && section != "Home" && section != "What's On") { section = "Home" }
val navFocus = remember { FocusRequester() }
val driveInFocus = remember { FocusRequester() }
Box(Modifier.fillMaxSize().background(Navy)) {
@@ -119,6 +123,7 @@ private fun OrbitApp() {
mainGuide = section == "TV Guide" && realChannelAvailable,
mainHome = section == "Home" && realChannelAvailable,
mainDriveIn = section == "Drive-In" && realChannelAvailable,
mainWhatsOn = section == "What's On" && realChannelAvailable,
onChannelAvailable = { realChannelAvailable = it }, onRestoreChecked = { restoreChecked = true },
onGuide = { section = "TV Guide" }, onHome = { section = "Home" }, onDriveIn = { section = "Drive-In" })
}
@@ -128,12 +133,17 @@ private fun OrbitApp() {
// The whole-screen Drive-In has nothing for down to find by itself, so it's told.
val below = if (section == "Drive-In") driveInFocus else null
Spacer(Modifier.width(8.dp))
NavItem("Home", section == "Home" || section == "TV Guide", navFocus, below) { section = "Home" }
NavItem("Home", section == "Home", navFocus, below) { section = "Home" }
NavItem("What's On", section == "What's On", null, below) { section = "What's On" }
NavItem("TV Guide", section == "TV Guide", null, below) { section = "TV Guide" }
NavItem("Drive-In", section == "Drive-In", null, below) { section = "Drive-In" }
NavItem("Arcade", section == "Arcade", null, below) { section = "Arcade" }
}
Spacer(Modifier.weight(1f))
Text(SimpleDateFormat("EEE d MMM HH:mm", Locale.UK).format(Date(now)), Modifier.background(if (section == "Drive-In") Navy.copy(alpha = .72f) else Color.Transparent).padding(horizontal = 6.dp, vertical = 3.dp), color = Color.White, fontSize = 17.sp)
Column(horizontalAlignment = Alignment.End) {
Text(SimpleDateFormat("HH:mm", Locale.UK).format(Date(now)), color = Color.White, fontFamily = BarlowCondensed, fontSize = 20.sp)
Text(SimpleDateFormat("EEEE d MMMM", Locale.UK).format(Date(now)), color = Muted, fontSize = 10.sp)
}
if (realChannelAvailable) HomeCard(Modifier.size(38.dp, 32.dp).focusProperties { if (section == "Drive-In") down = driveInFocus }, onClick = { section = "Connect Emby" }) { focused ->
Image(painterResource(R.drawable.orbit_icon_gear), "Settings", Modifier.fillMaxSize().padding(5.dp), colorFilter = if (focused) ColorFilter.tint(Navy) else null)
}
@@ -162,6 +162,16 @@ internal class ScheduleStore(private val directory: File) {
saved.keys().asSequence().associate { it.toLong() to saved.getInt(it) }
}.orEmpty()
/** Programme reminders set from What's On: channel, start, title and how far their reminders have got. */
fun saveReminders(userId: String, reminders: List<ProgrammeReminder>) =
write(file("reminders", 0), root(userId, 0).put("reminders", JSONArray().also { saved ->
reminders.forEach { saved.put(JSONObject().put("c", it.channel).put("a", it.startMs).put("t", it.title).put("s", it.stage)) }
}))
fun loadReminders(userId: String): List<ProgrammeReminder> = read(file("reminders", 0), userId, 0) { root ->
val saved = root.getJSONArray("reminders")
(0 until saved.length()).map { saved.getJSONObject(it) }.map { ProgrammeReminder(it.getInt("c"), it.getLong("a"), it.getString("t").take(120), it.getInt("s")) }
}.orEmpty()
/** Your accepted and rejected suggestions. Kept apart from the schedule, so a rebuild or a damaged plan never loses them. */
fun saveChoices(userId: String, number: Int, choices: ChannelChoices) {
val accepted = JSONArray()
@@ -33,7 +33,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B
next.instanceFollowRedirects = false
next.connectTimeout = 10_000
next.readTimeout = 20_000
next.setRequestProperty("User-Agent", "OrbitTV/0.99.17")
next.setRequestProperty("User-Agent", "OrbitTV/0.100.0")
next.setRequestProperty("Accept-Encoding", "identity")
session.mediaHeaders(address).forEach { (key, value) -> next.setRequestProperty(key, value) }
if (dataSpec.position != 0L || dataSpec.length != C.LENGTH_UNSET.toLong()) {
@@ -0,0 +1,229 @@
package tv.orbit.classic
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.Image
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.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusProperties
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
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.tv.material3.Text
import kotlinx.coroutines.delay
/** Orbit's v2 colours beyond the originals (design/whats-on/v2). */
internal val Deep = Color(0xFF0C2148)
internal val Sky = Color(0xFF7FD1FF)
internal val Mint = Color(0xFF7EE0A8)
internal val Anton = FontFamily(Font(R.font.anton_regular))
internal val BarlowCondensed = FontFamily(Font(R.font.barlow_condensed_medium))
private val Corner = RoundedCornerShape(6.dp)
/** A reminder set from What's On, shown 5 minutes before and at the start, as the Drive-In's are. Stage 0 set, 1 warned, 2 started. */
internal data class ProgrammeReminder(val channel: Int, val startMs: Long, val title: String, val stage: Int = 0)
internal fun programmeReminderDue(reminders: List<ProgrammeReminder>, nowMs: Long): ProgrammeReminder? = reminders.firstOrNull { r ->
(nowMs >= r.startMs && nowMs < r.startMs + REMINDER_LATE_MS && r.stage < 2) || (nowMs >= r.startMs - REMINDER_BEFORE_MS && nowMs < r.startMs && r.stage < 1)
}?.let { it.copy(stage = if (nowMs >= it.startMs) 2 else 1) }
/** Old reminders drop off, so the file stays small. */
internal fun liveReminders(reminders: List<ProgrammeReminder>, nowMs: Long) = reminders.filter { it.startMs > nowMs - 24 * 60 * 60_000L }
private fun tagColour(tag: String) = when (tag) { "FIRST ON ORBIT", "COMPLETE STORY" -> Sky; else -> Yellow }
@Composable
private fun Tag(text: String, colour: Color = tagColour(text), size: Int = 10) {
Text(text, Modifier.background(colour, RoundedCornerShape(3.dp)).padding(horizontal = 6.dp, vertical = 2.dp), color = Navy, fontSize = size.sp, fontWeight = FontWeight.SemiBold, letterSpacing = .5.sp, maxLines = 1)
}
@Composable
private fun Logo(channel: Int, width: Int, height: Int) {
val brand = ChannelBrands.forNumber(channel)
if (brand != null) Image(painterResource(brand.logo), brand.displayName, Modifier.width(width.dp).height(height.dp), alignment = Alignment.CenterStart)
else if (channel == DRIVE_IN_NUMBER) Image(painterResource(R.drawable.orbit_drive_in_epg), "Orbit Drive-In", Modifier.width(width.dp).height(height.dp), alignment = Alignment.CenterStart)
}
private fun dayAndTime(startMs: Long, nowMs: Long): String {
val today = java.text.SimpleDateFormat("yyyyDDD", java.util.Locale.UK)
return if (today.format(java.util.Date(startMs)) == today.format(java.util.Date(nowMs))) (if (startMs <= nowMs) "On now" else "Tonight ${clock(startMs)}")
else java.text.SimpleDateFormat("EEEE HH:mm", java.util.Locale.UK).format(java.util.Date(startMs))
}
/** A card the remote can land on: gold ring and a lift when focused. */
@Composable
private fun FocusCard(modifier: Modifier, focus: FocusRequester? = null, onClick: () -> Unit, content: @Composable BoxScope.(Boolean) -> Unit) {
var focused by remember { mutableStateOf(false) }
Box(modifier.then(if (focus != null) Modifier.focusRequester(focus) else Modifier).onFocusChanged { focused = it.isFocused }
.border(if (focused) 2.dp else 0.dp, if (focused) Yellow else Color.Transparent, RoundedCornerShape(8.dp))
.clip(Corner).clickable(onClick = onClick)) { content(focused) }
}
/**
* What's On on one screen: Tonight's Pick, Tonight on Orbit and Coming Up, from confirmed bookings only. OK opens the
* pop-up: Watch live when it's on now, Remind me when it's later, Back. A Drive-In card goes to the Drive-In.
*/
@Composable
internal fun WhatsOnScreen(session: EmbySampleSession, plans: Map<Int, ChannelPlan>, driveIn: ChannelPlan?, modifier: Modifier, reminders: List<ProgrammeReminder>,
onWatch: (Int) -> Unit, onDriveIn: () -> Unit, onRemind: (WhatsOnItem) -> Unit, onBack: () -> Unit) {
var now by remember { mutableLongStateOf(System.currentTimeMillis()) }
LaunchedEffect(Unit) { while (true) { delay(1000); if (!FullScreen.active) now = System.currentTimeMillis() } }
val minute = now / 60_000
val page = remember(plans, driveIn, minute) { whatsOnPage(plans, driveIn, now) }
var open by remember { mutableStateOf<WhatsOnItem?>(null) }
val first = remember { FocusRequester() }
val nav = LocalNavFocus.current
LaunchedEffect(open == null) { if (open == null) runCatching { first.requestFocus() } }
BackHandler(open == null, onBack)
fun choose(item: WhatsOnItem) { if (item.channel == DRIVE_IN_NUMBER) onDriveIn() else open = item }
Column(modifier.fillMaxSize().padding(top = 10.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) {
Row(Modifier.fillMaxWidth().height(280.dp), horizontalArrangement = Arrangement.spacedBy(16.dp)) {
val pick = page.pick
FocusCard(Modifier.weight(1f).fillMaxHeight().focusProperties { if (nav != null) up = nav }, first, onClick = { pick?.let(::choose) }) { focused ->
if (pick == null) {
Box(Modifier.fillMaxSize().background(Panel), contentAlignment = Alignment.Center) {
Text("Tonight's Pick appears here once tonight's events are booked.", color = Muted, fontSize = 15.sp)
}
return@FocusCard
}
val picture = rememberFilmPicture(session, pick.entry.media.item.id)
Box(Modifier.fillMaxSize().background(Panel)) {
if (picture != null) Image(picture.asImageBitmap(), null, Modifier.fillMaxSize(), contentScale = ContentScale.Crop)
else Image(painterResource(R.drawable.drive_in_lot), null, Modifier.fillMaxSize(), contentScale = ContentScale.Crop, alpha = .35f)
Box(Modifier.fillMaxSize().background(Brush.horizontalGradient(0f to Navy.copy(alpha = .97f), .45f to Navy.copy(alpha = .88f), .75f to Navy.copy(alpha = .35f), 1f to Navy.copy(alpha = .15f))))
Column(Modifier.fillMaxSize().padding(16.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
Tag("TONIGHT'S PICK", Yellow, 11)
Logo(pick.channel, 96, 30)
Text(dayAndTime(pick.startMs, now), color = Yellow, fontFamily = BarlowCondensed, fontSize = 20.sp)
Text(pick.title.uppercase(java.util.Locale.UK), color = Color.White, fontFamily = Anton, fontSize = 30.sp, lineHeight = 32.sp, maxLines = 2, overflow = TextOverflow.Ellipsis)
pick.detail?.let { Text(it, color = Color.White, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis) }
Spacer(Modifier.weight(1f))
Row(horizontalArrangement = Arrangement.spacedBy(10.dp), verticalAlignment = Alignment.CenterVertically) {
Tag(pick.tag)
Text("${(pick.endMs - pick.startMs) / 60_000} min · OK for details", color = Muted, fontSize = 11.sp)
}
}
}
}
Column(Modifier.width(288.dp).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(5.dp)) {
Text("TONIGHT ON ORBIT", color = Color.White, fontFamily = Anton, fontSize = 16.sp)
if (page.tonight.isEmpty()) Text("Nothing else is marked out tonight. The TV Guide has every programme.", color = Muted, fontSize = 12.sp)
page.tonight.forEach { item ->
FocusCard(Modifier.fillMaxWidth().height(46.dp), onClick = { choose(item) }) { focused ->
Row(Modifier.fillMaxSize().background(if (focused) Yellow else Panel).padding(horizontal = 9.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(9.dp)) {
Text(if (item.startMs <= now) "NOW" else clock(item.startMs), Modifier.width(44.dp), color = if (focused) Navy else Yellow, fontFamily = BarlowCondensed, fontSize = 18.sp)
Column(Modifier.weight(1f)) {
Logo(item.channel, 56, 17)
Text(item.title, color = if (focused) Navy else Color.White, fontSize = 12.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis)
}
}
}
}
}
}
Row(verticalAlignment = Alignment.Bottom, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Text("COMING UP", color = Color.White, fontFamily = Anton, fontSize = 16.sp)
Text("Premieres, specials and events, already booked", color = Muted, fontSize = 11.sp)
}
Row(Modifier.fillMaxWidth().weight(1f), horizontalArrangement = Arrangement.spacedBy(12.dp)) {
if (page.comingUp.isEmpty()) Text("Nothing special is booked for the week ahead yet.", color = Muted, fontSize = 12.sp)
page.comingUp.forEach { item ->
FocusCard(Modifier.weight(1f).fillMaxHeight(), onClick = { choose(item) }) { focused ->
Column(Modifier.fillMaxSize().background(if (focused) Yellow else Panel).padding(10.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) {
Row(verticalAlignment = Alignment.CenterVertically) {
Tag(item.tag)
Spacer(Modifier.weight(1f))
Logo(item.channel, 56, 17)
}
Text(item.title, color = if (focused) Navy else Color.White, fontSize = 14.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis)
Row(verticalAlignment = Alignment.CenterVertically) {
Text(dayAndTime(item.startMs, now), color = if (focused) Navy else Yellow, fontFamily = BarlowCondensed, fontSize = 16.sp)
Spacer(Modifier.weight(1f))
if (item.channel == DRIVE_IN_NUMBER) Text("Go to the Drive-In ▶", color = if (focused) Navy else Yellow, fontSize = 10.sp, fontWeight = FontWeight.SemiBold)
}
}
}
}
}
Row(Modifier.fillMaxWidth()) {
Text("OK Details ◄►▲▼ Move Back Home", Modifier.weight(1f), color = Muted, fontSize = 10.sp)
Text("Chosen from confirmed bookings · refreshed daily at 12:00", color = Muted, fontSize = 10.sp)
}
}
open?.let { item -> WhatsOnPopup(item, now, reminders.any { it.channel == item.channel && it.startMs == item.startMs },
onWatch = { open = null; onWatch(item.channel) }, onRemind = { onRemind(item) }, onClose = { open = null }) }
}
/** The details pop-up: what it is, when it's booked, why it's here, and one press to watch or be reminded. */
@Composable
private fun WhatsOnPopup(item: WhatsOnItem, nowMs: Long, reminded: Boolean, onWatch: () -> Unit, onRemind: () -> Unit, onClose: () -> Unit) {
BackHandler(onBack = onClose)
val first = remember { FocusRequester() }
LaunchedEffect(Unit) { first.requestFocus() }
val onNow = item.startMs <= nowMs
Box(Modifier.fillMaxSize().background(Navy.copy(alpha = .8f)), contentAlignment = Alignment.Center) {
Column(Modifier.width(600.dp).background(Deep, RoundedCornerShape(10.dp)).border(1.dp, Blue, RoundedCornerShape(10.dp)).padding(20.dp), verticalArrangement = Arrangement.spacedBy(7.dp)) {
Logo(item.channel, 96, 30)
Text(item.title.uppercase(java.util.Locale.UK), color = Color.White, fontFamily = Anton, fontSize = 32.sp, maxLines = 2, overflow = TextOverflow.Ellipsis)
item.detail?.let { Text(it, color = Color.White, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis) }
Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) {
Tag(item.tag)
Text("${(item.endMs - item.startMs) / 60_000} min", Modifier.border(1.dp, Muted, RoundedCornerShape(3.dp)).padding(horizontal = 6.dp, vertical = 1.dp), color = Color.White, fontSize = 10.sp)
}
Row(Modifier.fillMaxWidth().background(Panel, Corner).padding(12.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) {
Text("${dayAndTime(item.startMs, nowMs)} to ${clock(item.endMs)}", color = Yellow, fontFamily = BarlowCondensed, fontSize = 22.sp)
Text("BOOKED", Modifier.border(1.dp, Mint, RoundedCornerShape(3.dp)).padding(horizontal = 6.dp, vertical = 1.dp), color = Mint, fontSize = 10.sp, fontWeight = FontWeight.SemiBold)
}
Text("Why it's here: ${item.reason.replaceFirstChar { it.lowercase() }}.", color = Muted, fontSize = 11.sp)
Spacer(Modifier.height(4.dp))
Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
when {
onNow -> OrbitButton("Watch live", Modifier.focusRequester(first), onClick = onWatch)
reminded -> OrbitButton("Reminder set for ${clock(item.startMs)}", Modifier.focusRequester(first), onClick = onClose)
else -> OrbitButton("Remind me at ${clock(item.startMs)}", Modifier.focusRequester(first), onClick = onRemind)
}
OrbitButton("Back", onClick = onClose)
}
}
}
}
/** Over whatever's on, as the Drive-In's reminders are. It clears itself if nobody answers. */
@Composable
internal fun ProgrammeReminderCard(reminder: ProgrammeReminder, nowMs: Long, onWatch: () -> Unit, onDismiss: () -> Unit) {
LaunchedEffect(reminder.startMs, reminder.stage) { delay(60_000); onDismiss() }
androidx.compose.ui.window.Dialog(onDismissRequest = onDismiss, properties = androidx.compose.ui.window.DialogProperties(usePlatformDefaultWidth = false, securePolicy = androidx.compose.ui.window.SecureFlagPolicy.SecureOn)) {
val window = (androidx.compose.ui.platform.LocalView.current.parent as? androidx.compose.ui.window.DialogWindowProvider)?.window
SideEffect { window?.setDimAmount(0f); window?.setGravity(android.view.Gravity.TOP or android.view.Gravity.END) }
val first = remember { FocusRequester() }
LaunchedEffect(reminder.stage) { first.requestFocus() }
Column(Modifier.padding(20.dp).width(380.dp).background(Deep.copy(alpha = .95f), Corner).border(2.dp, Yellow, Corner).padding(14.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) {
val left = ((reminder.startMs - nowMs + 59_999) / 60_000).coerceAtLeast(1)
Text(if (reminder.stage == 2) "STARTING NOW" else "STARTS IN $left ${if (left == 1L) "MINUTE" else "MINUTES"}", color = Yellow, fontFamily = Anton, fontSize = 16.sp, maxLines = 1)
Logo(reminder.channel, 84, 26)
Text(reminder.title, color = Color.White, fontWeight = FontWeight.SemiBold, fontSize = 19.sp, maxLines = 2, overflow = TextOverflow.Ellipsis)
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
OrbitButton("Watch", Modifier.focusRequester(first), onClick = onWatch)
OrbitButton(if (reminder.stage == 2) "Not now" else "Later", onClick = onDismiss)
}
}
}
}
@@ -0,0 +1,91 @@
package tv.orbit.classic
import java.time.Instant
import java.time.LocalDate
import java.time.ZoneId
/**
* What's On's editorial choice (Paul's v2 design, 4 November 2026): Tonight's Pick, Tonight on Orbit and Coming Up, read
* only from confirmed bookings, the channels' committed plans and the Drive-In's own plan. Nothing here books, moves or
* changes a programme, and a proposal that isn't booked can never appear, because only plans are read.
*
* The choice belongs to an edition, which turns over at 12:00 each day, so the screen doesn't reshuffle while you watch.
* Programmes that have finished drop out as the evening goes on.
*/
internal const val WHATS_ON_TONIGHT_ROWS = 5
internal const val WHATS_ON_COMING_UP = 3
private const val EDITION_HOUR = 12
private const val EVENING_FROM_HOUR = 18
private const val COMING_UP_DAYS = 7L
/** One programme What's On may show: a booking, the rule that chose it, and its tag. */
internal data class WhatsOnItem(val channel: Int, val entry: ScheduleEntry, val tag: String, val reason: String, val score: Int, val driveIn: DriveInBill? = null) {
val startMs get() = entry.startMs
val endMs get() = driveIn?.endMs ?: entry.endMs
val title get() = driveIn?.title ?: guideTitleParts(entry.media.item.title).first
val detail get() = if (driveIn != null) driveIn.kind.label else guideTitleParts(entry.media.item.title).second
}
internal data class WhatsOnPage(val pick: WhatsOnItem?, val tonight: List<WhatsOnItem>, val comingUp: List<WhatsOnItem>)
/** The edition a moment belongs to: the day whose 12:00 it follows. */
internal fun whatsOnEdition(nowMs: Long, zone: ZoneId): LocalDate {
val local = Instant.ofEpochMilli(nowMs).atZone(zone)
return if (local.hour < EDITION_HOUR) local.toLocalDate().minusDays(1) else local.toLocalDate()
}
/** A franchise, roughly: the title before its first colon or dash, so every Dragon Ball counts as one. */
internal fun whatsOnFranchise(title: String) = seriesKey(title.split(":", " - ", "(").first().trim().split(" ").take(2).joinToString(" "))
/** Why a booking is worth featuring, strongest first, or null when it's an ordinary programme. */
internal fun whatsOnRule(channel: Int, entry: ScheduleEntry, zone: ZoneId): Triple<String, String, Int>? {
val why = entry.why
val hour = Instant.ofEpochMilli(entry.startMs).atZone(zone).hour
return when {
"premiere: first airing on Orbit" in why -> Triple("FIRST ON ORBIT", "A first airing on Orbit", 100)
entry.presentation.isNotEmpty() && why.startsWith("event") -> Triple(if (channel == 401) "SPECIAL EVENT" else "WEEKLY EVENT", "A booked channel event", 80)
why.contains("story: part 1 of") -> Triple("COMPLETE STORY", "A whole multi-part story, back to back", 60)
entry.media.item.type == "Movie" && channel in 300..399 && hour in 19..22 -> Triple("TONIGHT'S FILM", "An evening film on a film channel", 40)
else -> null
}
}
private fun driveInItem(bill: DriveInBill) = WhatsOnItem(DRIVE_IN_NUMBER, bill.entries.first(), "AT THE DRIVE-IN", "A Drive-In bill",
if (bill.kind == DriveInKind.Double || bill.kind == DriveInKind.Triple) 70 else 50, bill)
/**
* The page for [nowMs]. [plans] are the channels' committed plans by number; [driveIn] the Drive-In's. Tonight is this
* edition's evening, 18:00 to the small hours, still to finish; Coming Up is the next seven days after tonight.
*/
internal fun whatsOnPage(plans: Map<Int, ChannelPlan>, driveIn: ChannelPlan?, nowMs: Long, zone: ZoneId = ZoneId.systemDefault()): WhatsOnPage {
val edition = whatsOnEdition(nowMs, zone)
val eveningStart = edition.atTime(EVENING_FROM_HOUR, 0).atZone(zone).toInstant().toEpochMilli()
val eveningEnd = edition.plusDays(1).atTime(6, 0).atZone(zone).toInstant().toEpochMilli()
val horizon = edition.plusDays(1 + COMING_UP_DAYS).atTime(6, 0).atZone(zone).toInstant().toEpochMilli()
val candidates = plans.flatMap { (channel, plan) ->
plan.entries.mapNotNull { entry -> whatsOnRule(channel, entry, zone)?.let { (tag, reason, score) -> WhatsOnItem(channel, entry, tag, reason, score) } }
} + driveIn?.let { plan -> driveInBills(plan, zone).map(::driveInItem) }.orEmpty()
val live = candidates.filter { it.endMs > nowMs }
// A programme booked across several channels' events (a premiere's second episode) is shown once, at its first.
val firstOfRuns = live.sortedBy { it.startMs }.distinctBy { Triple(it.channel, it.tag, whatsOnEdition(it.startMs, zone)) }
/** At most one card per channel and one per franchise, so no channel or franchise takes over the page. */
fun varied(items: List<WhatsOnItem>, count: Int, already: List<WhatsOnItem> = emptyList()): List<WhatsOnItem> {
val channels = already.mapTo(HashSet()) { it.channel }; val franchises = already.mapTo(HashSet()) { whatsOnFranchise(it.title) }; val out = mutableListOf<WhatsOnItem>()
for (item in items) {
if (out.size == count) break
if (!channels.add(item.channel)) continue
if (!franchises.add(whatsOnFranchise(item.title))) { channels.remove(item.channel); continue }
out += item
}
return out
}
val evening = firstOfRuns.filter { it.startMs in eveningStart until eveningEnd || (it.startMs < eveningStart && it.endMs > maxOf(nowMs, eveningStart)) }
val ranked = evening.sortedWith(compareByDescending<WhatsOnItem> { it.score }.thenBy { it.startMs })
val pick = ranked.firstOrNull()
val tonight = varied(ranked.filter { it !== pick }, WHATS_ON_TONIGHT_ROWS, listOfNotNull(pick)).sortedBy { it.startMs }
val later = firstOfRuns.filter { it.startMs >= eveningEnd && it.startMs < horizon && it.score >= 70 }
// One of each kind of event, soonest first, so a weekly event doesn't fill Coming Up by itself.
val comingUp = varied(later.sortedBy { it.startMs }.distinctBy { it.entry.presentation.ifEmpty { it.tag + it.channel } }, WHATS_ON_COMING_UP)
return WhatsOnPage(pick, tonight, comingUp)
}
@@ -0,0 +1,87 @@
package tv.orbit.classic
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import java.time.LocalDate
import java.time.ZoneId
/** What's On reads confirmed bookings only, picks by explainable rules, and never lets one channel or franchise take over. */
class WhatsOnPageTest {
private val zone = ZoneId.of("Europe/London")
private val minute = 60_000L
private fun at(date: String, hour: Int, min: Int = 0) = LocalDate.parse(date).atTime(hour, min).atZone(zone).toInstant().toEpochMilli()
private fun entry(title: String, start: Long, minutes: Int, why: String = "block 18-23; weighted", key: String = "", movie: Boolean = false, id: String = title.filter(Char::isLetterOrDigit)) =
ScheduleEntry(id, EpisodeMark(1, 1), ScheduledMedia(SampleItem(title, if (movie) "Movie" else "Episode", minutes.toLong(), "", id, minutes * minute), "src", minutes * minute), start, why, key)
private fun plan(vararg entries: ScheduleEntry) = ChannelPlan(entries.sortedBy { it.startMs }, ScheduleCursor())
private val saturday = "2026-11-21"
private val plans = mapOf(
601 to plan(entry("Dragon Ball Super: Beerus / S1 E1 / The God Who Destroys", at(saturday, 21, 8), 23, "event 21-22; weighted; premiere: first airing on Orbit", "vortex.afterburn.premiere"),
entry("Dragon Ball Super: Beerus / S1 E2 / Planet of the Kai", at(saturday, 21, 31), 23, "event 21-22; weighted; premiere: first airing on Orbit", "vortex.afterburn.premiere"),
entry("Dragon Ball Z: Dead Zone", at(saturday, 20, 27), 41, "event 20-21; weighted", "vortex.movie", movie = true),
entry("Batman Beyond / S1 E1 / Rebirth", at(saturday, 19, 0), 22)),
AFTER_DARK_NUMBER to plan(entry("Joe Bob's Drive-In / S1 E2 / Sleepaway Camp", at(saturday, 21, 3), 120, "event 21-1; weighted", "afterdark.drivein")),
106 to plan(entry("The X-Files / S2 E25 / Anasazi (1)", at(saturday, 22, 0), 45, "block 18-23; weighted; story: part 1 of 2, booked whole")),
303 to plan(entry("Aliens", at(saturday, 20, 0), 137, "block 18-24; next in turn", movie = true)),
401 to plan(entry("WrestleMania III", at("2026-11-22", 19, 8), 184, "event 19-24; next in turn", "ringx.ppv", movie = true)),
101 to plan(entry("Friends / S1 E1 / Pilot", at(saturday, 20, 0), 22)))
@Test fun picksByExplainableRulesFromBookingsOnly() {
val page = whatsOnPage(plans, null, at(saturday, 15), zone)
// The premiere beats every other rule, and its two episodes are one card.
assertEquals("Dragon Ball Super: Beerus", page.pick!!.title)
assertEquals("FIRST ON ORBIT", page.pick!!.tag)
// Tonight, in time order: no ordinary programme (Friends, Batman Beyond), one card per channel, Vortex not repeated.
val tonight = page.tonight.map { it.title }
assertEquals(listOf("Aliens", "Joe Bob's Drive-In", "The X-Files"), tonight)
assertTrue(page.tonight.none { it.channel == 601 })
// Coming Up: the special event after tonight.
assertEquals(listOf("WrestleMania III"), page.comingUp.map { it.title })
}
@Test fun nothingUnbookedEverAppears() {
// Before the premiere is booked, it can't be featured: with no plans there is nothing at all.
val empty = whatsOnPage(emptyMap(), null, at(saturday, 15), zone)
assertNull(empty.pick); assertTrue(empty.tonight.isEmpty() && empty.comingUp.isEmpty())
val withoutBeerus = whatsOnPage(plans - 601, null, at(saturday, 15), zone)
assertTrue((listOfNotNull(withoutBeerus.pick) + withoutBeerus.tonight + withoutBeerus.comingUp).none { "Beerus" in it.title })
}
@Test fun finishedProgrammesDropOutAndTheEditionTurnsAtNoon() {
val late = whatsOnPage(plans, null, at(saturday, 22, 30), zone)
assertTrue((listOfNotNull(late.pick) + late.tonight).none { it.endMs <= at(saturday, 22, 30) })
assertEquals(LocalDate.parse("2026-11-20"), whatsOnEdition(at(saturday, 11, 59), zone))
assertEquals(LocalDate.parse(saturday), whatsOnEdition(at(saturday, 12, 0), zone))
// After midnight it's still Saturday night's edition.
assertEquals(LocalDate.parse(saturday), whatsOnEdition(at("2026-11-22", 0, 30), zone))
}
@Test fun oneFranchiseCantTakeOver() {
assertEquals(whatsOnFranchise("Dragon Ball Z: Dead Zone"), whatsOnFranchise("Dragon Ball Super: Beerus"))
val crowded = mapOf(301 to plan(entry("Dragon Ball: Curse of the Blood Rubies", at(saturday, 20, 0), 50, movie = true)),
302 to plan(entry("Dragon Ball Z: Lord Slug", at(saturday, 20, 0), 52, movie = true)), 303 to plan(entry("Aliens", at(saturday, 20, 0), 137, movie = true)))
val page = whatsOnPage(crowded, null, at(saturday, 15), zone)
assertEquals(1, (listOfNotNull(page.pick) + page.tonight).count { it.title.startsWith("Dragon Ball") })
}
@Test fun driveInBillsComeFromTheDriveInPlan() {
val driveIn = plan(entry("Back to the Future", at(saturday, 19, 0), 116, "", movie = true, id = "bttf1"), entry("Back to the Future Part II", at(saturday, 20, 56), 108, "", movie = true, id = "bttf2"),
entry("Back to the Future Part III", at(saturday, 22, 44), 118, "", movie = true, id = "bttf3"))
val page = whatsOnPage(emptyMap(), driveIn, at(saturday, 15), zone)
assertEquals(DRIVE_IN_NUMBER, page.pick!!.channel)
assertEquals("AT THE DRIVE-IN", page.pick!!.tag)
}
@Test fun remindersComeAtFiveMinutesAndAtTheStartOnce() {
val r = ProgrammeReminder(106, at(saturday, 22, 0), "The X-Files")
assertNull(programmeReminderDue(listOf(r), at(saturday, 21, 50)))
assertEquals(1, programmeReminderDue(listOf(r), at(saturday, 21, 56))!!.stage)
assertNull(programmeReminderDue(listOf(r.copy(stage = 1)), at(saturday, 21, 57)))
assertEquals(2, programmeReminderDue(listOf(r.copy(stage = 1)), at(saturday, 22, 1))!!.stage)
assertNull(programmeReminderDue(listOf(r.copy(stage = 2)), at(saturday, 22, 2)))
assertNull(programmeReminderDue(listOf(r), at(saturday, 22, 20)))
assertEquals(emptyList<ProgrammeReminder>(), liveReminders(listOf(r), at("2026-11-23", 0)))
}
}
-1
View File
@@ -81,7 +81,6 @@ def home():
s.img(x + 32, y + 13, 36, 36, icon(key, NAVY if focused else WHITE), f"{label} icon")
s.text(x + 92, y + 43, label.upper(), 30, NAVY if focused else WHITE, BODY, 600, spacing=1)
if focused:
s.text(x + w - 26, y + 43, "▶", 26, NAVY, BODY, 600, "end")
s.focus(x, y, w, h, 6)
s.end()
s.end()
Binary file not shown.
Binary file not shown.
Binary file not shown.

Before

Width:  |  Height:  |  Size: 135 KiB

After

Width:  |  Height:  |  Size: 135 KiB