2015-05-14 19:24:40 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2015 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.
|
|
|
|
|
*/
|
2015-05-22 11:12:27 -07:00
|
|
|
package com.android.launcher3.allapps;
|
2015-03-10 16:28:47 -07:00
|
|
|
|
2022-03-09 17:25:15 +00:00
|
|
|
import static com.android.launcher3.touch.ItemLongClickListener.INSTANCE_ALL_APPS;
|
|
|
|
|
|
2015-03-10 16:28:47 -07:00
|
|
|
import android.content.Context;
|
2022-03-09 17:25:15 +00:00
|
|
|
import android.content.res.Resources;
|
|
|
|
|
import android.view.Gravity;
|
2015-03-10 16:28:47 -07:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
|
import android.view.View;
|
2022-03-09 17:25:15 +00:00
|
|
|
import android.view.View.OnClickListener;
|
|
|
|
|
import android.view.View.OnFocusChangeListener;
|
|
|
|
|
import android.view.View.OnLongClickListener;
|
2015-03-10 16:28:47 -07:00
|
|
|
import android.view.ViewGroup;
|
2015-07-30 12:53:33 -07:00
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
2022-03-09 17:25:15 +00:00
|
|
|
import android.widget.TextView;
|
2016-04-28 17:39:03 -07:00
|
|
|
|
2022-03-09 17:25:15 +00:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
2019-12-10 12:19:13 -08:00
|
|
|
import androidx.core.view.accessibility.AccessibilityEventCompat;
|
|
|
|
|
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
|
|
|
|
|
import androidx.core.view.accessibility.AccessibilityRecordCompat;
|
|
|
|
|
import androidx.recyclerview.widget.GridLayoutManager;
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
|
2022-03-09 17:25:15 +00:00
|
|
|
import com.android.launcher3.BubbleTextView;
|
|
|
|
|
import com.android.launcher3.R;
|
|
|
|
|
import com.android.launcher3.config.FeatureFlags;
|
|
|
|
|
import com.android.launcher3.model.data.AppInfo;
|
|
|
|
|
import com.android.launcher3.model.data.ItemInfoWithIcon;
|
2022-01-14 23:15:47 -05:00
|
|
|
import com.android.launcher3.views.ActivityContext;
|
2017-02-21 16:43:56 -08:00
|
|
|
|
2022-03-09 17:25:15 +00:00
|
|
|
import java.util.Arrays;
|
2017-02-21 16:43:56 -08:00
|
|
|
import java.util.List;
|
2015-04-06 15:12:49 -07:00
|
|
|
|
2015-03-10 16:28:47 -07:00
|
|
|
/**
|
|
|
|
|
* The grid view adapter of all the apps.
|
2022-01-14 23:15:47 -05:00
|
|
|
*
|
|
|
|
|
* @param <T> Type of context inflating all apps.
|
2015-03-10 16:28:47 -07:00
|
|
|
*/
|
2022-01-14 23:15:47 -05:00
|
|
|
public class AllAppsGridAdapter<T extends Context & ActivityContext> extends
|
2022-03-09 17:25:15 +00:00
|
|
|
RecyclerView.Adapter<AllAppsGridAdapter.ViewHolder> {
|
2015-03-10 16:28:47 -07:00
|
|
|
|
|
|
|
|
public static final String TAG = "AppsGridAdapter";
|
|
|
|
|
|
2022-03-09 17:25:15 +00:00
|
|
|
// A normal icon
|
|
|
|
|
public static final int VIEW_TYPE_ICON = 1 << 1;
|
|
|
|
|
// The message shown when there are no filtered results
|
|
|
|
|
public static final int VIEW_TYPE_EMPTY_SEARCH = 1 << 2;
|
|
|
|
|
// The message to continue to a market search when there are no filtered results
|
|
|
|
|
public static final int VIEW_TYPE_SEARCH_MARKET = 1 << 3;
|
|
|
|
|
|
|
|
|
|
// We use various dividers for various purposes. They share enough attributes to reuse layouts,
|
|
|
|
|
// but differ in enough attributes to require different view types
|
|
|
|
|
|
|
|
|
|
// A divider that separates the apps list and the search market button
|
|
|
|
|
public static final int VIEW_TYPE_ALL_APPS_DIVIDER = 1 << 4;
|
|
|
|
|
|
|
|
|
|
// Common view type masks
|
|
|
|
|
public static final int VIEW_TYPE_MASK_DIVIDER = VIEW_TYPE_ALL_APPS_DIVIDER;
|
|
|
|
|
public static final int VIEW_TYPE_MASK_ICON = VIEW_TYPE_ICON;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final BaseAdapterProvider[] mAdapterProviders;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* ViewHolder for each icon.
|
|
|
|
|
*/
|
|
|
|
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
|
|
|
|
|
|
|
|
|
public ViewHolder(View v) {
|
|
|
|
|
super(v);
|
|
|
|
|
}
|
2015-03-10 16:28:47 -07:00
|
|
|
}
|
|
|
|
|
|
2020-08-15 09:40:26 -07:00
|
|
|
/**
|
2022-03-09 17:25:15 +00:00
|
|
|
* Info about a particular adapter item (can be either section or app)
|
2020-08-15 09:40:26 -07:00
|
|
|
*/
|
2022-03-09 17:25:15 +00:00
|
|
|
public static class AdapterItem {
|
|
|
|
|
/** Common properties */
|
|
|
|
|
// The index of this adapter item in the list
|
|
|
|
|
public int position;
|
|
|
|
|
// The type of this item
|
|
|
|
|
public int viewType;
|
|
|
|
|
|
|
|
|
|
// The section name of this item. Note that there can be multiple items with different
|
|
|
|
|
// sectionNames in the same section
|
|
|
|
|
public String sectionName = null;
|
|
|
|
|
// The row that this item shows up on
|
|
|
|
|
public int rowIndex;
|
|
|
|
|
// The index of this app in the row
|
|
|
|
|
public int rowAppIndex;
|
|
|
|
|
// The associated ItemInfoWithIcon for the item
|
|
|
|
|
public ItemInfoWithIcon itemInfo = null;
|
|
|
|
|
// The index of this app not including sections
|
|
|
|
|
public int appIndex = -1;
|
|
|
|
|
// Search section associated to result
|
|
|
|
|
public DecorationInfo decorationInfo = null;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory method for AppIcon AdapterItem
|
|
|
|
|
*/
|
|
|
|
|
public static AdapterItem asApp(int pos, String sectionName, AppInfo appInfo,
|
|
|
|
|
int appIndex) {
|
|
|
|
|
AdapterItem item = new AdapterItem();
|
|
|
|
|
item.viewType = VIEW_TYPE_ICON;
|
|
|
|
|
item.position = pos;
|
|
|
|
|
item.sectionName = sectionName;
|
|
|
|
|
item.itemInfo = appInfo;
|
|
|
|
|
item.appIndex = appIndex;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory method for empty search results view
|
|
|
|
|
*/
|
|
|
|
|
public static AdapterItem asEmptySearch(int pos) {
|
|
|
|
|
AdapterItem item = new AdapterItem();
|
|
|
|
|
item.viewType = VIEW_TYPE_EMPTY_SEARCH;
|
|
|
|
|
item.position = pos;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory method for a dividerView in AllAppsSearch
|
|
|
|
|
*/
|
|
|
|
|
public static AdapterItem asAllAppsDivider(int pos) {
|
|
|
|
|
AdapterItem item = new AdapterItem();
|
|
|
|
|
item.viewType = VIEW_TYPE_ALL_APPS_DIVIDER;
|
|
|
|
|
item.position = pos;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Factory method for a market search button
|
|
|
|
|
*/
|
|
|
|
|
public static AdapterItem asMarketSearch(int pos) {
|
|
|
|
|
AdapterItem item = new AdapterItem();
|
|
|
|
|
item.viewType = VIEW_TYPE_SEARCH_MARKET;
|
|
|
|
|
item.position = pos;
|
|
|
|
|
return item;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected boolean isCountedForAccessibility() {
|
|
|
|
|
return viewType == VIEW_TYPE_ICON || viewType == VIEW_TYPE_SEARCH_MARKET;
|
|
|
|
|
}
|
2020-08-15 09:40:26 -07:00
|
|
|
}
|
|
|
|
|
|
2015-07-30 12:53:33 -07:00
|
|
|
/**
|
|
|
|
|
* A subclass of GridLayoutManager that overrides accessibility values during app search.
|
|
|
|
|
*/
|
|
|
|
|
public class AppsGridLayoutManager extends GridLayoutManager {
|
|
|
|
|
|
|
|
|
|
public AppsGridLayoutManager(Context context) {
|
|
|
|
|
super(context, 1, GridLayoutManager.VERTICAL, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
|
|
|
|
|
super.onInitializeAccessibilityEvent(event);
|
2015-07-10 12:38:30 -07:00
|
|
|
|
|
|
|
|
// Ensure that we only report the number apps for accessibility not including other
|
|
|
|
|
// adapter views
|
|
|
|
|
final AccessibilityRecordCompat record = AccessibilityEventCompat
|
|
|
|
|
.asRecord(event);
|
|
|
|
|
record.setItemCount(mApps.getNumFilteredApps());
|
2017-02-21 16:43:56 -08:00
|
|
|
record.setFromIndex(Math.max(0,
|
|
|
|
|
record.getFromIndex() - getRowsNotForAccessibility(record.getFromIndex())));
|
|
|
|
|
record.setToIndex(Math.max(0,
|
|
|
|
|
record.getToIndex() - getRowsNotForAccessibility(record.getToIndex())));
|
2015-07-30 12:53:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getRowCountForAccessibility(RecyclerView.Recycler recycler,
|
|
|
|
|
RecyclerView.State state) {
|
2017-02-21 16:43:56 -08:00
|
|
|
return super.getRowCountForAccessibility(recycler, state) -
|
|
|
|
|
getRowsNotForAccessibility(mApps.getAdapterItems().size() - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onInitializeAccessibilityNodeInfoForItem(RecyclerView.Recycler recycler,
|
|
|
|
|
RecyclerView.State state, View host, AccessibilityNodeInfoCompat info) {
|
|
|
|
|
super.onInitializeAccessibilityNodeInfoForItem(recycler, state, host, info);
|
|
|
|
|
|
|
|
|
|
ViewGroup.LayoutParams lp = host.getLayoutParams();
|
|
|
|
|
AccessibilityNodeInfoCompat.CollectionItemInfoCompat cic = info.getCollectionItemInfo();
|
|
|
|
|
if (!(lp instanceof LayoutParams) || (cic == null)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
LayoutParams glp = (LayoutParams) lp;
|
|
|
|
|
info.setCollectionItemInfo(AccessibilityNodeInfoCompat.CollectionItemInfoCompat.obtain(
|
|
|
|
|
cic.getRowIndex() - getRowsNotForAccessibility(glp.getViewAdapterPosition()),
|
|
|
|
|
cic.getRowSpan(),
|
|
|
|
|
cic.getColumnIndex(),
|
|
|
|
|
cic.getColumnSpan(),
|
|
|
|
|
cic.isHeading(),
|
|
|
|
|
cic.isSelected()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the number of rows before {@param adapterPosition}, including this position
|
|
|
|
|
* which should not be counted towards the collection info.
|
|
|
|
|
*/
|
|
|
|
|
private int getRowsNotForAccessibility(int adapterPosition) {
|
|
|
|
|
List<AdapterItem> items = mApps.getAdapterItems();
|
2022-03-09 17:25:15 +00:00
|
|
|
adapterPosition = Math.max(adapterPosition, mApps.getAdapterItems().size() - 1);
|
2017-02-21 16:43:56 -08:00
|
|
|
int extraRows = 0;
|
|
|
|
|
for (int i = 0; i <= adapterPosition; i++) {
|
2018-01-23 13:52:48 -08:00
|
|
|
if (!isViewType(items.get(i).viewType, VIEW_TYPE_MASK_ICON)) {
|
2017-02-21 16:43:56 -08:00
|
|
|
extraRows++;
|
|
|
|
|
}
|
2015-07-30 12:53:33 -07:00
|
|
|
}
|
2017-02-21 16:43:56 -08:00
|
|
|
return extraRows;
|
2015-07-30 12:53:33 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 16:28:47 -07:00
|
|
|
/**
|
|
|
|
|
* Helper class to size the grid items.
|
|
|
|
|
*/
|
|
|
|
|
public class GridSpanSizer extends GridLayoutManager.SpanSizeLookup {
|
2015-05-05 17:21:58 -07:00
|
|
|
|
|
|
|
|
public GridSpanSizer() {
|
|
|
|
|
super();
|
|
|
|
|
setSpanIndexCacheEnabled(true);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 16:28:47 -07:00
|
|
|
@Override
|
|
|
|
|
public int getSpanSize(int position) {
|
2020-09-20 11:28:18 -07:00
|
|
|
int viewType = mApps.getAdapterItems().get(position).viewType;
|
2021-03-05 14:59:13 -06:00
|
|
|
int totalSpans = mGridLayoutMgr.getSpanCount();
|
2020-09-20 11:28:18 -07:00
|
|
|
if (isIconViewType(viewType)) {
|
2021-03-05 14:59:13 -06:00
|
|
|
return totalSpans / mAppsPerRow;
|
2016-07-07 14:47:05 -07:00
|
|
|
} else {
|
2021-06-14 00:31:00 -05:00
|
|
|
BaseAdapterProvider adapterProvider = getAdapterProvider(viewType);
|
|
|
|
|
if (adapterProvider != null) {
|
|
|
|
|
return totalSpans / adapterProvider.getItemsPerRow(viewType, mAppsPerRow);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-24 16:40:03 +08:00
|
|
|
// Section breaks span the full width
|
2021-03-05 14:59:13 -06:00
|
|
|
return totalSpans;
|
2015-03-10 16:28:47 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-09 17:25:15 +00:00
|
|
|
|
|
|
|
|
private final T mActivityContext;
|
|
|
|
|
private final LayoutInflater mLayoutInflater;
|
|
|
|
|
private final AlphabeticalAppsList<T> mApps;
|
|
|
|
|
private final GridLayoutManager mGridLayoutMgr;
|
|
|
|
|
private final GridSpanSizer mGridSizer;
|
|
|
|
|
|
|
|
|
|
private final OnClickListener mOnIconClickListener;
|
|
|
|
|
private OnLongClickListener mOnIconLongClickListener = INSTANCE_ALL_APPS;
|
|
|
|
|
|
|
|
|
|
private int mAppsPerRow;
|
|
|
|
|
|
|
|
|
|
private OnFocusChangeListener mIconFocusListener;
|
|
|
|
|
|
|
|
|
|
// The text to show when there are no search results and no market search handler.
|
|
|
|
|
protected String mEmptySearchMessage;
|
|
|
|
|
// The click listener to send off to the market app, updated each time the search query changes.
|
|
|
|
|
private OnClickListener mMarketSearchClickListener;
|
|
|
|
|
|
|
|
|
|
private final int mExtraHeight;
|
|
|
|
|
|
|
|
|
|
public AllAppsGridAdapter(T activityContext, LayoutInflater inflater,
|
|
|
|
|
AlphabeticalAppsList<T> apps, BaseAdapterProvider[] adapterProviders) {
|
|
|
|
|
Resources res = activityContext.getResources();
|
|
|
|
|
mActivityContext = activityContext;
|
|
|
|
|
mApps = apps;
|
|
|
|
|
mEmptySearchMessage = res.getString(R.string.all_apps_loading_message);
|
|
|
|
|
mGridSizer = new GridSpanSizer();
|
|
|
|
|
mGridLayoutMgr = new AppsGridLayoutManager(mActivityContext);
|
|
|
|
|
mGridLayoutMgr.setSpanSizeLookup(mGridSizer);
|
|
|
|
|
mLayoutInflater = inflater;
|
|
|
|
|
|
|
|
|
|
mOnIconClickListener = mActivityContext.getItemOnClickListener();
|
|
|
|
|
|
|
|
|
|
mAdapterProviders = adapterProviders;
|
|
|
|
|
setAppsPerRow(mActivityContext.getDeviceProfile().numShownAllAppsColumns);
|
|
|
|
|
mExtraHeight = mActivityContext.getResources().getDimensionPixelSize(
|
|
|
|
|
R.dimen.all_apps_height_extra);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mGridLayoutMgr.setSpanCount(totalSpans);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the long click listener for icons
|
|
|
|
|
*/
|
|
|
|
|
public void setOnIconLongClickListener(@Nullable OnLongClickListener listener) {
|
|
|
|
|
mOnIconLongClickListener = listener;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isDividerViewType(int viewType) {
|
|
|
|
|
return isViewType(viewType, VIEW_TYPE_MASK_DIVIDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isIconViewType(int viewType) {
|
|
|
|
|
return isViewType(viewType, VIEW_TYPE_MASK_ICON);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isViewType(int viewType, int viewTypeMask) {
|
|
|
|
|
return (viewType & viewTypeMask) != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setIconFocusListener(OnFocusChangeListener focusListener) {
|
|
|
|
|
mIconFocusListener = focusListener;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the last search query that was made, used to show when there are no results and to also
|
|
|
|
|
* seed the intent for searching the market.
|
|
|
|
|
*/
|
|
|
|
|
public void setLastSearchQuery(String query, OnClickListener marketSearchClickListener) {
|
|
|
|
|
Resources res = mActivityContext.getResources();
|
|
|
|
|
mEmptySearchMessage = res.getString(R.string.all_apps_no_search_results, query);
|
|
|
|
|
mMarketSearchClickListener = marketSearchClickListener;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the grid layout manager.
|
|
|
|
|
*/
|
|
|
|
|
public GridLayoutManager getLayoutManager() {
|
|
|
|
|
return mGridLayoutMgr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
|
switch (viewType) {
|
|
|
|
|
case VIEW_TYPE_ICON:
|
|
|
|
|
int layout = !FeatureFlags.ENABLE_TWOLINE_ALLAPPS.get() ? R.layout.all_apps_icon
|
|
|
|
|
: R.layout.all_apps_icon_twoline;
|
|
|
|
|
BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(
|
|
|
|
|
layout, parent, false);
|
|
|
|
|
icon.setLongPressTimeoutFactor(1f);
|
|
|
|
|
icon.setOnFocusChangeListener(mIconFocusListener);
|
|
|
|
|
icon.setOnClickListener(mOnIconClickListener);
|
|
|
|
|
icon.setOnLongClickListener(mOnIconLongClickListener);
|
|
|
|
|
// Ensure the all apps icon height matches the workspace icons in portrait mode.
|
|
|
|
|
icon.getLayoutParams().height =
|
|
|
|
|
mActivityContext.getDeviceProfile().allAppsCellHeightPx;
|
|
|
|
|
if (FeatureFlags.ENABLE_TWOLINE_ALLAPPS.get()) {
|
|
|
|
|
icon.getLayoutParams().height += mExtraHeight;
|
|
|
|
|
}
|
|
|
|
|
return new ViewHolder(icon);
|
|
|
|
|
case VIEW_TYPE_EMPTY_SEARCH:
|
|
|
|
|
return new ViewHolder(mLayoutInflater.inflate(R.layout.all_apps_empty_search,
|
|
|
|
|
parent, false));
|
|
|
|
|
case VIEW_TYPE_SEARCH_MARKET:
|
|
|
|
|
View searchMarketView = mLayoutInflater.inflate(R.layout.all_apps_search_market,
|
|
|
|
|
parent, false);
|
|
|
|
|
searchMarketView.setOnClickListener(mMarketSearchClickListener);
|
|
|
|
|
return new ViewHolder(searchMarketView);
|
|
|
|
|
case VIEW_TYPE_ALL_APPS_DIVIDER:
|
|
|
|
|
return new ViewHolder(mLayoutInflater.inflate(
|
|
|
|
|
R.layout.all_apps_divider, parent, false));
|
|
|
|
|
default:
|
|
|
|
|
BaseAdapterProvider adapterProvider = getAdapterProvider(viewType);
|
|
|
|
|
if (adapterProvider != null) {
|
|
|
|
|
return adapterProvider.onCreateViewHolder(mLayoutInflater, parent, viewType);
|
|
|
|
|
}
|
|
|
|
|
throw new RuntimeException("Unexpected view type" + viewType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onBindViewHolder(ViewHolder holder, int position) {
|
|
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
|
case VIEW_TYPE_ICON:
|
|
|
|
|
AdapterItem adapterItem = mApps.getAdapterItems().get(position);
|
|
|
|
|
BubbleTextView icon = (BubbleTextView) holder.itemView;
|
|
|
|
|
icon.reset();
|
|
|
|
|
if (adapterItem.itemInfo instanceof AppInfo) {
|
|
|
|
|
icon.applyFromApplicationInfo((AppInfo) adapterItem.itemInfo);
|
|
|
|
|
} else {
|
|
|
|
|
icon.applyFromItemInfoWithIcon(adapterItem.itemInfo);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VIEW_TYPE_EMPTY_SEARCH:
|
|
|
|
|
TextView emptyViewText = (TextView) holder.itemView;
|
|
|
|
|
emptyViewText.setText(mEmptySearchMessage);
|
|
|
|
|
emptyViewText.setGravity(mApps.hasNoFilteredResults() ? Gravity.CENTER :
|
|
|
|
|
Gravity.START | Gravity.CENTER_VERTICAL);
|
|
|
|
|
break;
|
|
|
|
|
case VIEW_TYPE_SEARCH_MARKET:
|
|
|
|
|
TextView searchView = (TextView) holder.itemView;
|
|
|
|
|
if (mMarketSearchClickListener != null) {
|
|
|
|
|
searchView.setVisibility(View.VISIBLE);
|
|
|
|
|
} else {
|
|
|
|
|
searchView.setVisibility(View.GONE);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case VIEW_TYPE_ALL_APPS_DIVIDER:
|
|
|
|
|
// nothing to do
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
BaseAdapterProvider adapterProvider = getAdapterProvider(holder.getItemViewType());
|
|
|
|
|
if (adapterProvider != null) {
|
|
|
|
|
adapterProvider.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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemCount() {
|
|
|
|
|
return mApps.getAdapterItems().size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getItemViewType(int position) {
|
|
|
|
|
AdapterItem item = mApps.getAdapterItems().get(position);
|
|
|
|
|
return item.viewType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
|
private BaseAdapterProvider getAdapterProvider(int viewType) {
|
|
|
|
|
return Arrays.stream(mAdapterProviders).filter(
|
|
|
|
|
adapterProvider -> adapterProvider.isViewSupported(viewType)).findFirst().orElse(
|
|
|
|
|
null);
|
|
|
|
|
}
|
2015-03-10 16:28:47 -07:00
|
|
|
}
|