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 01bc687e..c78b0f14 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyConnectionScreen.kt @@ -46,6 +46,8 @@ import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.tv.material3.Text import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll import kotlinx.coroutines.Job import kotlinx.coroutines.ensureActive import kotlinx.coroutines.delay @@ -54,6 +56,57 @@ import kotlinx.coroutines.withContext private const val RESTORE_QUIET_TRIES = 4 +/** The connection screen's state, held in one place so the screen itself stays small enough for the runtime to compile. */ +private class ConnectionUi(savedTicket: Long) { + var setupSaved by mutableStateOf(false) + var pendingSaved by mutableStateOf(null) + var restoring by mutableStateOf(true) + var restoreAttempt by mutableIntStateOf(0) + var restoreFailures by mutableIntStateOf(0) + var saveTicket by mutableLongStateOf(savedTicket) + var username by mutableStateOf("") + var serverText by mutableStateOf(EmbyServer.origin) + var busy by mutableStateOf(false) + var seriesMatches by mutableStateOf?>(null) + var episodeSamples by mutableStateOf?>(null) + var approvedSeries by mutableStateOf>(emptySet()) + var sample by mutableStateOf(null) + var session by mutableStateOf(null) + var darkMovies by mutableStateOf>(emptyList()) + var approvedDark by mutableStateOf>(emptySet()) + var lastNumber by mutableStateOf(null) + var afterDarkChannel by mutableStateOf(null) + var toonamiChannel by mutableStateOf(null) + var extraChannels by mutableStateOf>(emptyList()) + var selectedNumber by mutableIntStateOf(101) + var channel by mutableStateOf(null) + var watchingChannel by mutableStateOf(false) + var watchingDriveIn by mutableStateOf(false) + var driveInPlan by mutableStateOf(null) + var tickets by mutableStateOf>(emptyMap()) + var pendingDriveInWatch by mutableStateOf(false) + var reminder by mutableStateOf(null) + var reminders by mutableStateOf>(emptyList()) + var programmeReminder by mutableStateOf(null) + var windingDown by mutableStateOf(false) + var catchUpOpen by mutableStateOf(null) + var driveInVisits by mutableIntStateOf((System.currentTimeMillis() / 60_000 % DRIVE_IN_SCENES).toInt()) + var guideCategory by mutableStateOf(ChannelCategory.All) + var scheduledChannels by mutableStateOf>(emptyMap()) + var suggesting by mutableStateOf(null) + var suggestions by mutableStateOf>(emptyList()) + var settingsSection by mutableStateOf(SettingsSection.Channels) + var savingSuggestions by mutableStateOf(false) + var tickedSuggestions by mutableStateOf>(emptySet()) + var lastSmartPress by mutableLongStateOf(0L) + var channelClockOffset by mutableLongStateOf(0) + var busyLabel by mutableStateOf("Connecting…") + var message by mutableStateOf(null) + var nextAttemptAt by mutableLongStateOf(0) + var now by mutableLongStateOf(System.currentTimeMillis()) + var job by mutableStateOf(null) +} + @Composable internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolean, /** The first-launch flow is showing: it draws everything once signed in, so this screen draws nothing. */ @@ -65,64 +118,65 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea // schedules are never open at the same time, and work begun for one keeps writing only to its own. val workspace = Workspaces.current(appContext) val savedStore = remember(workspace) { workspace.connection } - var setupSaved by remember { mutableStateOf(false) } - var pendingSaved by remember { mutableStateOf(null) } - var restoring by remember { mutableStateOf(true) } - var restoreAttempt by remember { mutableIntStateOf(0) } - var restoreFailures by remember { mutableIntStateOf(0) } - var saveTicket by remember { mutableLongStateOf(savedStore.ticket()) } - var username by remember { mutableStateOf("") } - var serverText by remember { mutableStateOf(EmbyServer.origin) } + val ui = remember { ConnectionUi(savedStore.ticket()) } + var setupSaved by ui::setupSaved + var pendingSaved by ui::pendingSaved + var restoring by ui::restoring + var restoreAttempt by ui::restoreAttempt + var restoreFailures by ui::restoreFailures + var saveTicket by ui::saveTicket + var username by ui::username + var serverText by ui::serverText // Deliberately not rememberSaveable: credentials never enter saved instance state. val password = remember { TextFieldState() } - var busy by remember { mutableStateOf(false) } - var seriesMatches by remember { mutableStateOf?>(null) } - var episodeSamples by remember { mutableStateOf?>(null) } - var approvedSeries by remember { mutableStateOf>(emptySet()) } - var sample by remember { mutableStateOf(null) } - var session by remember { mutableStateOf(null) } - var darkMovies by remember { mutableStateOf>(emptyList()) } - var approvedDark by remember { mutableStateOf>(emptySet()) } + var busy by ui::busy + var seriesMatches by ui::seriesMatches + var episodeSamples by ui::episodeSamples + var approvedSeries by ui::approvedSeries + var sample by ui::sample + var session by ui::session + var darkMovies by ui::darkMovies + var approvedDark by ui::approvedDark val catalogue = remember(workspace) { workspace.catalogue } - var lastNumber by remember { mutableStateOf(null) } - var afterDarkChannel by remember { mutableStateOf(null) } - var toonamiChannel by remember { mutableStateOf(null) } - var extraChannels by remember { mutableStateOf>(emptyList()) } - var selectedNumber by remember { mutableIntStateOf(101) } - var channel by remember { mutableStateOf(null) } - var watchingChannel by remember { mutableStateOf(false) } - var watchingDriveIn by remember { mutableStateOf(false) } - var driveInPlan by remember { mutableStateOf(null) } - var tickets by remember { mutableStateOf>(emptyMap()) } - var pendingDriveInWatch by remember { mutableStateOf(false) } - var reminder by remember { mutableStateOf(null) } - var reminders by remember { mutableStateOf>(emptyList()) } - var programmeReminder by remember { mutableStateOf(null) } - var windingDown by remember { mutableStateOf(false) } - var catchUpOpen by remember { mutableStateOf(null) } + var lastNumber by ui::lastNumber + var afterDarkChannel by ui::afterDarkChannel + var toonamiChannel by ui::toonamiChannel + var extraChannels by ui::extraChannels + var selectedNumber by ui::selectedNumber + var channel by ui::channel + var watchingChannel by ui::watchingChannel + var watchingDriveIn by ui::watchingDriveIn + var driveInPlan by ui::driveInPlan + var tickets by ui::tickets + var pendingDriveInWatch by ui::pendingDriveInWatch + var reminder by ui::reminder + var reminders by ui::reminders + var programmeReminder by ui::programmeReminder + var windingDown by ui::windingDown + var catchUpOpen by ui::catchUpOpen // Each visit opens on the next of the three scenes. - var driveInVisits by remember { mutableIntStateOf((System.currentTimeMillis() / 60_000 % DRIVE_IN_SCENES).toInt()) } - var guideCategory by remember { mutableStateOf(ChannelCategory.All) } + var driveInVisits by ui::driveInVisits + var guideCategory by ui::guideCategory val liveHandoff = remember { LiveHandoff() } val scheduleStore = remember(workspace) { workspace.schedules } // Your own channels (Create your own) are this server's, read before anything plans or restores. remember(workspace) { CustomChannels.load(workspace.scheduleDir); true } val scheduler = remember(workspace) { ChannelScheduler(scheduleStore, copies = { if (catalogue.complete()) catalogue.idsByImdb(it) else null }, original = workspace.original) } - var scheduledChannels by remember { mutableStateOf>(emptyMap()) } - var suggesting by remember { mutableStateOf(null) } - var suggestions by remember { mutableStateOf>(emptyList()) } - var settingsSection by remember { mutableStateOf(SettingsSection.Channels) } - var savingSuggestions by remember { mutableStateOf(false) } - var tickedSuggestions by remember { mutableStateOf>(emptySet()) } - var lastSmartPress by remember { mutableLongStateOf(0L) } + var scheduledChannels by ui::scheduledChannels + var suggesting by ui::suggesting + var suggestions by ui::suggestions + var settingsSection by ui::settingsSection + var savingSuggestions by ui::savingSuggestions + var tickedSuggestions by ui::tickedSuggestions + var lastSmartPress by ui::lastSmartPress fun onAir(loop: SampleChannel) = scheduledChannels[loop.number]?.takeIf { it.loop === loop } ?: loop - var channelClockOffset by remember { mutableLongStateOf(0) } - var busyLabel by remember { mutableStateOf("Connecting…") } + var channelClockOffset by ui::channelClockOffset + var busyLabel by ui::busyLabel val sessionSlot = remember { EmbySessionSlot() } - var message by remember { mutableStateOf(null) } - var nextAttemptAt by remember { mutableLongStateOf(0) } - var now by remember { mutableLongStateOf(System.currentTimeMillis()) } - var job by remember { mutableStateOf(null) } + var message by ui::message + var nextAttemptAt by ui::nextAttemptAt + var now by ui::now + var job by ui::job val scope = rememberCoroutineScope() val keyboard = LocalSoftwareKeyboardController.current val focus = LocalFocusManager.current @@ -190,24 +244,38 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea LaunchedEffect(restoreAttempt) { restoring = true try { + val opening = System.currentTimeMillis() val saved = withContext(Dispatchers.IO) { savedStore.load() } + android.util.Log.i("OrbitStartup", "saved sign-in readMs=${System.currentTimeMillis() - opening}") pendingSaved = saved if (saved?.identity?.token != null && session == null) { val slotTicket = sessionSlot.ticket() - val resumed = withContext(Dispatchers.IO) { - // The server this sign-in was saved with: always this workspace's own. - EmbyServer.origin = saved.origin - val active = EmbyClient(HttpsEmbyTransport(saved.identity.deviceId, saved.origin)).resume(saved) - if (!sessionSlot.attach(active, slotTicket)) { active.detach(); throw CancellationException() } - active + val started = System.currentTimeMillis() + // The channels' plans are on the box: read them while the server is asked about the sign-in, four at a time, + // so the guide is ready as soon as the server answers. A plan that can't be read leaves its channel on the loop. + val loops = saved.extra + listOfNotNull(saved.orbitOne, saved.afterDark, saved.toonami) + val reading = async(Dispatchers.IO) { + loops.chunked(((loops.size + 3) / 4).coerceAtLeast(1)).map { group -> async { group.mapNotNull { loop -> + try { scheduler.load(saved.identity.userId, loop) } catch (cancelled: CancellationException) { throw cancelled } catch (_: Exception) { null } + } } }.awaitAll().flatten() } + val resumed = try { + withContext(Dispatchers.IO) { + // The server this sign-in was saved with: always this workspace's own. + EmbyServer.origin = saved.origin + val active = EmbyClient(HttpsEmbyTransport(saved.identity.deviceId, saved.origin)).resume(saved) + if (!sessionSlot.attach(active, slotTicket)) { active.detach(); throw CancellationException() } + active + } + } catch (failure: Throwable) { reading.cancel(); throw failure } + val resumedMs = System.currentTimeMillis() - started // Read before the channels appear, so the guide never shows the loop for a moment first. // A problem here falls back to the loops. It must never count against the saved connection below. - scheduledChannels = try { - withContext(Dispatchers.IO) { - (saved.extra + listOfNotNull(saved.orbitOne, saved.afterDark, saved.toonami)).mapNotNull { loop -> scheduler.load(saved.identity.userId, loop)?.also { resumed.rememberScheduledItems(it.plan.entries.map { entry -> entry.media.item }) } }.associateBy { it.number } - } - } catch (cancelled: CancellationException) { throw cancelled } catch (_: Exception) { emptyMap() } + val plans = try { reading.await() } catch (cancelled: CancellationException) { throw cancelled } catch (_: Exception) { emptyList() } + // Every channel's items at once: adding them channel by channel copied the growing map each time. + resumed.rememberScheduledItems(plans.flatMap { it.plan.entries.map { entry -> entry.media.item } }) + scheduledChannels = plans.associateBy { it.number } + android.util.Log.i("OrbitStartup", "restore resumeMs=$resumedMs readyMs=${System.currentTimeMillis() - started} channels=${plans.size}") session = resumed; sample = resumed.sample; applyChoices(saved) saveTicket = savedStore.ticket() } else if (saved != null && session == null) message = "Sign in again to restore your saved channel choices." @@ -564,7 +632,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea finally { busy = false; savingSuggestions = false } } } - val channelMaker = session?.let { active -> ChannelMaker( + // Remembered, so the phone link isn't handed a new one on every redraw. + val channelMaker = remember(session, workspace) { session?.let { active -> ChannelMaker( suggest = { description, chosen, skipped -> withContext(Dispatchers.IO) { val wish = wishOf(description) val rows = catalogue.chairRows(wish.genres, wish.years, wish.type, if (wish.genres.isEmpty() && wish.years == null) description else null) @@ -580,7 +649,7 @@ 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." - }) } + }) } } // 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) { PhoneLink.handler = channelMaker?.let { m -> PhoneHandler(m, isOn = { n -> scheduledChannels.containsKey(n) }, watch = { n -> @@ -661,13 +730,63 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea }) return } + // The sign-in form is a composable of its own, so this screen's method stays small enough for the runtime to compile. + fun signIn() { + if (!ready) return + val loginName = username.trim() + val secret = password.text.toString() + val server = EmbyServer.normalise(serverText) + if (server == null) { message = "Enter your server's https:// address, like https://emby.example.com, or http:// with a home-network address."; return } + clearPassword(); keyboard?.hide(); focus.clearFocus() + closeSession() + val ticket = sessionSlot.ticket() + busyLabel = "Connecting…" + busy = true; message = null; sample = null + nextAttemptAt = System.currentTimeMillis() + 15_000 + job = scope.launch { + try { + var switched = false + val connected = withContext(Dispatchers.IO) { + // It must answer as an Emby server before the password goes anywhere. + EmbyClient(HttpsEmbyTransport(origin = server)).checkServer() + // Another server opens its own workspace; this one's data stays exactly where it is. + if (server != Workspaces.current(appContext).origin) { Workspaces.open(appContext, server); switched = true } + val opened = EmbyClient(HttpsEmbyTransport(origin = server)).connect(loginName, secret) + if (!sessionSlot.attach(opened, ticket)) { opened.close(); throw CancellationException() } + opened + } + val saved = if (switched) withContext(Dispatchers.IO) { runCatching { Workspaces.current(appContext).connection.load() }.getOrNull() }.also { pendingSaved = it } + else pendingSaved + if (saved != null && connected.matchesAccount(saved.identity)) { + connected.restoreRemembered(saved); applyChoices(saved) + } + session = connected; sample = connected.sample + saveTicket = Workspaces.current(appContext).connection.ticket() + } + catch (cancelled: CancellationException) { throw cancelled } + catch (failure: EmbyCheckException) { message = failure.message } + catch (_: Exception) { message = "Signing in couldn't finish. Try again later." } + finally { busy = false } + } + } + SignInForm(modifier, serverText, { serverText = it }, username, { username = it }, password, busy, restoring, ready, now < nextAttemptAt, message, + pendingSaved?.identity?.token != null, keyboard, focus, passwordFocus, submitFocus, ::signIn, { restoreAttempt++ }, { closeSession(signOut = true) }) + +} + +/** Signing in: the server's address, username and password, and what to do with them. */ +@Composable +private fun SignInForm(modifier: Modifier, serverText: String, onServer: (String) -> Unit, username: String, onUsername: (String) -> Unit, + password: TextFieldState, busy: Boolean, restoring: Boolean, ready: Boolean, waiting: Boolean, message: String?, hasSaved: Boolean, + keyboard: androidx.compose.ui.platform.SoftwareKeyboardController?, focus: androidx.compose.ui.focus.FocusManager, + passwordFocus: FocusRequester, submitFocus: FocusRequester, onSignIn: () -> Unit, onRetry: () -> Unit, onForget: () -> Unit) { Box(modifier.fillMaxSize(), contentAlignment = Alignment.Center) { Column(Modifier.width(460.dp).verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.spacedBy(8.dp)) { Text("Sign in to Emby or Jellyfin", color = Ink, fontSize = 26.sp, fontWeight = FontWeight.SemiBold) // The server's address (release essentials, 6 November 2026): typed in, HTTPS, or plain HTTP to a home server only. Text("Server address", color = Muted, fontSize = 14.sp) var serverFocused by remember { mutableStateOf(false) } - BasicTextField(value = serverText, onValueChange = { if (it.length <= 255) serverText = it.replace("\n", "").trim() }, + BasicTextField(value = serverText, onValueChange = { if (it.length <= 255) onServer(it.replace("\n", "").trim()) }, enabled = !busy && !restoring, singleLine = true, textStyle = TextStyle(color = Ink, fontSize = 18.sp), cursorBrush = SolidColor(Yellow), keyboardOptions = KeyboardOptions(autoCorrectEnabled = false, keyboardType = KeyboardType.Uri, imeAction = ImeAction.Next), @@ -687,7 +806,7 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea color = Yellow, fontSize = 11.sp) Text("Username", color = Muted, fontSize = 14.sp) var userFocused by remember { mutableStateOf(false) } - BasicTextField(value = username, onValueChange = { if (it.length <= 256) username = it.replace("\n", "") }, + BasicTextField(value = username, onValueChange = { if (it.length <= 256) onUsername(it.replace("\n", "")) }, enabled = !busy && !restoring, singleLine = true, textStyle = TextStyle(color = Ink, fontSize = 18.sp), cursorBrush = SolidColor(Yellow), keyboardOptions = KeyboardOptions(autoCorrectEnabled = false, imeAction = ImeAction.Next), @@ -717,51 +836,14 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea true } else false }.padding(12.dp)) - OrbitButton(if (busy) "Signing in…" else if (now < nextAttemptAt) "Wait before trying again" else "Sign in", - Modifier.fillMaxWidth().focusRequester(submitFocus), enabled = ready, onClick = { - if (!ready) return@OrbitButton - val loginName = username.trim() - val secret = password.text.toString() - val server = EmbyServer.normalise(serverText) - if (server == null) { message = "Enter your server's https:// address, like https://emby.example.com, or http:// with a home-network address."; return@OrbitButton } - clearPassword(); keyboard?.hide(); focus.clearFocus() - closeSession() - val ticket = sessionSlot.ticket() - busyLabel = "Connecting…" - busy = true; message = null; sample = null - nextAttemptAt = System.currentTimeMillis() + 15_000 - job = scope.launch { - try { - var switched = false - val connected = withContext(Dispatchers.IO) { - // It must answer as an Emby server before the password goes anywhere. - EmbyClient(HttpsEmbyTransport(origin = server)).checkServer() - // Another server opens its own workspace; this one's data stays exactly where it is. - if (server != Workspaces.current(appContext).origin) { Workspaces.open(appContext, server); switched = true } - val opened = EmbyClient(HttpsEmbyTransport(origin = server)).connect(loginName, secret) - if (!sessionSlot.attach(opened, ticket)) { opened.close(); throw CancellationException() } - opened - } - val saved = if (switched) withContext(Dispatchers.IO) { runCatching { Workspaces.current(appContext).connection.load() }.getOrNull() }.also { pendingSaved = it } - else pendingSaved - if (saved != null && connected.matchesAccount(saved.identity)) { - connected.restoreRemembered(saved); applyChoices(saved) - } - session = connected; sample = connected.sample - saveTicket = Workspaces.current(appContext).connection.ticket() - } - catch (cancelled: CancellationException) { throw cancelled } - catch (failure: EmbyCheckException) { message = failure.message } - catch (_: Exception) { message = "Signing in couldn't finish. Try again later." } - finally { busy = false } - } - }) + OrbitButton(if (busy) "Signing in…" else if (waiting) "Wait before trying again" else "Sign in", + Modifier.fillMaxWidth().focusRequester(submitFocus), enabled = ready, onClick = onSignIn) message?.let { Text(it, color = Yellow, fontSize = 14.sp, maxLines = 4) } if (restoring) Text("Restoring your saved connection…", color = Yellow, fontSize = 14.sp) - if (pendingSaved?.identity?.token != null) - OrbitButton("Try the saved connection again", Modifier.fillMaxWidth(), enabled = !restoring && !busy, onClick = { restoreAttempt++ }) - if (pendingSaved?.identity?.token != null) - OrbitButton("Forget the saved sign-in", Modifier.fillMaxWidth(), enabled = !restoring && !busy, onClick = { closeSession(signOut = true) }) + if (hasSaved) + OrbitButton("Try the saved connection again", Modifier.fillMaxWidth(), enabled = !restoring && !busy, onClick = onRetry) + if (hasSaved) + OrbitButton("Forget the saved sign-in", Modifier.fillMaxWidth(), enabled = !restoring && !busy, onClick = onForget) Text("Your password is never saved. This box only keeps a sign-in token, in encrypted storage.", color = Muted, fontSize = 12.sp) } } 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 5e75678f..bb9089d2 100644 --- a/android/app/src/main/java/tv/orbit/classic/MainActivity.kt +++ b/android/app/src/main/java/tv/orbit/classic/MainActivity.kt @@ -71,9 +71,9 @@ class MainActivity : ComponentActivity() { @Composable internal fun OrbitButton(label: String, modifier: Modifier = Modifier, selected: Boolean = false, - enabled: Boolean = true, onFocus: () -> Unit = {}, onClick: () -> Unit) { + enabled: Boolean = true, onFocus: () -> Unit = {}, centred: Boolean = false, onClick: () -> Unit) { var focused by remember { mutableStateOf(false) } - Box(modifier.onFocusChanged { focused = it.isFocused; if (it.isFocused) onFocus() } + Box(contentAlignment = if (centred) Alignment.Center else Alignment.TopStart, modifier = modifier.onFocusChanged { focused = it.isFocused; if (it.isFocused) onFocus() } .background(if (focused) Yellow else if (selected) Blue else Panel) .border(if (focused) 2.dp else 1.dp, if (focused) Ink else themed(Color(0xFF38629A)) { Blue }) .clickable(enabled = enabled, onClick = onClick).padding(horizontal = 14.dp, vertical = 8.dp)) { diff --git a/android/app/src/main/java/tv/orbit/classic/Onboarding.kt b/android/app/src/main/java/tv/orbit/classic/Onboarding.kt index 73ad840d..8915d346 100644 --- a/android/app/src/main/java/tv/orbit/classic/Onboarding.kt +++ b/android/app/src/main/java/tv/orbit/classic/Onboarding.kt @@ -151,7 +151,7 @@ private fun WelcomeStep(onNext: () -> Unit) { Text("Welcome to Orbit", color = Ink, fontFamily = Anton, fontSize = 40.sp) Text("Proper TV channels, made from your own films and series.", color = Muted, fontSize = 18.sp, modifier = Modifier.padding(top = 8.dp)) Text("It takes about five minutes. I'm Ollie, and I'll show you round.", color = Muted, fontSize = 16.sp) - OrbitButton("Let's go", Modifier.padding(top = 24.dp).width(200.dp).focusRequester(go), onClick = onNext) + OrbitButton("Let's go", Modifier.padding(top = 24.dp).width(200.dp).focusRequester(go), centred = true, onClick = onNext) } } @@ -164,7 +164,7 @@ private fun LookStep(onNext: () -> Unit) { Text("Choose your look", color = Ink, fontFamily = Anton, fontSize = 32.sp) Text(if (Onboarding.tour) "Try one: it goes back to yours when the tour ends." else "It changes straight away. You can change it any time in Settings › Look.", color = Muted, fontSize = 15.sp) LookPicker(first, cardWidth = 200.dp) - OrbitButton("Next", Modifier.padding(top = 6.dp).width(200.dp), onClick = onNext) + OrbitButton("Next", Modifier.padding(top = 6.dp).width(200.dp), centred = true, onClick = onNext) } } @@ -208,8 +208,8 @@ private fun TourSignedIn(onNext: () -> Unit) { LaunchedEffect(Unit) { go.requestFocus() } Column(Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) { Text("Sign in to your server", color = Ink, fontFamily = Anton, fontSize = 32.sp) - Text("A new box signs in here with an Emby account. This box is already signed in, so the tour moves on.", color = Muted, fontSize = 15.sp, modifier = Modifier.padding(8.dp)) - OrbitButton("Next", Modifier.width(200.dp).focusRequester(go), onClick = onNext) + Text("A new box signs in here with an Emby or Jellyfin account. This box is already signed in, so the tour moves on.", color = Muted, fontSize = 15.sp, modifier = Modifier.padding(8.dp)) + OrbitButton("Next", Modifier.width(200.dp).focusRequester(go), centred = true, onClick = onNext) } } @@ -221,10 +221,15 @@ private fun ChannelsStep(onNext: () -> Unit) { // nothing is saved, so its last step only says what would have happened. var creating by remember { mutableStateOf(false) } var made by remember { mutableStateOf(null) } - val maker = PhoneLink.handler?.maker?.let { real -> if (!Onboarding.tour) real else ChannelMaker(real.suggest, real.search, - { c, _ -> "This is a tour, so nothing was saved: ${c.name} would be ready on ${c.number}." }, real.showsOf) } + val real = PhoneLink.handler?.maker + val maker = remember(real, Onboarding.tour) { real?.let { r -> if (!Onboarding.tour) r else ChannelMaker(r.suggest, r.search, + { c, _ -> "This is a tour, so nothing was saved: ${c.name} would be ready on ${c.number}." }, r.showsOf) } } if (!setting && creating && maker != null) { - CreateChannelFlow(maker, null, { result -> made = result; creating = false }, Modifier.fillMaxSize(), phone = !Onboarding.tour) + // In the tour a phone makes its channel the tour's way too: nothing saved, and it can't change channel. + if (Onboarding.tour) DisposableEffect(maker) { + PhoneLink.standIn = PhoneHandler(maker, isOn = { false }, watch = {}); onDispose { PhoneLink.standIn = null } + } + CreateChannelFlow(maker, null, { result -> made = result; creating = false }, Modifier.fillMaxSize()) return } if (!setting) { @@ -280,7 +285,7 @@ private fun ChannelsStep(onNext: () -> Unit) { val now = System.currentTimeMillis() Text(if (ChannelSetup.finished) "${ChannelSetup.found.values.filter { it > 0 }.sum()} titles across ${ChannelSetup.found.count { it.value > 0 }} channels" else "${ChannelSetup.found.size} of ${ChannelSetup.wanted.size} channels · about ${ChannelSetup.minutesLeft(now + t * 0)} min left", color = Yellow, fontSize = 14.sp, textAlign = TextAlign.Center) - if (ChannelSetup.finished) OrbitButton("Next", Modifier.padding(top = 16.dp).width(180.dp).focusRequester(go), onClick = onNext) + if (ChannelSetup.finished) OrbitButton("Next", Modifier.padding(top = 16.dp).width(180.dp).focusRequester(go), centred = true, onClick = onNext) } Column(Modifier.weight(1f).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(5.dp)) { Text("Here's where everything goes", color = Ink, fontFamily = Anton, fontSize = 26.sp) @@ -339,7 +344,7 @@ private fun WhoWatchesStep(onNext: () -> Unit) { } } note?.let { Text(it, color = Yellow, fontSize = 14.sp) } - OrbitButton("Next", Modifier.padding(top = 8.dp).width(200.dp), onClick = onNext) + OrbitButton("Next", Modifier.padding(top = 8.dp).width(200.dp), centred = true, onClick = onNext) Text("You can skip this: with no PIN, Adult opens without one. Change both in Settings › Profiles.", color = Muted, fontSize = 12.sp) } } @@ -374,7 +379,7 @@ private fun AllSetStep(onStart: () -> Unit) { Column(Modifier.align(Alignment.BottomCenter).padding(bottom = 30.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(10.dp)) { Text("You're on air", color = Ink, fontFamily = Anton, fontSize = 44.sp) Text(if (count > 0) "$count channels are planning their first week. The Drive-In opens on Friday." else "Your channels are ready.", color = Muted, fontSize = 16.sp) - OrbitButton("Start watching", Modifier.width(240.dp).focusRequester(go), onClick = onStart) + OrbitButton("Start watching", Modifier.width(240.dp).focusRequester(go), centred = true, onClick = onStart) } } } 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 83dbeb1d..0d5c06ed 100644 --- a/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt +++ b/android/app/src/main/java/tv/orbit/classic/PhoneLink.kt @@ -61,6 +61,8 @@ internal object PhoneLink { @Volatile private var server: ServerSocket? = null private val workers = Executors.newFixedThreadPool(4) @Volatile var handler: PhoneHandler? = null + /** Put in front of [handler] for a while: the Welcome Tour's, which saves nothing. */ + @Volatile var standIn: PhoneHandler? = null var pairing by mutableStateOf(null) private set /** The phone that last did something, for the TV to say so. */ @@ -236,7 +238,7 @@ internal object PhoneLink { if (o.isNull("year")) null else o.optInt("year"), o.optString("type").takeIf { it == "Movie" || it == "Series" } ?: "Series", "", "Chosen for your channel") private fun api(r: Request, out: OutputStream, phone: String) { - val h = handler ?: return json(out, 403, JSONObject().put("error", "The TV isn't signed in to a library right now.")) + val h = standIn ?: handler ?: return json(out, 403, JSONObject().put("error", "The TV isn't signed in to a library right now.")) active = prefs().get(phone)?.substringBefore('|') when ("${r.method} ${r.path}") { "GET /api/channels" -> json(out, 200, JSONObject().put("next", CustomChannels.nextNumber() ?: JSONObject.NULL).put("channels", JSONArray(CustomChannels.list.map { c -> diff --git a/android/app/src/main/java/tv/orbit/classic/Profiles.kt b/android/app/src/main/java/tv/orbit/classic/Profiles.kt index ac88a12c..da61a44e 100644 --- a/android/app/src/main/java/tv/orbit/classic/Profiles.kt +++ b/android/app/src/main/java/tv/orbit/classic/Profiles.kt @@ -174,7 +174,9 @@ internal fun WhosWatching(onClose: () -> Unit) { // Kids first, so a child's OK goes straight to their own. Profiles.all.sortedBy { if (it.kind == ProfileKind.Kids) 0 else 1 }.forEachIndexed { i, p -> var focused by remember { mutableStateOf(false) } - Column(Modifier.then(if (i == 0) Modifier.focusRequester(first) else Modifier).onFocusChanged { focused = it.isFocused }.clickable { choose(p) }, + Column(Modifier.then(if (i == 0) Modifier.focusRequester(first) else Modifier).onFocusChanged { focused = it.isFocused } + // No grey focus box behind the picture (Paul, 6 November 2026): the gold ring and name say it's chosen. + .clickable(remember { androidx.compose.foundation.interaction.MutableInteractionSource() }, indication = null) { choose(p) }, horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(10.dp)) { Box { ProfileAvatar(p.picture, 132.dp, ringed = focused)