Snappier: the connection screen split so the runtime compiles it; faster restore; tour and welcome polish (0.108.50)
- EmbyConnectionScreen was 16,995 instructions, over ART's compile limit, so it ran interpreted on every redraw. Its state now lives in one ConnectionUi holder and the sign-in form is its own composable: 7,152. - Restore reads the channels' plans four at a time while the server is asked about the sign-in, and adds their items in one go. Startup timings logged (milliseconds only). - The Create your own maker is remembered, so the phone link isn't reset on every redraw. - Welcome buttons centred; the tour's sign-in names Jellyfin; the tour offers the phone, which saves nothing there; Who's watching has no grey focus box. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,8 +9,8 @@ android {
|
||||
applicationId = "tv.orbit.classic"
|
||||
minSdk = 26
|
||||
targetSdk = 36
|
||||
versionCode = 209
|
||||
versionName = "0.108.49-phonecard"
|
||||
versionCode = 210
|
||||
versionName = "0.108.50-snappier"
|
||||
}
|
||||
buildFeatures { compose = true }
|
||||
// Android logging and the like do nothing in unit tests, so whole flows (a channel read from a fake server) can run.
|
||||
|
||||
@@ -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.49\"") +
|
||||
ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.50\"") +
|
||||
(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.49\"" +
|
||||
ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.50\"" +
|
||||
(token?.let { ", Token=\"$it\"" } ?: ""))
|
||||
}
|
||||
/** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */
|
||||
|
||||
@@ -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<RememberedState?>(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<List<SeriesMatches>?>(null)
|
||||
var episodeSamples by mutableStateOf<List<SeriesEpisodes>?>(null)
|
||||
var approvedSeries by mutableStateOf<Set<String>>(emptySet())
|
||||
var sample by mutableStateOf<EmbySample?>(null)
|
||||
var session by mutableStateOf<EmbySampleSession?>(null)
|
||||
var darkMovies by mutableStateOf<List<AfterDarkMovie>>(emptyList())
|
||||
var approvedDark by mutableStateOf<Set<String>>(emptySet())
|
||||
var lastNumber by mutableStateOf<Int?>(null)
|
||||
var afterDarkChannel by mutableStateOf<SampleChannel?>(null)
|
||||
var toonamiChannel by mutableStateOf<SampleChannel?>(null)
|
||||
var extraChannels by mutableStateOf<List<SampleChannel>>(emptyList())
|
||||
var selectedNumber by mutableIntStateOf(101)
|
||||
var channel by mutableStateOf<SampleChannel?>(null)
|
||||
var watchingChannel by mutableStateOf(false)
|
||||
var watchingDriveIn by mutableStateOf(false)
|
||||
var driveInPlan by mutableStateOf<ChannelPlan?>(null)
|
||||
var tickets by mutableStateOf<Map<Long, Int>>(emptyMap())
|
||||
var pendingDriveInWatch by mutableStateOf(false)
|
||||
var reminder by mutableStateOf<DriveInReminder?>(null)
|
||||
var reminders by mutableStateOf<List<ProgrammeReminder>>(emptyList())
|
||||
var programmeReminder by mutableStateOf<ProgrammeReminder?>(null)
|
||||
var windingDown by mutableStateOf(false)
|
||||
var catchUpOpen by mutableStateOf<CatchUpEntry?>(null)
|
||||
var driveInVisits by mutableIntStateOf((System.currentTimeMillis() / 60_000 % DRIVE_IN_SCENES).toInt())
|
||||
var guideCategory by mutableStateOf(ChannelCategory.All)
|
||||
var scheduledChannels by mutableStateOf<Map<Int, ScheduledChannel>>(emptyMap())
|
||||
var suggesting by mutableStateOf<ChannelProgramming?>(null)
|
||||
var suggestions by mutableStateOf<List<Suggestion>>(emptyList())
|
||||
var settingsSection by mutableStateOf(SettingsSection.Channels)
|
||||
var savingSuggestions by mutableStateOf(false)
|
||||
var tickedSuggestions by mutableStateOf<Set<String>>(emptySet())
|
||||
var lastSmartPress by mutableLongStateOf(0L)
|
||||
var channelClockOffset by mutableLongStateOf(0)
|
||||
var busyLabel by mutableStateOf("Connecting…")
|
||||
var message by mutableStateOf<String?>(null)
|
||||
var nextAttemptAt by mutableLongStateOf(0)
|
||||
var now by mutableLongStateOf(System.currentTimeMillis())
|
||||
var job by mutableStateOf<Job?>(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<RememberedState?>(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<List<SeriesMatches>?>(null) }
|
||||
var episodeSamples by remember { mutableStateOf<List<SeriesEpisodes>?>(null) }
|
||||
var approvedSeries by remember { mutableStateOf<Set<String>>(emptySet()) }
|
||||
var sample by remember { mutableStateOf<EmbySample?>(null) }
|
||||
var session by remember { mutableStateOf<EmbySampleSession?>(null) }
|
||||
var darkMovies by remember { mutableStateOf<List<AfterDarkMovie>>(emptyList()) }
|
||||
var approvedDark by remember { mutableStateOf<Set<String>>(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<Int?>(null) }
|
||||
var afterDarkChannel by remember { mutableStateOf<SampleChannel?>(null) }
|
||||
var toonamiChannel by remember { mutableStateOf<SampleChannel?>(null) }
|
||||
var extraChannels by remember { mutableStateOf<List<SampleChannel>>(emptyList()) }
|
||||
var selectedNumber by remember { mutableIntStateOf(101) }
|
||||
var channel by remember { mutableStateOf<SampleChannel?>(null) }
|
||||
var watchingChannel by remember { mutableStateOf(false) }
|
||||
var watchingDriveIn by remember { mutableStateOf(false) }
|
||||
var driveInPlan by remember { mutableStateOf<ChannelPlan?>(null) }
|
||||
var tickets by remember { mutableStateOf<Map<Long, Int>>(emptyMap()) }
|
||||
var pendingDriveInWatch by remember { mutableStateOf(false) }
|
||||
var reminder by remember { mutableStateOf<DriveInReminder?>(null) }
|
||||
var reminders by remember { mutableStateOf<List<ProgrammeReminder>>(emptyList()) }
|
||||
var programmeReminder by remember { mutableStateOf<ProgrammeReminder?>(null) }
|
||||
var windingDown by remember { mutableStateOf(false) }
|
||||
var catchUpOpen by remember { mutableStateOf<CatchUpEntry?>(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<Map<Int, ScheduledChannel>>(emptyMap()) }
|
||||
var suggesting by remember { mutableStateOf<ChannelProgramming?>(null) }
|
||||
var suggestions by remember { mutableStateOf<List<Suggestion>>(emptyList()) }
|
||||
var settingsSection by remember { mutableStateOf(SettingsSection.Channels) }
|
||||
var savingSuggestions by remember { mutableStateOf(false) }
|
||||
var tickedSuggestions by remember { mutableStateOf<Set<String>>(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<String?>(null) }
|
||||
var nextAttemptAt by remember { mutableLongStateOf(0) }
|
||||
var now by remember { mutableLongStateOf(System.currentTimeMillis()) }
|
||||
var job by remember { mutableStateOf<Job?>(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 ->
|
||||
@@ -654,13 +723,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),
|
||||
@@ -680,7 +799,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),
|
||||
@@ -710,51 +829,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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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<String?>(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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Pairing?>(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 ->
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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.49")
|
||||
next.setRequestProperty("User-Agent", "OrbitTV/0.108.50")
|
||||
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()) {
|
||||
|
||||
Reference in New Issue
Block a user