Orbit Companion: a phone can keep its own look instead of following the TV
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -55,13 +55,16 @@ internal object OrbitCompanion {
|
||||
val volumes = mapOf("up" to AudioManager.ADJUST_RAISE, "down" to AudioManager.ADJUST_LOWER, "mute" to AudioManager.ADJUST_TOGGLE_MUTE)
|
||||
|
||||
private fun hex(c: Color) = "#%06X".format(c.toArgb() and 0xFFFFFF)
|
||||
/** The TV's look, so the phone wears the same colours. */
|
||||
fun look(): JSONObject = OrbitTheme.palette.let { p ->
|
||||
JSONObject().put("name", OrbitTheme.look.title).put("light", p.light).put("background", hex(p.background)).put("surface", hex(p.surface))
|
||||
/** The TV's look, so the phone wears the same colours (Paul: by default; a phone can keep a look of its own from [looks]). */
|
||||
fun look(look: OrbitLook = OrbitTheme.look): JSONObject = look.palette.let { p ->
|
||||
JSONObject().put("name", look.title).put("light", p.light).put("background", hex(p.background)).put("surface", hex(p.surface))
|
||||
.put("raised", hex(p.raised)).put("deep", hex(p.deep)).put("accent", hex(p.accent)).put("onAccent", hex(p.onAccent))
|
||||
.put("ink", hex(p.ink)).put("muted", hex(p.muted)).put("mint", hex(p.mint)).put("sky", hex(p.sky)).put("gold", hex(p.gold))
|
||||
}
|
||||
|
||||
/** Every look, for a phone that keeps its own rather than following the TV. */
|
||||
fun looks(): JSONArray = JSONArray(OrbitLook.entries.map { look(it) })
|
||||
|
||||
fun programme(b: SampleBroadcast): JSONObject = guideTitleParts(b.media.item.title).let { (title, sub) ->
|
||||
JSONObject().put("title", title).put("sub", sub ?: JSONObject.NULL).put("startMs", b.startMs).put("endMs", b.endMs)
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@ internal object PhoneLink {
|
||||
}
|
||||
}
|
||||
|
||||
private val companionRoutes = setOf("GET /api/now", "GET /api/guide", "GET /api/catchup", "GET /api/rooms", "POST /api/key", "POST /api/volume",
|
||||
private val companionRoutes = setOf("GET /api/now", "GET /api/guide", "GET /api/catchup", "GET /api/rooms", "GET /api/looks", "POST /api/key", "POST /api/volume",
|
||||
"POST /api/channel", "POST /api/tune", "POST /api/section", "POST /api/catchup/watch")
|
||||
/** The Companion's remote, guide, Catch Up and rooms (see [OrbitCompanion]); false when [r] is for Create your own. */
|
||||
private fun companion(r: Request, out: OutputStream): Boolean {
|
||||
@@ -340,6 +340,7 @@ internal object PhoneLink {
|
||||
"GET /api/guide" -> json(out, 200, OrbitCompanion.guide(s, now))
|
||||
"GET /api/catchup" -> json(out, 200, JSONObject().put("shelves", OrbitCompanion.catchUp(s, now)))
|
||||
"GET /api/rooms" -> json(out, 200, OrbitCompanion.rooms(appContext))
|
||||
"GET /api/looks" -> json(out, 200, JSONObject().put("looks", OrbitCompanion.looks()))
|
||||
"POST /api/key" -> {
|
||||
val code = OrbitCompanion.keys[body().optString("key")] ?: return json(out, 400, JSONObject().put("error", "Unknown button"))
|
||||
OrbitCompanion.press(code); json(out, 202, JSONObject().put("ok", true))
|
||||
|
||||
Reference in New Issue
Block a user