mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-04 09:56:49 +00:00
Merge "Removing unnecessary abstraction of AdapterProvider" into tm-qpr-dev am: 150b7b0497
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/21091032 Change-Id: I06fea81790cea2df014f492e7246f5abeb7fae51 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -143,7 +143,7 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
|
||||
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 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
|
||||
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 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
|
||||
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 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
|
||||
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 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
|
||||
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 @@ public class ActivityAllAppsContainerView<T extends Context & ActivityContext>
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import androidx.recyclerview.widget.GridLayoutManager;
|
||||
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 class AllAppsGridAdapter<T extends Context & ActivityContext> extends
|
||||
|
||||
|
||||
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 class AllAppsGridAdapter<T extends Context & ActivityContext> extends
|
||||
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 @@ public class AllAppsGridAdapter<T extends Context & ActivityContext> extends
|
||||
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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,18 +27,16 @@ import android.view.View.OnLongClickListener;
|
||||
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 abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
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 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
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 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
|
||||
mOnIconClickListener = mActivityContext.getItemOnClickListener();
|
||||
|
||||
mAdapterProviders = adapterProviders;
|
||||
mAdapterProvider = adapterProvider;
|
||||
mExtraHeight = res.getDimensionPixelSize(R.dimen.all_apps_height_extra);
|
||||
}
|
||||
|
||||
@@ -216,9 +213,8 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
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,18 +246,12 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
((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
|
||||
@@ -283,10 +273,4 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
|
||||
return (viewType & viewTypeMask) != 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected BaseAdapterProvider getAdapterProvider(int viewType) {
|
||||
return Arrays.stream(mAdapterProviders).filter(
|
||||
adapterProvider -> adapterProvider.isViewSupported(viewType)).findFirst().orElse(
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 class DefaultSearchAdapterProvider extends SearchAdapterProvider<Activity
|
||||
|
||||
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
|
||||
|
||||
@@ -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 @@ import com.android.launcher3.views.ActivityContext;
|
||||
*
|
||||
* @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 @@ public abstract class SearchAdapterProvider<T extends ActivityContext> extends B
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user