Revise homepage highlight mechanism

- Create TopLevelHighlightMixin to handle highlight actions and simplify
  TopLevelSettings
- Fix the error highlight and the flicker after screen rotation
- Postpone creating the fragment until it's needed to accelerate the
  initialization and to fix the search highlight function breakage after
  toggling light/dark mode
- Register activity embedding rules only once for injection and
  wallpaper
- Do not highlight Tips & support since it's full screen
- Refactor ActivityEmbeddingRulesController

Bug: 207316936
Test: manual, robotest build pass
Change-Id: If322ec180b03ee123987c70779a25c6a570d9faf
This commit is contained in:
Jason Chiu
2021-11-30 16:13:37 +08:00
parent 506c6b804f
commit a305c23f5e
9 changed files with 346 additions and 166 deletions

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
@@ -59,17 +60,18 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
private final int mNormalBackgroundRes;
private final int mHighlightBackgroundRes;
private String mHighlightKey;
private String mPreviousHighlightKey;
private int mHighlightPosition = RecyclerView.NO_POSITION;
private int mScrollPosition = RecyclerView.NO_POSITION;
private boolean mHighlightNeeded;
private boolean mScrolled;
private SparseArray<PreferenceViewHolder> mViewHolders;
public HighlightableTopLevelPreferenceAdapter(SettingsHomepageActivity homepageActivity,
PreferenceGroup preferenceGroup, RecyclerView recyclerView, String key) {
super(preferenceGroup);
mRecyclerView = recyclerView;
mHighlightKey = key;
mViewHolders = new SparseArray<>();
mContext = preferenceGroup.getContext();
mHomepageActivity = homepageActivity;
final TypedValue outValue = new TypedValue();
@@ -92,6 +94,7 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
@Override
public void onBindViewHolder(PreferenceViewHolder holder, int position) {
super.onBindViewHolder(holder, position);
mViewHolders.put(position, holder);
updateBackground(holder, position);
}
@@ -120,9 +123,9 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
return;
}
final int previousPosition = mHighlightPosition;
if (TextUtils.isEmpty(mHighlightKey)) {
// De-highlight previous preference.
final int previousPosition = mHighlightPosition;
mHighlightPosition = RecyclerView.NO_POSITION;
mScrolled = true;
if (previousPosition >= 0) {
@@ -145,10 +148,14 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
// Turn on/off highlight when screen split mode is changed.
if (highlightNeeded != mHighlightNeeded) {
Log.d(TAG, "Highlight change needed: " + highlightNeeded);
Log.d(TAG, "Highlight needed change: " + highlightNeeded);
mHighlightNeeded = highlightNeeded;
mHighlightPosition = position;
notifyItemChanged(position);
if (!highlightNeeded) {
// De-highlight to prevent a flicker
removeHighlightAt(previousPosition);
}
return;
}
@@ -156,7 +163,6 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
return;
}
final int previousPosition = mHighlightPosition;
mHighlightPosition = position;
Log.d(TAG, "Request highlight position " + position);
Log.d(TAG, "Is highlight needed: " + highlightNeeded);
@@ -178,20 +184,11 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
* preference is clicked.
*/
public void highlightPreference(String key, boolean scrollNeeded) {
mPreviousHighlightKey = mHighlightKey;
mHighlightKey = key;
mScrolled = !scrollNeeded;
requestHighlight();
}
/**
* A function that restores the previous highlighted setting.
*/
public void restorePreviousHighlight() {
mHighlightKey = mPreviousHighlightKey;
requestHighlight();
}
@Override
public void onHomepageLoaded() {
scroll();
@@ -224,6 +221,17 @@ public class HighlightableTopLevelPreferenceAdapter extends PreferenceGroupAdapt
}
}
private void removeHighlightAt(int position) {
if (position >= 0) {
// De-highlight the existing preference view holder at an early stage
final PreferenceViewHolder holder = mViewHolders.get(position);
if (holder != null) {
removeHighlightBackground(holder);
}
notifyItemChanged(position);
}
}
private void addHighlightBackground(PreferenceViewHolder holder) {
final View v = holder.itemView;
v.setBackgroundResource(mHighlightBackgroundRes);