Skip to content

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

Launcher: dock slots that dock_apps leaves free stay empty

abuhasanrumi0c9fcfef8f1d
diff --git a/docs/specs/card.md b/docs/specs/card.md
index 3531d2271..f9ecdceb6 100644
--- a/docs/specs/card.md
+++ b/docs/specs/card.md
@@ -135,8 +135,9 @@ any violation drops that one card, with a log line and no other effect.
next to it. A package in `hidden_apps` (`config.xml`) shows neither a tile nor a card. A package in
`dock_apps` gets its card in that dock slot. Other cards sort right after the configured dock apps
and before the alphabetical grid, by label. On the default configuration, four dock apps and four
- columns, that is the first grid tile. With fewer `dock_apps` than columns, a shown card fills the
- empty dock slot, since the dock is simply the first row. In the dock, the top shelf shows the label and the glow uses
+ columns, that is the first grid tile. With fewer `dock_apps` than columns, the free dock slots stay
+ empty and a shown card is the first grid tile; with `fill_dock` on, a shown card fills the free
+ dock slot, since the dock is then simply the first row. In the dock, the top shelf shows the label and the glow uses
the accent; in the grid, the name line under the focused tile shows the label and the caption,
as far as they fit on one line. A card uses the app's own banner (or icon) for its artwork.
7. Hide. A hidden card leaves the app's ordinary tile exactly as before: hiding a card never
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/AppAdapter.java b/launcher/app/src/main/java/com/gathin/tvhome/AppAdapter.java
index 5fc171081..1c351396f 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/AppAdapter.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/AppAdapter.java
@@ -41,8 +41,9 @@ import java.util.Map;
import java.util.Set;
/**
- * App tiles. The first {@link MainActivity#COLUMNS} positions are the pinned dock (favourites, fixed order),
- * then the module cards the owner chose to show (by label), the rest is alphabetical.
+ * App tiles. The first {@link MainActivity#COLUMNS} positions are the pinned dock (favourites, fixed order,
+ * then empty slots up to a full row, see {@link DockSlots}), then the module cards the owner chose to show
+ * (by label), the rest is alphabetical.
*/
public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
@@ -54,7 +55,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
}
static final class Entry {
- static final int APP = 0, HOME_SETTINGS = 1, CARD = 2;
+ static final int APP = 0, HOME_SETTINGS = 1, CARD = 2, EMPTY = 3;
final int kind;
final String label;
@@ -113,6 +114,10 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
private final int dockSize;
/** Dock order (config.xml dock_apps, or a theme's config.json). */
private final List<String> favourites;
+ /** Grid apps fill the dock slots dock_apps leaves free (config.xml, fill_dock). */
+ private final boolean fillDock;
+ /** Dock apps found at the last reload, and the empty slots after them. */
+ private int docked, emptySlots;
/** Never shown as tiles (res/values/config.xml, hidden_apps). */
private final Set<String> hidden;
private final boolean animations;
@@ -127,6 +132,7 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
this.listener = listener;
this.dockSize = dockSize;
this.favourites = cfg.dockApps;
+ this.fillDock = cfg.fillDock;
this.hidden = new HashSet<>(cfg.hiddenApps);
this.animations = cfg.animations;
this.advancedEffects = cfg.animations && cfg.advancedEffects;
@@ -184,6 +190,13 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
new ComponentName(ctx, HomeSettingsActivity.class), null,
ctx.getDrawable(R.drawable.ic_home_settings), null, 0));
}
+ docked = 0;
+ while (docked < fresh.size() && favourites.contains(fresh.get(docked).pkg)) docked++;
+ emptySlots = DockSlots.empty(docked, dockSize, fresh.size(), fillDock);
+ for (int i = 0; i < emptySlots; i++) {
+ fresh.add(docked + i, new Entry(Entry.EMPTY, "", new ComponentName(ctx, "empty-dock-slot-" + i),
+ null, null, null, 0));
+ }
items.clear();
items.addAll(fresh);
notifyDataSetChanged();
@@ -228,6 +241,19 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
@Override
public void onBindViewHolder(@NonNull Holder h, int position) {
Entry e = items.get(position);
+ if (e.kind == Entry.EMPTY) {
+ // A free dock slot keeps its place in the row and the band, but shows nothing and takes no focus.
+ h.card.setVisibility(View.INVISIBLE);
+ h.card.setFocusable(false);
+ h.name.setVisibility(View.INVISIBLE);
+ h.banner.setImageDrawable(null);
+ h.icon.setImageDrawable(null);
+ h.card.setOnClickListener(null);
+ h.card.setOnLongClickListener(null);
+ return;
+ }
+ h.card.setVisibility(View.VISIBLE);
+ h.card.setFocusable(true);
h.name.setText(e.name);
h.name.setVisibility(position < dockSize ? View.INVISIBLE : View.VISIBLE); // the dock has no labels
boolean focused = h.card.isFocused(); // a rebind after reload() can hit the focused tile
@@ -308,6 +334,16 @@ public class AppAdapter extends RecyclerView.Adapter<AppAdapter.Holder> {
return -1;
}
+ /** Dock slots that hold an app: the whole dock unless some slots are empty. */
+ int dockFilled() {
+ return emptySlots > 0 ? docked : dockSize;
+ }
+
+ /** A position focus can land on: an empty dock slot gives the last dock app. */
+ int focusablePosition(int position) {
+ return DockSlots.focusable(position, docked, emptySlots);
+ }
+
String labelAt(int position) {
return position >= 0 && position < items.size() ? items.get(position).label : "";
}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/Config.java b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
index f346f6afd..553270c33 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/Config.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/Config.java
@@ -36,6 +36,8 @@ final class Config {
private static final String THEME_SIGNATURE_KEY = "theme_signature";
final List<String> dockApps;
+ /** Grid apps fill the dock slots dock_apps leaves free (config.xml, fill_dock); off by default. */
+ final boolean fillDock;
final List<String> hiddenApps;
final String liveTvPackage;
final String liveTvAction;
@@ -61,13 +63,14 @@ final class Config {
/** Whether the overlay file was present and parsed. */
final boolean overlayApplied;
- private Config(List<String> dockApps, List<String> hiddenApps, String liveTvPackage, String liveTvAction,
- String sourcePanelService, String sourcePanelAction, String inputAction,
+ private Config(List<String> dockApps, boolean fillDock, List<String> hiddenApps, String liveTvPackage,
+ String liveTvAction, String sourcePanelService, String sourcePanelAction, String inputAction,
int columns, int rowsBelowDock, boolean animations, boolean advancedEffects,
boolean shamsiDate, boolean moduleCards, boolean reducedMotion, String vpnApp,
boolean showHomeSettingsShortcut, int backgroundColor, int skyIntensity,
File wallpaper, boolean overlayApplied) {
this.dockApps = Collections.unmodifiableList(dockApps);
+ this.fillDock = fillDock;
this.hiddenApps = Collections.unmodifiableList(hiddenApps);
this.liveTvPackage = liveTvPackage;
this.liveTvAction = liveTvAction;
@@ -97,6 +100,7 @@ final class Config {
static Config load(Context ctx) {
Resources res = ctx.getResources();
List<String> dock = new ArrayList<>(Arrays.asList(res.getStringArray(R.array.dock_apps)));
+ boolean fillDock = res.getBoolean(R.bool.fill_dock);
List<String> hidden = new ArrayList<>(Arrays.asList(res.getStringArray(R.array.hidden_apps)));
String liveTv = res.getString(R.string.live_tv_package).trim();
String liveTvAction = res.getString(R.string.live_tv_action).trim();
@@ -122,6 +126,7 @@ final class Config {
if (json != null) {
applied = true;
dock = stringList(json, "dock_apps", dock);
+ fillDock = bool(json, "fill_dock", fillDock);
hidden = stringList(json, "hidden_apps", hidden);
liveTv = string(json, "live_tv_package", liveTv);
liveTvAction = string(json, "live_tv_action", liveTvAction);
@@ -153,7 +158,7 @@ final class Config {
// A theme can also switch the wallpaper off while the file is still there.
if (json != null && json.has("wallpaper") && !bool(json, "wallpaper", true)) wallpaper = null;
- return new Config(dock, hidden, liveTv, liveTvAction, panelService, panelAction, inputAction,
+ return new Config(dock, fillDock, hidden, liveTv, liveTvAction, panelService, panelAction, inputAction,
Math.max(1, columns), Math.max(0, rowsBelow), animations, advancedEffects,
shamsi, moduleCards, reducedMotion, vpn, homeSettings, background,
Math.max(0, Math.min(100, skyIntensity)), wallpaper, applied);
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/DockSlots.java b/launcher/app/src/main/java/com/gathin/tvhome/DockSlots.java
new file mode 100644
index 000000000..e2f5df963
--- /dev/null
+++ b/launcher/app/src/main/java/com/gathin/tvhome/DockSlots.java
@@ -0,0 +1,23 @@
+package com.gathin.tvhome;
+
+/**
+ * The dock is the first row of the grid. dock_apps decides what is in it: a slot it leaves free stays
+ * empty instead of taking the first grid app (#162), unless fill_dock asks for the old behaviour.
+ */
+final class DockSlots {
+ private DockSlots() { }
+
+ /**
+ * Empty slots to put after the {@code docked} dock apps found. None when the dock is full, when no
+ * dock app is installed (the first row fills so Home still has a dock) or when nothing follows.
+ */
+ static int empty(int docked, int dockSize, int tiles, boolean fill) {
+ if (fill || docked <= 0 || docked >= dockSize || tiles <= docked) return 0;
+ return dockSize - docked;
+ }
+
+ /** A position focus can land on: an empty slot sends it to the last dock app. */
+ static int focusable(int position, int docked, int empty) {
+ return empty > 0 && position >= docked && position < docked + empty ? docked - 1 : position;
+ }
+}
diff --git a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
index 653182d8e..d54ece2d2 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -757,7 +757,9 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
// Horizontal: swallow the key at a row's ends so focus never wraps to the next row or
// escapes up into the top bar. Mid-row moves fall through to the default focus search.
if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
- return GridNavigation.atHorizontalEdge(position, count, COLUMNS,
+ // In the dock, the last app is the row's end: the empty slots after it take no focus.
+ int rowCount = position < COLUMNS ? Math.min(count, adapter.dockFilled()) : count;
+ return GridNavigation.atHorizontalEdge(position, rowCount, COLUMNS,
rtlAppGrid, keyCode == KeyEvent.KEYCODE_DPAD_LEFT);
}
if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
@@ -777,7 +779,7 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
btnWifi.requestFocus();
return;
}
- final int pos = Math.max(0, Math.min(position, adapter.getItemCount() - 1));
+ final int pos = adapter.focusablePosition(Math.max(0, Math.min(position, adapter.getItemCount() - 1)));
RecyclerView.ViewHolder vh = grid.findViewHolderForAdapterPosition(pos);
if (vh != null) {
View card = vh.itemView.findViewById(R.id.card);
diff --git a/launcher/app/src/main/res/values/config.xml b/launcher/app/src/main/res/values/config.xml
index 11b7e2214..e25ce5e5d 100644
--- a/launcher/app/src/main/res/values/config.xml
+++ b/launcher/app/src/main/res/values/config.xml
@@ -14,6 +14,9 @@
<item>com.google.android.youtube.tv</item>
<item>in.startv.hotstar</item>
</string-array>
+ <!-- With fewer dock_apps than columns, the free dock slots stay empty. true fills them with the first
+ grid apps instead, as older versions did. -->
+ <bool name="fill_dock">false</bool>
<!-- Apps never shown as tiles (e.g. the Live TV app, which the Inputs menu already covers). -->
<string-array name="hidden_apps">
diff --git a/launcher/app/src/test/java/com/gathin/tvhome/DockSlotsTest.java b/launcher/app/src/test/java/com/gathin/tvhome/DockSlotsTest.java
new file mode 100644
index 000000000..411b364bd
--- /dev/null
+++ b/launcher/app/src/test/java/com/gathin/tvhome/DockSlotsTest.java
@@ -0,0 +1,40 @@
+package com.gathin.tvhome;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+public class DockSlotsTest {
+ @Test public void threeDockAppsInFourColumnsLeaveOneSlotEmpty() {
+ assertEquals(1, DockSlots.empty(3, 4, 20, false));
+ }
+
+ @Test public void fillDockKeepsTheOldBehaviour() {
+ assertEquals(0, DockSlots.empty(3, 4, 20, true));
+ }
+
+ @Test public void aFullDockNeedsNoEmptySlot() {
+ assertEquals(0, DockSlots.empty(4, 4, 20, false));
+ assertEquals(0, DockSlots.empty(6, 6, 20, false));
+ }
+
+ @Test public void noInstalledDockAppFillsTheFirstRow() {
+ assertEquals(0, DockSlots.empty(0, 4, 20, false));
+ }
+
+ @Test public void nothingAfterTheDockNeedsNoEmptySlot() {
+ assertEquals(0, DockSlots.empty(2, 4, 2, false));
+ }
+
+ @Test public void focusOnAnEmptySlotGoesToTheLastDockApp() {
+ assertEquals(2, DockSlots.focusable(3, 3, 1));
+ assertEquals(1, DockSlots.focusable(2, 2, 2));
+ assertEquals(1, DockSlots.focusable(3, 2, 2));
+ }
+
+ @Test public void focusOnATileStaysPut() {
+ assertEquals(0, DockSlots.focusable(0, 3, 1));
+ assertEquals(2, DockSlots.focusable(2, 3, 1));
+ assertEquals(4, DockSlots.focusable(4, 3, 1));
+ assertEquals(3, DockSlots.focusable(3, 4, 0));
+ }
+}
diff --git a/themes/README.md b/themes/README.md
index c1e25037f..c8bc38f9f 100644
--- a/themes/README.md
+++ b/themes/README.md
@@ -27,6 +27,7 @@ is ignored, and a file that doesn't parse is ignored as a whole, so a theme can
| Key | Type | Meaning |
|---|---|---|
| `dock_apps` | list of package names | The dock row, in order; missing apps are skipped |
+| `fill_dock` | bool | Fill the dock slots `dock_apps` leaves free with the first grid apps; false (empty slots) by default |
| `hidden_apps` | list of package names | Never shown as tiles |
| `live_tv_package`, `live_tv_action` | string | The Live TV app and, if it has no leanback entry, the action to start it with |
| `source_panel_service`, `source_panel_action` | string | The TV's own source panel, for sets with no TvInputManager |