diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 474f0afd..5af6343d 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 = 185 - versionName = "0.108.25-orb-man-cast" + versionCode = 186 + versionName = "0.108.26-luna-drift" } buildFeatures { compose = true } compileOptions { sourceCompatibility = JavaVersion.VERSION_17; targetCompatibility = JavaVersion.VERSION_17 } diff --git a/android/app/src/main/java/tv/orbit/classic/CatchUp.kt b/android/app/src/main/java/tv/orbit/classic/CatchUp.kt index 05bc7bcd..2ccacf11 100644 --- a/android/app/src/main/java/tv/orbit/classic/CatchUp.kt +++ b/android/app/src/main/java/tv/orbit/classic/CatchUp.kt @@ -220,3 +220,26 @@ internal fun CatchUpBadge(modifier: Modifier = Modifier) { internal fun ScheduledPlayback.catchingUp() = clockOffsetMs < 0 internal fun catchUpDim() = CatchUpDim + +/** + * Drift waits with you (Paul, 5 November 2026: "Drift = Catch Up loading, buffering, gentle waiting"): the sleepy nebula from + * the cast's model sheet, breathing gently (still with Reduce motion on), while a Catch Up programme loads or catches its breath. + */ +@Composable +internal fun DriftWaiting(modifier: Modifier = Modifier) { + val context = androidx.compose.ui.platform.LocalContext.current + val calm = remember { OrbitSettings(context).reduceMotion } + var t by remember { mutableLongStateOf(0L) } + LaunchedEffect(calm) { if (!calm) while (true) withFrameMillis { t = it } } + Row(modifier.background(Navy.copy(alpha = .85f), RoundedCornerShape(10.dp)).padding(horizontal = 14.dp, vertical = 8.dp), + verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) { + androidx.compose.foundation.Canvas(Modifier.size(46.dp)) { + val bob = if (calm) 0f else kotlin.math.sin(t / 600.0).toFloat() * size.height * .05f + drawOrbChaser(center + androidx.compose.ui.geometry.Offset(0f, bob), size.minDimension * .36f, OrbCharacter.Drift, OrbDir.Right, false, false, false, t / 500f) + } + Column { + Text("Drift's fetching it", color = Color.White, fontSize = 15.sp, fontWeight = FontWeight.SemiBold) + Text("Just a moment" + if (calm) "…" else ".".repeat(1 + (t / 500 % 3).toInt()), color = Muted, fontSize = 12.sp) + } + } +} 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 833b76c8..fa4dc06f 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt @@ -66,7 +66,7 @@ internal class HttpsEmbyTransport(internal val deviceId: String = UUID.randomUUI connection.connectTimeout = 10_000 connection.readTimeout = request.readTimeoutMs ?: if (request.path == "/Sessions/Logout") 5_000 else 15_000 connection.setRequestProperty("Accept", "application/json") - connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.25\"") + connection.setRequestProperty("X-Emby-Authorization", "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.26\"") request.token?.let { connection.setRequestProperty("X-Emby-Token", it) } if (request.method == "POST") { val bytes = request.body.orEmpty().toByteArray(Charsets.UTF_8) diff --git a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt index ccad8a7b..84148e49 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyPlaybackDialog.kt @@ -87,6 +87,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl var tuningNumberVisible by remember { mutableStateOf(announce) } var ready by remember { mutableStateOf(false) } var playing by remember { mutableStateOf(false) } + var buffering by remember { mutableStateOf(false) } var infoVisible by remember { mutableStateOf(announce) } var lastInteraction by remember { mutableLongStateOf(SystemClock.elapsedRealtime()) } fun showInfo() { infoVisible = true; lastInteraction = SystemClock.elapsedRealtime() } @@ -259,6 +260,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl } } override fun onPlaybackStateChanged(state: Int) { + buffering = state == Player.STATE_BUFFERING if (state == Player.STATE_ENDED && scheduled != null) onEndedEarly?.invoke() if (state == Player.STATE_READY) { if (scheduled != null && !joinedSchedule) { @@ -294,6 +296,11 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl } DisposableEffect(player) { onDispose { watchAudioClock(false) } } val covered = ident != null + // Luna's goodnight: the programme fades out beneath her, and back up if a button keeps Orbit on. + LaunchedEffect(player, SleepTimer.goodnight) { + if (SleepTimer.goodnight) repeat(20) { step -> player.volume = 1f - (step + 1) / 20f; delay(100) } + else if (player.volume < 1f && intro?.showing != true && ident == null) player.volume = 1f + } LaunchedEffect(player, intro?.showing) { if (intro != null) player.volume = if (intro.showing) 0f else 1f } LaunchedEffect(player, covered) { if (covered) { @@ -343,7 +350,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl val isOk = code == KeyEvent.KEYCODE_DPAD_CENTER || code == KeyEvent.KEYCODE_ENTER val typedDigit = if (code in KeyEvent.KEYCODE_0..KeyEvent.KEYCODE_9) code - KeyEvent.KEYCODE_0 else null // The sleep timer's last minute: any button keeps you watching, and does nothing else. - if (SleepTimer.warning) { + if (SleepTimer.warning || SleepTimer.goodnight) { if (event.action == KeyEvent.ACTION_UP) SleepTimer.keepWatching(System.currentTimeMillis()) return@setOnKeyListener true } @@ -452,7 +459,8 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl true } } - setShowBuffering(PlayerView.SHOW_BUFFERING_WHEN_PLAYING) + // Catching up, Drift does the waiting instead of the spinner. + setShowBuffering(if (scheduled?.catchingUp() == true) PlayerView.SHOW_BUFFERING_NEVER else PlayerView.SHOW_BUFFERING_WHEN_PLAYING) this.player = player isFocusable = true; isFocusableInTouchMode = true post { requestFocus() } @@ -461,6 +469,8 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl if (scheduled != null && !ready && failure == null && foreground) ChannelTuningBackdrop(scheduled.channel.number) { ProgrammeArtwork(session, scheduled.channel, scheduled.programme) } if (scheduled?.catchingUp() == true && ready && failure == null) CatchUpBadge(Modifier.align(Alignment.TopStart).padding(top = 28.dp, start = 40.dp)) + // Catching its breath part-way through a Catch Up programme, after a skip or a slow patch: Drift waits with you. + if (scheduled?.catchingUp() == true && ready && buffering && failure == null) DriftWaiting(Modifier.align(Alignment.BottomEnd).padding(end = 40.dp, bottom = 32.dp)) if (scheduled != null && ready && tuningNumberVisible && failure == null) ClassicTuningNumber(scheduled.channel.number, Modifier.align(Alignment.TopEnd).padding(top = 32.dp, end = 44.dp)) @@ -477,6 +487,7 @@ internal fun EmbyPlaybackDialog(session: EmbySampleSession, plan: EmbyPlaybackPl numberEntry?.let { ChannelNumberBox(it, numberProblem, Modifier.align(Alignment.TopCenter).padding(top = 44.dp)) } // In a window of its own; a scheduled channel draws it over its idents instead. if (window == null && SleepTimer.warning) SleepWarning(Modifier.align(Alignment.TopCenter).padding(top = 44.dp)) + if (window == null && SleepTimer.goodnight) LunaGoodnight() if (failure != null) Column(Modifier.align(Alignment.Center).widthIn(max = 620.dp).background(Navy).padding(24.dp)) { Text(failure.orEmpty(), color = Color.White, fontSize = 20.sp) Spacer(Modifier.height(16.dp)) diff --git a/android/app/src/main/java/tv/orbit/classic/MainActivity.kt b/android/app/src/main/java/tv/orbit/classic/MainActivity.kt index a0ccc75c..9fb1cfdb 100644 --- a/android/app/src/main/java/tv/orbit/classic/MainActivity.kt +++ b/android/app/src/main/java/tv/orbit/classic/MainActivity.kt @@ -121,7 +121,7 @@ private fun OrbitApp() { LaunchedEffect(Unit) { while (true) { delay(1000); if (SleepTimer.tick(System.currentTimeMillis())) { SleepTimer.clear(); activity?.finish() } } } Box(Modifier.fillMaxSize().background(Navy).onPreviewKeyEvent { event -> // During the timer's last minute any button keeps you watching, and does nothing else. - if (!SleepTimer.warning) return@onPreviewKeyEvent false + if (!SleepTimer.warning && !SleepTimer.goodnight) return@onPreviewKeyEvent false if (event.nativeKeyEvent.action == android.view.KeyEvent.ACTION_UP) SleepTimer.keepWatching(System.currentTimeMillis()) true }) { @@ -166,6 +166,7 @@ private fun OrbitApp() { } // Full screen draws its own, over the programme. if (SleepTimer.warning && !FullScreen.active) SleepWarning(Modifier.align(Alignment.TopCenter).padding(top = 64.dp)) + if (SleepTimer.goodnight && !FullScreen.active) LunaGoodnight() } } } 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 f0fca8a5..787393b2 100644 --- a/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt +++ b/android/app/src/main/java/tv/orbit/classic/SampleChannelScreens.kt @@ -202,9 +202,12 @@ internal fun ScheduledChannelPlayer(session: EmbySampleSession, channel: SampleC } if (catchUpFor != null && problem == null && (!catchUpIdentDone || !catchUpPicture)) key("catch-up-ident") { IdentOverlay(session, channel, current, identLength(channel.number, catchUpFor), 0, heading = "CATCH UP") + // The ident has played and the programme isn't ready yet: Drift waits with you. + if (catchUpIdentDone) DriftWaiting(Modifier.align(Alignment.BottomEnd).padding(end = 40.dp, bottom = 32.dp)) } introPlayback?.let { IntroOverlay(it) } if (SleepTimer.warning) SleepWarning(Modifier.align(Alignment.TopCenter).padding(top = 44.dp)) + if (SleepTimer.goodnight) LunaGoodnight() } } } 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 5ec22d35..fc67edcd 100644 --- a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt +++ b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt @@ -33,7 +33,7 @@ internal class SecureMediaDataSource(private val session: EmbySampleSession) : B next.instanceFollowRedirects = false next.connectTimeout = 10_000 next.readTimeout = 20_000 - next.setRequestProperty("User-Agent", "OrbitTV/0.108.25") + next.setRequestProperty("User-Agent", "OrbitTV/0.108.26") 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/SleepTimer.kt b/android/app/src/main/java/tv/orbit/classic/SleepTimer.kt index 5f55c99f..af7d3c1f 100644 --- a/android/app/src/main/java/tv/orbit/classic/SleepTimer.kt +++ b/android/app/src/main/java/tv/orbit/classic/SleepTimer.kt @@ -9,6 +9,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp @@ -21,6 +22,8 @@ import androidx.tv.material3.Text * nothing is saved, so each time Orbit opens it starts off. */ internal const val SLEEP_WARNING_MS = 60_000L +/** Luna's goodnight (Paul, 5 November 2026): how long she says it before Orbit switches off. */ +internal const val GOODNIGHT_MS = 8_000L internal enum class SleepChoice(val label: String, val minutes: Int?) { Off("Off", null), Thirty("30 min", 30), Sixty("60 min", 60), Ninety("90 min", 90), AfterThis("After this programme", null) @@ -33,6 +36,10 @@ internal object SleepTimer { var endsAt by mutableStateOf(null) private set var warning by mutableStateOf(false) + /** When Luna began saying goodnight, or null. */ + var goodnightSince by mutableStateOf(null) + private set + val goodnight get() = goodnightSince != null /** [programmeEndMs] is when the programme being watched ends on the wall clock, for [SleepChoice.AfterThis]. */ fun set(choice: SleepChoice, nowMs: Long, programmeEndMs: Long?) { @@ -41,17 +48,24 @@ internal object SleepTimer { if (endsAt == null) this.choice = SleepChoice.Off } - /** Any button during the warning: the same length again, or off after a programme-length timer. */ - fun keepWatching(nowMs: Long) = set(if (choice == SleepChoice.AfterThis) SleepChoice.Off else choice, nowMs, null) - - /** Checked every second: true when it's time to switch off. */ - fun tick(nowMs: Long): Boolean { - val end = endsAt ?: return false - warning = end - nowMs <= SLEEP_WARNING_MS - return nowMs >= end + /** + * Any button during the warning: the same length again, or off after a programme-length timer. During Luna's goodnight: + * the timer is off and you carry on watching. + */ + fun keepWatching(nowMs: Long) { + if (goodnight) clear() else set(if (choice == SleepChoice.AfterThis) SleepChoice.Off else choice, nowMs, null) } - fun clear() { choice = SleepChoice.Off; endsAt = null; warning = false } + /** Checked every second. When the time comes Luna says goodnight; true once she has, and Orbit should switch off. */ + fun tick(nowMs: Long): Boolean { + goodnightSince?.let { return nowMs - it >= GOODNIGHT_MS } + val end = endsAt ?: return false + warning = end - nowMs <= SLEEP_WARNING_MS + if (nowMs >= end) { warning = false; goodnightSince = nowMs } + return false + } + + fun clear() { choice = SleepChoice.Off; endsAt = null; warning = false; goodnightSince = null } } internal fun sleepEnd(choice: SleepChoice, nowMs: Long, programmeEndMs: Long?): Long? = when { @@ -74,3 +88,45 @@ internal fun SleepWarning(modifier: Modifier = Modifier) { Text("Press any button to keep watching", color = Muted, fontSize = 15.sp) } } + +/** + * Luna says goodnight (Paul, 5 November 2026: "Luna = bedtime"). Over everything, the programme quietened beneath: the night sky, + * Luna drawn to the cast's model sheet with her sleepy lids, and a few drifting z's (still, with Reduce motion on). Any button + * keeps Orbit on. + */ +@Composable +internal fun LunaGoodnight(modifier: Modifier = Modifier) { + val context = androidx.compose.ui.platform.LocalContext.current + val calm = androidx.compose.runtime.remember { OrbitSettings(context).reduceMotion } + val fade = androidx.compose.runtime.remember { androidx.compose.animation.core.Animatable(0f) } + androidx.compose.runtime.LaunchedEffect(Unit) { fade.animateTo(1f, androidx.compose.animation.core.tween(1_200)) } + var t by androidx.compose.runtime.remember { androidx.compose.runtime.mutableLongStateOf(0L) } + androidx.compose.runtime.LaunchedEffect(calm) { if (!calm) while (true) androidx.compose.runtime.withFrameMillis { t = it } } + Box(modifier.fillMaxSize().graphicsLayer { alpha = fade.value }.background(Color(0xFF040B22))) { + androidx.compose.foundation.Canvas(Modifier.fillMaxSize()) { + val stars = java.util.Random(11) + repeat(70) { + val twinkle = if (calm) .5f else .35f + .3f * kotlin.math.sin(t / 900.0 + it).toFloat() + drawCircle(Color.White.copy(alpha = twinkle), 1f + stars.nextFloat() * 1.6f, androidx.compose.ui.geometry.Offset(stars.nextFloat() * size.width, stars.nextFloat() * size.height)) + } + val luna = androidx.compose.ui.geometry.Offset(size.width / 2, size.height * .4f) + val r = size.minDimension * .14f + drawCircle(OrbCharacter.Luna.colour.copy(alpha = .16f), r * 1.7f, luna) + drawOrbChaser(luna, r, OrbCharacter.Luna, OrbDir.Down, false, false, false, 0f) + // Three z's drifting up from her shoulder. + for (k in 0..2) { + val rise = if (calm) 0f else ((t / 1400f + k / 3f) % 1f) + val at = luna + androidx.compose.ui.geometry.Offset(r * (1.1f + k * .45f + rise * .3f), -r * (.6f + k * .45f + rise * .6f)) + val z = r * (.18f + k * .06f) + val p = androidx.compose.ui.graphics.Path().apply { moveTo(at.x, at.y); lineTo(at.x + z, at.y); lineTo(at.x, at.y + z); lineTo(at.x + z, at.y + z) } + drawPath(p, Color.White.copy(alpha = if (calm) .8f else .9f * (1f - rise * .7f)), style = androidx.compose.ui.graphics.drawscope.Stroke(z * .18f)) + } + } + Column(Modifier.align(androidx.compose.ui.Alignment.BottomCenter).padding(bottom = 70.dp), horizontalAlignment = androidx.compose.ui.Alignment.CenterHorizontally, + verticalArrangement = Arrangement.spacedBy(6.dp)) { + Text("Goodnight from Orbit", color = Color.White, fontFamily = Anton, fontSize = 34.sp) + Text("Luna's turning the lights down. Sleep well.", color = Muted, fontSize = 17.sp) + Text("Any button keeps Orbit on", color = Muted.copy(alpha = .7f), fontSize = 12.sp, modifier = Modifier.padding(top = 10.dp)) + } + } +} diff --git a/android/app/src/test/java/tv/orbit/classic/CatchUpTest.kt b/android/app/src/test/java/tv/orbit/classic/CatchUpTest.kt index a782a05b..813349f8 100644 --- a/android/app/src/test/java/tv/orbit/classic/CatchUpTest.kt +++ b/android/app/src/test/java/tv/orbit/classic/CatchUpTest.kt @@ -112,10 +112,21 @@ class CatchUpTest { // Any button: the same length again. SleepTimer.keepWatching(now + 29 * minute + 5_000) assertFalse(SleepTimer.warning); assertEquals(now + 59 * minute + 5_000, SleepTimer.endsAt) - assertTrue(SleepTimer.tick(now + 60 * minute)) + // Time's up: Luna says goodnight first, then Orbit switches off. + assertFalse(SleepTimer.tick(now + 60 * minute)); assertTrue(SleepTimer.goodnight); assertFalse(SleepTimer.warning) + assertFalse(SleepTimer.tick(now + 60 * minute + GOODNIGHT_MS - 1)) + assertTrue(SleepTimer.tick(now + 60 * minute + GOODNIGHT_MS)) assertEquals("2 min left", sleepLeft(now + 90_000, now)) } + @Test fun anyButtonDuringGoodnightKeepsOrbitOn() { + SleepTimer.set(SleepChoice.Thirty, now, null) + SleepTimer.tick(now + 30 * minute) + assertTrue(SleepTimer.goodnight) + SleepTimer.keepWatching(now + 30 * minute + 2_000) + assertFalse(SleepTimer.goodnight); assertEquals(SleepChoice.Off, SleepTimer.choice); assertFalse(SleepTimer.tick(now + day)) + } + @Test fun afterThisProgrammeEndsWithItAndAlwaysWarnsFirst() { SleepTimer.set(SleepChoice.AfterThis, now, now + 20 * minute) assertEquals(now + 20 * minute, SleepTimer.endsAt)