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) <noreply@anthropic.com>
This commit is contained in:
2026-11-07 13:24:06 +00:00
co-authored by Claude Opus 5.5
parent 1bc38e7c86
commit 2ce22fe2e9
12 changed files with 71 additions and 10 deletions
+2 -2
View File
@@ -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
@@ -252,9 +252,10 @@ function more() {
h += `<button class="ch" data-director="1" style="margin-top:16px;background:var(--raised)"><div class="grow"><div class="what">Director's Chair</div><div class="then">${waiting ? 'Ideas and titles waiting for you' : 'Suggestions for your channels'}</div></div>
${waiting ? `<span style="min-width:28px;height:28px;border-radius:14px;background:var(--accent);color:var(--on-accent);font-weight:800;display:flex;align-items:center;justify-content:center">${waiting}</span>` : ''}</button>`;
h += `<div style="display:flex;justify-content:space-between;align-items:baseline"><div class="label">Your channels</div></div>
<div style="display:flex;gap:10px;overflow-x:auto;padding-bottom:4px;scrollbar-width:none">${(yours?.channels || []).map(c => `<button data-edit="${c.number}" style="flex:0 0 140px;text-align:left;background:var(--surface);border-radius:16px;padding:14px">
<div style="display:flex;gap:10px;overflow-x:auto;padding-bottom:4px;scrollbar-width:none">${(yours?.channels || []).map(c => `<div style="flex:0 0 140px;position:relative"><button data-edit="${c.number}" style="width:100%;height:100%;text-align:left;background:var(--surface);border-radius:16px;padding:14px">
<div style="color:var(--accent);font-weight:800;font-size:18px">${c.number}</div><div style="font-weight:700;margin-top:6px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">${esc(c.name)}</div>
<div class="small">${esc((c.styleTitle || '').replace(' by the Director', ''))} · ${c.on ? 'on' : 'off'}</div><div class="small" style="color:var(--accent);font-weight:700;margin-top:8px">Edit</div></button>`).join('')}
<div class="small">${esc((c.styleTitle || '').replace(' by the Director', ''))} · ${c.on ? 'on' : 'off'}</div><div class="small" style="color:var(--accent);font-weight:700;margin-top:8px">Edit</div></button>
<button data-kremove="${c.number}" aria-label="Remove ${esc(c.name)}" style="position:absolute;top:6px;right:6px;width:32px;height:32px;border-radius:16px;display:flex;align-items:center;justify-content:center;color:var(--muted);font-size:18px">×</button></div>`).join('')}
${!yours || yours.next ? `<button data-create="1" aria-label="Create a channel" style="flex:0 0 ${yours?.channels?.length ? '64px' : '100%'};border:2px dashed var(--accent);border-radius:16px;color:var(--accent);font-size:${yours?.channels?.length ? '28px' : '16px'};font-weight:700;padding:14px">${yours?.channels?.length ? '+' : '+ Create a channel'}</button>` : ''}</div>`;
const line = (label, value, attr, first) => `<button ${attr} style="display:flex;width:100%;align-items:center;padding:15px 16px;${first ? '' : 'border-top:1px solid var(--raised);'}text-align:left"><span style="flex:1;font-weight:600">${label}</span><span class="small" style="margin-right:8px">${value}</span>${fold(false).replace('M6 9l6 6 6-6', 'M9 6l6 6-6 6')}</button>`;
h += `<div class="label">Settings</div><div style="background:var(--surface);border-radius:16px;overflow:hidden">
@@ -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(`<div class="title">Remove ${esc(ch.name)}?</div><div class="small" style="margin:8px 0 14px">${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.</div>
<button class="btn gold" data-kremoveyes="${ch.number}">Remove ${esc(ch.name)}</button><button class="btn" data-kremoveno="1" style="margin-top:8px">Keep it</button>`); 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.
@@ -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<String> = 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<String> = 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<PoolSeries>, parts: List<DayPart>, startMs: L
/** A few names and how many more, so a reason stays short. */
private fun someOf(names: List<String>) = 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<PoolSeries>, seed: Int): List<PoolSeries> = pool.sortedBy { it.id }.shuffled(java.util.Random(seed.toLong()))
internal fun turnOrder(pool: List<PoolSeries>, last: String?): List<PoolSeries> {
val after = pool.indexOfFirst { it.id == last } + 1
return (0 until pool.size).map { pool[(after + it) % pool.size] }
@@ -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.")
@@ -58,7 +58,9 @@ internal class ChannelMaker(
/** Titles by item from the catalogue alone, quickly, for listing a collection. */
val rowsOf: suspend (List<String>) -> List<ShapeRow> = { emptyList() },
/** Networks and studios by name, with their title counts. */
val studios: suspend (String) -> List<Pair<String, Int>> = { emptyList() })
val studios: suspend (String) -> List<Pair<String, Int>> = { 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<String>, val total: Int, val complete: Boolean)
@@ -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,
@@ -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<String, String> = 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. */
@@ -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) {
@@ -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) } }
@@ -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() }
@@ -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()) {
@@ -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 })
}
}