Refactors Search results into separate RV for Toast.

This will help enable transitions between A-Z apps lists and
search results because both can be seen simultaneously and
manipulated independently.

Some high level items of the refactor:
 - SearchRecyclerView is added; logic that populated the main
   (personal) tab with search results was simply redirected to
   this RV instead.
 - BaseAllAppsContainerView added isSearching() method. Returns
   false, and ActivityAllAppsContainerView overrides (as search
   is handled there).
 - Renamed BaseRecyclerView to FastScrollRecyclerView to better
   describe what it does. SearchRecyclerView extends this, but
   returns false for supportsFastScrolling().
 - AlphabeticalAppsList#mAllAppsStore is now optional, so the
   Search RV doesn't need to store/listen to apps. Note this
   doesn't affect the predicted app row which is still updated
   if one of the predicted apps is uninstalled (I tested this).

Future work:
 - Determine why dispatchRestoreInstanceState is not called for
   BaseAllAppsContainerView. Save is called, e.g. on rotation.
   Effect of restore not called: rotating while searching goes
   back to A-Z list.
 - Keep suggested apps in Header while searching. Currently they
   are rendered in the SearchRV above search results, as before.
 - Potentially extract Personal/Work tabs to move independently of
   header.
 - AlphabeticalAppsList is a misleading name because it can also
   contains search results. However, things are pretty intertwined
   between that and BaseAllAppsAdapter (effectively a circular
   dependency), so I figured cleaning all that up was out of the
   immediate scope of this refactor, which is mainly meant to
   unblock transition work.

Bug: 206905515
Test: Manually checked for regressions, ran tests.
Change-Id: I4d3757c8a8f9b774956ca6be541dd4fcdad1de13
This commit is contained in:
Andy Wickham
2022-04-11 16:17:50 -07:00
parent 833b0a0b5b
commit 6729f0b950
21 changed files with 300 additions and 146 deletions

View File

@@ -33,6 +33,7 @@ import androidx.recyclerview.widget.RecyclerView;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.Insettable;
import com.android.launcher3.R;
import com.android.launcher3.allapps.BaseAllAppsContainerView.AdapterHolder;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.uioverrides.plugins.PluginManagerWrapper;
import com.android.launcher3.views.ActivityContext;
@@ -90,8 +91,8 @@ public class FloatingHeaderView extends LinearLayout implements
protected ViewGroup mTabLayout;
private AllAppsRecyclerView mMainRV;
private AllAppsRecyclerView mWorkRV;
private SearchRecyclerView mSearchRV;
private AllAppsRecyclerView mCurrentRV;
private ViewGroup mParent;
public boolean mHeaderCollapsed;
protected int mSnappedScrolledY;
private int mTranslationY;
@@ -100,7 +101,6 @@ public class FloatingHeaderView extends LinearLayout implements
protected boolean mTabsHidden;
protected int mMaxTranslation;
private boolean mMainRVActive = true;
private boolean mCollapsed = false;
@@ -232,7 +232,8 @@ public class FloatingHeaderView extends LinearLayout implements
return super.getFocusedChild();
}
void setup(AllAppsRecyclerView mainRV, AllAppsRecyclerView workRV, boolean tabsHidden) {
void setup(AllAppsRecyclerView mainRV, AllAppsRecyclerView workRV, SearchRecyclerView searchRV,
int activeRV, boolean tabsHidden) {
for (FloatingHeaderRow row : mAllRows) {
row.setup(this, mAllRows, tabsHidden);
}
@@ -242,8 +243,8 @@ public class FloatingHeaderView extends LinearLayout implements
mTabLayout.setVisibility(tabsHidden ? View.GONE : View.VISIBLE);
mMainRV = setupRV(mMainRV, mainRV);
mWorkRV = setupRV(mWorkRV, workRV);
mParent = (ViewGroup) mMainRV.getParent();
setMainActive(mMainRVActive || mWorkRV == null);
mSearchRV = (SearchRecyclerView) setupRV(mSearchRV, searchRV);
setActiveRV(activeRV);
reset(false);
}
@@ -267,9 +268,10 @@ public class FloatingHeaderView extends LinearLayout implements
}
}
public void setMainActive(boolean active) {
mCurrentRV = active ? mMainRV : mWorkRV;
mMainRVActive = active;
public void setActiveRV(int rvType) {
mCurrentRV =
rvType == AdapterHolder.MAIN ? mMainRV
: rvType == AdapterHolder.WORK ? mWorkRV : mSearchRV;
}
public int getMaxTranslation() {
@@ -332,10 +334,15 @@ public class FloatingHeaderView extends LinearLayout implements
mHeaderClip.top = clipTop;
// clipping on a draw might cause additional redraw
setClipBounds(mHeaderClip);
mMainRV.setClipBounds(mRVClip);
if (mMainRV != null) {
mMainRV.setClipBounds(mRVClip);
}
if (mWorkRV != null) {
mWorkRV.setClipBounds(mRVClip);
}
if (mSearchRV != null) {
mSearchRV.setClipBounds(mRVClip);
}
}
/**
@@ -402,8 +409,8 @@ public class FloatingHeaderView extends LinearLayout implements
}
private void calcOffset(Point p) {
p.x = getLeft() - mCurrentRV.getLeft() - mParent.getLeft();
p.y = getTop() - mCurrentRV.getTop() - mParent.getTop();
p.x = getLeft() - mCurrentRV.getLeft() - ((ViewGroup) mCurrentRV.getParent()).getLeft();
p.y = getTop() - mCurrentRV.getTop() - ((ViewGroup) mCurrentRV.getParent()).getTop();
}
public boolean hasVisibleContent() {