Merge "Removing unnecessary abstraction of AdapterProvider" into tm-qpr-dev
diff --git a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
index 95e61b8..3aa9f7c 100644
--- a/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/ActivityAllAppsContainerView.java
@@ -143,7 +143,7 @@
private boolean mRebindAdaptersAfterSearchAnimation;
private int mNavBarScrimHeight = 0;
private SearchRecyclerView mSearchRecyclerView;
- private SearchAdapterProvider<?> mMainAdapterProvider;
+ protected SearchAdapterProvider<?> mMainAdapterProvider;
private View mBottomSheetHandleArea;
private boolean mHasWorkApps;
private float[] mBottomSheetCornerRadii;
@@ -202,9 +202,12 @@
protected void initContent() {
mMainAdapterProvider = createMainAdapterProvider();
- mAH.set(AdapterHolder.MAIN, new AdapterHolder(AdapterHolder.MAIN));
- mAH.set(AdapterHolder.WORK, new AdapterHolder(AdapterHolder.WORK));
- mAH.set(SEARCH, new AdapterHolder(SEARCH));
+ mAH.set(AdapterHolder.MAIN, new AdapterHolder(AdapterHolder.MAIN,
+ new AlphabeticalAppsList<>(mActivityContext, mAllAppsStore, null)));
+ mAH.set(AdapterHolder.WORK, new AdapterHolder(AdapterHolder.WORK,
+ new AlphabeticalAppsList<>(mActivityContext, mAllAppsStore, mWorkManager)));
+ mAH.set(SEARCH, new AdapterHolder(SEARCH,
+ new AlphabeticalAppsList<>(mActivityContext, null, null)));
getLayoutInflater().inflate(R.layout.all_apps_content, this);
mHeader = findViewById(R.id.all_apps_header);
@@ -344,7 +347,7 @@
mAH.get(i).mRecyclerView.scrollToTop();
}
}
- if (isHeaderVisible()) {
+ if (mHeader != null && mHeader.getVisibility() == VISIBLE) {
mHeader.reset(animate);
}
// Reset the base recycler view after transitioning home.
@@ -627,10 +630,9 @@
layoutParams.removeRule(RelativeLayout.ALIGN_PARENT_TOP);
}
- protected BaseAllAppsAdapter<T> createAdapter(AlphabeticalAppsList<T> appsList,
- BaseAdapterProvider[] adapterProviders) {
+ protected BaseAllAppsAdapter<T> createAdapter(AlphabeticalAppsList<T> appsList) {
return new AllAppsGridAdapter<>(mActivityContext, getLayoutInflater(), appsList,
- adapterProviders);
+ mMainAdapterProvider);
}
// TODO(b/216683257): Remove when Taskbar All Apps supports search.
@@ -1001,10 +1003,6 @@
return rv == null ? null : rv.getScrollbar();
}
- public boolean isHeaderVisible() {
- return mHeader != null && mHeader.getVisibility() == View.VISIBLE;
- }
-
/**
* Adds an update listener to animator that adds springs to the animation.
*/
@@ -1155,15 +1153,10 @@
final Rect mPadding = new Rect();
AllAppsRecyclerView mRecyclerView;
- AdapterHolder(int type) {
+ AdapterHolder(int type, AlphabeticalAppsList<T> appsList) {
mType = type;
- mAppsList = new AlphabeticalAppsList<>(mActivityContext,
- isSearch() ? null : mAllAppsStore,
- isWork() ? mWorkManager : null);
- BaseAdapterProvider[] adapterProviders =
- new BaseAdapterProvider[]{mMainAdapterProvider};
-
- mAdapter = createAdapter(mAppsList, adapterProviders);
+ mAppsList = appsList;
+ mAdapter = createAdapter(mAppsList);
mAppsList.setAdapter(mAdapter);
mLayoutManager = mAdapter.getLayoutManager();
}
diff --git a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
index 112d47e..866932a 100644
--- a/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
+++ b/src/com/android/launcher3/allapps/AllAppsGridAdapter.java
@@ -29,6 +29,7 @@
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.Adapter;
+import com.android.launcher3.allapps.search.SearchAdapterProvider;
import com.android.launcher3.util.ScrollableLayoutManager;
import com.android.launcher3.views.ActivityContext;
@@ -73,8 +74,8 @@
public AllAppsGridAdapter(T activityContext, LayoutInflater inflater,
- AlphabeticalAppsList apps, BaseAdapterProvider[] adapterProviders) {
- super(activityContext, inflater, apps, adapterProviders);
+ AlphabeticalAppsList apps, SearchAdapterProvider<?> adapterProvider) {
+ super(activityContext, inflater, apps, adapterProvider);
mGridLayoutMgr = new AppsGridLayoutManager(mActivityContext);
mGridLayoutMgr.setSpanSizeLookup(new GridSpanSizer());
setAppsPerRow(activityContext.getDeviceProfile().numShownAllAppsColumns);
@@ -195,11 +196,9 @@
public void setAppsPerRow(int appsPerRow) {
mAppsPerRow = appsPerRow;
int totalSpans = mAppsPerRow;
- for (BaseAdapterProvider adapterProvider : mAdapterProviders) {
- for (int itemPerRow : adapterProvider.getSupportedItemsPerRowArray()) {
- if (totalSpans % itemPerRow != 0) {
- totalSpans *= itemPerRow;
- }
+ for (int itemPerRow : mAdapterProvider.getSupportedItemsPerRowArray()) {
+ if (totalSpans % itemPerRow != 0) {
+ totalSpans *= itemPerRow;
}
}
mGridLayoutMgr.setSpanCount(totalSpans);
@@ -226,9 +225,8 @@
if (isIconViewType(viewType)) {
return totalSpans / mAppsPerRow;
} else {
- BaseAdapterProvider adapterProvider = getAdapterProvider(viewType);
- if (adapterProvider != null) {
- return totalSpans / adapterProvider.getItemsPerRow(viewType, mAppsPerRow);
+ if (mAdapterProvider.isViewSupported(viewType)) {
+ return totalSpans / mAdapterProvider.getItemsPerRow(viewType, mAppsPerRow);
}
// Section breaks span the full width
diff --git a/src/com/android/launcher3/allapps/BaseAdapterProvider.java b/src/com/android/launcher3/allapps/BaseAdapterProvider.java
deleted file mode 100644
index 308294c..0000000
--- a/src/com/android/launcher3/allapps/BaseAdapterProvider.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.launcher3.allapps;
-
-import android.view.LayoutInflater;
-import android.view.ViewGroup;
-
-/**
- * A UI expansion wrapper providing for providing dynamic recyclerview items
- */
-public abstract class BaseAdapterProvider {
-
- /**
- * Returns whether or not viewType can be handled by searchProvider
- */
- public abstract boolean isViewSupported(int viewType);
-
- /**
- * Called from RecyclerView.Adapter#onBindViewHolder
- */
- public abstract void onBindView(AllAppsGridAdapter.ViewHolder holder, int position);
-
- /**
- * Called from RecyclerView.Adapter#onCreateViewHolder
- */
- public abstract AllAppsGridAdapter.ViewHolder onCreateViewHolder(LayoutInflater layoutInflater,
- ViewGroup parent, int viewType);
-
- /**
- * Returns supported item per row combinations supported
- */
- public int[] getSupportedItemsPerRowArray() {
- return new int[]{};
- }
-
- /**
- * Returns how many cells a view should span
- */
- public int getItemsPerRow(int viewType, int appsPerRow) {
- return appsPerRow;
- }
-
-}
diff --git a/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java b/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java
index 42f8b0c..7040de5 100644
--- a/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java
+++ b/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java
@@ -27,18 +27,16 @@
import android.view.ViewGroup;
import android.widget.TextView;
-import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import com.android.launcher3.BubbleTextView;
import com.android.launcher3.R;
+import com.android.launcher3.allapps.search.SearchAdapterProvider;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.views.ActivityContext;
-import java.util.Arrays;
-
/**
* Adapter for all the apps.
*
@@ -65,8 +63,7 @@
public static final int VIEW_TYPE_MASK_DIVIDER = VIEW_TYPE_ALL_APPS_DIVIDER;
public static final int VIEW_TYPE_MASK_ICON = VIEW_TYPE_ICON;
-
- protected final BaseAdapterProvider[] mAdapterProviders;
+ protected final SearchAdapterProvider<?> mAdapterProvider;
/**
* ViewHolder for each icon.
@@ -146,7 +143,7 @@
private final int mExtraHeight;
public BaseAllAppsAdapter(T activityContext, LayoutInflater inflater,
- AlphabeticalAppsList<T> apps, BaseAdapterProvider[] adapterProviders) {
+ AlphabeticalAppsList<T> apps, SearchAdapterProvider<?> adapterProvider) {
Resources res = activityContext.getResources();
mActivityContext = activityContext;
mApps = apps;
@@ -154,7 +151,7 @@
mOnIconClickListener = mActivityContext.getItemOnClickListener();
- mAdapterProviders = adapterProviders;
+ mAdapterProvider = adapterProvider;
mExtraHeight = res.getDimensionPixelSize(R.dimen.all_apps_height_extra);
}
@@ -216,9 +213,8 @@
return new ViewHolder(mLayoutInflater.inflate(
R.layout.work_apps_paused, parent, false));
default:
- BaseAdapterProvider adapterProvider = getAdapterProvider(viewType);
- if (adapterProvider != null) {
- return adapterProvider.onCreateViewHolder(mLayoutInflater, parent, viewType);
+ if (mAdapterProvider.isViewSupported(viewType)) {
+ return mAdapterProvider.onCreateViewHolder(mLayoutInflater, parent, viewType);
}
throw new RuntimeException("Unexpected view type" + viewType);
}
@@ -250,19 +246,13 @@
((WorkEduCard) holder.itemView).setPosition(position);
break;
default:
- BaseAdapterProvider adapterProvider = getAdapterProvider(holder.getItemViewType());
- if (adapterProvider != null) {
- adapterProvider.onBindView(holder, position);
+ if (mAdapterProvider.isViewSupported(holder.getItemViewType())) {
+ mAdapterProvider.onBindView(holder, position);
}
}
}
@Override
- public void onViewRecycled(@NonNull ViewHolder holder) {
- super.onViewRecycled(holder);
- }
-
- @Override
public boolean onFailedToRecycleView(ViewHolder holder) {
// Always recycle and we will reset the view when it is bound
return true;
@@ -283,10 +273,4 @@
return (viewType & viewTypeMask) != 0;
}
- @Nullable
- protected BaseAdapterProvider getAdapterProvider(int viewType) {
- return Arrays.stream(mAdapterProviders).filter(
- adapterProvider -> adapterProvider.isViewSupported(viewType)).findFirst().orElse(
- null);
- }
}
diff --git a/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java b/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java
index 20edf8a..714304b 100644
--- a/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java
+++ b/src/com/android/launcher3/allapps/search/DefaultSearchAdapterProvider.java
@@ -15,12 +15,10 @@
*/
package com.android.launcher3.allapps.search;
-import android.graphics.Canvas;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.android.launcher3.BubbleTextView;
@@ -38,13 +36,7 @@
public DefaultSearchAdapterProvider(ActivityContext launcher) {
super(launcher);
- mDecoration = new RecyclerView.ItemDecoration() {
- @Override
- public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent,
- @NonNull RecyclerView.State state) {
- super.onDraw(c, parent, state);
- }
- };
+ mDecoration = new RecyclerView.ItemDecoration() { };
}
@Override
diff --git a/src/com/android/launcher3/allapps/search/SearchAdapterProvider.java b/src/com/android/launcher3/allapps/search/SearchAdapterProvider.java
index 4f7f9af..15756f5 100644
--- a/src/com/android/launcher3/allapps/search/SearchAdapterProvider.java
+++ b/src/com/android/launcher3/allapps/search/SearchAdapterProvider.java
@@ -16,11 +16,13 @@
package com.android.launcher3.allapps.search;
+import android.view.LayoutInflater;
import android.view.View;
+import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
-import com.android.launcher3.allapps.BaseAdapterProvider;
+import com.android.launcher3.allapps.AllAppsGridAdapter;
import com.android.launcher3.views.ActivityContext;
/**
@@ -28,7 +30,7 @@
*
* @param <T> Context for this adapter provider.
*/
-public abstract class SearchAdapterProvider<T extends ActivityContext> extends BaseAdapterProvider {
+public abstract class SearchAdapterProvider<T extends ActivityContext> {
protected final T mLauncher;
@@ -56,4 +58,34 @@
* Clear the highlighted view.
*/
public abstract void clearHighlightedItem();
+
+ /**
+ * Returns whether or not viewType can be handled by searchProvider
+ */
+ public abstract boolean isViewSupported(int viewType);
+
+ /**
+ * Called from RecyclerView.Adapter#onBindViewHolder
+ */
+ public abstract void onBindView(AllAppsGridAdapter.ViewHolder holder, int position);
+
+ /**
+ * Called from RecyclerView.Adapter#onCreateViewHolder
+ */
+ public abstract AllAppsGridAdapter.ViewHolder onCreateViewHolder(LayoutInflater layoutInflater,
+ ViewGroup parent, int viewType);
+
+ /**
+ * Returns supported item per row combinations supported
+ */
+ public int[] getSupportedItemsPerRowArray() {
+ return new int[]{};
+ }
+
+ /**
+ * Returns how many cells a view should span
+ */
+ public int getItemsPerRow(int viewType, int appsPerRow) {
+ return appsPerRow;
+ }
}