Skip to content

Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.

Launcher: game_day's rotation of each team's next game and the F1 weekend

Justin Newman7ffa8f58a935
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/GameDay.java b/launcher/app/src/main/java/com/gathin/tvhome/GameDay.java
new file mode 100644
index 000000000..dbb2a1331
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/GameDay.java
@@ -0,0 +1,72 @@
+package com.gathin.tvhome;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * game_day (config.xml or a theme): each team's next game in the race panel's place, from an add-on such as
+ * addons/game-day, rotating with the theme's F1 weekend. The launcher only reads what the add-on publishes and stays
+ * offline. Contract: docs/modules.md.
+ */
+final class GameDay {
+
+ /** One turn in the rotation: a game from the add-on, or the theme's F1 weekend ({@link #f1}). */
+ static final class Turn {
+ final String topLine;
+ /** "Puck drop": the countdown reads "Puck drop in 2h 18m". */
+ final String word;
+ /** For the F1 turn: when its next session starts, or now while one is live (the sort key). */
+ final long startMs;
+ final long endMs;
+ /** ARGB, for the short bar. */
+ final int colour;
+ final boolean f1;
+
+ Turn(String topLine, String word, long startMs, long endMs, int colour) {
+ this(topLine, word, startMs, endMs, colour, false);
+ }
+
+ private Turn(String topLine, String word, long startMs, long endMs, int colour, boolean f1) {
+ this.topLine = topLine;
+ this.word = word;
+ this.startMs = startMs;
+ this.endMs = endMs;
+ this.colour = colour;
+ this.f1 = f1;
+ }
+ }
+
+ /**
+ * The turns to rotate through, soonest first: the games that have not ended, and the F1 weekend as one turn
+ * while the race panel would show it (sorted by its next session, or now while a session is live).
+ */
+ static List<Turn> merge(List<Turn> games, RaceWeekend.State f1, long nowMs) {
+ List<Turn> out = new ArrayList<>();
+ for (Turn t : games) {
+ if (t.endMs > nowMs) out.add(t);
+ }
+ if (f1 != null) {
+ long key = f1.live == null && f1.next != null ? f1.next.start.toEpochMilli() : nowMs;
+ out.add(new Turn("", "", key, Long.MAX_VALUE, 0, true));
+ }
+ Collections.sort(out, Comparator.comparingLong(t -> t.startMs));
+ return out;
+ }
+
+ /** Which turn is on screen, {@code sinceMs} after the rotation started. */
+ static int current(int count, long sinceMs, int turnSeconds) {
+ if (count <= 0) return 0;
+ return (int) ((Math.max(0, sinceMs) / (turnSeconds * 1000L)) % count);
+ }
+
+ static boolean live(Turn t, long nowMs) {
+ return nowMs >= t.startMs && nowMs < t.endMs;
+ }
+
+ static Duration until(Turn t, long nowMs) {
+ return Duration.ofMillis(t.startMs - nowMs);
+ }
+}
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/GameDayTest.java b/launcher/app/src/test/java/com/gathin/tvhome/GameDayTest.java
new file mode 100644
index 000000000..4d22d0858
--- /dev/null
+++ b/launcher/app/src/test/java/com/gathin/tvhome/GameDayTest.java
@@ -0,0 +1,89 @@
+package com.gathin.tvhome;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+
+public class GameDayTest {
+ private static final RaceWeekend.Race AUSTIN = new RaceWeekend.Race(18, "United States Grand Prix", "Austin",
+ Arrays.asList(
+ new RaceWeekend.Session("FP1", Instant.parse("2026-10-23T17:30:00Z")),
+ new RaceWeekend.Session("FP2", Instant.parse("2026-10-23T21:00:00Z")),
+ new RaceWeekend.Session("FP3", Instant.parse("2026-10-24T17:30:00Z")),
+ new RaceWeekend.Session("Qualifying", Instant.parse("2026-10-24T21:00:00Z")),
+ new RaceWeekend.Session("race", Instant.parse("2026-10-25T20:00:00Z"))));
+ private static final List<RaceWeekend.Race> CALENDAR = Collections.singletonList(AUSTIN);
+ /** Saturday afternoon: FP3 is over, qualifying is in 2h 05m. */
+ private static final Instant NOW = Instant.parse("2026-10-24T18:55:00Z");
+ private static final long HOUR = 3_600_000L;
+
+ private static GameDay.Turn game(String top, long fromNowMs, long lengthMs) {
+ long start = NOW.toEpochMilli() + fromNowMs;
+ return new GameDay.Turn(top, "Puck drop", start, start + lengthMs, 0xFF2E7D32);
+ }
+
+ @Test public void noTurnsHidesPanel() {
+ assertTrue(GameDay.merge(Collections.emptyList(), null, NOW.toEpochMilli()).isEmpty());
+ }
+
+ @Test public void endedGamesAreDropped() {
+ List<GameDay.Turn> t = GameDay.merge(Arrays.asList(
+ game("Ended", -4 * HOUR, 3 * HOUR), game("Tonight", HOUR, 3 * HOUR)), null, NOW.toEpochMilli());
+ assertEquals(1, t.size());
+ assertEquals("Tonight", t.get(0).topLine);
+ }
+
+ @Test public void f1JoinsSortedByItsNextSession() {
+ RaceWeekend.State f1 = RaceWeekend.at(CALENDAR, NOW);
+ List<GameDay.Turn> t = GameDay.merge(Arrays.asList(
+ game("In two days", 48 * HOUR, 3 * HOUR), game("In an hour", HOUR, 3 * HOUR)), f1, NOW.toEpochMilli());
+ assertEquals(3, t.size());
+ assertEquals("In an hour", t.get(0).topLine);
+ assertTrue(t.get(1).f1);
+ assertEquals(Instant.parse("2026-10-24T21:00:00Z").toEpochMilli(), t.get(1).startMs);
+ assertEquals("In two days", t.get(2).topLine);
+ }
+
+ @Test public void f1LiveSortsFirst() {
+ Instant duringQualifying = Instant.parse("2026-10-24T21:20:00Z");
+ RaceWeekend.State f1 = RaceWeekend.at(CALENDAR, duringQualifying);
+ long soon = duringQualifying.toEpochMilli() + 30 * 60_000L;
+ List<GameDay.Turn> t = GameDay.merge(Arrays.asList(
+ new GameDay.Turn("Soon", "Puck drop", soon, soon + 3 * HOUR, 0)), f1, duringQualifying.toEpochMilli());
+ assertTrue(t.get(0).f1);
+ assertEquals(duringQualifying.toEpochMilli(), t.get(0).startMs);
+ }
+
+ @Test public void noF1OutsideItsWeekend() {
+ RaceWeekend.State none = RaceWeekend.at(CALENDAR, Instant.parse("2026-11-10T12:00:00Z"));
+ assertEquals(1, GameDay.merge(Arrays.asList(game("Tonight", HOUR, 3 * HOUR)), none, NOW.toEpochMilli()).size());
+ }
+
+ @Test public void rotationIndex() {
+ assertEquals(0, GameDay.current(3, 29_999, 30));
+ assertEquals(1, GameDay.current(3, 31_000, 30));
+ assertEquals(0, GameDay.current(3, 90_000, 30));
+ assertEquals(0, GameDay.current(0, 5_000, 30));
+ assertEquals(0, GameDay.current(1, 500_000, 30));
+ }
+
+ @Test public void turnIsLiveOnlyBetweenStartAndEnd() {
+ GameDay.Turn t = game("Game", HOUR, 3 * HOUR);
+ assertFalse(GameDay.live(t, t.startMs - 1));
+ assertTrue(GameDay.live(t, t.startMs));
+ assertTrue(GameDay.live(t, t.endMs - 1));
+ assertFalse(GameDay.live(t, t.endMs));
+ }
+
+ @Test public void durationHelperMatchesTheCountdown() {
+ assertEquals(Duration.ofMinutes(125), GameDay.until(game("Game", 125 * 60_000L, HOUR), NOW.toEpochMilli()));
+ }
+}