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 30d8d423..fed7451e 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -779,8 +779,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea return } if ((mainGuide || mainHome || mainWhatsOn || mainCatchUp) && liveSession != null && liveChannel != null) { - orbiFaxFromTv?.let { fromTv -> OrbiFaxScreen({ orbiFaxData(availableChannels, scheduledChannels.mapValues { it.value.plan }, driveInPlan, - { session?.let { scheduleStore.loadArrivals(it.accountId).first }.orEmpty() }, orbiFaxRecords(OrbitSettings(appContext)), Profiles.current, System.currentTimeMillis()) }, + orbiFaxFromTv?.let { fromTv -> OrbiFaxScreen({ shows, pause -> orbiFaxData(availableChannels, scheduledChannels.mapValues { it.value.plan }, driveInPlan, + { session?.let { scheduleStore.loadArrivals(it.accountId).first }.orEmpty() }, orbiFaxRecords(OrbitSettings(appContext)), Profiles.current, System.currentTimeMillis(), shows = shows, pause = pause) }, onClose = { orbiFaxFromTv = null; watchingChannel = fromTv }); return } if (watchingChannel) ScheduledChannelPlayer(liveSession, liveChannel, channelClockOffset, intro = remember { CurtainIntro.takeIf { IntroTrial.take() } }, diff --git a/android/app/src/main/java/tv/orbit/classic/OrbiFaxNav.kt b/android/app/src/main/java/tv/orbit/classic/OrbiFaxNav.kt index 45860d5e..888778d5 100644 --- a/android/app/src/main/java/tv/orbit/classic/OrbiFaxNav.kt +++ b/android/app/src/main/java/tv/orbit/classic/OrbiFaxNav.kt @@ -4,44 +4,44 @@ package tv.orbit.classic internal const val ORBI_FAX_CHANNEL = 0 internal const val ORBI_FAX_INDEX = 100 internal const val ORBI_FAX_WIZARD_PAGE = 999 -/** The Fastext row's four links, then the "Page" box that opens the digit picker. */ -internal const val ORBI_FAX_LINKS = 4 -internal const val ORBI_FAX_PAGE_BOX = 4 -private const val HISTORY_MAX = 16 +/** The Fastext row's three page links (red, green, yellow); the fourth place (cyan) is "Go to page". */ +internal const val ORBI_FAX_LINKS = 3 +/** In a page's choices, the "Go to page" link that opens the digit picker. */ +internal const val ORBI_FAX_GO_TO = -1 internal enum class OrbiFaxKey { Up, Down, Left, Right, Ok, Back, Red, Green, Yellow, Cyan, PageUp, PageDown } -/** What navigation needs to know about the pages: which can be stepped through, their sub-pages and their links. */ +/** What navigation needs to know about the pages: their order, their sub-pages and the links on each. */ internal interface OrbiFaxBook { - /** The pages Up and Down step through, in order. 999 is never among them: it has to be keyed. */ + /** The pages Left and Right turn through, in order. 999 is never among them: it has to be keyed. */ val pages: IntArray fun subPages(page: Int): Int - /** Where Fastext link [index] (0 red, 1 green, 2 yellow, 3 cyan) goes from [page]. */ + /** Where Fastext link [index] (0 red, 1 green, 2 yellow) goes from [page]. */ fun link(page: Int, index: Int): Int + /** Everything Up and Down move between on [page], top to bottom: page numbers, ending with [ORBI_FAX_GO_TO]. */ + fun choices(page: Int): IntArray } /** - * Where the viewer is. [typed] holds digits keyed so far (up to two), [picker] the D-pad digit picker when it's open, - * and [bar] the focused link on the Fastext row (-1 when the row isn't focused). + * Where the viewer is (simpler controls, Paul, 8 November 2026: "a lil confused with controls"). + * Up/Down move [focus] between the page's links and OK goes there; Left/Right turn sub-pages, then pages; "Go to page" + * (or the cyan key, or the number keys) keys a page; Back always returns to the TV or the guide. + * [typed] holds number-key digits so far, [picker] the digit picker while it's open. */ -internal data class OrbiFaxNav(val page: Int = ORBI_FAX_INDEX, val sub: Int = 0, val typed: String = "", val picker: ChannelEntry? = null, - val bar: Int = -1, val history: List = emptyList()) { +internal data class OrbiFaxNav(val page: Int = ORBI_FAX_INDEX, val sub: Int = 0, val focus: Int = 0, val typed: String = "", + val picker: ChannelEntry? = null) { - fun go(number: Int): OrbiFaxNav { - val target = if (number in 100..999) number else ORBI_FAX_INDEX - return OrbiFaxNav(page = target, history = (history + page).takeLast(HISTORY_MAX)) - } + fun go(number: Int) = OrbiFaxNav(page = if (number in 100..999) number else ORBI_FAX_INDEX) - /** One digit, from the number keys: the third one goes to the page. */ + /** One digit from the number keys (or into the open picker): the third goes to the page. */ fun digit(d: Int): OrbiFaxNav { picker?.let { p -> val next = p.type(d); return if (p.onLastSlot) go(next.number) else copy(picker = next) } val now = typed + digitText(d) - return if (now.length == 3) go(now.toInt()) else copy(typed = now, bar = -1) + return if (now.length == 3) go(now.toInt()) else copy(typed = now) } - /** A key; null means Back with nothing left to close, so Orbi-Fax hands back to the TV. */ + /** A key; null means Back with nothing left to close, so Orbi-Fax hands back to the TV or the guide. */ fun press(key: OrbiFaxKey, book: OrbiFaxBook): OrbiFaxNav? { - val count = book.subPages(page).coerceAtLeast(1) picker?.let { p -> return when (key) { OrbiFaxKey.Up -> copy(picker = p.dial(1)) @@ -53,31 +53,38 @@ internal data class OrbiFaxNav(val page: Int = ORBI_FAX_INDEX, val sub: Int = 0, else -> copy(picker = null).press(key, book) } } - if (bar >= 0) when (key) { - OrbiFaxKey.Left -> return copy(bar = (bar - 1).coerceAtLeast(0)) - OrbiFaxKey.Right -> return copy(bar = (bar + 1).coerceAtMost(ORBI_FAX_PAGE_BOX)) - OrbiFaxKey.Ok -> return if (bar == ORBI_FAX_PAGE_BOX) copy(bar = -1, picker = ChannelEntry.from(page)) else go(book.link(page, bar)) - OrbiFaxKey.Back -> return copy(bar = -1) - else -> {} - } + val choices = book.choices(page) + val at = focus.coerceIn(0, (choices.size - 1).coerceAtLeast(0)) return when (key) { OrbiFaxKey.Back -> if (typed.isNotEmpty()) copy(typed = "") else null - OrbiFaxKey.Up, OrbiFaxKey.PageUp -> go(step(book.pages, 1)) - OrbiFaxKey.Down, OrbiFaxKey.PageDown -> go(step(book.pages, -1)) - OrbiFaxKey.Left -> copy(sub = Math.floorMod(sub - 1, count), typed = "") - OrbiFaxKey.Right -> copy(sub = Math.floorMod(sub + 1, count), typed = "") - OrbiFaxKey.Ok -> copy(bar = ORBI_FAX_PAGE_BOX, typed = "") + OrbiFaxKey.Up -> copy(focus = (at - 1).coerceAtLeast(0), typed = "") + OrbiFaxKey.Down -> copy(focus = (at + 1).coerceAtMost((choices.size - 1).coerceAtLeast(0)), typed = "") + OrbiFaxKey.Ok -> choices.getOrNull(at)?.let { open(it) } ?: this + OrbiFaxKey.Right -> turn(book, 1) + OrbiFaxKey.Left -> turn(book, -1) + OrbiFaxKey.PageUp -> go(step(book.pages, 1)) + OrbiFaxKey.PageDown -> go(step(book.pages, -1)) OrbiFaxKey.Red -> go(book.link(page, 0)) OrbiFaxKey.Green -> go(book.link(page, 1)) OrbiFaxKey.Yellow -> go(book.link(page, 2)) - OrbiFaxKey.Cyan -> go(book.link(page, 3)) + OrbiFaxKey.Cyan -> open(ORBI_FAX_GO_TO) } } - /** The carousel's turn to the next sub-page (never while the viewer is keying or choosing). */ - fun turn(book: OrbiFaxBook): OrbiFaxNav { + private fun open(choice: Int) = if (choice == ORBI_FAX_GO_TO) copy(picker = ChannelEntry.from(page), typed = "") else go(choice) + + /** Left/Right: the next or previous sub-page while there are some, then the next or previous page. */ + private fun turn(book: OrbiFaxBook, direction: Int): OrbiFaxNav { + val next = sub + direction + if (book.subPages(page) > 1 && next in 0 until book.subPages(page)) return copy(sub = next, typed = "") + val target = go(step(book.pages, direction)) + return if (direction < 0) target.copy(sub = book.subPages(target.page) - 1) else target + } + + /** The carousel's turn to the next sub-page (never while a number is being keyed). */ + fun carousel(book: OrbiFaxBook): OrbiFaxNav { val count = book.subPages(page) - return if (count <= 1 || typed.isNotEmpty() || picker != null || bar >= 0) this else copy(sub = (sub + 1) % count) + return if (count <= 1 || typed.isNotEmpty() || picker != null) this else copy(sub = (sub + 1) % count) } /** The next or previous page in [pages]; from a page that isn't among them, the nearest one in that direction. */ diff --git a/android/app/src/main/java/tv/orbit/classic/OrbiFaxPage.kt b/android/app/src/main/java/tv/orbit/classic/OrbiFaxPage.kt index cf852464..139582a9 100644 --- a/android/app/src/main/java/tv/orbit/classic/OrbiFaxPage.kt +++ b/android/app/src/main/java/tv/orbit/classic/OrbiFaxPage.kt @@ -150,15 +150,17 @@ internal object TeletextRenderer { return if (code in 0 until 95 && row in 0 until 9) glyphs[code * 9 + row].toInt() else 0 } - fun render(page: TeletextPage, out: IntArray) { + /** Draws rows [fromRow] to [toRow] (inclusive): the whole page, or only the header as the clock ticks. */ + fun render(page: TeletextPage, out: IntArray, fromRow: Int = 0, toRow: Int = Teletext.ROWS - 1) { require(out.size == Teletext.WIDTH * Teletext.HEIGHT) val w = Teletext.WIDTH - for (cell in 0 until Teletext.CELLS) { + val first = fromRow * Teletext.COLS; val last = (toRow + 1) * Teletext.COLS + for (cell in first until last) { val x0 = (cell % Teletext.COLS) * Teletext.CELL_W; val y0 = (cell / Teletext.COLS) * Teletext.CELL_H val colour = Teletext.PALETTE[page.bg[cell].toInt()] for (y in y0 until y0 + Teletext.CELL_H) out.fill(colour, y * w + x0, y * w + x0 + Teletext.CELL_W) } - for (cell in 0 until Teletext.CELLS) { + for (cell in first until last) { val flag = page.flags[cell].toInt() if (flag and TeletextPage.LOWER != 0) continue val x0 = (cell % Teletext.COLS) * Teletext.CELL_W; val y0 = (cell / Teletext.COLS) * Teletext.CELL_H @@ -179,7 +181,7 @@ internal object TeletextRenderer { if (bits == 0) continue for (s in 0 until scale) { val y = y0 + (gy + 1) * scale + s - if (y >= Teletext.HEIGHT) continue + if (y >= Teletext.HEIGHT || y >= (toRow + 1) * Teletext.CELL_H) continue for (gx in 0 until 5) if (bits shr (4 - gx) and 1 != 0) out[y * w + x0 + gx] = colour } } diff --git a/android/app/src/main/java/tv/orbit/classic/OrbiFaxPages.kt b/android/app/src/main/java/tv/orbit/classic/OrbiFaxPages.kt index 98da41ed..765e6d6f 100644 --- a/android/app/src/main/java/tv/orbit/classic/OrbiFaxPages.kt +++ b/android/app/src/main/java/tv/orbit/classic/OrbiFaxPages.kt @@ -45,7 +45,7 @@ private val WarningLines = arrayOf("You have gone", "too far, young", "traveller /** The pages that will come later: shown greyed on the index and as their own "coming later" page. */ internal val OrbiFaxLater = linkedMapOf(101 to "News", 300 to "Sport", 400 to "Weather", 800 to "House and Rooms") -private val LinkLabels = mapOf(100 to "Index", 500 to "On Now", 501 to "Listing", 510 to "Tonight", 520 to "DriveIn", 600 to "Library", 700 to "Arcade") +private val LinkLabels = mapOf(100 to "Index", 500 to "On Now", 501 to "Listing", 510 to "Tonight", 520 to "Drive-In", 600 to "Library", 700 to "Arcade") internal class OrbiFaxPages(val data: OrbiFaxData) : OrbiFaxBook { /** Whether this profile may see [page]. Kids never sees the library page, and the Drive-In and Arcade only when allowed. */ @@ -74,13 +74,23 @@ internal class OrbiFaxPages(val data: OrbiFaxData) : OrbiFaxBook { } override fun link(page: Int, index: Int) = links(page).getOrElse(index) { ORBI_FAX_INDEX } + /** The index's sections, in order, for this profile. */ + private val sections = listOf("On Orbit Now" to 500, "Tonight's Highlights" to 510, "The Drive-In" to 520, + "New In Your Library" to 600, "Arcade Records" to 700).filter { allowed(it.second) } + private val choiceCache = HashMap() + override fun choices(page: Int) = choiceCache.getOrPut(page) { + (if (page == ORBI_FAX_INDEX) sections.map { it.second } else emptyList()).toIntArray() + links(page) + ORBI_FAX_GO_TO + } + /** How many of [page]'s choices come before the Fastext row (the index's sections). */ + private fun sectionsOn(page: Int) = if (page == ORBI_FAX_INDEX) sections.size else 0 + /** Builds [page] into [out], all but the header row, which [header] writes each second. */ - fun build(out: TeletextPage, page: Int, sub: Int, nowMs: Long, zone: ZoneId, reveal: Int = Int.MAX_VALUE) { + fun build(out: TeletextPage, page: Int, sub: Int, nowMs: Long, zone: ZoneId, reveal: Int = Int.MAX_VALUE, focus: Int = -1) { out.clear() val s = sub.coerceIn(0, subPages(page) - 1) when { !allowed(page) -> notAllowed(out, page) - page == ORBI_FAX_INDEX -> index(out) + page == ORBI_FAX_INDEX -> index(out, focus) page == ORBI_FAX_NOW_NEXT -> nowNext(out, s, nowMs, zone) page == ORBI_FAX_LISTINGS -> listings(out, s, nowMs, zone) page == ORBI_FAX_HIGHLIGHTS -> highlights(out, s, zone) @@ -112,17 +122,18 @@ internal class OrbiFaxPages(val data: OrbiFaxData) : OrbiFaxBook { out.put(0, 32, ClockFormat.format(at), YELLOW) } - /** Row 24: the four Fastext links (red, green, yellow, cyan) and "Page", the focused one shown in reverse. */ + /** Row 24: three Fastext page links (red, green, yellow) and "Go to page" (cyan), the highlighted one in reverse. */ fun fastext(out: TeletextPage, nav: OrbiFaxNav) { out.clearRow(24) - val colours = intArrayOf(RED, GREEN, YELLOW, CYAN) + val colours = intArrayOf(RED, GREEN, YELLOW) + val focused = nav.focus.coerceIn(0, choices(nav.page).size - 1) - sectionsOn(nav.page) for (i in 0 until ORBI_FAX_LINKS) { val label = LinkLabels[link(nav.page, i)] ?: "Index" - val focused = nav.bar == i - out.put(24, i * 9 + 1, label, if (focused) BLACK else colours[i], if (focused) colours[i] else BLACK) + val on = focused == i && nav.picker == null + out.put(24, i * 9 + 1, label, if (on) BLACK else colours[i], if (on) colours[i] else BLACK) } - val focused = nav.bar == ORBI_FAX_PAGE_BOX - out.put(24, 36, "Page", if (focused) BLACK else WHITE, if (focused) WHITE else BLACK) + val on = focused == ORBI_FAX_LINKS || nav.picker != null + out.put(24, 29, "Go to page", if (on) BLACK else CYAN, if (on) CYAN else BLACK) } private fun title(out: TeletextPage, text: String, colour: Int = YELLOW) = out.put(1, 1, text, colour, double = true) @@ -132,18 +143,16 @@ internal class OrbiFaxPages(val data: OrbiFaxData) : OrbiFaxBook { out.put(1, Teletext.COLS - text.length, text, WHITE) } - private fun index(out: TeletextPage) { + private fun index(out: TeletextPage, focus: Int) { for (r in 1..4) out.fill(r, 0, Teletext.COLS, BLUE) out.art(1, 0, ORBI_FAX_MARK) out.put(1, 14, "ORBI-FAX", YELLOW, BLUE, double = true) out.put(3, 14, "Orbit's own pages", WHITE, BLUE) out.put(4, 14, "Channel 000 opens Orbi-Fax", CYAN, BLUE) out.rule(5, YELLOW) - val sections = listOf("On Orbit Now" to 500, "Tonight's Highlights" to 510, "The Drive-In" to 520, - "New In Your Library" to 600, "Arcade Records" to 700).filter { allowed(it.second) } sections.forEachIndexed { i, (name, number) -> val row = 7 + i * 2 - out.put(row, 2, name, YELLOW) + if (i == focus) out.put(row, 1, " $name ", BLACK, YELLOW) else out.put(row, 2, name, YELLOW) out.put(row, 4 + name.length, ".".repeat((32 - name.length).coerceAtLeast(0)), BLUE) out.putNumber(row, 38, number) } @@ -152,7 +161,6 @@ internal class OrbiFaxPages(val data: OrbiFaxData) : OrbiFaxBook { var col = 2 OrbiFaxLater.entries.take(3).forEach { (number, name) -> col = out.put(21, col, "$name $number", BLUE) + 3 } OrbiFaxLater[800]?.let { out.put(22, 2, "$it 800", BLUE) } - out.put(23, 2, "OK for links, or key a page number", CYAN) } private fun nowNext(out: TeletextPage, sub: Int, nowMs: Long, zone: ZoneId) { @@ -183,7 +191,6 @@ internal class OrbiFaxPages(val data: OrbiFaxData) : OrbiFaxBook { ch.shows.filter { it.startMs >= (current?.startMs ?: Long.MIN_VALUE) }.take(LISTING_ROWS).forEachIndexed { i, s -> show(out, 5 + i, s, if (s === current) WHITE else CYAN, zone, timeColour = if (s === current) YELLOW else WHITE) } - out.put(23, 1, "< > for the next channel", WHITE) } private fun show(out: TeletextPage, row: Int, s: OrbiFaxShow, colour: Int, zone: ZoneId, timeColour: Int = colour) { diff --git a/android/app/src/main/java/tv/orbit/classic/OrbiFaxScreen.kt b/android/app/src/main/java/tv/orbit/classic/OrbiFaxScreen.kt index 4b1b8dc7..e51cc76f 100644 --- a/android/app/src/main/java/tv/orbit/classic/OrbiFaxScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/OrbiFaxScreen.kt @@ -19,7 +19,6 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width -import androidx.compose.foundation.shape.CircleShape import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -48,7 +47,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.tv.material3.Text import java.time.ZoneId -import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.asCoroutineDispatcher import kotlinx.coroutines.delay import kotlinx.coroutines.withContext @@ -57,7 +56,7 @@ internal const val ORBI_FAX_CAROUSEL_MS = 12_000L /** The pages' records are read again this often while Orbi-Fax is open. */ private const val ORBI_FAX_REFRESH_MS = 60_000L private const val ARRIVALS_SHOWN = 64 -private const val LISTED_SHOWS = 18 +internal const val LISTED_SHOWS = 18 /** Orbit Classic's own colours, for the 16:9 margins only (design/orbi-fax/NOTES.md). Inside the page it's teletext's eight. */ private val MarginTop = Color(0xFF030915) @@ -72,12 +71,14 @@ private val MarginOrange = Color(0xFFF7A928) * filtered by the After Dark lock and the profile; Kids also never sees After Dark or the late show here, whatever is ticked. */ internal fun orbiFaxData(channels: List, plans: Map, driveIn: ChannelPlan?, arrivals: () -> List, - records: List, profile: Profile?, nowMs: Long, zone: ZoneId = ZoneId.systemDefault()): OrbiFaxData { + records: List, profile: Profile?, nowMs: Long, zone: ZoneId = ZoneId.systemDefault(), + shows: Int = LISTED_SHOWS, pause: () -> Unit = {}): OrbiFaxData { val kids = profile?.kind == ProfileKind.Kids fun kidsMayNotSee(number: Int) = kids && (number == AFTER_DARK_NUMBER || number in LockedChannels) val shown = channels.filterNot { lockedOut(it.number) || profileHides(it.number, profile) || kidsMayNotSee(it.number) }.sortedBy { it.number } val listed = shown.map { ch -> - val shows = runCatching { ch.guide(nowMs, LISTED_SHOWS) }.getOrDefault(emptyList()).map { show -> + pause() + val shows = runCatching { ch.guide(nowMs, shows.coerceIn(1, LISTED_SHOWS)) }.getOrDefault(emptyList()).map { show -> val title = if (kids && takeoverOf(ch.number, show, zone)?.kidsSafe == false) "Asleep till 6am" else guideTitle(ch.number, show).first OrbiFaxShow(show.startMs, teletextText(title)) } @@ -126,15 +127,26 @@ private class RenderTimer { * nothing to quieten. Back closes whatever's open, then hands back to the TV. */ @Composable -internal fun OrbiFaxScreen(load: () -> OrbiFaxData, onClose: () -> Unit) { +internal fun OrbiFaxScreen(load: (shows: Int, pause: () -> Unit) -> OrbiFaxData, onClose: () -> Unit) { val zone = remember { ZoneId.systemDefault() } val reduce = Motion.reduce var data by remember { mutableStateOf(null) } - LaunchedEffect(Unit) { + // The records are read on one low-priority thread of Orbi-Fax's own, a channel at a time with a breath between, so the + // reading never crowds the screen: now and next first, then the full listings, then again each minute. + val reader = remember { + java.util.concurrent.Executors.newSingleThreadExecutor { r -> Thread(r, "OrbiFax").apply { priority = Thread.MIN_PRIORITY; isDaemon = true } } + } + androidx.compose.runtime.DisposableEffect(reader) { onDispose { reader.shutdownNow() } } + LaunchedEffect(reader) { + val context = reader.asCoroutineDispatcher() + var shows = 2 while (true) { - data = withContext(Dispatchers.Default) { runCatching(load).onFailure { android.util.Log.w("OrbiFax", "load failed=${it.javaClass.simpleName}") }.getOrNull() } - ?: data ?: OrbiFaxData(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), kids = false) - delay(ORBI_FAX_REFRESH_MS) + val started = SystemClock.elapsedRealtime() + data = withContext(context) { + runCatching { load(shows) { Thread.sleep(2) } }.onFailure { android.util.Log.w("OrbiFax", "load failed=${it.javaClass.simpleName}") }.getOrNull() + } ?: data ?: OrbiFaxData(emptyList(), emptyList(), emptyList(), emptyList(), emptyList(), kids = false) + android.util.Log.i("OrbiFax", "load shows=$shows channels=${data?.channels?.size} ms=${SystemClock.elapsedRealtime() - started}") + if (shows < LISTED_SHOWS) { shows = LISTED_SHOWS; delay(1_500) } else delay(ORBI_FAX_REFRESH_MS) } } val book = remember(data) { data?.let(::OrbiFaxPages) } @@ -148,8 +160,10 @@ internal fun OrbiFaxScreen(load: () -> OrbiFaxData, onClose: () -> Unit) { } LaunchedEffect(nav, book, reduce) { val b = book ?: return@LaunchedEffect - if (!reduce && b.subPages(nav.page) > 1) { delay(ORBI_FAX_CAROUSEL_MS); nav = nav.turn(b) } + if (!reduce && b.subPages(nav.page) > 1) { delay(ORBI_FAX_CAROUSEL_MS); nav = nav.carousel(b) } } + // Which page is showing, in the log, so the TV's measurements can be split by page. + LaunchedEffect(nav.page, nav.sub) { android.util.Log.i("OrbiFax", "page=${nav.page} sub=${nav.sub}") } // Fixed buffers, made once: the page, its 240 x 250 dots and the bitmap they're copied into. val page = remember { TeletextPage() } @@ -158,17 +172,28 @@ internal fun OrbiFaxScreen(load: () -> OrbiFaxData, onClose: () -> Unit) { val image = remember(bitmap) { bitmap.asImageBitmap() } val timer = remember { RenderTimer() } val minute = nowMs / 60_000 - remember(book, nav.page, nav.sub, reveal, minute) { book?.build(page, nav.page, nav.sub, nowMs, zone, reveal); 0 } - val stamp = remember(book, nav, reveal, nowMs) { + // The whole page is built and drawn only when it changes; each second only the header row (the clock) is. + val body = remember(book, nav, reveal, minute) { val b = book if (b != null) { val started = SystemClock.elapsedRealtimeNanos() + b.build(page, nav.page, nav.sub, nowMs, zone, reveal, nav.focus.takeIf { nav.picker == null } ?: -1) b.header(page, nav, nowMs, zone); b.fastext(page, nav) TeletextRenderer.render(page, pixels) bitmap.setPixels(pixels, 0, Teletext.WIDTH, 0, 0, Teletext.WIDTH, Teletext.HEIGHT) timer.record(SystemClock.elapsedRealtimeNanos() - started) } - nowMs + nav.hashCode() + reveal + Any() + } + val drawn = remember { IntArray(1) } + val stamp = remember(body, nowMs) { + val b = book + if (b != null) { + b.header(page, nav, nowMs, zone) + TeletextRenderer.render(page, pixels, 0, 0) + bitmap.setPixels(pixels, 0, Teletext.WIDTH, 0, 0, Teletext.WIDTH, Teletext.CELL_H) + } + ++drawn[0] } val focus = remember { FocusRequester() } @@ -234,11 +259,13 @@ internal fun OrbiFaxScreen(load: () -> OrbiFaxData, onClose: () -> Unit) { val count = book?.subPages(nav.page) ?: 1 if (count > 1) Text("${nav.sub.coerceIn(0, count - 1) + 1}/$count", color = MarginMuted, fontSize = 13.sp) Spacer(Modifier.weight(1f)) - listOf(Color(0xFFFF0000), Color(0xFF00FF00), Color(0xFFFFFF00), Color(0xFF00FFFF)).forEach { dot -> - Box(Modifier.padding(4.dp).size(12.dp).background(dot, CircleShape)) + val hints = if (nav.picker != null) listOf("\u25B2\u25BC" to "Digit", "\u25C0\u25B6" to "Move", "OK" to "Go", "Back" to "Cancel") + else listOf("\u25B2\u25BC" to "Choose", "OK" to "Open", "\u25C0\u25B6" to "Turn", "Back" to "TV") + hints.forEach { (key, what) -> + Text(key, color = MarginFocus, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, modifier = Modifier.padding(top = 10.dp)) + Text(what, color = MarginMuted, fontSize = 13.sp) } - Text("OK links and pages", color = MarginMuted, fontSize = 11.sp, modifier = Modifier.padding(top = 8.dp)) - Text("Back to the TV", color = MarginMuted, fontSize = 11.sp) + Spacer(Modifier.height(24.dp)) } } } diff --git a/android/app/src/test/java/tv/orbit/classic/OrbiFaxTest.kt b/android/app/src/test/java/tv/orbit/classic/OrbiFaxTest.kt index e270d729..57e0af59 100644 --- a/android/app/src/test/java/tv/orbit/classic/OrbiFaxTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/OrbiFaxTest.kt @@ -57,17 +57,15 @@ class OrbiFaxTest { assertEquals("5--", typing.rowText(0).substring(16, 19)) } - @Test fun theFastextRowHasFourColouredLinksAndThePageBox() { + @Test fun theFastextRowHasThreeColouredLinksAndGoToPage() { val book = OrbiFaxPages(data()) val page = built(book, 100) val row = page.rowText(24) assertTrue(row, row.startsWith(" On Now")) - assertEquals("Page", row.substring(36)) - assertEquals(listOf(Teletext.RED, Teletext.GREEN, Teletext.YELLOW, Teletext.CYAN), (0 until 4).map { page.fg[24 * 40 + it * 9 + 1].toInt() }) + assertEquals("Go to page", row.substring(29, 39)) + assertEquals(listOf(Teletext.RED, Teletext.GREEN, Teletext.YELLOW, Teletext.CYAN), (0 until 4).map { page.fg[24 * 40 + it * 9 + 1 + (if (it == 3) 1 else 0)].toInt() }) } - // ---- drawing ---- - @Test fun theRendererDrawsDotsMosaicsAndBackgroundsInThePalette() { val page = TeletextPage(); val out = IntArray(Teletext.WIDTH * Teletext.HEIGHT) page.put(0, 0, "I", Teletext.YELLOW, Teletext.BLUE) @@ -99,60 +97,81 @@ class OrbiFaxTest { @Test fun threeDigitsGoToThePageAndBackClearsWhatsKeyed() { val book = OrbiFaxPages(data()) - var nav = OrbiFaxNav().digit(5).digit(0) + val nav = OrbiFaxNav().digit(5).digit(0) assertEquals(100, nav.page); assertEquals("50", nav.typed) assertEquals("", nav.press(OrbiFaxKey.Back, book)!!.typed) - nav = nav.digit(1) - assertEquals(501, nav.page); assertEquals(listOf(100), nav.history) + assertEquals(501, nav.digit(1).page) assertEquals(100, OrbiFaxNav().digit(0).digit(4).digit(2).page) // below 100 is the index } - @Test fun upAndDownStepThroughThePagesButNeverOnto999() { - val book = OrbiFaxPages(data()) + @Test fun leftAndRightTurnThePagesButNeverOnto999() { + val book = OrbiFaxPages(data(channels = 1)) // one channel: no page has sub-pages to turn first var nav = OrbiFaxNav() val seen = mutableListOf() - repeat(book.pages.size) { nav = nav.press(OrbiFaxKey.Up, book)!!; seen += nav.page } + repeat(book.pages.size) { nav = nav.press(OrbiFaxKey.Right, book)!!; seen += nav.page } assertEquals(book.pages.drop(1) + 100, seen) assertFalse(ORBI_FAX_WIZARD_PAGE in seen) - assertEquals(book.pages.last(), OrbiFaxNav().press(OrbiFaxKey.Down, book)!!.page) - assertEquals(ORBI_FAX_INDEX, OrbiFaxNav(page = ORBI_FAX_WIZARD_PAGE).press(OrbiFaxKey.Up, book)!!.page) + assertEquals(book.pages.last(), OrbiFaxNav().press(OrbiFaxKey.Left, book)!!.page) + assertEquals(ORBI_FAX_INDEX, OrbiFaxNav(page = ORBI_FAX_WIZARD_PAGE).press(OrbiFaxKey.Right, book)!!.page) } - @Test fun leftAndRightTurnSubPagesAndTheCarouselWaitsForTheViewer() { + @Test fun leftAndRightTurnSubPagesFirstThenPagesAndTheCarouselWaitsForKeying() { val book = OrbiFaxPages(data(channels = 13)) assertEquals(3, book.subPages(ORBI_FAX_NOW_NEXT)) var nav = OrbiFaxNav(page = ORBI_FAX_NOW_NEXT) - nav = nav.press(OrbiFaxKey.Left, book)!!; assertEquals(2, nav.sub) - nav = nav.turn(book); assertEquals(0, nav.sub) - assertEquals(0, nav.digit(1).turn(book).sub) - assertEquals(nav, OrbiFaxNav(page = 100).turn(book).copy(page = ORBI_FAX_NOW_NEXT)) + nav = nav.press(OrbiFaxKey.Right, book)!!; assertEquals(1, nav.sub) + nav = nav.press(OrbiFaxKey.Right, book)!!; assertEquals(2, nav.sub) + nav = nav.press(OrbiFaxKey.Right, book)!!; assertEquals(ORBI_FAX_LISTINGS, nav.page); assertEquals(0, nav.sub) + nav = nav.press(OrbiFaxKey.Left, book)!!; assertEquals(ORBI_FAX_NOW_NEXT, nav.page); assertEquals(2, nav.sub) // back onto its last sub-page + assertEquals(ORBI_FAX_INDEX, OrbiFaxNav(page = ORBI_FAX_NOW_NEXT).press(OrbiFaxKey.Left, book)!!.page) + assertEquals(1, OrbiFaxNav(page = ORBI_FAX_NOW_NEXT).carousel(book).sub) + assertEquals(0, OrbiFaxNav(page = ORBI_FAX_NOW_NEXT).digit(1).carousel(book).sub) assertTrue(built(book, ORBI_FAX_NOW_NEXT, 1).rowText(1).endsWith("2/3")) } - @Test fun okOpensTheFastextRowAndThePageBoxOpensTheDigitPicker() { + @Test fun upAndDownChooseALinkAndOkGoesThere() { val book = OrbiFaxPages(data()) - var nav = OrbiFaxNav().press(OrbiFaxKey.Ok, book)!! - assertEquals(ORBI_FAX_PAGE_BOX, nav.bar) - nav = nav.press(OrbiFaxKey.Ok, book)!! - assertEquals(listOf(1, 0, 0), nav.picker!!.digits) - nav = nav.press(OrbiFaxKey.Up, book)!!.press(OrbiFaxKey.Up, book)!!.press(OrbiFaxKey.Right, book)!!.press(OrbiFaxKey.Down, book)!! - assertEquals(listOf(3, 9, 0), nav.picker!!.digits) - assertEquals(390, nav.press(OrbiFaxKey.Ok, book)!!.page) - val linked = OrbiFaxNav().press(OrbiFaxKey.Ok, book)!!.press(OrbiFaxKey.Left, book)!!.press(OrbiFaxKey.Left, book)!!.press(OrbiFaxKey.Ok, book)!! - assertEquals(book.link(100, 2), linked.page) + val choices = book.choices(100) + assertEquals(listOf(500, 510, 520, 600, 700), choices.take(5)) + assertEquals(ORBI_FAX_GO_TO, choices.last()) + var nav = OrbiFaxNav() + assertEquals(500, nav.press(OrbiFaxKey.Ok, book)!!.page) // the first section is chosen to start with + nav = nav.press(OrbiFaxKey.Down, book)!! + assertEquals(510, nav.press(OrbiFaxKey.Ok, book)!!.page) + assertEquals(0, nav.press(OrbiFaxKey.Up, book)!!.press(OrbiFaxKey.Up, book)!!.focus) // stops at the top + repeat(20) { nav = nav.press(OrbiFaxKey.Down, book)!! } + assertEquals(choices.size - 1, nav.focus) // stops at Go to page + val linked = OrbiFaxNav(page = 700, focus = 1).press(OrbiFaxKey.Ok, book)!! + assertEquals(book.link(700, 1), linked.page) assertEquals(book.link(100, 0), OrbiFaxNav().press(OrbiFaxKey.Red, book)!!.page) } - @Test fun backClosesThePickerThenTheRowThenHandsBackToTheTv() { + @Test fun goToPageOpensTheDigitPickerInOnePress() { val book = OrbiFaxPages(data()) - val bar = OrbiFaxNav().press(OrbiFaxKey.Ok, book)!! - val picker = bar.press(OrbiFaxKey.Ok, book)!! - assertNull(picker.press(OrbiFaxKey.Back, book)!!.picker) - assertEquals(-1, bar.press(OrbiFaxKey.Back, book)!!.bar) - assertNull(OrbiFaxNav(page = 700).press(OrbiFaxKey.Back, book)) + var nav = OrbiFaxNav(page = 700, focus = book.choices(700).size - 1).press(OrbiFaxKey.Ok, book)!! + assertEquals(listOf(7, 0, 0), nav.picker!!.digits) + nav = nav.press(OrbiFaxKey.Up, book)!!.press(OrbiFaxKey.Up, book)!!.press(OrbiFaxKey.Right, book)!!.press(OrbiFaxKey.Down, book)!! + assertEquals(listOf(9, 9, 0), nav.picker!!.digits) + assertEquals(990, nav.press(OrbiFaxKey.Ok, book)!!.page) + assertNotNull(OrbiFaxNav().press(OrbiFaxKey.Cyan, book)!!.picker) // the cyan key too + val page = built(book, 700, nav = OrbiFaxNav(page = 700).press(OrbiFaxKey.Cyan, book)!!) + assertEquals(Teletext.CYAN, page.bg[24 * 40 + 29].toInt()) // Go to page shows as chosen } - // ---- 999 ---- + @Test fun theChosenSectionShowsInReverse() { + val book = OrbiFaxPages(data()) + val page = TeletextPage().also { book.build(it, 100, 0, now, zone, focus = 1) } + assertEquals(Teletext.YELLOW, page.bg[9 * 40 + 2].toInt()); assertEquals(Teletext.BLACK, page.fg[9 * 40 + 2].toInt()) + assertEquals(Teletext.BLACK, page.bg[7 * 40 + 2].toInt()) + } + + @Test fun backClosesThePickerThenAlwaysHandsBackToTheTv() { + val book = OrbiFaxPages(data()) + val picker = OrbiFaxNav().press(OrbiFaxKey.Cyan, book)!! + assertNull(picker.press(OrbiFaxKey.Back, book)!!.picker) + assertNull(OrbiFaxNav(page = 700).press(OrbiFaxKey.Back, book)) + assertNull(OrbiFaxNav(page = 501, sub = 3, focus = 2).press(OrbiFaxKey.Back, book)) + } @Test fun page999IsTheWizardWithHisWarningWordForWord() { val page = built(OrbiFaxPages(data()), 999, nav = OrbiFaxNav().digit(9).digit(9).digit(9)) @@ -190,7 +209,7 @@ class OrbiFaxTest { assertFalse(ORBI_FAX_ARRIVALS in book.pages); assertFalse(ORBI_FAX_ARCADE in book.pages); assertFalse(ORBI_FAX_DRIVE_IN in book.pages) assertTrue(built(book, ORBI_FAX_ARCADE).rowText(6).contains("isn't on this profile")) assertFalse((0 until 25).any { built(book, 100).rowText(it).contains("Arcade Records") }) - assertTrue((0 until 4).none { book.link(100, it) in setOf(ORBI_FAX_ARRIVALS, ORBI_FAX_ARCADE, ORBI_FAX_DRIVE_IN) }) + assertTrue(book.choices(100).none { it in setOf(ORBI_FAX_ARRIVALS, ORBI_FAX_ARCADE, ORBI_FAX_DRIVE_IN) }) } @Test fun grownUpsSeeEveryChannelWithNowAndNext() { diff --git a/docs/orbi-fax-stage1.md b/docs/orbi-fax-stage1.md index 6478ee81..22613f14 100644 --- a/docs/orbi-fax-stage1.md +++ b/docs/orbi-fax-stage1.md @@ -10,14 +10,12 @@ This is Orbit's own teletext, entirely offline. Paul approved it on 8 November 2 - Dial **000** on the channel number entry while watching. Back returns to the channel you were on. - Or choose **Text** at the end of the TV guide's category row. Back returns to the guide. - **The screen:** a 40 x 25 teletext page in the eight teletext colours, with 2x3 mosaics and double-height titles. The 4:3 page sits in the middle, with Orbit Classic margins either side. It follows the concept previews in `design/orbi-fax/`. -- **Remote:** - - **0–9** keys a page. The third digit goes there. - - **Up / Down** moves to the next or previous page. Page 999 is skipped: it has to be keyed. - - **Left / Right** turns sub-pages. - - **OK** focuses the Fastext row. Left and Right move along it, and OK follows a link. - - The **Page** box at the end of the row opens a digit picker for remotes with no number keys. Up and Down dial a digit, Left and Right move between digits, and OK goes. - - The **red, green, yellow and blue** keys follow the Fastext links where the remote has them. Channel and page up/down keys step through pages. - - **Back** closes the picker or the row. With nothing open, it returns to the TV. +- **Remote** (simpler controls after the first downstairs trial, 8 November 2026; the key hints sit in the right-hand margin, not on the page): + - **Up / Down** moves the yellow highlight between the links on the page: the sections on page 100, then the coloured links and **Go to page** along the bottom. + - **OK** opens the highlighted link. **Go to page** opens a three-digit picker: Up/Down sets a digit, Left/Right moves between digits, OK goes and Back cancels. + - **Left / Right** turns sub-pages while there are some, then moves to the next or previous page. Page 999 is never turned to: it has to be keyed. + - **Number keys** key a page directly. The **red, green and yellow** keys follow the coloured links and the **blue** key opens Go to page. + - **Back** always returns to the TV or the guide. - **Pages:** | Page | What it shows | Source (all on the box) | @@ -57,6 +55,8 @@ Any other number shows a short "no page" message, or "coming later" for 101, 300 - `GuideGrid.kt`: the optional `onText` parameter and the Text chip - **Memory:** fixed and made once per visit. The page is five arrays of 1,000 cells, the dot buffer is a 240 x 250 `IntArray` (240 KB), and the bitmap is 240 x 250 ARGB (240 KB). Drawing a frame allocates nothing. The pages are rebuilt (small allocations) only when the page, sub-page or minute changes. The header is redrawn once a second. The records are read again once a minute while Orbi-Fax is open. Lists are capped (18 programmes a channel, 64 arrivals, 4 Drive-In bills). - **Saved data:** nothing. Orbi-Fax saves no state, so there's nothing that needs an atomic write. +- **Reading the records:** done on one low-priority thread of Orbi-Fax's own, a channel at a time with a short pause between. Now and next come first, the full listings 1.5 s later, then a refresh every minute. Each read is logged (`OrbiFax load`), and so is each page shown (`OrbiFax page=… sub=…`), so the TV's numbers can be split by page. +- **Drawing:** the whole page is built and drawn only when it changes. Each second only the header row is redrawn, for the clock. - **Glyphs:** the original 5x9 dot-matrix set drawn for the concept, not Bedstead, which still needs Paul's OK. The page is drawn at 240 x 250 dots and scaled without smoothing. - **Not built:** - entering pages from the phone (the Companion)