diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 337646bf..c881d441 100644 --- a/android/app/build.gradle.kts +++ b/android/app/build.gradle.kts @@ -9,8 +9,8 @@ android { applicationId = "tv.orbit.classic" minSdk = 26 targetSdk = 36 - versionCode = 269 - versionName = "0.108.109-restore" + versionCode = 270 + versionName = "0.110.0-times" } buildFeatures { compose = true } // The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so diff --git a/android/app/src/main/assets/phone/companion.html b/android/app/src/main/assets/phone/companion.html index aa13667e..8b9c25b4 100644 --- a/android/app/src/main/assets/phone/companion.html +++ b/android/app/src/main/assets/phone/companion.html @@ -186,7 +186,8 @@ function guide() { const f = cats.includes(state.filter) ? state.filter : 'all', list = g.channels.filter(c => f === 'all' || c.category === f); const chips = `
${cats.map(k => ``).join('')}
`; if (f === 'Drive-In') return head('Guide') + chips + driveIn(); - return head('Guide') + chips + + const times = `Orbit TV Times · the week's listings, picks and films ›`; + return head('Guide') + times + chips + (list.map(c => ``).join('') || '
No channels here.
'); @@ -196,7 +197,8 @@ function pickSheet(n) { return `
${esc(c.now.title)}
${c.number} ${esc(c.name)} · Live now · ends ${hm(c.now.endMs)}${c.now.sub ? ' · ' + esc(c.now.sub) : ''}
Watching on: ${esc(state.now?.room || 'this TV')}
-
Queue next switches to ${c.number} ${esc(c.name)} when the programme on the TV ends. Next on it at ${hm(c.next.startMs)}: ${esc(c.next.title)}
`; +
Queue next switches to ${c.number} ${esc(c.name)} when the programme on the TV ends. Next on it at ${hm(c.next.startMs)}: ${esc(c.next.title)}
+ `; } // The Drive-In (phase 2): the coming bills, tickets, and out to the lot while one is showing. function driveIn() { @@ -852,6 +854,7 @@ document.addEventListener('click', e => { if (d.filter) { state.filter = d.filter; render(); } if (d.pick) openSheet(pickSheet(+d.pick)); if (d.tune) send('/api/tune', {number: +d.tune}, () => { closeSheet(); toast('Watching on the TV'); setTimeout(() => load('guide'), 700); }); + if (d.remind) { const [number, startMs, on] = d.remind.split(':').map(Number); send('/api/remind', {number, startMs, on: !!on}, () => { closeSheet(); setTimeout(() => load('guide'), 400); toast(on ? 'The TV will remind you before it starts' : 'Reminder taken off'); }); return; } if (d.queue) send('/api/queue', {number: +d.queue}, j => { state.now = {...state.now, queue: j.queue}; closeSheet(); toast('Queued: switches when this one ends'); }); if (d.cupick) { const [n, st] = d.cupick.split(':').map(Number); openSheet(cuSheet(n, st)); return; } if (d.cuq) { const [number, startMs] = d.cuq.split(':').map(Number); send('/api/queue', {number, startMs}, j => { state.now = {...state.now, queue: j.queue}; closeSheet(); render(); toast('Queued for when this one ends'); }); return; } diff --git a/android/app/src/main/assets/phone/times.html b/android/app/src/main/assets/phone/times.html new file mode 100644 index 00000000..e139ce7f --- /dev/null +++ b/android/app/src/main/assets/phone/times.html @@ -0,0 +1,82 @@ + + +Orbit TV Times + + +
ORBIT TV Times THE WEEK'S PROGRAMMES · EVERY CHANNEL FREE WITH YOUR ORBIT PICKS · FILMS · DRIVE-IN
+
‹ Back to Orbit
+
+
Loading this week's listings…
+ + diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt index 6ee09a89..57aae760 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt @@ -62,9 +62,9 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI } /** The sign-in headers for this kind of server. */ internal fun authHeaders(token: String?): Map = when (kind) { - ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.109\"") + + ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.110.0\"") + (token?.let { mapOf("X-Emby-Token" to it) } ?: emptyMap()) - ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.109\"" + + ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.110.0\"" + (token?.let { ", Token=\"$it\"" } ?: "")) } /** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */ diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt index 46a9c56b..942c4208 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -703,6 +703,12 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea if (offset == 0L) liveHandoff.handOver(number) channelClockOffset = offset; watchingChannel = true } + /** Carries on a Continue watching programme from where it was left, from Catch Up or Home, while it's still in Catch Up. */ + fun resumeContinue(c: ContinueEntry) { + if (c.entry.show.startMs < System.currentTimeMillis() - CATCH_UP_MS || lockedOut(c.entry.channel.number) || profileHides(c.entry.channel.number)) return + tune(c.entry.channel.number, c.entry.show.startMs + c.positionMs - System.currentTimeMillis()) + Taste.record(TasteKind.Chose, c.entry.show.media.item.id, (c.entry.channel as? ScheduledChannel)?.seriesIdAt(c.entry.show.startMs), c.entry.show.media.item.title, c.entry.channel.number, "continue") + } // Orbit Companion: the channels this TV shows right now, and tuning as the guide does. Set here, before any screen // returns early, so the phone works from every section (the Drive-In and the Arcade go to the guide to tune). val shownChannels by rememberUpdatedState(availableChannels.filter { !lockedOut(it.number) && !profileHides(it.number) }) @@ -716,6 +722,11 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea val companionBills by rememberUpdatedState(driveInPlan.takeIf { Profiles.current?.let { it.kind != ProfileKind.Kids || it.driveIn } ?: true } ?.let { plan -> driveInLineup(driveInBills(plan), System.currentTimeMillis()).filter { !lockedOut(it) } }.orEmpty()) val companionDriveIn by rememberUpdatedState(mainDriveIn) + val companionReminders by rememberUpdatedState(reminders) + val companionRemind by rememberUpdatedState { number: Int, startMs: Long, title: String, on: Boolean -> + val kept = liveReminders(reminders, System.currentTimeMillis()).filterNot { it.channel == number && it.startMs == startMs } + saveReminders(if (on) kept + ProgrammeReminder(number, startMs, title) else kept) + } val companionScreen = remember { CompanionScreen(channels = { shownChannels }, selected = { selectedNumber }, watching = { watchingChannel }, offset = { channelClockOffset }, tune = { n, offset -> companionTune(n, offset) }, driveIn = { companionBills }, tickets = { companionTickets.keys }, @@ -736,7 +747,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea decision == "approved" -> "${idea.theme} approved for ${idea.evening}. It books once the Drive-In plans that evening, after its films are checked again." decision == "deferred" -> "${idea.theme} deferred: it can come back in four weeks." else -> "${idea.theme} dismissed: it won't be proposed again unless its films change." } - }) + }, + reminders = { companionReminders }, remind = { number, startMs, title, on -> companionRemind(number, startMs, title, on) }) } DisposableEffect(Unit) { PhoneLink.screen = companionScreen @@ -796,12 +808,10 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea } val picture = @Composable { GuidePicture(liveSession, liveChannel, live = !watchingChannel, handoff = liveHandoff, onUnplayable = ::rememberUnplayable) } when { - mainHome -> HomeScreen(availableChannels, modifier, onCategory = { guideCategory = it; onGuide() }) + mainHome -> HomeScreen(availableChannels, modifier, onCategory = { guideCategory = it; onGuide() }, + carryOn = continueEntries(availableChannels.filter { !lockedOut(it.number) && !profileHides(it.number) }, ContinueWatching.marks, System.currentTimeMillis()), onResume = ::resumeContinue) mainCatchUp -> CatchUpScreen(availableChannels, liveSession, modifier, onOpen = { catchUpOpen = it }, - onResume = { c -> if (c.entry.show.startMs >= System.currentTimeMillis() - CATCH_UP_MS) { - tune(c.entry.channel.number, c.entry.show.startMs + c.positionMs - System.currentTimeMillis()) - Taste.record(TasteKind.Chose, c.entry.show.media.item.id, (c.entry.channel as? ScheduledChannel)?.seriesIdAt(c.entry.show.startMs), c.entry.show.media.item.title, c.entry.channel.number, "continue") - } }) + onResume = ::resumeContinue) mainWhatsOn -> WhatsOnScreen(liveSession, scheduledChannels.filterKeys { !lockedOut(it) && !profileHides(it) }.mapValues { it.value.plan }, driveInPlan.takeIf { Profiles.current?.let { it.kind != ProfileKind.Kids || it.driveIn } ?: true }, modifier, reminders, onWatch = { tune(it, 0) }, onDriveIn = onDriveIn, onBack = onHome, diff --git a/android/app/src/main/java/tv/orbit/classic/HomeScreen.kt b/android/app/src/main/java/tv/orbit/classic/HomeScreen.kt index 53095759..2a2780b3 100644 --- a/android/app/src/main/java/tv/orbit/classic/HomeScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/HomeScreen.kt @@ -32,6 +32,9 @@ internal enum class ChannelCategory(val label: String, val icon: Int) { } /** All Channels, then only the categories that have a channel in them. */ +/** Continue watching rows on Home; the rest are in Catch Up. */ +internal const val HOME_CONTINUE_MAX = 3 + internal fun homeCategories(numbers: List): List { val used = numbers.mapNotNull { ChannelBrands.forNumber(it)?.category }.toSet() return ChannelCategory.entries.filter { it == ChannelCategory.All || it in used } @@ -68,7 +71,9 @@ internal fun HomeCard(modifier: Modifier = Modifier, focusRequester: FocusReques * Guide on that category. What's On holds the evening's highlights. */ @Composable -internal fun HomeScreen(channels: List, modifier: Modifier = Modifier, onCategory: (ChannelCategory) -> Unit) { +internal fun HomeScreen(channels: List, modifier: Modifier = Modifier, onCategory: (ChannelCategory) -> Unit, + /** Continue watching, newest first (Paul, 8 November 2026): one press back into a half-watched programme. */ + carryOn: List = emptyList(), onResume: (ContinueEntry) -> Unit = {}) { val firstFocus = remember { FocusRequester() } val nav = LocalNavFocus.current LaunchedEffect(Unit) { runCatching { firstFocus.requestFocus() } } @@ -87,6 +92,23 @@ internal fun HomeScreen(channels: List, modifier: Modifier = Modi } } } } + // Words only, no pictures, so Home stays as quick as it is. + if (carryOn.isNotEmpty()) { + Spacer(Modifier.height(14.dp)) + Text("CONTINUE WATCHING", Modifier.width(400.dp), color = Yellow, fontFamily = Anton, fontSize = 13.sp) + Spacer(Modifier.height(4.dp)) + CompositionLocalProvider(LocalGlide provides glide) { Column(Modifier.width(400.dp).glideArea(glide, Yellow, 6.dp), verticalArrangement = Arrangement.spacedBy(4.dp)) { + carryOn.take(HOME_CONTINUE_MAX).forEach { c -> + HomeCard(Modifier.fillMaxWidth().height(31.dp), onClick = { onResume(c) }) { focused -> + Row(Modifier.fillMaxSize().padding(horizontal = 16.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) { + Text(guideTitle(c.entry.channel.number, c.entry.show).first, Modifier.weight(1f), color = if (focused) OnAccent else Ink, fontSize = 14.sp, + fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = androidx.compose.ui.text.style.TextOverflow.Ellipsis) + Text(leftLabel(c.leftMs), color = if (focused) OnAccent else Muted, fontSize = 12.sp, maxLines = 1) + } + } + } + } } + } 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)) diff --git a/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt b/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt index 95d71070..f4fa0a5c 100644 --- a/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt +++ b/android/app/src/main/java/tv/orbit/classic/OrbitCompanion.kt @@ -45,7 +45,10 @@ internal class CompanionScreen( val director: () -> DeskReport? = { null }, val place: (ChairChoice, Int) -> Unit = { _, _ -> }, val drop: (ChairChoice) -> Unit = {}, - val decideIdea: (DeskEventIdea, String) -> String = { _, _ -> "" }) + val decideIdea: (DeskEventIdea, String) -> String = { _, _ -> "" }, + /** Programme reminders, the same ones the TV guide and What's On set (8 November 2026). */ + val reminders: () -> List = { emptyList() }, + val remind: (number: Int, startMs: Long, title: String, on: Boolean) -> Unit = { _, _, _, _ -> }) /** * Phase 2's queue (Paul, 6 November 2026): what plays when the programme on now ends. A channel, live from then ("switch @@ -138,18 +141,28 @@ internal object OrbitCompanion { /** Every channel's now and next. */ fun guide(screen: CompanionScreen, nowMs: Long): JSONObject = JSONObject().put("selected", screen.selected()).put("serverMs", nowMs).put("channels", JSONArray(screen.channels().map { c -> val on = c.at(nowMs) - channelJson(c).put("category", ChannelBrands.forNumber(c.number)?.category?.label ?: JSONObject.NULL).put("now", programme(on)).put("next", programme(c.at(on.endMs))) })) + channelJson(c).put("category", ChannelBrands.forNumber(c.number)?.category?.label ?: JSONObject.NULL).put("now", programme(on)).put("next", programme(c.at(on.endMs)).let { next -> + next.put("reminded", screen.reminders().any { it.channel == c.number && it.startMs == next.getLong("startMs") }) }) })) fun catchUp(screen: CompanionScreen, nowMs: Long): JSONArray = JSONArray(catchUpShelves(screen.channels(), nowMs).map { shelf -> JSONObject().put("title", shelf.title).put("entries", JSONArray(shelf.entries.map { e -> programme(e.show).put("number", e.channel.number).put("channel", e.channel.name).put("continues", e.continues) })) }) + /** A reminder from the phone, for a programme still to come on a channel this TV shows; false when there's no such programme. */ + fun remind(screen: CompanionScreen, number: Int, startMs: Long, on: Boolean, nowMs: Long): Boolean { + val c = screen.channels().firstOrNull { it.number == number } ?: return false + val show = runCatching { c.at(startMs) }.getOrNull()?.takeIf { it.startMs == startMs && it.startMs > nowMs } ?: return false + screen.remind(number, startMs, guideTitle(number, show).first, on); return true + } + /** The Catch Up programme the phone chose, only if it's still in Catch Up on a channel this TV shows. */ fun catchUpEntry(screen: CompanionScreen, number: Int, startMs: Long, nowMs: Long): CatchUpEntry? = catchUpShelves(screen.channels(), nowMs).flatMap { it.entries }.firstOrNull { it.channel.number == number && it.show.startMs == startMs } const val QUEUE_MAX = 5 + const val TIMES_DAYS = 7 + const val TIMES_FILMS = 12 /** How long before the programme's end the queue takes over. */ const val QUEUE_LEAD_MS = 2_500L var queue by mutableStateOf>(emptyList()) @@ -209,6 +222,42 @@ internal object OrbitCompanion { }) } + /** + * Orbit TV Times (Paul, 8 November 2026): the week ahead as a listings magazine, from the real schedules. Each day is + * What's On's choice for that evening (its pick and highlights), the evening's films across the channels, and the + * Drive-In's bills, only for the channels this TV shows now (Kids' own, and After Dark only while unlocked). + */ + fun times(screen: CompanionScreen, nowMs: Long, zone: java.time.ZoneId = java.time.ZoneId.systemDefault()): JSONObject { + val channels = screen.channels() + val plans = channels.mapNotNull { c -> (c as? ScheduledChannel)?.let { c.number to it.plan } }.toMap() + val names = channels.associate { it.number to ChannelBrands.displayName(it) } + fun item(channel: Int, e: ScheduleEntry, tag: String?, reason: String?) = guideTitleParts(e.media.item.title).let { (title, sub) -> + JSONObject().put("channel", channel).put("name", names[channel] ?: channel.toString()).put("title", title).put("sub", sub ?: JSONObject.NULL) + .put("startMs", e.startMs).put("endMs", e.endMs).put("type", e.media.item.type) + .put("tag", tag ?: JSONObject.NULL).put("reason", reason ?: JSONObject.NULL) + } + val first = whatsOnEdition(nowMs, zone) + val days = JSONArray() + for (d in 0 until TIMES_DAYS) { + val date = first.plusDays(d.toLong()) + val noon = maxOf(nowMs, date.atTime(12, 0).atZone(zone).toInstant().toEpochMilli()) + val evening = date.atTime(18, 0).atZone(zone).toInstant().toEpochMilli(); val night = date.plusDays(1).atTime(0, 0).atZone(zone).toInstant().toEpochMilli() + val end = date.plusDays(1).atTime(6, 0).atZone(zone).toInstant().toEpochMilli() + val page = whatsOnPage(plans, null, noon, zone) + val films = plans.flatMap { (n, plan) -> plan.entries.filter { it.media.item.type == "Movie" && it.startMs in evening until night && !kidsAsleep(takeoverOf(n, it, zone)) }.map { n to it } } + .sortedBy { it.second.startMs }.distinctBy { it.second.media.item.id }.take(TIMES_FILMS) + val bills = screen.driveIn().filter { it.startMs in noon until end } + if (page.pick == null && page.tonight.isEmpty() && films.isEmpty() && bills.isEmpty()) continue + days.put(JSONObject().put("date", date.toString()).put("noonMs", noon) + .put("pick", page.pick?.let { item(it.channel, it.entry, it.tag, it.reason) } ?: JSONObject.NULL) + .put("highlights", JSONArray(page.tonight.map { item(it.channel, it.entry, it.tag, it.reason) })) + .put("films", JSONArray(films.map { (n, e) -> item(n, e, null, null) })) + .put("drivein", JSONArray(bills.map { b -> JSONObject().put("kind", b.kind.label).put("event", b.event ?: JSONObject.NULL).put("startMs", b.startMs).put("endMs", b.endMs) + .put("films", JSONArray(b.entries.map { guideTitleParts(it.media.item.title).first })) }))) + } + return JSONObject().put("generatedMs", nowMs).put("room", Rooms.name).put("days", days) + } + // --- Phase 3: Director approvals and profiles. --- private fun choiceJson(c: ChairChoice) = JSONObject().put("id", c.id).put("title", c.title).put("type", c.type).put("year", c.year ?: JSONObject.NULL) .put("line", c.line).put("ask", c.ask).put("options", JSONArray(c.options.map { JSONObject().put("number", it.number).put("name", it.name).put("reason", it.reason) })) diff --git a/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt b/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt index b3a1a5a5..41c54de1 100644 --- a/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt +++ b/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt @@ -241,6 +241,7 @@ internal object PhoneLink { phone == null -> page(out, PhonePages.join(null)) r.path == "/" -> page(out, PhonePages.companion()) r.path == "/create" -> page(out, PhonePages.app()) + r.path == "/times" -> page(out, PhonePages.times()) r.method == "POST" && r.headers["x-orbit"] != "1" -> json(out, 403, JSONObject().put("error", "Refused")) else -> api(r, out, phone) } @@ -479,7 +480,7 @@ internal object PhoneLink { } private val companionRoutes = setOf("GET /api/now", "GET /api/guide", "GET /api/catchup", "GET /api/rooms", "GET /api/looks", "POST /api/key", "POST /api/volume", - "POST /api/channel", "POST /api/tune", "POST /api/section", "POST /api/catchup/watch", + "POST /api/channel", "POST /api/tune", "POST /api/remind", "GET /api/times", "POST /api/section", "POST /api/catchup/watch", "GET /api/queue", "POST /api/queue", "POST /api/queue/remove", "GET /api/drivein", "POST /api/drivein/ticket", "POST /api/drivein/watch", "GET /api/director", "POST /api/director/place", "POST /api/director/drop", "POST /api/director/idea", "GET /api/profiles", "POST /api/profile", "POST /api/profile/add", "POST /api/profile/rename", "POST /api/profile/remove") @@ -516,6 +517,13 @@ internal object PhoneLink { val number = body().optInt("number").takeIf { n -> s.channels().any { it.number == n } } ?: return json(out, 404, JSONObject().put("error", "That channel isn't on this TV right now.")) onScreen { s.tune(number, 0) }; json(out, 200, JSONObject().put("number", number)) } + "GET /api/times" -> json(out, 200, OrbitCompanion.times(s, now)) + "POST /api/remind" -> { + val o = body(); var done = false + onScreen { done = OrbitCompanion.remind(s, o.optInt("number"), o.optLong("startMs"), o.optBoolean("on", true), now) } + if (!done) return json(out, 404, JSONObject().put("error", "That programme isn't coming up on this TV.")) + json(out, 200, JSONObject().put("ok", true)) + } "POST /api/section" -> { val section = OrbitCompanion.sections[body().optString("section")] ?: return json(out, 400, JSONObject().put("error", "Unknown place")) onScreen { OrbitCompanion.open(section) }; json(out, 200, JSONObject().put("ok", true)) diff --git a/android/app/src/main/java/tv/orbit/classic/PhonePages.kt b/android/app/src/main/java/tv/orbit/classic/PhonePages.kt index d7c657bd..f2f42cec 100644 --- a/android/app/src/main/java/tv/orbit/classic/PhonePages.kt +++ b/android/app/src/main/java/tv/orbit/classic/PhonePages.kt @@ -21,6 +21,7 @@ background:#ffde59;color:#071632;font-size:18px;font-weight:700}.note{color:#ffd fun app(): String = asset("app.html") /** The Companion, at /: Remote, Guide, Catch Up, Rooms and More (which leads to Create your own). */ fun companion(): String = asset("companion.html") + fun times(): String = asset("times.html") /** For "Add to home screen": Orbit's icon and name, opening on the remote. */ val icons = setOf("/icon-180.png", "/icon-192.png", "/icon-512.png") fun icon(path: String): ByteArray? = runCatching { PhoneLink.context()?.assets?.open("phone" + path)?.use { it.readBytes() } }.getOrNull() diff --git a/android/app/src/main/java/tv/orbit/classic/Rooms.kt b/android/app/src/main/java/tv/orbit/classic/Rooms.kt index 7484c760..ed157e03 100644 --- a/android/app/src/main/java/tv/orbit/classic/Rooms.kt +++ b/android/app/src/main/java/tv/orbit/classic/Rooms.kt @@ -69,7 +69,7 @@ internal enum class RoomPart(val title: String, val line: String) { } /** On screen and Arcade settings that may travel; the sound output and anything about this box stay where they are. */ -private val LookKeys = listOf("look", "subtitles_on", "channel_logo", "idents", "ident_sound", "special_idents", "block_ident_sound", "squeeze_back", +private val LookKeys = listOf("look", "subtitles_on", "channel_logo", "idents", "ident_sound", "special_idents", "block_ident_sound", "squeeze_back", "up_next", "cast_on", "drive_in_intro", "reduce_motion") private val ArcadeKeys = listOf("snake_best", "block_drop_best", "brick_break_best", "pairs_best", "patience_wins", "orb_man_best", "blast_best", "skydoku_solved", "snake_music") private val DirectorFiles = listOf("director-decisions-0.json", "director-learning-0.json", "event-ideas-history-0.json") diff --git a/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt b/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt index e1b4cd5b..b637047a 100644 --- a/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt +++ b/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt @@ -71,6 +71,7 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC val squeezeOn = remember { OrbitSettings(settingsContext).squeezeBack } val cameosOn = remember { OrbitSettings(settingsContext).let { it.characterCameos && it.castOn } } val calmMotion = remember { OrbitSettings(settingsContext).reduceMotion } + val upNextOn = remember { OrbitSettings(settingsContext).upNext } val squeezing = squeezeOn && channel is ScheduledChannel && squeezeBackDue(channel.number, current.startMs, current.endMs, next.startMs, now, if (identsHere) identMs else 0L, clockOffsetMs, squeezeLength(current.media.item.type)) val squeeze by androidx.compose.animation.core.animateFloatAsState(if (squeezing) 1f else 0f, if (calmMotion) androidx.compose.animation.core.snap() else androidx.compose.animation.core.tween(1_000), label = "squeeze") @@ -218,6 +219,8 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC } } if (plan != null && squeeze > 0f) SqueezePanel(session, channel, current, next, now, squeeze) + if (plan != null && upNextOn && squeeze == 0f && phase == IdentPhase.None && channel is ScheduledChannel && clockOffsetMs == 0L && next.startMs == current.endMs) + UpNextBanner(channel, current, next, now) heldIdent?.let { held -> key(held.startMs) { val early = endedEarly == held.startMs diff --git a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt index 46098f1b..2a553008 100644 --- a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt +++ b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt @@ -39,7 +39,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.108.109") + next.setRequestProperty("User-Agent", "OrbitTV/0.110.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()) { diff --git a/android/app/src/main/java/tv/orbit/classic/Settings.kt b/android/app/src/main/java/tv/orbit/classic/Settings.kt index a3e262d1..bebe3575 100644 --- a/android/app/src/main/java/tv/orbit/classic/Settings.kt +++ b/android/app/src/main/java/tv/orbit/classic/Settings.kt @@ -102,6 +102,10 @@ internal class OrbitSettings(context: Context) { var identSoundNightQuiet: Boolean get() = saved.getBoolean("ident_sound_night_quiet", true) set(value) { saved.edit().putBoolean("ident_sound_night_quiet", value).apply() } + /** A small "Coming up next" card near the end of each programme (Paul, 8 November 2026). On by default. */ + var upNext: Boolean + get() = saved.getBoolean("up_next", true) + set(value) { saved.edit().putBoolean("up_next", value).apply() } var driveInIntro: Boolean get() = saved.getBoolean("drive_in_intro", true) set(value) { saved.edit().putBoolean("drive_in_intro", value).apply() } @@ -270,6 +274,7 @@ private fun ViewingDetail(firstSwitch: FocusRequester, modifier: Modifier, top: var identSound by remember { mutableStateOf(settings.identSound) } var identSoundQuiet by remember { mutableStateOf(settings.identSoundQuiet) } var identSoundNightQuiet by remember { mutableStateOf(settings.identSoundNightQuiet) } + var upNext by remember { mutableStateOf(settings.upNext) } var driveInIntro by remember { mutableStateOf(settings.driveInIntro) } var reduceMotion by remember { mutableStateOf(settings.reduceMotion) } var squeezeBack by remember { mutableStateOf(settings.squeezeBack) } @@ -300,6 +305,9 @@ private fun ViewingDetail(firstSwitch: FocusRequester, modifier: Modifier, top: SettingLine("Quieter late at night", "From 11pm to 7am, ident sounds play softly on their own, so nobody's woken.") { OnOff(identSoundNightQuiet, Modifier, enabled = identSound && !identSoundQuiet, onClick = { identSoundNightQuiet = !identSoundNightQuiet; settings.identSoundNightQuiet = identSoundNightQuiet }) } + SettingLine("Coming up next", "Near the end of a programme, a small card in the corner says what's on next.") { + OnOff(upNext, Modifier, onClick = { upNext = !upNext; settings.upNext = upNext }) + } SettingLine("Special idents", "Give named blocks and events their own ident as they begin, such as Riot Laughs or PPV Sunday. Off uses each channel's usual ident.") { OnOff(specialIdents, Modifier, onClick = { specialIdents = !specialIdents; settings.specialIdents = specialIdents }) } diff --git a/android/app/src/main/java/tv/orbit/classic/UpNext.kt b/android/app/src/main/java/tv/orbit/classic/UpNext.kt new file mode 100644 index 00000000..78839039 --- /dev/null +++ b/android/app/src/main/java/tv/orbit/classic/UpNext.kt @@ -0,0 +1,54 @@ +package tv.orbit.classic + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableLongStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +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 + +/** + * Coming up next (Paul, 8 November 2026): near the end of a programme, a small card in the corner names what's on next, as + * a channel would, for [UP_NEXT_SHOW_MS] and once per programme. It comes in the last few minutes, before the squeeze-back + * and the ident, so they never overlap. + */ +internal const val UP_NEXT_FROM_MS = 3 * 60_000L +internal const val UP_NEXT_UNTIL_MS = 75_000L +internal const val UP_NEXT_SHOW_MS = 10_000L + +/** Whether the card may start now, with [remainingMs] of the programme left. */ +internal fun upNextMayStart(remainingMs: Long) = remainingMs in (UP_NEXT_UNTIL_MS + 1)..UP_NEXT_FROM_MS + +/** The words on the card: "in 3 min", or "next" in the final minute or so. */ +internal fun upNextWhen(remainingMs: Long): String = ((remainingMs + 59_999) / 60_000).let { m -> if (m <= 1) "in a minute" else "in $m min" } + +@Composable +internal fun UpNextBanner(channel: SampleChannel, current: SampleBroadcast, next: SampleBroadcast, now: Long, modifier: Modifier = Modifier) { + // Kids never sees what a grown-up takeover will show, and nothing is named when the channel goes to sleep. + if (kidsAsleep(takeoverOf(channel.number, next))) return + var until by remember(current.startMs) { mutableLongStateOf(0L) } + val remaining = current.endMs - now + LaunchedEffect(current.startMs, upNextMayStart(remaining)) { if (until == 0L && upNextMayStart(remaining)) until = now + UP_NEXT_SHOW_MS } + if (until == 0L || now >= until) return + val (title, detail) = guideTitle(channel.number, next) + val corner = RoundedCornerShape(10.dp) + Box(Modifier.fillMaxSize().padding(36.dp), contentAlignment = Alignment.BottomEnd) { + Column(modifier.riseIn(0).widthIn(max = 460.dp).background(Navy.copy(alpha = .94f), corner).border(2.dp, Yellow, corner).padding(horizontal = 18.dp, vertical = 12.dp), + verticalArrangement = Arrangement.spacedBy(3.dp)) { + Text("COMING UP NEXT • ${upNextWhen(remaining).uppercase()}", color = Yellow, fontFamily = Anton, fontSize = 14.sp) + Text(title, color = Ink, fontSize = 20.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis) + Text(listOfNotNull(detail, "${channel.number} ${ChannelBrands.displayName(channel)}").joinToString(" • "), color = Muted, fontSize = 13.sp, maxLines = 1, overflow = TextOverflow.Ellipsis) + } + } +} diff --git a/android/app/src/test/java/tv/orbit/classic/PhoneLinkTest.kt b/android/app/src/test/java/tv/orbit/classic/PhoneLinkTest.kt index 276d9a46..87c902c0 100644 --- a/android/app/src/test/java/tv/orbit/classic/PhoneLinkTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/PhoneLinkTest.kt @@ -145,7 +145,9 @@ class PhoneLinkTest { val pressed = mutableListOf(); val volume = mutableListOf() OrbitCompanion.inject = { synchronized(pressed) { pressed += it } }; OrbitCompanion.volume = { volume += it } PhoneLink.clock = { now } - PhoneLink.screen = CompanionScreen({ companionChannels }, { selected }, { true }, { 0 }, { n, o -> tuned += n to o; selected = n }) + val reminders = mutableListOf() + PhoneLink.screen = CompanionScreen({ companionChannels }, { selected }, { true }, { 0 }, { n, o -> tuned += n to o; selected = n }, + reminders = { reminders.toList() }, remind = { n, start, title, on -> reminders.removeAll { it.channel == n && it.startMs == start }; if (on) reminders += ProgrammeReminder(n, start, title) }) try { assertTrue(call("/api/now").body.contains("Enter the code")) // not joined: nothing // The home-screen manifest needs no phone, and carries Orbit's name only. @@ -191,6 +193,19 @@ class PhoneLinkTest { assertEquals(0, JSONObject(call("/api/drivein", cookie = cookie).body).getJSONArray("bills").length()) assertEquals(404, call("/api/drivein/ticket", "POST", """{"startMs":1}""", cookie = cookie).status) assertEquals(409, call("/api/drivein/watch", "POST", "{}", cookie = cookie).status) + // Reminders from the phone (8 November 2026): only for a programme still to come on a channel this TV shows. + val next = JSONObject(call("/api/guide", cookie = cookie).body).getJSONArray("channels").getJSONObject(0).getJSONObject("next") + assertFalse(next.getBoolean("reminded")) + assertEquals(200, call("/api/remind", "POST", """{"number":101,"startMs":${next.getLong("startMs")},"on":true}""", cookie = cookie).status) + assertEquals(listOf(101 to "Friends"), reminders.map { it.channel to it.title }) + assertTrue(JSONObject(call("/api/guide", cookie = cookie).body).getJSONArray("channels").getJSONObject(0).getJSONObject("next").getBoolean("reminded")) + assertEquals(404, call("/api/remind", "POST", """{"number":999,"startMs":${next.getLong("startMs")}}""", cookie = cookie).status) + assertEquals(404, call("/api/remind", "POST", """{"number":101,"startMs":${next.getLong("startMs") + 1}}""", cookie = cookie).status) + assertEquals(200, call("/api/remind", "POST", """{"number":101,"startMs":${next.getLong("startMs")},"on":false}""", cookie = cookie).status) + assertTrue(reminders.isEmpty()) + // Orbit TV Times: the page and its listings, for a joined phone. + assertTrue(call("/times", cookie = cookie).status == 200) + assertTrue(JSONObject(call("/api/times", cookie = cookie).body).has("days")) // Titles and times only. val everything = call("/api/now", cookie = cookie).body + call("/api/guide", cookie = cookie).body + call("/api/rooms", cookie = cookie).body listOf("token", "api_key", "password", "X-Emby", "MediaBrowser", "s-a1", "a1").forEach { assertFalse(it, everything.contains("\"$it\"", ignoreCase = true)) } diff --git a/android/app/src/test/java/tv/orbit/classic/UpNextAndTimesTest.kt b/android/app/src/test/java/tv/orbit/classic/UpNextAndTimesTest.kt new file mode 100644 index 00000000..24a6c977 --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/UpNextAndTimesTest.kt @@ -0,0 +1,34 @@ +package tv.orbit.classic + +import org.junit.Assert.* +import org.junit.Test +import java.time.ZoneId +import java.time.ZonedDateTime + +/** 8 November 2026: the Coming up next card's timing, and Orbit TV Times built from real plans. */ +class UpNextAndTimesTest { + private val minute = 60_000L + @Test fun comingUpNextShowsBetweenThreeMinutesAndTheSqueeze() { + assertFalse(upNextMayStart(3 * minute + 1)); assertTrue(upNextMayStart(3 * minute)); assertTrue(upNextMayStart(76_000)) + assertFalse(upNextMayStart(75_000)); assertFalse(upNextMayStart(10_000)) + assertEquals("in 3 min", upNextWhen(3 * minute)); assertEquals("in 2 min", upNextWhen(90_000)); assertEquals("in a minute", upNextWhen(50_000)) + } + + @Test fun tvTimesListsEachEveningsFilmsAndPicksFromThePlans() { + val zone = ZoneId.of("Europe/London") + val day = ZonedDateTime.of(2026, 11, 9, 13, 0, 0, 0, zone).toInstant().toEpochMilli() + val eight = ZonedDateTime.of(2026, 11, 9, 20, 0, 0, 0, zone).toInstant().toEpochMilli() + fun film(id: String, title: String, at: Long) = ScheduleEntry("", EpisodeMark(0, 0), ScheduledMedia(SampleItem(title, "Movie", 100, "", id, 100 * minute), "s-$id", 100 * minute), at) + val plan = ChannelPlan(listOf(film("f1", "Hot Fuzz", eight), film("f2", "Paul", eight + 100 * minute)), ScheduleCursor()) + val channel = ScheduledChannel(SampleChannel(plan.entries.map { it.media }, "BritX", 309), plan) + val screen = CompanionScreen({ listOf(channel) }, { 309 }, { false }, { 0 }, { _, _ -> }) + val times = OrbitCompanion.times(screen, day, zone) + val first = times.getJSONArray("days").getJSONObject(0) + assertEquals("2026-11-09", first.getString("date")) + val films = first.getJSONArray("films") + assertEquals(listOf("Hot Fuzz", "Paul"), (0 until films.length()).map { films.getJSONObject(it).getString("title") }) + assertEquals(309, films.getJSONObject(0).getInt("channel")) + // Ids and sources never go to the phone. + assertFalse(times.toString().contains("s-f1")); assertFalse(times.toString().contains("\"f1\"")) + } +} diff --git a/design/times/masthead-preview.png b/design/times/masthead-preview.png new file mode 100644 index 00000000..aa307688 Binary files /dev/null and b/design/times/masthead-preview.png differ diff --git a/design/times/masthead.svg b/design/times/masthead.svg new file mode 100644 index 00000000..1f3e0c9a --- /dev/null +++ b/design/times/masthead.svg @@ -0,0 +1,15 @@ + + + + + + + + + + ORBIT + TV Times + THE WEEK'S PROGRAMMES · EVERY CHANNEL + FREE WITH YOUR ORBIT + PICKS · FILMS · DRIVE-IN +