What's on: the channel last watched leads onNow, marked lastWatched
For Orbit Central's Resume Orbit card. Orbit keeps the last tuned channel number in its plain settings (no sign-in data) for the provider to read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -733,6 +733,8 @@ internal fun EmbyConnectionScreen(modifier: Modifier = Modifier, visible: Boolea
|
||||
SmartChannels.firstOrNull { it.number == number }?.takeIf { scheduledChannels.containsKey(number) }?.let { setSmartSchedule(it, true) }
|
||||
"${fresh.size} added to ${ch.name}. They join as it plans ahead; nothing already booked changes."
|
||||
}) } }
|
||||
// The channel last tuned, kept for Orbit Central's Resume card (a number, in plain settings: no sign-in data).
|
||||
LaunchedEffect(selectedNumber) { withContext(Dispatchers.IO) { runCatching { OrbitSettings(appContext).lastChannel = selectedNumber } } }
|
||||
// A channel asked for from outside (Orbit Central's cards, ExternalTune): tuned once it's on and allowed, as Watch from a phone.
|
||||
LaunchedEffect(ExternalTune.pending, scheduledChannels.keys) {
|
||||
val n = ExternalTune.pending ?: return@LaunchedEffect
|
||||
|
||||
@@ -28,7 +28,8 @@ class ScheduleSummaryProvider : ContentProvider() {
|
||||
runCatching {
|
||||
AfterDarkLock.load(context); Profiles.load(context)
|
||||
val dir = Workspaces.current(context).scheduleDir
|
||||
scheduleSummary(dir, System.currentTimeMillis(), OrbitSettings(context).look.name)?.let { cursor.addRow(arrayOf(it.toString())) }
|
||||
val settings = OrbitSettings(context)
|
||||
scheduleSummary(dir, System.currentTimeMillis(), settings.look.name, lastWatched = settings.lastChannel)?.let { cursor.addRow(arrayOf(it.toString())) }
|
||||
}
|
||||
return cursor
|
||||
}
|
||||
@@ -48,7 +49,9 @@ internal const val SUMMARY_TONIGHT_MAX = 8
|
||||
* events, and the Drive-In's show tonight. [allowed] says which channels the viewer may see; [look] is Orbit's look by name.
|
||||
*/
|
||||
internal fun scheduleSummary(dir: File, nowMs: Long, look: String, allowed: (Int) -> Boolean = { !lockedOut(it) && !profileHides(it) },
|
||||
zone: java.time.ZoneId = java.time.ZoneId.systemDefault()): JSONObject? {
|
||||
zone: java.time.ZoneId = java.time.ZoneId.systemDefault(),
|
||||
/** The channel last watched: it leads onNow, marked "lastWatched" (Orbit Central's Resume Orbit card). */
|
||||
lastWatched: Int = 0): JSONObject? {
|
||||
val plans = (dir.listFiles { f -> Regex("schedule-\\d+\\.json").matches(f.name) } ?: return null).mapNotNull { f ->
|
||||
val number = f.name.removePrefix("schedule-").removeSuffix(".json").toIntOrNull() ?: return@mapNotNull null
|
||||
val user = runCatching { JSONObject(f.readText()).optString("user") }.getOrNull()?.takeIf { it.isNotBlank() } ?: return@mapNotNull null
|
||||
@@ -60,11 +63,11 @@ internal fun scheduleSummary(dir: File, nowMs: Long, look: String, allowed: (Int
|
||||
fun name(n: Int) = ChannelBrands.forNumber(n)?.displayName ?: SmartChannels.firstOrNull { it.number == n }?.name ?: n.toString()
|
||||
fun title(e: ScheduleEntry) = e.media.item.title.substringBefore(" / ")
|
||||
val onNow = JSONArray()
|
||||
plans.filterKeys { it != DRIVE_IN_NUMBER }.toSortedMap().forEach { (n, plan) ->
|
||||
plans.filterKeys { it != DRIVE_IN_NUMBER }.toSortedMap(compareBy<Int> { if (it == lastWatched) 0 else 1 }.thenBy { it }).forEach { (n, plan) ->
|
||||
val at = plan.entries.indexOfFirst { nowMs >= it.startMs && nowMs < it.endMs }.takeIf { it >= 0 } ?: return@forEach
|
||||
val now = plan.entries[at]; val next = plan.entries.getOrNull(at + 1)
|
||||
onNow.put(JSONObject().put("channel", name(n)).put("number", n).put("channelId", n.toString()).put("title", title(now))
|
||||
.put("start", now.startMs).put("end", now.endMs).also { o -> next?.let { o.put("next", JSONObject().put("title", title(it)).put("start", it.startMs)) } })
|
||||
.put("start", now.startMs).put("end", now.endMs).also { o -> next?.let { o.put("next", JSONObject().put("title", title(it)).put("start", it.startMs)) }; if (n == lastWatched) o.put("lastWatched", true) })
|
||||
}
|
||||
val today = java.time.Instant.ofEpochMilli(nowMs).atZone(zone).toLocalDate()
|
||||
val eveningFrom = today.atTime(SUMMARY_TONIGHT_FROM_HOUR, 0).atZone(zone).toInstant().toEpochMilli()
|
||||
|
||||
@@ -152,6 +152,10 @@ internal class OrbitSettings(context: Context) {
|
||||
var arcadeBackdrop: String
|
||||
get() = saved.getString("arcade_backdrop", null) ?: "Auto"
|
||||
set(value) { saved.edit().putString("arcade_backdrop", value).apply() }
|
||||
/** The channel last tuned, for Orbit Central's "Resume Orbit" card (ScheduleSummaryProvider). A number only. */
|
||||
var lastChannel: Int
|
||||
get() = saved.getInt("last_channel", 0)
|
||||
set(value) { saved.edit().putInt("last_channel", value).apply() }
|
||||
var reduceMotion: Boolean
|
||||
get() = saved.getBoolean("reduce_motion", false)
|
||||
set(value) { saved.edit().putBoolean("reduce_motion", value).apply() }
|
||||
|
||||
Reference in New Issue
Block a user