Fixing search behavior in Launcher3

> Showing no-result found only when there are no results
> Removing unnecessary view inflation in RecyclerViewPool for
  various search vide types
> Removing unused market-search link and no-empty-result illustration

Bug: 240343082
Bug: 207573083
Test: Verified Launcher3
Change-Id: Ia44799cd2385ea5dc837ef25732ca237975abde7
This commit is contained in:
Sunny Goyal
2022-07-27 16:38:27 -07:00
parent f6003ff070
commit af95ddbadc
16 changed files with 33 additions and 623 deletions

View File

@@ -19,7 +19,6 @@ import static com.android.launcher3.touch.ItemLongClickListener.INSTANCE_ALL_APP
import android.content.Context;
import android.content.res.Resources;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -54,19 +53,13 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
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;
public static final int VIEW_TYPE_ALL_APPS_DIVIDER = 1 << 3;
public static final int VIEW_TYPE_WORK_EDU_CARD = 1 << 5;
public static final int VIEW_TYPE_WORK_DISABLED_CARD = 1 << 6;
public static final int VIEW_TYPE_WORK_EDU_CARD = 1 << 4;
public static final int VIEW_TYPE_WORK_DISABLED_CARD = 1 << 5;
public static final int NEXT_ID = 7;
public static final int NEXT_ID = 6;
// Common view type masks
public static final int VIEW_TYPE_MASK_DIVIDER = VIEW_TYPE_ALL_APPS_DIVIDER;
@@ -117,7 +110,7 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
}
protected boolean isCountedForAccessibility() {
return viewType == VIEW_TYPE_ICON || viewType == VIEW_TYPE_SEARCH_MARKET;
return viewType == VIEW_TYPE_ICON;
}
/**
@@ -139,15 +132,12 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
protected final T mActivityContext;
protected final AlphabeticalAppsList<T> mApps;
// The text to show when there are no search results and no market search handler.
protected String mEmptySearchMessage;
protected int mAppsPerRow;
protected final LayoutInflater mLayoutInflater;
protected final OnClickListener mOnIconClickListener;
protected OnLongClickListener mOnIconLongClickListener = INSTANCE_ALL_APPS;
protected OnFocusChangeListener mIconFocusListener;
// 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 BaseAllAppsAdapter(T activityContext, LayoutInflater inflater,
@@ -155,7 +145,6 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
Resources res = activityContext.getResources();
mActivityContext = activityContext;
mApps = apps;
mEmptySearchMessage = res.getString(R.string.all_apps_loading_message);
mLayoutInflater = inflater;
mOnIconClickListener = mActivityContext.getItemOnClickListener();
@@ -185,16 +174,6 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
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 layout manager.
*/
@@ -222,11 +201,6 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
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));
@@ -248,26 +222,21 @@ public abstract class BaseAllAppsAdapter<T extends Context & ActivityContext> ex
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
switch (holder.getItemViewType()) {
case VIEW_TYPE_ICON:
case VIEW_TYPE_ICON: {
AdapterItem adapterItem = mApps.getAdapterItems().get(position);
BubbleTextView icon = (BubbleTextView) holder.itemView;
icon.reset();
icon.applyFromApplicationInfo(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);
}
case VIEW_TYPE_EMPTY_SEARCH: {
AppInfo info = mApps.getAdapterItems().get(position).itemInfo;
if (info != null) {
((TextView) holder.itemView).setText(mActivityContext.getString(
R.string.all_apps_no_search_results, info.title));
}
break;
}
case VIEW_TYPE_ALL_APPS_DIVIDER:
case VIEW_TYPE_WORK_DISABLED_CARD:
// nothing to do