Debloat any Android or Google TV over Wi-Fi and get an Apple TV-style home.
Python adbadblockandroid-tvandroid-tv-launcherapple-tvbloatware-removalclaude-codedebloatfire-tvgoogle-tvlauncherprivacysmart-tvsony-braviatclvibe-codingxiaomi
feat(wallpapers): persist sequential/shuffle playback order
Hari Harand2f33ff7a9b3
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.javaindex 8f41173e3..6eec195ab 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java@@ -96,6 +96,11 @@ final class Config {final List<File> wallpapers;final int wallpaperRotationMinutes;final int wallpaperDim;+ /**+ * Playback order for a wallpaper collection: {@code sequential} or {@code shuffle}. Missing or+ * invalid values keep the historical shuffle so existing themes rotate exactly as before.+ */+ final String wallpaperOrder;/** Whether the overlay file was present and parsed. */final boolean overlayApplied;/** Festive skin from a theme (festival, festival_until, greeting, accent_color); {@link Festival#NONE} if none. */@@ -112,7 +117,7 @@ final class Config {boolean shamsiDate, String greetingName, boolean moduleCards, boolean reducedMotion, boolean dockTitle, boolean dockRow, boolean reorderButton, String vpnApp,boolean showHomeSettingsShortcut, boolean showStats, boolean appLibrary, int backgroundColor, int skyIntensity,int[] settingsKeycodes, boolean settingsKeyPanel, boolean wallpaperEnabled, File wallpaper, List<File> wallpapers,- int wallpaperRotationMinutes, int wallpaperDim, boolean overlayApplied,+ int wallpaperRotationMinutes, int wallpaperDim, String wallpaperOrder, boolean overlayApplied,Festival festival, int[] inputKeycodes, List<String> appKeys,List<RaceWeekend.Race> raceCalendar, boolean cinematicHome) {this.inputKeycodes = inputKeycodes;@@ -152,6 +157,7 @@ final class Config {this.wallpapers = Collections.unmodifiableList(wallpapers);this.wallpaperRotationMinutes = wallpaperRotationMinutes;this.wallpaperDim = wallpaperDim;+ this.wallpaperOrder = wallpaperOrder;this.overlayApplied = overlayApplied;this.festival = festival;this.raceCalendar = Collections.unmodifiableList(raceCalendar);@@ -256,6 +262,10 @@ final class Config {if (!wallpaperEnabled) wallpaper = null;int rotationMinutes = json == null ? 0 : integer(json, "wallpaper_rotation_minutes", 0, 0, 1440);int wallpaperDim = json == null ? 0 : integer(json, "wallpaper_dim", 0, 0, 90);+ String wallpaperOrder = json == null ? WallpaperRotation.ORDER_SHUFFLE+ : string(json, "wallpaper_order", WallpaperRotation.ORDER_SHUFFLE);+ // An unknown order must not silently change how an existing collection rotates.+ if (!WallpaperRotation.validOrder(wallpaperOrder)) wallpaperOrder = WallpaperRotation.ORDER_SHUFFLE;List<File> wallpapers = new ArrayList<>();if (rotationMinutes > 0 && dir != null && wallpaperEnabled) {wallpapers.addAll(WallpaperRotation.images(new File(dir, "wallpapers")));@@ -290,7 +300,7 @@ final class Config {Math.max(1, columns), Math.max(0, rowsBelow), animations, advancedEffects,shamsi, greetingName, moduleCards, reducedMotion, dockTitle, dockRow, reorderButton, vpn, homeSettings, showStats, library, background,Math.max(0, Math.min(100, skyIntensity)), settingsKeycodes, settingsKeyPanel, wallpaperEnabled, wallpaper,- wallpapers, rotationMinutes, wallpaperDim, applied,+ wallpapers, rotationMinutes, wallpaperDim, wallpaperOrder, applied,festival, inputKeycodes, appKeys, json == null ? Collections.emptyList() : raceCalendar(json), cinematic);}diff --git a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.java b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.javaindex 7292276c6..7d94891cb 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperPlayer.java@@ -24,6 +24,7 @@ final class WallpaperPlayer {private final ImageView image;private final List<File> files;private final long interval;+ private final String order;private final SharedPreferences preferences;private final ExecutorService decoder = Executors.newSingleThreadExecutor();private final Random random = new Random();@@ -38,7 +39,15 @@ final class WallpaperPlayer {this.root = root;files = new ArrayList<>(config.wallpapers);interval = config.wallpaperRotationMinutes * 60_000L;+ order = config.wallpaperOrder;preferences = context.getSharedPreferences("wallpaper_rotation", Context.MODE_PRIVATE);+ // Playback state belongs to one collection. Changing the collection starts from its first+ // picture instead of resuming a filename that belonged to the previous one.+ String collection = collectionKey(files);+ if (!collection.equals(preferences.getString("collection", ""))) {+ preferences.edit().putString("collection", collection)+ .remove("image").remove("changed").apply();+ }DisplayMetrics metrics = context.getResources().getDisplayMetrics();width = metrics.widthPixels;height = metrics.heightPixels;@@ -68,7 +77,7 @@ final class WallpaperPlayer {private void showFirst() {String previous = preferences.getString("image", "");File first = WallpaperRotation.find(files, previous);- if (first == null) first = WallpaperRotation.pick(files, previous, random);+ if (first == null) first = WallpaperRotation.pick(files, previous, order, random);while (first != null) {Bitmap bitmap = decode(first);if (bitmap != null) {@@ -81,7 +90,7 @@ final class WallpaperPlayer {return;}files.remove(first); // unreadable or over 4K: try another, or keep the plain colour- first = WallpaperRotation.pick(files, previous, random);+ first = WallpaperRotation.pick(files, previous, order, random);}}@@ -106,7 +115,7 @@ final class WallpaperPlayer {File selected = WallpaperRotation.find(files, previous);long changed = preferences.getLong("changed", 0);if (selected == null || WallpaperRotation.due(changed, System.currentTimeMillis(), interval)) {- selected = WallpaperRotation.pick(files, previous, random);+ selected = WallpaperRotation.pick(files, previous, order, random);}if (selected == null || selected.getName().equals(displayed)) return;File next = selected;@@ -135,6 +144,13 @@ final class WallpaperPlayer {});}+ /** Names plus sizes: enough to notice a different collection without hashing every image. */+ private static String collectionKey(List<File> images) {+ StringBuilder key = new StringBuilder();+ for (File file : images) key.append(file.getName()).append(':').append(file.length()).append(';');+ return key.toString();+ }+private Bitmap decode(File file) {try {BitmapFactory.Options options = new BitmapFactory.Options();diff --git a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperRotation.java b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperRotation.javaindex f1e7e553b..06b658fa1 100644--- a/launcher/app/src/main/java/com/gathin/tvhome/WallpaperRotation.java+++ b/launcher/app/src/main/java/com/gathin/tvhome/WallpaperRotation.java@@ -9,6 +9,14 @@ import java.util.Locale;import java.util.Random;final class WallpaperRotation {+ /** Playback orders persisted in config.json (wallpaper_order). */+ static final String ORDER_SEQUENTIAL = "sequential";+ static final String ORDER_SHUFFLE = "shuffle";++ static boolean validOrder(String order) {+ return ORDER_SEQUENTIAL.equals(order) || ORDER_SHUFFLE.equals(order);+ }+static List<File> images(File directory) {List<File> result = new ArrayList<>();File[] entries = directory == null ? null : directory.listFiles();@@ -37,6 +45,26 @@ final class WallpaperRotation {return candidates.isEmpty() ? null : candidates.get(random.nextInt(candidates.size()));}+ /**+ * The next picture in the sorted collection, wrapping to the first at the end. The list from+ * {@link #images(File)} is sorted by filename, so this is a stable order across restarts. A+ * previous name that is no longer in the collection starts again at the first picture.+ */+ static File next(List<File> images, String previous) {+ if (images.isEmpty()) return null;+ for (int i = 0; i < images.size(); i++) {+ if (images.get(i).getName().equals(previous)) {+ return images.get((i + 1) % images.size());+ }+ }+ return images.get(0);+ }++ /** Picks the next picture for {@code order}; an unknown order keeps the historical shuffle. */+ static File pick(List<File> images, String previous, String order, Random random) {+ return ORDER_SEQUENTIAL.equals(order) ? next(images, previous) : pick(images, previous, random);+ }+static boolean due(long previous, long now, long interval) {return interval > 0 && (previous == 0 || now < previous || now - previous >= interval);}diff --git a/launcher/app/src/test/java/com/gathin/tvhome/WallpaperRotationTest.java b/launcher/app/src/test/java/com/gathin/tvhome/WallpaperRotationTest.javaindex b75d8d294..3946ea357 100644--- a/launcher/app/src/test/java/com/gathin/tvhome/WallpaperRotationTest.java+++ b/launcher/app/src/test/java/com/gathin/tvhome/WallpaperRotationTest.java@@ -52,6 +52,40 @@ public class WallpaperRotationTest {assertNull(WallpaperRotation.pick(Collections.emptyList(), "", random));}+ @Test+ public void sequentialAdvancesInSortedOrderAndWraps() {+ List<File> images = Arrays.asList(new File("a.jpg"), new File("b.jpg"), new File("c.jpg"));+ assertEquals("b.jpg", WallpaperRotation.next(images, "a.jpg").getName());+ assertEquals("c.jpg", WallpaperRotation.next(images, "b.jpg").getName());+ assertEquals("a.jpg", WallpaperRotation.next(images, "c.jpg").getName());+ // A first run, or an image removed from the collection, starts at the first picture.+ assertEquals("a.jpg", WallpaperRotation.next(images, "").getName());+ assertEquals("a.jpg", WallpaperRotation.next(images, "gone.jpg").getName());+ assertEquals("only.jpg", WallpaperRotation.next(+ Collections.singletonList(new File("only.jpg")), "only.jpg").getName());+ assertNull(WallpaperRotation.next(Collections.emptyList(), ""));+ }++ @Test+ public void pickUsesTheRequestedOrder() {+ List<File> images = Arrays.asList(new File("a.jpg"), new File("b.jpg"), new File("c.jpg"));+ Random random = new Random(1);+ assertEquals("b.jpg", WallpaperRotation.pick(images, "a.jpg", WallpaperRotation.ORDER_SEQUENTIAL, random).getName());+ assertEquals("a.jpg", WallpaperRotation.pick(images, "c.jpg", WallpaperRotation.ORDER_SEQUENTIAL, random).getName());+ for (int i = 0; i < 20; i++) {+ assertNotEquals("a.jpg", WallpaperRotation.pick(+ images, "a.jpg", WallpaperRotation.ORDER_SHUFFLE, random).getName());+ }+ // Unknown order keeps the historical shuffle rather than failing or blanking.+ assertNotEquals("a.jpg", WallpaperRotation.pick(images, "a.jpg", "random", random).getName());+ }++ @Test+ public void findsTheFirstPictureWhenThePreviousOneIsGone() {+ List<File> images = Arrays.asList(new File("a.jpg"), new File("b.jpg"));+ assertEquals("a.jpg", WallpaperRotation.next(images, "deleted.jpg").getName());+ }+@Testpublic void findMatchesByName() {List<File> images = Arrays.asList(new File("a.jpg"), new File("b.jpg"));diff --git a/themes/README.md b/themes/README.mdindex d08c19670..bfafa291e 100644--- a/themes/README.md+++ b/themes/README.md@@ -53,8 +53,9 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can| `background_color` | `#RRGGBB` | Colour behind everything; black by default || `sky_intensity` | 0 to 100 | Time-of-day backdrop: a dark gradient that follows the clock, 0 hides it (default) || `wallpaper` | bool | Show `wallpaper.jpg` from the theme folder (`true`), or ignore it (`false`) |-| `wallpaper_rotation_minutes` | 0 to 1440 | Randomly rotate images in the theme's `wallpapers/` folder at this interval; 0 keeps the single-image behaviour |-| `wallpaper_dim` | 0 to 90 | Black overlay over wallpaper images, in percent; 0 by default |+| `wallpaper_rotation_minutes` | 0 to 1440 | Rotate images in the theme's `wallpapers/` folder at this interval; 0 keeps the single-image behaviour. A negative or non-numeric value is ignored, and 0 means "no rotation", not "every minute" |+| `wallpaper_order` | `shuffle` or `sequential` | How a collection advances. `shuffle` (the default, and what launchers did before this key existed) avoids repeating the current picture; `sequential` walks the folder in filename order and wraps at the end. An unknown value falls back to `shuffle` |+| `wallpaper_dim` | 0 to 90 | Black overlay over wallpaper images, in percent; 0 by default and no shade view at all || `festival` | string | Turns on a festive skin: the network pill becomes a diya whose flame follows the connection, Inputs a temple bell, Settings a marigold, and the first Home of the day gets a petal shower. `dussehra` and `diwali` have built-in greetings || `festival_until` | `YYYY-MM-DD` | Last day the festive skin shows; it switches itself off after that. A malformed date turns it off || `greeting` | string | Replaces the time-of-day greeting while the festive skin is on |@@ -76,9 +77,16 @@ it; a picture that is still over 4K (about 8.4 million pixels) after it is samplFor a wallpaper collection, place JPEG, PNG or WebP files in the theme’s `wallpapers/` folder beside `config.json`, then set:```json-{ "wallpaper": true, "wallpaper_rotation_minutes": 30, "wallpaper_dim": 40 }+{ "wallpaper": true, "wallpaper_rotation_minutes": 30, "wallpaper_dim": 40, "wallpaper_order": "sequential" }```+The last displayed picture is remembered on the TV, so a restart or reboot resumes from it rather than+starting over at the first image in `sequential` mode. Missing an interval while the TV is asleep or+unplugged does not replay the missed pictures: Home moves on at most once when it wakes. Replacing the+collection starts playback from the new collection's first picture. A collection with one picture is+shown once and never blanked on a timer. Images are centre-cropped to fill the 16:9 screen; dimming is+drawn as a black overlay above the picture and below the launcher's text.+When you apply a theme, its collection replaces the one already on the TV. Use filenames containingonly letters, digits, underscores, dots and hyphens. Images can come from any source; check that youhave permission to use them. The launcher considers