Fix the scrolling behavior in Settings homepage

- we always scroll to top of homepage first.
- if target position already exist on screen,
  we don't need to scroll.
- if target position doesn't exist on screen,
  scroll to the target position.

Bug: 349696107
Test: manual
Flag: com.android.settings.flags.homepage_revamp
Change-Id: I18c314d19eb38f22f799cb8bf087bf71f4f7d466
This commit is contained in:
Edgar Wang
2024-07-24 07:55:12 +00:00
parent 5c466c5ba3
commit 615133cc00

View File

@@ -17,6 +17,7 @@
package com.android.settings.widget;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;
@@ -212,6 +213,14 @@ public class HighlightableTopLevelPreferenceAdapter extends RoundCornerPreferenc
// Scroll to the top to reset the position.
mRecyclerView.nestedScrollBy(0, -mRecyclerView.getHeight());
// get the visible area of the recycler view
Rect rvRect = new Rect();
mRecyclerView.getGlobalVisibleRect(rvRect);
if (Flags.homepageRevamp() && view.getBottom() <= rvRect.height()) {
// the request position already fully visible in the visible area
return;
}
final int scrollY = view.getTop();
if (scrollY > 0) {
mRecyclerView.nestedScrollBy(0, scrollY);