From f28c4977dde98bc8b07576c29eb7762d8ad87d67 Mon Sep 17 00:00:00 2001 From: Pauljd Date: Sat, 7 Nov 2026 20:00:13 +0000 Subject: [PATCH] Family v2: profiles for everyone, a four-step add, a page per person, Kids channels full screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Settings › Family now shows everyone with Add someone; each person can be renamed, given a picture, switched between Adult and Kids, have Personalise turned off or what Orbit has learnt cleared, or be removed (their Continue watching and Taste go with them; the last grown-up stays). Kids channels open full screen with big tiles. Who's watching asks whenever more than one grown-up has a profile. 0.108.98. Co-Authored-By: Claude Opus 5.5 --- android/app/build.gradle.kts | 4 +- .../main/java/tv/orbit/classic/EmbyClient.kt | 4 +- .../java/tv/orbit/classic/FamilySettings.kt | 348 ++++++++++++++++++ .../java/tv/orbit/classic/MainActivity.kt | 6 +- .../main/java/tv/orbit/classic/Profiles.kt | 101 ++--- .../tv/orbit/classic/SecureMediaDataSource.kt | 2 +- .../main/java/tv/orbit/classic/Settings.kt | 7 +- .../test/java/tv/orbit/classic/FamilyTest.kt | 51 +++ 8 files changed, 442 insertions(+), 81 deletions(-) create mode 100644 android/app/src/main/java/tv/orbit/classic/FamilySettings.kt create mode 100644 android/app/src/test/java/tv/orbit/classic/FamilyTest.kt diff --git a/android/app/build.gradle.kts b/android/app/build.gradle.kts index 360d06c5..13f94c5c 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 = 257 - versionName = "0.108.97-taste-signals" + versionCode = 258 + versionName = "0.108.98-family-v2" } buildFeatures { compose = true } // The finished build for the TVs (Paul, 6 November 2026: the test build stuttered on the box). Not debuggable, so 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 17ab5258..0c1efe34 100644 --- a/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt +++ b/android/app/src/main/java/tv/orbit/classic/EmbyClient.kt @@ -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 = when (kind) { - ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.97\"") + + ServerKind.Emby -> mapOf("X-Emby-Authorization" to "Emby Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.98\"") + (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.97\"" + + ServerKind.Jellyfin -> mapOf("Authorization" to "MediaBrowser Client=\"Orbit TV\", Device=\"Orbit TV\", DeviceId=\"$deviceId\", Version=\"0.108.98\"" + (token?.let { ", Token=\"$it\"" } ?: "")) } /** One picture from the provider, or nothing. Same fixed origin and no redirects, and failures are never shown or logged. */ diff --git a/android/app/src/main/java/tv/orbit/classic/FamilySettings.kt b/android/app/src/main/java/tv/orbit/classic/FamilySettings.kt new file mode 100644 index 00000000..ce64a2ec --- /dev/null +++ b/android/app/src/main/java/tv/orbit/classic/FamilySettings.kt @@ -0,0 +1,348 @@ +package tv.orbit.classic + +import androidx.activity.compose.BackHandler +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.grid.GridCells +import androidx.compose.foundation.lazy.grid.LazyVerticalGrid +import androidx.compose.foundation.lazy.grid.items +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.focus.FocusRequester +import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.focus.onFocusChanged +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.compose.ui.window.Dialog +import androidx.compose.ui.window.DialogProperties +import androidx.tv.material3.Text +import java.io.File + +/** + * Settings › Family v2 (Paul, 7 November 2026; design/profiles/v2): everyone at a glance with Add someone, a four-step add, + * one person's page (rename, picture, Adult or Kids, Personalise, what Orbit has learnt, remove) and Kids' channels full + * screen. Adult and Kids are access classes; each person keeps their own Continue watching and Taste. + */ +private sealed interface FamilyPage { + object Home : FamilyPage + class Person(val id: String) : FamilyPage + class Add(val step: Int, val name: String, val kind: ProfileKind, val picture: String) : FamilyPage + class Picture(val id: String) : FamilyPage + object Lock : FamilyPage +} + +/** A profile's own data on this box: its Continue watching and its Taste files. Cleared when it's removed. */ +internal fun forgetProfileData(scheduleDir: File, id: String) { + File(scheduleDir, "continue-${id.filter { it.isLetterOrDigit() }.take(40)}.json").delete() + val safe = id.filter { it.isLetterOrDigit() || it == '-' || it == '_' }.take(40) + File(scheduleDir, "taste").listFiles { f -> f.name.startsWith("$safe.") }?.forEach { it.delete() } +} + +@Composable +internal fun FamilySettings(firstSwitch: FocusRequester, bedtime: @Composable () -> Unit, modifier: Modifier) { + var page by remember { mutableStateOf(FamilyPage.Home) } + var kidsChannelsFor by remember { mutableStateOf(null) } + when (val p = page) { + FamilyPage.Home -> FamilyHome(firstSwitch, onOpen = { page = FamilyPage.Person(it) }, + onAdd = { page = FamilyPage.Add(0, "", ProfileKind.Grown, "sil-pink") }, onLock = { page = FamilyPage.Lock }, bedtime, modifier) + is FamilyPage.Person -> PersonPage(p.id, onBack = { page = FamilyPage.Home }, onPicture = { page = FamilyPage.Picture(p.id) }, onChannels = { kidsChannelsFor = p.id }, modifier) + is FamilyPage.Add -> AddSomeone(p, onStep = { page = it }, onDone = { id -> page = FamilyPage.Person(id) }, onCancel = { page = FamilyPage.Home }, onChannels = { kidsChannelsFor = it }, modifier) + is FamilyPage.Picture -> PicturePicker(p.id, onDone = { page = FamilyPage.Person(p.id) }, modifier) + FamilyPage.Lock -> Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) { + BackHandler { page = FamilyPage.Home } + LockDetail(firstSwitch, Modifier.fillMaxWidth()) + } + } + kidsChannelsFor?.let { id -> KidsChannels(id, onDone = { kidsChannelsFor = null }) } +} + +@Composable +private fun FamilyHome(firstSwitch: FocusRequester, onOpen: (String) -> Unit, onAdd: () -> Unit, onLock: () -> Unit, bedtime: @Composable () -> Unit, modifier: Modifier) { + Column(modifier, verticalArrangement = Arrangement.spacedBy(10.dp)) { + Text("WHO WATCHES", color = Muted, fontSize = 11.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.sp) + Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) { + Profiles.all.forEachIndexed { i, p -> PersonCard(p, if (i == 0) Modifier.focusRequester(firstSwitch) else Modifier) { onOpen(p.id) } } + if (Profiles.all.size < MAX_PROFILES) AddCard(onAdd) + } + Text("Everyone gets their own Continue watching and picks. Channels, schedules and the Drive-In stay shared.", color = Muted, fontSize = 12.sp) + Text("FOR THE WHOLE HOUSE", color = Muted, fontSize = 11.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.sp, modifier = Modifier.padding(top = 6.dp)) + HouseRow("PIN and After Dark", when { !AfterDarkLock.pinSet -> "No PIN set"; AfterDarkLock.unlocked -> "Unlocked until you lock it"; else -> "Locked" } + + if (AfterDarkLock.nightly) " · locks nightly at 3am" else "", onLock) + bedtime() + } +} + +/** At most this many profiles, so Who's watching fits the screen. */ +internal const val MAX_PROFILES = 6 + +@Composable +private fun PersonCard(p: Profile, modifier: Modifier, onClick: () -> Unit) { + var focused by remember { mutableStateOf(false) } + val corner = RoundedCornerShape(12.dp) + Column(modifier.width(118.dp).onFocusChanged { focused = it.isFocused }.background(if (focused) Navy else Panel, corner) + .border(if (focused) 3.dp else 0.dp, if (focused) Yellow else Color.Transparent, corner).clickable(onClick = onClick).padding(vertical = 10.dp), + horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(4.dp)) { + ProfileAvatar(p.picture, 58.dp) + Text(p.name, color = Ink, fontSize = 15.sp, fontWeight = FontWeight.SemiBold, maxLines = 1, overflow = TextOverflow.Ellipsis) + ClassChip(p.kind) + Text(if (p.kind == ProfileKind.Kids) "${p.channels.size} channels" else if (Taste.store?.state(p)?.personalise != false) "Personalise on" else "Personalise off", + color = Muted, fontSize = 11.sp, maxLines = 1) + } +} + +@Composable +private fun ClassChip(kind: ProfileKind) = Text(if (kind == ProfileKind.Kids) "Kids" else "Adult", + Modifier.background(if (kind == ProfileKind.Kids) Yellow else themed(Color(0xFF6EDCAA)) { Mint }, RoundedCornerShape(10.dp)).padding(horizontal = 10.dp, vertical = 1.dp), + color = OnAccent, fontSize = 11.sp, fontWeight = FontWeight.Bold) + +@Composable +private fun AddCard(onAdd: () -> Unit) { + var focused by remember { mutableStateOf(false) } + val corner = RoundedCornerShape(12.dp) + Column(Modifier.width(118.dp).height(150.dp).onFocusChanged { focused = it.isFocused }.background(if (focused) Navy else Color.Transparent, corner) + .border(2.dp, Yellow, corner).clickable(onClick = onAdd).padding(8.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) { + Text("+", color = Yellow, fontSize = 40.sp) + Text("Add someone", color = Yellow, fontSize = 14.sp, fontWeight = FontWeight.SemiBold) + Text("Adult or Kids", color = Muted, fontSize = 11.sp) + } +} + +@Composable +private fun HouseRow(title: String, detail: String, onClick: () -> Unit) { + var focused by remember { mutableStateOf(false) } + val corner = RoundedCornerShape(8.dp) + Row(Modifier.fillMaxWidth().onFocusChanged { focused = it.isFocused }.background(if (focused) Navy else Panel, corner) + .border(if (focused) 3.dp else 0.dp, if (focused) Yellow else Color.Transparent, corner).clickable(onClick = onClick).padding(horizontal = 12.dp, vertical = 8.dp), + verticalAlignment = Alignment.CenterVertically) { + Column(Modifier.weight(1f)) { + Text(title, color = Ink, fontSize = 15.sp, fontWeight = FontWeight.SemiBold) + Text(detail, color = Muted, fontSize = 12.sp, maxLines = 1) + } + Text("›", color = Muted, fontSize = 20.sp) + } +} + +/** One person's page: everything about them in one list. */ +@Composable +private fun PersonPage(id: String, onBack: () -> Unit, onPicture: () -> Unit, onChannels: () -> Unit, modifier: Modifier) { + val context = LocalContext.current + val p = Profiles.all.firstOrNull { it.id == id } ?: run { LaunchedEffect(Unit) { onBack() }; return } + var renaming by remember { mutableStateOf(false) } + var removing by remember { mutableStateOf(false) } + var clearing by remember { mutableStateOf(false) } + var note by remember { mutableStateOf(null) } + val first = remember { FocusRequester() } + LaunchedEffect(id) { runCatching { first.requestFocus() } } + BackHandler { onBack() } + val taste = Taste.store + val state = remember(id, note) { taste?.state(p) } + val learnt = remember(id, note) { taste?.events(p.id)?.size ?: 0 } + val lastGrown = p.kind == ProfileKind.Grown && Profiles.all.count { it.kind == ProfileKind.Grown } == 1 + Row(modifier, horizontalArrangement = Arrangement.spacedBy(16.dp)) { + Column(Modifier.width(170.dp), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(6.dp)) { + ProfileAvatar(p.picture, 96.dp) + Text(p.name, color = Ink, fontFamily = Anton, fontSize = 24.sp, maxLines = 1, overflow = TextOverflow.Ellipsis) + ClassChip(p.kind) + note?.let { Text(it, color = Yellow, fontSize = 12.sp) } + } + Column(Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(6.dp)) { + if (renaming) NameField(p.name, onDone = { Profiles.update(context, p.copy(name = cleanProfileName(it))); renaming = false; note = "Renamed." }, onCancel = { renaming = false }) + else PersonRow("Name", p.name, "Rename", Modifier.focusRequester(first)) { renaming = true } + PersonRow("Picture", pictureName(p.picture), "Change") { onPicture() } + PersonRow("Profile type", if (p.kind == ProfileKind.Kids) "Kids: only the channels ticked for it" else "Adult: everything, After Dark behind the PIN", + if (lastGrown) "Needed" else "Change") { + if (!lastGrown) { Profiles.update(context, p.asKind(if (p.kind == ProfileKind.Kids) ProfileKind.Grown else ProfileKind.Kids)); note = "Now ${if (p.kind == ProfileKind.Kids) "Adult" else "Kids"}." } + else note = "Someone has to stay Adult." + } + if (p.kind == ProfileKind.Kids) { + PersonRow("Channels", "${p.channels.size} ticked", "Choose") { onChannels() } + PersonRow("Arcade", if (p.arcade) "On: the games chosen for Kids" else "Off", if (p.arcade) "Turn off" else "Turn on") { + Profiles.update(context, p.copy(arcade = !p.arcade)) } + PersonRow("Drive-In", if (p.driveIn) "Family showings only, never The Late Show" else "Off", if (p.driveIn) "Turn off" else "Turn on") { + Profiles.update(context, p.copy(driveIn = !p.driveIn)) } + } + if (taste != null && state != null) { + PersonRow("Personalise", if (state.personalise) "On: Orbit learns from what ${p.name} watches" else "Off: nothing is noted", if (state.personalise) "Turn off" else "Turn on") { + taste.saveState(p, TasteState(!state.personalise, state.suppressions, state.resetAtMs)); note = if (state.personalise) "Personalise off." else "Personalise on." } + if (clearing) ConfirmRow("Clear what Orbit has learnt for ${p.name}?", "Yes, clear it", onYes = { taste.reset(p, System.currentTimeMillis()); clearing = false; note = "Cleared." }, onNo = { clearing = false }) + else PersonRow("What Orbit has learnt", if (learnt == 0) "Nothing yet" else "$learnt programmes noted", "Clear") { clearing = true } + } + if (removing) ConfirmRow("Remove ${p.name}? Their Continue watching and picks go too. Channels and schedules stay.", "Remove", onYes = { + if (Profiles.remove(context, p.id)) { runCatching { forgetProfileData(Workspaces.current(context).scheduleDir, p.id) }; onBack() } else { removing = false; note = "Someone has to stay Adult." } + }, onNo = { removing = false }) + else if (!lastGrown) OrbitButton("Remove this profile", onClick = { removing = true }) + } + } +} + +@Composable +private fun PersonRow(title: String, detail: String, action: String, modifier: Modifier = Modifier, onClick: () -> Unit) { + Row(Modifier.fillMaxWidth().background(Panel, RoundedCornerShape(8.dp)).padding(horizontal = 12.dp, vertical = 6.dp), verticalAlignment = Alignment.CenterVertically) { + Column(Modifier.weight(1f)) { + Text(title, color = Ink, fontSize = 15.sp, fontWeight = FontWeight.SemiBold) + Text(detail, color = Muted, fontSize = 12.sp, maxLines = 1, overflow = TextOverflow.Ellipsis) + } + OrbitButton(action, modifier.width(130.dp), onClick = onClick) + } +} + +@Composable +private fun ConfirmRow(question: String, yes: String, onYes: () -> Unit, onNo: () -> Unit) { + val keep = remember { FocusRequester() } + LaunchedEffect(Unit) { runCatching { keep.requestFocus() } } + BackHandler { onNo() } + Column(Modifier.fillMaxWidth().background(Deep, RoundedCornerShape(8.dp)).border(2.dp, Yellow, RoundedCornerShape(8.dp)).padding(12.dp), verticalArrangement = Arrangement.spacedBy(8.dp)) { + Text(question, color = Ink, fontSize = 14.sp) + Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + OrbitButton("Keep it", Modifier.focusRequester(keep), onClick = onNo) + OrbitButton(yes, onClick = onYes) + } + } +} + +@Composable +private fun NameField(current: String, onDone: (String) -> Unit, onCancel: () -> Unit) { + var text by remember { mutableStateOf(current) } + val field = remember { FocusRequester() } + LaunchedEffect(Unit) { runCatching { field.requestFocus() } } + BackHandler { onCancel() } + Row(Modifier.fillMaxWidth().background(Deep, RoundedCornerShape(8.dp)).padding(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) { + OrbitField(text, { text = it.take(20) }, "Their name", Modifier.weight(1f).focusRequester(field)) + OrbitButton("Done", onClick = { if (text.isNotBlank()) onDone(text) }) + } +} + +/** Add someone: name, Adult or Kids, picture, then (Kids) channels. Nothing is saved until the picture step. */ +@Composable +private fun AddSomeone(a: FamilyPage.Add, onStep: (FamilyPage.Add) -> Unit, onDone: (String) -> Unit, onCancel: () -> Unit, onChannels: (String) -> Unit, modifier: Modifier) { + val context = LocalContext.current + val steps = listOf("Name", "Adult or Kids", "Picture", "Channels") + BackHandler { if (a.step == 0) onCancel() else onStep(FamilyPage.Add(a.step - 1, a.name, a.kind, a.picture)) } + Column(modifier, verticalArrangement = Arrangement.spacedBy(10.dp)) { + Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) { + steps.forEachIndexed { i, s -> + if (i == 3 && a.kind != ProfileKind.Kids) return@forEachIndexed + Column(Modifier.weight(1f)) { + Box(Modifier.fillMaxWidth().height(4.dp).background(if (i <= a.step) Yellow else Panel, RoundedCornerShape(2.dp))) + Text("${i + 1} $s", color = if (i == a.step) Ink else Muted, fontSize = 12.sp, fontWeight = if (i == a.step) FontWeight.SemiBold else FontWeight.Normal) + } + } + } + when (a.step) { + 0 -> { + Text("What's their name?", color = Ink, fontFamily = Anton, fontSize = 26.sp) + Text("As it shows on Who's watching. You can change it later.", color = Muted, fontSize = 13.sp) + NameField(a.name, onDone = { onStep(FamilyPage.Add(1, cleanProfileName(it), a.kind, a.picture)) }, onCancel = onCancel) + } + 1 -> { + Text("Who's this profile for?", color = Ink, fontFamily = Anton, fontSize = 26.sp) + Text("${a.name}. You can change it later; Kids profiles always keep their limits.", color = Muted, fontSize = 13.sp) + val first = remember { FocusRequester() } + LaunchedEffect(Unit) { runCatching { first.requestFocus() } } + Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) { + KindChoice("Adult", listOf("Own Continue watching and picks", "Personalise on, can be turned off", "After Dark behind the PIN"), Modifier.weight(1f).focusRequester(first)) { + onStep(FamilyPage.Add(2, a.name, ProfileKind.Grown, a.picture)) } + KindChoice("Kids", listOf("Starts with Orbit's kids channels", "Never After Dark or The Late Show", "Leaving Kids needs the PIN"), Modifier.weight(1f)) { + onStep(FamilyPage.Add(2, a.name, ProfileKind.Kids, "ollie")) } + } + } + else -> { + Text("Choose a picture for ${a.name}", color = Ink, fontFamily = Anton, fontSize = 26.sp) + PictureGrid(a.picture, Modifier.weight(1f)) { pic -> + val made = Profiles.add(context, a.name, a.kind, pic) + if (made.kind == ProfileKind.Kids) onChannels(made.id) + onDone(made.id) + } + } + } + } +} + +@Composable +private fun KindChoice(title: String, lines: List, modifier: Modifier, onClick: () -> Unit) { + var focused by remember { mutableStateOf(false) } + val corner = RoundedCornerShape(12.dp) + Column(modifier.onFocusChanged { focused = it.isFocused }.background(if (focused) Navy else Panel, corner) + .border(if (focused) 3.dp else 0.dp, if (focused) Yellow else Color.Transparent, corner).clickable(onClick = onClick).padding(16.dp), verticalArrangement = Arrangement.spacedBy(6.dp)) { + Text(title, color = Ink, fontFamily = Anton, fontSize = 24.sp) + lines.forEach { Text("✓ $it", color = Ink, fontSize = 13.sp) } + } +} + +@Composable +private fun PicturePicker(id: String, onDone: () -> Unit, modifier: Modifier) { + val context = LocalContext.current + val p = Profiles.all.firstOrNull { it.id == id } ?: run { LaunchedEffect(Unit) { onDone() }; return } + BackHandler { onDone() } + Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) { + Text("Choose a picture for ${p.name}", color = Yellow, fontFamily = Anton, fontSize = 22.sp) + PictureGrid(p.picture, Modifier.weight(1f)) { pic -> Profiles.update(context, p.copy(picture = pic)); onDone() } + } +} + +@Composable +private fun PictureGrid(current: String, modifier: Modifier, onPick: (String) -> Unit) { + val first = remember { FocusRequester() } + LaunchedEffect(Unit) { runCatching { first.requestFocus() } } + LazyVerticalGrid(GridCells.Fixed(6), modifier, verticalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) { + items(ProfilePictures) { pic -> + var focused by remember { mutableStateOf(false) } + Column(Modifier.then(if (pic == current) Modifier.focusRequester(first) else Modifier).onFocusChanged { focused = it.isFocused }.clickable { onPick(pic) }, + horizontalAlignment = Alignment.CenterHorizontally) { + ProfileAvatar(pic, 60.dp, ringed = focused) + Text(pictureName(pic) + if (pic == current) " (now)" else "", color = if (focused) Yellow else Ink, fontSize = 11.sp, maxLines = 1) + } + } + } +} + +/** What a Kids profile can watch, full screen with big logo tiles. Saved as you go. */ +@Composable +private fun KidsChannels(id: String, onDone: () -> Unit) { + val context = LocalContext.current + Dialog(onDismissRequest = onDone, properties = DialogProperties(usePlatformDefaultWidth = false)) { + val p = Profiles.all.firstOrNull { it.id == id && it.kind == ProfileKind.Kids } ?: run { LaunchedEffect(Unit) { onDone() }; return@Dialog } + val channels = SmartChannels.sortedBy { it.number }.filter { it.number !in LockedChannels } + val first = remember { FocusRequester() } + LaunchedEffect(Unit) { runCatching { first.requestFocus() } } + Column(Modifier.fillMaxSize().background(Navy).padding(horizontal = 40.dp, vertical = 24.dp), verticalArrangement = Arrangement.spacedBy(10.dp)) { + Text("What ${p.name} can watch", color = Ink, fontFamily = Anton, fontSize = 30.sp) + Text("Tick a channel to add it. After Dark and The Late Show are never here. Saved as you go.", color = Muted, fontSize = 13.sp) + Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) { + OrbitButton("Orbit's kids picks", onClick = { Profiles.update(context, p.copy(channels = KidsStartChannels)) }) + OrbitButton("Clear all", onClick = { Profiles.update(context, p.copy(channels = emptySet())) }) + Spacer(Modifier.weight(1f)) + Text("${p.channels.size} channels on", color = OnAccent, fontSize = 13.sp, fontWeight = FontWeight.Bold, + modifier = Modifier.background(themed(Color(0xFF6EDCAA)) { Mint }, RoundedCornerShape(12.dp)).padding(horizontal = 12.dp, vertical = 4.dp)) + OrbitButton("Done", onClick = onDone) + } + LazyVerticalGrid(GridCells.Fixed(5), Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(10.dp), horizontalArrangement = Arrangement.spacedBy(10.dp)) { + items(channels, key = { it.number }) { programming -> + val on = programming.number in p.channels + var focused by remember { mutableStateOf(false) } + val corner = RoundedCornerShape(10.dp) + Box(Modifier.height(78.dp).then(if (programming == channels.first()) Modifier.focusRequester(first) else Modifier).onFocusChanged { focused = it.isFocused } + .background(if (focused) Deep else Panel, corner) + .border(if (focused) 3.dp else if (on) 2.dp else 0.dp, if (focused) Yellow else if (on) themed(Color(0xFF6EDCAA)) { Mint } else Color.Transparent, corner) + .clickable { Profiles.update(context, p.copy(channels = if (on) p.channels - programming.number else p.channels + programming.number)) }.padding(10.dp)) { + val brand = ChannelBrands.forNumber(programming.number) + if (brand != null) Image(cachedPainter(brand.logo), brand.displayName, Modifier.align(Alignment.CenterStart).logoPlate().width(120.dp).height(36.dp)) + else Text(programming.name, Modifier.align(Alignment.CenterStart), color = Ink, fontSize = 15.sp) + Box(Modifier.align(Alignment.BottomEnd).size(22.dp).background(if (on) themed(Color(0xFF6EDCAA)) { Mint } else Deep, RoundedCornerShape(5.dp)), contentAlignment = Alignment.Center) { + if (on) Text("✓", color = OnAccent, fontSize = 14.sp, fontWeight = FontWeight.Bold) + } + } + } + } + } + } +} 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 d78d9aea..b1d7c398 100644 --- a/android/app/src/main/java/tv/orbit/classic/MainActivity.kt +++ b/android/app/src/main/java/tv/orbit/classic/MainActivity.kt @@ -153,10 +153,10 @@ private fun OrbitApp() { } val onboarding = Onboarding.step != null // With no Kids profile there's no one to ask: Adult goes straight in. - LaunchedEffect(realChannelAvailable, profile, Profiles.kidsOn, onboarding) { - if (realChannelAvailable && profile == null && !Profiles.kidsOn && !onboarding) Profiles.current = Profiles.all.first { it.kind == ProfileKind.Grown } + LaunchedEffect(realChannelAvailable, profile, Profiles.asks, onboarding) { + if (realChannelAvailable && profile == null && !Profiles.asks && !onboarding) Profiles.current = Profiles.all.first { it.kind == ProfileKind.Grown } } - val picking = realChannelAvailable && restoreChecked && !chosen && Profiles.kidsOn && !onboarding + val picking = realChannelAvailable && restoreChecked && !chosen && Profiles.asks && !onboarding val kidsDriveIn = profile?.kind != ProfileKind.Kids || profile.driveIn val kidsArcade = profile?.kind != ProfileKind.Kids || profile.arcade // Kids never reaches Settings, and only the parts of Orbit chosen for it. 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 04ca4b8b..cbff2c1b 100644 --- a/android/app/src/main/java/tv/orbit/classic/Profiles.kt +++ b/android/app/src/main/java/tv/orbit/classic/Profiles.kt @@ -48,6 +48,18 @@ internal data class Profile(val id: String, val name: String, val picture: Strin /** Kids' channels to start with, from the approved design: Tots, Junior, Wonder, PixelZ, ToonZ, Heroes, Rewind, Vortex, Terra, Wild. */ internal val KidsStartChannels = setOf(TOTS_NUMBER, 611, 612, 613, 605, 602, 604, VORTEX_NUMBER, 201, 203) +/** A new profile: its name tidied, a fresh id, and Kids starting with Orbit's kids channels. */ +internal fun newProfile(name: String, kind: ProfileKind, picture: String, taken: Set, random: java.util.Random = java.util.Random()): Profile { + var id: String + do { id = "p" + (1..6).map { "abcdefghijkmnpqrstuvwxyz23456789"[random.nextInt(32)] }.joinToString("") } while (id in taken) + return Profile(id, cleanProfileName(name), picture, kind, if (kind == ProfileKind.Kids) KidsStartChannels else emptySet()) +} +internal fun cleanProfileName(name: String) = name.replace(Regex("\\s+"), " ").trim().take(20).ifEmpty { "Someone" } +/** [all] without [id], or null when that would leave no grown-up (someone has to be able to change things). */ +internal fun profilesWithout(all: List, id: String): List? = all.filter { it.id != id }.takeIf { rest -> rest.any { it.kind == ProfileKind.Grown } && rest.size < all.size } +/** A profile switched between Adult and Kids: Kids starts with Orbit's kids channels and no Drive-In. */ +internal fun Profile.asKind(kind: ProfileKind) = if (kind == this.kind) this else if (kind == ProfileKind.Kids) copy(kind = kind, channels = KidsStartChannels, driveIn = false) else copy(kind = kind, channels = emptySet()) + internal val DefaultProfiles = listOf(Profile("grown", "Adult", "sil-blue", ProfileKind.Grown), Profile("kids", "Kids", "ollie", ProfileKind.Kids, KidsStartChannels)) /** Every picture there is to choose: the cast, favourite things, and silhouettes in Orbit's colours. */ @@ -75,6 +87,22 @@ internal object Profiles { var kidsOn by mutableStateOf(true) private set fun setKidsOn(context: Context, on: Boolean) { kidsOn = on; prefs(context).edit().putBoolean("kids_on", on).apply() } + /** Orbit asks who's watching when Kids is in use or more than one grown-up has a profile (Family v2, 7 November 2026). */ + val asks get() = kidsOn || all.count { it.kind == ProfileKind.Grown } > 1 + + /** Someone new (Family v2): a stable id of their own, so their Continue watching and Taste stay theirs. */ + fun add(context: Context, name: String, kind: ProfileKind, picture: String): Profile { + val p = newProfile(name, kind, picture, all.map { it.id }.toSet()) + all = all + p; prefs(context).edit().putString("profiles", encode(all)).apply() + return p + } + /** Removes a profile; the last grown-up can't go. False when refused. */ + fun remove(context: Context, id: String): Boolean { + val next = profilesWithout(all, id) ?: return false + all = next; if (current?.id == id) current = null + prefs(context).edit().putString("profiles", encode(all)).apply() + return true + } private fun prefs(context: Context) = context.getSharedPreferences("orbit_profiles", Context.MODE_PRIVATE) fun load(context: Context) { @@ -179,7 +207,9 @@ internal fun WhosWatching(onClose: () -> Unit) { Column(Modifier.align(Alignment.Center), horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(28.dp)) { Image(cachedPainter(R.drawable.orbit_logo), "Orbit", Modifier.logoPlate().width(150.dp).height(38.dp)) Text("Who's watching?", color = Ink, fontFamily = Anton, fontSize = 40.sp) - Row(horizontalArrangement = Arrangement.spacedBy(56.dp)) { + // Room for the whole family (Family v2): smaller and closer as more join. + val many = Profiles.all.size > 4 + Row(horizontalArrangement = Arrangement.spacedBy(if (many) 28.dp else 56.dp)) { // 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) } @@ -188,7 +218,7 @@ internal fun WhosWatching(onClose: () -> Unit) { .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) + ProfileAvatar(p.picture, if (many) 108.dp else 132.dp, ringed = focused) if (p.kind == ProfileKind.Grown && AfterDarkLock.pinSet) Canvas(Modifier.align(Alignment.BottomEnd).size(28.dp)) { val s = size.minDimension drawRoundRect(Yellow, Offset(s * .15f, s * .45f), Size(s * .7f, s * .5f), androidx.compose.ui.geometry.CornerRadius(s * .08f)) @@ -217,70 +247,3 @@ internal fun WhosWatching(onClose: () -> Unit) { } } -/** Settings › Profiles: the PIN, each profile's picture, and what Kids can see and play. */ -@Composable -internal fun ProfilesDetail(firstSwitch: FocusRequester, modifier: Modifier) { - val context = LocalContext.current - var choosingFor by remember { mutableStateOf(null) } - val kids = Profiles.all.firstOrNull { it.kind == ProfileKind.Kids } - val grown = Profiles.all.first { it.kind == ProfileKind.Grown } - choosingFor?.let { p -> - Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) { - BackHandler { choosingFor = null } - Text("Choose a picture for ${p.name}", color = Yellow, fontFamily = Anton, fontSize = 22.sp) - Text("The cast, a few favourite things, or a silhouette in a colour of your own.", color = Muted, fontSize = 12.sp) - val first = remember { FocusRequester() } - LaunchedEffect(Unit) { first.requestFocus() } - LazyVerticalGrid(GridCells.Fixed(6), Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp)) { - items(ProfilePictures) { pic -> - var focused by remember { mutableStateOf(false) } - Column(Modifier.then(if (pic == p.picture) Modifier.focusRequester(first) else Modifier).onFocusChanged { focused = it.isFocused } - .clickable { Profiles.update(context, p.copy(picture = pic)); choosingFor = null }, horizontalAlignment = Alignment.CenterHorizontally) { - ProfileAvatar(pic, 64.dp, ringed = focused) - Text(pictureName(pic) + if (pic == p.picture) " (now)" else "", color = if (focused) Yellow else Ink, fontSize = 11.sp, maxLines = 1) - } - } - } - } - return - } - Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) { - Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp)) { - ProfileAvatar(grown.picture, 48.dp) - Text(grown.name, color = Ink, fontSize = 18.sp, fontWeight = FontWeight.SemiBold, modifier = Modifier.weight(1f)) - OrbitButton("Change picture", Modifier.focusRequester(firstSwitch), onClick = { choosingFor = grown }) - } - // The PIN: what keeps Adult, After Dark and The Late Show for grown-ups. - LockDetail(remember { FocusRequester() }, Modifier.fillMaxWidth()) - if (kids != null) { - Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier.padding(top = 6.dp)) { - ProfileAvatar(kids.picture, 48.dp) - Text(kids.name, color = Ink, fontSize = 18.sp, fontWeight = FontWeight.SemiBold, modifier = Modifier.weight(1f)) - OrbitButton("Change picture", onClick = { choosingFor = kids }) - OrbitButton("Arcade: ${if (kids.arcade) "On" else "Off"}", selected = kids.arcade, onClick = { Profiles.update(context, kids.copy(arcade = !kids.arcade)) }) - OrbitButton("Drive-In: ${if (kids.driveIn) "On" else "Off"}", selected = kids.driveIn, onClick = { Profiles.update(context, kids.copy(driveIn = !kids.driveIn)) }) - } - Text("CHANNELS FOR KIDS", color = Muted, fontSize = 12.sp, fontWeight = FontWeight.SemiBold) - val channels = SmartChannels.sortedBy { it.number }.filter { it.number !in LockedChannels } - LazyVerticalGrid(GridCells.Fixed(4), Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(6.dp), horizontalArrangement = Arrangement.spacedBy(6.dp)) { - items(channels, key = { it.number }) { programming -> - val on = programming.number in kids.channels - var focused by remember { mutableStateOf(false) } - val corner = RoundedCornerShape(8.dp) - Row(Modifier.height(44.dp).onFocusChanged { focused = it.isFocused }.background(if (focused) Navy else Panel, corner) - .border(if (focused) 3.dp else 0.dp, if (focused) Yellow else Color.Transparent, corner) - .clickable { Profiles.update(context, kids.copy(channels = if (on) kids.channels - programming.number else kids.channels + programming.number)) } - .padding(horizontal = 8.dp), verticalAlignment = Alignment.CenterVertically) { - val brand = ChannelBrands.forNumber(programming.number) - if (brand != null) Image(cachedPainter(brand.logo), brand.displayName, Modifier.logoPlate().width(84.dp).height(26.dp)) else Text(programming.name, color = Ink, fontSize = 13.sp) - Spacer(Modifier.weight(1f)) - Box(Modifier.size(22.dp).background(if (on) themed(Color(0xFF6EDCAA)) { Mint } else themed(Color(0xFF283C64)) { Blue }, RoundedCornerShape(5.dp)), contentAlignment = Alignment.Center) { - if (on) Text("✓", color = OnAccent, fontSize = 14.sp, fontWeight = FontWeight.Bold) - } - } - } - } - Text("Kids never sees After Dark or The Late Show. What's On and Catch Up show only Kids' channels. Leaving Kids needs the PIN.", color = Muted, fontSize = 11.sp) - } - } -} 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 9f97a006..e305f058 100644 --- a/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt +++ b/android/app/src/main/java/tv/orbit/classic/SecureMediaDataSource.kt @@ -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.97") + next.setRequestProperty("User-Agent", "OrbitTV/0.108.98") 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/Settings.kt b/android/app/src/main/java/tv/orbit/classic/Settings.kt index d4acda71..425dd7b0 100644 --- a/android/app/src/main/java/tv/orbit/classic/Settings.kt +++ b/android/app/src/main/java/tv/orbit/classic/Settings.kt @@ -326,9 +326,8 @@ private fun ViewingDetail(firstSwitch: FocusRequester, modifier: Modifier, top: @Composable private fun FamilyDetail(totsOn: Boolean, windingDown: Boolean, onWindDown: (Boolean) -> Unit, firstSwitch: FocusRequester, modifier: Modifier) { var confirming by remember { mutableStateOf(false) } - Column(modifier, verticalArrangement = Arrangement.spacedBy(8.dp)) { - ProfilesDetail(firstSwitch, Modifier.weight(1f)) - Heading("Bedtime") + // Family v2 (7 November 2026): everyone, Add someone, each person's page; the PIN and bedtime for the whole house. + FamilySettings(firstSwitch, bedtime = { if (totsOn) { if (confirming) SettingLine(if (windingDown) "Go back to Tots' usual schedule now?" else "Start Wind Down on Tots?", if (windingDown) "The programme on Tots changes straight away." else "Calm shows begin when the current programme ends, and run until morning unless you stop them.") { Row(horizontalArrangement = Arrangement.spacedBy(6.dp)) { @@ -341,7 +340,7 @@ private fun FamilyDetail(totsOn: Boolean, windingDown: Boolean, onWindDown: (Boo OnOff(windingDown, Modifier, onClick = { confirming = true }) } } else SettingLine("Wind Down", "Turn Tots on in Channels to use Wind Down: calm shows on Tots, with Luna.") {} - } + }, modifier = modifier) } /** Rooms and phones: the phones that can make channels, and (with Multiroom) the other TVs in the home. */ diff --git a/android/app/src/test/java/tv/orbit/classic/FamilyTest.kt b/android/app/src/test/java/tv/orbit/classic/FamilyTest.kt new file mode 100644 index 00000000..02e6614e --- /dev/null +++ b/android/app/src/test/java/tv/orbit/classic/FamilyTest.kt @@ -0,0 +1,51 @@ +package tv.orbit.classic + +import org.junit.Assert.* +import org.junit.Rule +import org.junit.Test +import org.junit.rules.TemporaryFolder + +/** Family v2: anyone can be added, renamed, switched between Adult and Kids or removed, but the last grown-up stays. */ +class FamilyTest { + @get:Rule val tmp = TemporaryFolder() + + @Test fun newPeopleGetTheirOwnIdAndKidsStartSafe() { + val taken = DefaultProfiles.map { it.id }.toSet() + val wife = newProfile(" Sarah Jane ", ProfileKind.Grown, "sil-pink", taken, java.util.Random(1)) + assertEquals("Sarah Jane", wife.name); assertTrue(wife.id !in taken); assertTrue(wife.channels.isEmpty()) + val child = newProfile("", ProfileKind.Kids, "ollie", taken + wife.id, java.util.Random(1)) + assertEquals("Someone", child.name); assertNotEquals(wife.id, child.id) + assertEquals(KidsStartChannels, child.channels); assertFalse(child.driveIn) + assertEquals(20, cleanProfileName("x".repeat(40)).length) + } + + @Test fun theLastGrownUpCantBeRemoved() { + val wife = newProfile("Wife", ProfileKind.Grown, "sil-pink", emptySet()) + val all = DefaultProfiles + wife + assertEquals(listOf("grown", "kids"), profilesWithout(all, wife.id)!!.map { it.id }) + assertNull(profilesWithout(DefaultProfiles, "grown")) + assertEquals(listOf("grown"), profilesWithout(DefaultProfiles, "kids")!!.map { it.id }) + assertNull("unknown id changes nothing", profilesWithout(DefaultProfiles, "nobody")) + } + + @Test fun switchingTypeResetsWhatKidsSee() { + val adult = newProfile("Paul", ProfileKind.Grown, "rocket", emptySet()) + val asKids = adult.asKind(ProfileKind.Kids) + assertEquals(KidsStartChannels, asKids.channels); assertFalse(asKids.driveIn) + assertTrue(asKids.asKind(ProfileKind.Grown).channels.isEmpty()) + // Saved and read back, every profile keeps its id, type and channels. + val back = Profiles.decode(Profiles.encode(DefaultProfiles + adult + asKids.copy(id = "pkids2"))) + assertEquals(4, back.size); assertEquals(ProfileKind.Kids, back.last().kind); assertEquals(KidsStartChannels, back.last().channels) + } + + @Test fun removingSomeoneClearsTheirOwnDataOnly() { + val dir = tmp.newFolder("schedule") + java.io.File(dir, "continue-pwife01.json").writeText("[]"); java.io.File(dir, "continue-grown.json").writeText("[]") + java.io.File(dir, "taste").mkdirs() + java.io.File(dir, "taste/pwife01.events.jsonl").writeText("x"); java.io.File(dir, "taste/pwife01.state.json").writeText("{}") + java.io.File(dir, "taste/grown.events.jsonl").writeText("y") + forgetProfileData(dir, "pwife01") + assertFalse(java.io.File(dir, "continue-pwife01.json").exists()); assertFalse(java.io.File(dir, "taste/pwife01.events.jsonl").exists()) + assertTrue(java.io.File(dir, "continue-grown.json").exists()); assertTrue(java.io.File(dir, "taste/grown.events.jsonl").exists()) + } +}