From 2ce22fe2e9f8704a87424c187fca44874515c776 Mon Sep 17 00:00:00 2001 From: Pauljd Date: Sat, 7 Nov 2026 13:24:06 +0000 Subject: [PATCH] Your channels: remove from the phone, and take turns in a mixed order Each channel of your own gets an x on the phone's More page, asked first; the TV sets its files aside so a new channel on that number starts clean. Shows and films on your own channels take turns in a fixed mixed order rather than the order chosen (Mistletoe played its collection A to Z). 0.108.89. Co-Authored-By: Claude Opus 5.5 (1M context) --- android/app/build.gradle.kts | 4 ++-- android/app/src/main/assets/phone/companion.html | 12 ++++++++++-- .../main/java/tv/orbit/classic/ChannelSchedule.kt | 8 ++++++++ .../main/java/tv/orbit/classic/ChannelScheduler.kt | 2 +- .../main/java/tv/orbit/classic/CreateChannel.kt | 4 +++- .../main/java/tv/orbit/classic/CustomChannels.kt | 2 +- .../src/main/java/tv/orbit/classic/EmbyClient.kt | 4 ++-- .../java/tv/orbit/classic/EmbyConnectionScreen.kt | 13 +++++++++++++ .../src/main/java/tv/orbit/classic/PhoneLink.kt | 7 +++++++ .../main/java/tv/orbit/classic/ScheduleStore.kt | 9 +++++++++ .../java/tv/orbit/classic/SecureMediaDataSource.kt | 2 +- .../test/java/tv/orbit/classic/SmartSetupTest.kt | 14 ++++++++++++++ 12 files changed, 71 insertions(+), 10 deletions(-) diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index a9b2fe99..3a71908a 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 = 248 - versionName = "0.108.88-big-collections" + versionCode = 249 + versionName = "0.108.89-remove-mixed" } 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 d8c5aec9..1588028e 100644 --- a/android/app/src/main/assets/phone/companion.html +++ b/android/app/src/main/assets/phone/companion.html @@ -252,9 +252,10 @@ function more() { h += ``; h += `
Your channels
-
${(yours?.channels || []).map(c => ``).join('')} +
${esc((c.styleTitle || '').replace(' by the Director', ''))} · ${c.on ? 'on' : 'off'}
Edit
+
`).join('')} ${!yours || yours.next ? `` : ''}`; const line = (label, value, attr, first) => ``; h += `
Settings
@@ -727,6 +728,13 @@ document.addEventListener('click', e => { if (d.kmake) { makeChannel(d.kmake); return; } if (d.kbrand !== undefined) { const c = state.create; c.draft.name = ($('#kname')?.value || c.draft.name || '').trim(); c.draft.brand = d.kbrand; render(); return; } if (d.create) { startCreate({name: '', description: '', style: 'Shaped', hours: null, shows: [], skipped: []}); return; } + // Remove a channel of your own (Paul, 7 November 2026: "a little x to remove ones"), always asked first. + if (d.kremove) { const ch = state.channels?.channels.find(x => x.number === +d.kremove); if (!ch) return; + openSheet(`
Remove ${esc(ch.name)}?
${ch.number} leaves the guide on ${esc(room())}, with everything it had planned. Your library isn't touched, and you can make it again any time.
+ `); return; } + if (d.kremoveno) { closeSheet(); return; } + if (d.kremoveyes) { const n = +d.kremoveyes; closeSheet(); + api('/api/channels/remove', {number: n}).then(r => { toast(r.message || 'Removed'); load('more'); }).catch(e => toast(e.message)); return; } if (d.edit) { const ch = state.channels?.channels.find(x => x.number === +d.edit); if (!ch) return; api('/api/shows?number=' + ch.number).then(shows => { // A shaped channel keeps its layout by title; the phone works by item. diff --git a/android/app/src/main/java/tv/orbit/classic/ChannelSchedule.kt b/android/app/src/main/java/tv/orbit/classic/ChannelSchedule.kt index dcbcb371..3de31a5c 100644 --- a/android/app/src/main/java/tv/orbit/classic/ChannelSchedule.kt +++ b/android/app/src/main/java/tv/orbit/classic/ChannelSchedule.kt @@ -51,6 +51,11 @@ internal data class ChannelProgramming(val number: Int, val name: String, val se val shuffleEpisodes: Boolean = false, /** Shows played in a mixed order on a channel that otherwise runs in season order, such as Paradox's standalone adventures. */ val shuffleTitles: Set = emptySet(), + /** + * Shows and films take their turns in a fixed mixed order rather than the order they were chosen in. On for channels of + * your own (Paul, 7 November 2026: Mistletoe played the Hallmark Christmas collection A to Z). + */ + val mixedTurns: Boolean = false, /** Films a series channel may carry, each only in an event that names it. Empty everywhere but Ring X. */ val channelFilms: List = emptyList(), /** Series a film channel may carry, each only in an event that names it, one whole episode a night in order. Empty everywhere but After Dark. */ @@ -379,6 +384,9 @@ internal fun dayPartFor(pool: List, parts: List, startMs: L /** A few names and how many more, so a reason stays short. */ private fun someOf(names: List) = names.take(3).joinToString(", ") + if (names.size > 3) " +${names.size - 3}" else "" +/** The pool in a mixed order that stays the same from one top-up to the next, so every title still gets its turn. */ +internal fun mixedTurnOrder(pool: List, seed: Int): List = pool.sortedBy { it.id }.shuffled(java.util.Random(seed.toLong())) + internal fun turnOrder(pool: List, last: String?): List { val after = pool.indexOfFirst { it.id == last } + 1 return (0 until pool.size).map { pool[(after + it) % pool.size] } diff --git a/android/app/src/main/java/tv/orbit/classic/ChannelScheduler.kt b/android/app/src/main/java/tv/orbit/classic/ChannelScheduler.kt index cbda71aa..9fddac2b 100644 --- a/android/app/src/main/java/tv/orbit/classic/ChannelScheduler.kt +++ b/android/app/src/main/java/tv/orbit/classic/ChannelScheduler.kt @@ -314,7 +314,7 @@ internal class ChannelScheduler(private val store: ScheduleStore, clashesWithAirings((SmartChannels.map { it.number }.filter { it != number } + DRIVE_IN_NUMBER).flatMap { airingsOn(userId, it) }) .also { othersMs = android.os.SystemClock.elapsedRealtime() - began } } - val plan = topUpPlan(existing, base, pool?.series?.let { withoutFailed(it, store.loadFailed(userId)) }, now, programming.filmRestMs, programming.finishTogether, programming.dayParts, + val plan = topUpPlan(existing, base, pool?.series?.let { withoutFailed(it, store.loadFailed(userId)) }?.let { if (programming.mixedTurns) mixedTurnOrder(it, number) else it }, now, programming.filmRestMs, programming.finishTogether, programming.dayParts, avoid = { show, startMs, endMs -> others(show, startMs, endMs) }, shuffle = programming.shuffleEpisodes, mixed = programming::mixes, weightOf = programming.tierWeights?.let { programming::weightOf }, adaptiveRest = programming.adaptiveFilmRest, fileRestMs = programming.fileRestMs, stories = programming.storyGrouping, shorts = programming.shorts, marathon = programming.marathon, seasonEndMs = seasonEndMs(number, now)) ?: throw EmbyCheckException("${programming.name} has no episodes to schedule.") diff --git a/android/app/src/main/java/tv/orbit/classic/CreateChannel.kt b/android/app/src/main/java/tv/orbit/classic/CreateChannel.kt index 31d4aecd..fd52ddbd 100644 --- a/android/app/src/main/java/tv/orbit/classic/CreateChannel.kt +++ b/android/app/src/main/java/tv/orbit/classic/CreateChannel.kt @@ -58,7 +58,9 @@ internal class ChannelMaker( /** Titles by item from the catalogue alone, quickly, for listing a collection. */ val rowsOf: suspend (List) -> List = { emptyList() }, /** Networks and studios by name, with their title counts. */ - val studios: suspend (String) -> List> = { emptyList() }) + val studios: suspend (String) -> List> = { emptyList() }, + /** Removes a channel of your own from every guide on this TV; what it says back. */ + val remove: suspend (Int) -> String = { "That channel can't be removed here." }) /** One of the library's collections as Orbit read it. [complete] is false when it stopped short of [total]. */ internal class LibraryCollection(val name: String, val members: List, val total: Int, val complete: Boolean) diff --git a/android/app/src/main/java/tv/orbit/classic/CustomChannels.kt b/android/app/src/main/java/tv/orbit/classic/CustomChannels.kt index 8c170c4d..02592ad1 100644 --- a/android/app/src/main/java/tv/orbit/classic/CustomChannels.kt +++ b/android/app/src/main/java/tv/orbit/classic/CustomChannels.kt @@ -108,7 +108,7 @@ internal object CustomChannels { internal fun programmingOf(channel: CustomChannel): ChannelProgramming = ChannelProgramming( channel.number, channel.name, emptyList(), seriesCount = 60, finishTogether = channel.style == PlayStyle.Standard || channel.style == PlayStyle.Blocks || channel.style == PlayStyle.Shaped, - exactTitles = true, shuffleEpisodes = channel.style == PlayStyle.Shuffled, + exactTitles = true, shuffleEpisodes = channel.style == PlayStyle.Shuffled, mixedTurns = true, dayParts = when (channel.style) { PlayStyle.Blocks -> timetableParts(channel.shows); PlayStyle.Shaped -> shapedParts(channel.slots); else -> emptyList() }, storyGrouping = channel.style == PlayStyle.Standard || channel.style == PlayStyle.Shaped, shorts = if (channel.style == PlayStyle.Standard || channel.style == PlayStyle.Shaped) YoursShorts else null, 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 fd6de87f..0516de8e 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.88\"") + + ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.89\"") + (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.88\"" + + ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.89\"" + (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 81ffa6dd..d1a984e3 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -570,6 +570,19 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea android.util.Log.i("OrbitSchedule", "yours channel=${channel.number} style=${channel.style} titles=${shows.size}") SmartChannels.firstOrNull { it.number == channel.number }?.let { setSmartSchedule(it, true) } "${channel.name} is ready on ${channel.number}. Its first programmes are being planned now." + }, + remove = { number -> + val gone = CustomChannels.of(number) ?: return@ChannelMaker "That channel has already gone." + withContext(Dispatchers.IO) { + scheduler.setEnabled(active.accountId, number, false) + CustomChannels.remove(workspace.scheduleDir, number) + scheduleStore.setAside(number) + } + scheduledChannels = scheduledChannels - number + extraChannels = extraChannels.filter { it.number != number } + if (selectedNumber == number) { selectedNumber = lastNumber.takeIf { it != number } ?: 101; channelClockOffset = 0 } + android.util.Log.i("OrbitSchedule", "yours removed channel=$number") + "${gone.name} has been removed from $number." }) } } // The phone page (Create your own from a phone) asks the same of this screen as Settings does, and can tune the TV. DisposableEffect(channelMaker) { 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 2b20de5c..66473a2d 100644 --- a/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt +++ b/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt @@ -386,6 +386,13 @@ internal object PhoneLink { val said = runBlocking { withContext(mainDispatcher) { h.maker.create(laidOut, shows) } } json(out, 200, JSONObject().put("message", said).put("number", number)) } + "POST /api/channels/remove" -> { + if (!OrbitCompanion.grownUp) return json(out, 403, JSONObject().put("error", "Kids is watching. Switch to Adult to remove channels.")) + val number = runCatching { JSONObject(r.body).getInt("number") }.getOrNull()?.takeIf { n -> CustomChannels.list.any { it.number == n } } + ?: return json(out, 404, JSONObject().put("error", "That channel has already gone.")) + val said = runBlocking { withContext(mainDispatcher) { h.maker.remove(number) } } + json(out, 200, JSONObject().put("message", said)) + } "POST /api/watch" -> { val number = runCatching { JSONObject(r.body).getInt("number") }.getOrNull() ?: return json(out, 400, JSONObject()) runBlocking { withContext(mainDispatcher) { h.watch(number) } } diff --git a/android/app/src/main/java/tv/orbit/classic/ScheduleStore.kt b/android/app/src/main/java/tv/orbit/classic/ScheduleStore.kt index 56e7eba5..fbdab331 100644 --- a/android/app/src/main/java/tv/orbit/classic/ScheduleStore.kt +++ b/android/app/src/main/java/tv/orbit/classic/ScheduleStore.kt @@ -235,6 +235,15 @@ internal class ScheduleStore(private val directory: File) { /** Only when you ask for the guide to change now. The saved place and your choices stay. */ fun deletePlan(number: Int) { listOf("schedule-$number.json", "schedule-$number.json.prev").forEach { File(directory, it).delete() } } + /** + * A channel of your own removed (Paul, 7 November 2026): its files are set aside with ".removed", so a new channel given + * the same number starts clean and nothing of the old one comes back, while a removal by mistake can still be undone by hand. + */ + fun setAside(number: Int) { + listOf("episodes", "schedule", "progress", "choices").flatMap { listOf("$it-$number.json", "$it-$number.json.prev") } + .map { File(directory, it) }.filter { it.exists() }.forEach { it.renameTo(File(directory, it.name + ".removed")) } + } + /** Bytes held for a channel, for the measurements. */ fun sizes(number: Int) = listOf("episodes", "schedule", "progress", "choices").associateWith { file(it, number).length() } 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 f660e258..811c1c45 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.88") + next.setRequestProperty("User-Agent", "OrbitTV/0.108.89") 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/test/java/tv/orbit/classic/SmartSetupTest.kt b/android/app/src/test/java/tv/orbit/classic/SmartSetupTest.kt index 11db7ae7..a42ab9ac 100644 --- a/android/app/src/test/java/tv/orbit/classic/SmartSetupTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/SmartSetupTest.kt @@ -94,4 +94,18 @@ class SmartSetupTest { assertNull(CustomChannel.fromJson(JSONObject(c.toJson().put("brand", "not-a-pack").toString())).brand) // only Orbit's own packs CustomChannels.clear() } + + // Mistletoe played the Hallmark Christmas collection A to Z (Paul, 7 November 2026): your own channels take turns in a + // mixed order, the same at every top-up, and every title still gets its turn. + @Test fun ownChannelsTakeTurnsInAMixedOrder() { + val films = (1..40).map { k -> PoolSeries("$k", "Film $k", listOf(PoolEpisode("$k", "s$k", EpisodeMark(1, 1), "Film $k", 90 * 60_000L))) } + val mixed = mixedTurnOrder(films, 701) + assertEquals(mixed, mixedTurnOrder(films.reversed(), 701)) + assertEquals(films.toSet(), mixed.toSet()) + assertNotEquals(films, mixed) + assertTrue(programmingOf(CustomChannel(701, "Mistletoe", PlayStyle.Shaped, null, "", films.map { it.title })).mixedTurns) + val plan = extendSchedule(mixed, ScheduleCursor(), 0L, 40 * 90 * 60_000L, finishTogether = true) + assertEquals(40, plan.entries.map { it.seriesId }.toSet().size) + assertNotEquals(films.map { it.id }, plan.entries.map { it.seriesId }) + } }