Skip to content

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

launcher: Up into a grid row scrolls it on screen, not to the dock line

Samuel Hinton72e4cfa7480a
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 499018535..5ee14562b 100644
--- a/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
+++ b/launcher/app/src/main/java/com/gathin/tvhome/MainActivity.java
@@ -215,7 +215,34 @@ public class MainActivity extends Activity implements AppAdapter.TileListener {
hiddenApps = new HashSet<>(cfg.hiddenApps);
grid = findViewById(R.id.grid);
- grid.setLayoutManager(new GridLayoutManager(this, COLUMNS));
+ grid.setLayoutManager(new GridLayoutManager(this, COLUMNS) {
+ /**
+ * Every "bring this tile on screen" scroll lands here, both RecyclerView's own on focus and
+ * onTileFocused's. The stock version treats the grid's top padding as the visible top, but that
+ * padding only pushes the dock down the screen: grid rows scroll up into it. With the stock rule,
+ * Up into a row above the padding dragged that row down to the padding line, cut it off at the
+ * bottom of the screen and could scroll the focused tile out entirely, dropping focus into the
+ * top bar. Grid tiles now scroll just enough to show the rect between the grid's top edge and its
+ * bottom; dock tiles are left to onTileFocused, which parks the dock row on the padding line.
+ */
+ @Override
+ public boolean requestChildRectangleOnScreen(@NonNull RecyclerView parent, @NonNull View child,
+ @NonNull Rect rect, boolean immediate,
+ boolean focusedChildVisible) {
+ if (getPosition(child) < COLUMNS) return false;
+ int top = child.getTop() + rect.top;
+ int bottom = top + rect.height();
+ int limitBottom = getHeight() - getPaddingBottom();
+ int dy;
+ if (top < 0) dy = top;
+ else if (bottom > limitBottom) dy = Math.min(top, bottom - limitBottom);
+ else dy = 0;
+ if (dy == 0) return false;
+ if (immediate || reducedMotion) parent.scrollBy(0, dy);
+ else parent.smoothScrollBy(0, dy);
+ return true;
+ }
+ });
grid.setHasFixedSize(true);
grid.setItemAnimator(null);
grid.addItemDecoration(new DockDecoration(COLUMNS, density));