mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-17 09:38:19 +00:00
Setup logging pipeline for search results
Bug: 168121204 Test: Manual Change-Id: I4abb6c75aa0f22416616a713733bef2802b703d1
This commit is contained in:
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -54,8 +55,13 @@ import com.android.launcher3.allapps.search.SearchSectionInfo;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.model.data.AppInfo;
|
||||
import com.android.launcher3.util.PackageManagerHelper;
|
||||
import com.android.launcher3.views.HeroSearchResultView;
|
||||
import com.android.systemui.plugins.AllAppsSearchPlugin;
|
||||
import com.android.systemui.plugins.shared.SearchTarget;
|
||||
import com.android.systemui.plugins.shared.SearchTargetEvent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.IntConsumer;
|
||||
|
||||
/**
|
||||
* The grid view adapter of all the apps.
|
||||
@@ -196,18 +202,28 @@ public class AllAppsGridAdapter extends
|
||||
*/
|
||||
public static class AdapterItemWithPayload<T> extends AdapterItem {
|
||||
private T mPayload;
|
||||
private Runnable mSelectionHandler;
|
||||
private AllAppsSearchPlugin mPlugin;
|
||||
private IntConsumer mSelectionHandler;
|
||||
|
||||
public AdapterItemWithPayload(T payload, int type) {
|
||||
mPayload = payload;
|
||||
viewType = type;
|
||||
public AllAppsSearchPlugin getPlugin() {
|
||||
return mPlugin;
|
||||
}
|
||||
|
||||
public void setSelectionHandler(Runnable runnable) {
|
||||
public void setPlugin(AllAppsSearchPlugin plugin) {
|
||||
mPlugin = plugin;
|
||||
}
|
||||
|
||||
public AdapterItemWithPayload(T payload, int type, AllAppsSearchPlugin plugin) {
|
||||
mPayload = payload;
|
||||
viewType = type;
|
||||
mPlugin = plugin;
|
||||
}
|
||||
|
||||
public void setSelectionHandler(IntConsumer runnable) {
|
||||
mSelectionHandler = runnable;
|
||||
}
|
||||
|
||||
public Runnable getSelectionHandler() {
|
||||
public IntConsumer getSelectionHandler() {
|
||||
return mSelectionHandler;
|
||||
}
|
||||
|
||||
@@ -396,10 +412,12 @@ public class AllAppsGridAdapter extends
|
||||
case VIEW_TYPE_ICON:
|
||||
BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate(
|
||||
R.layout.all_apps_icon, parent, false);
|
||||
icon.setOnClickListener(mOnIconClickListener);
|
||||
icon.setOnLongClickListener(mOnIconLongClickListener);
|
||||
icon.setLongPressTimeoutFactor(1f);
|
||||
icon.setOnFocusChangeListener(mIconFocusListener);
|
||||
if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
|
||||
icon.setOnClickListener(mOnIconClickListener);
|
||||
icon.setOnLongClickListener(mOnIconLongClickListener);
|
||||
}
|
||||
|
||||
// Ensure the all apps icon height matches the workspace icons in portrait mode.
|
||||
icon.getLayoutParams().height = mLauncher.getDeviceProfile().allAppsCellHeightPx;
|
||||
@@ -419,7 +437,6 @@ public class AllAppsGridAdapter extends
|
||||
case VIEW_TYPE_SEARCH_CORPUS_TITLE:
|
||||
return new ViewHolder(
|
||||
mLayoutInflater.inflate(R.layout.search_section_title, parent, false));
|
||||
|
||||
case VIEW_TYPE_SEARCH_HERO_APP:
|
||||
return new ViewHolder(mLayoutInflater.inflate(
|
||||
R.layout.search_result_hero_app, parent, false));
|
||||
@@ -447,10 +464,36 @@ public class AllAppsGridAdapter extends
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
switch (holder.getItemViewType()) {
|
||||
case VIEW_TYPE_ICON:
|
||||
AppInfo info = mApps.getAdapterItems().get(position).appInfo;
|
||||
AdapterItem adapterItem = mApps.getAdapterItems().get(position);
|
||||
AppInfo info = adapterItem.appInfo;
|
||||
BubbleTextView icon = (BubbleTextView) holder.itemView;
|
||||
icon.reset();
|
||||
icon.applyFromApplicationInfo(info);
|
||||
if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) {
|
||||
break;
|
||||
}
|
||||
//TODO: replace with custom TopHitBubbleTextView with support for both shortcut
|
||||
// and apps
|
||||
if (adapterItem instanceof AdapterItemWithPayload) {
|
||||
AdapterItemWithPayload withPayload = (AdapterItemWithPayload) adapterItem;
|
||||
IntConsumer selectionHandler = type -> {
|
||||
SearchTargetEvent e = new SearchTargetEvent(SearchTarget.ItemType.APP,
|
||||
type);
|
||||
e.bundle = HeroSearchResultView.getAppBundle(info);
|
||||
if (withPayload.getPlugin() != null) {
|
||||
withPayload.getPlugin().notifySearchTargetEvent(e);
|
||||
}
|
||||
};
|
||||
icon.setOnClickListener(view -> {
|
||||
selectionHandler.accept(SearchTargetEvent.SELECT);
|
||||
mOnIconClickListener.onClick(view);
|
||||
});
|
||||
icon.setOnLongClickListener(view -> {
|
||||
selectionHandler.accept(SearchTargetEvent.LONG_PRESS);
|
||||
return mOnIconLongClickListener.onLongClick(view);
|
||||
});
|
||||
withPayload.setSelectionHandler(selectionHandler);
|
||||
}
|
||||
break;
|
||||
case VIEW_TYPE_EMPTY_SEARCH:
|
||||
TextView emptyViewText = (TextView) holder.itemView;
|
||||
@@ -468,11 +511,22 @@ public class AllAppsGridAdapter extends
|
||||
break;
|
||||
case VIEW_TYPE_SEARCH_SLICE:
|
||||
SliceView sliceView = (SliceView) holder.itemView;
|
||||
Uri uri = ((AdapterItemWithPayload<Uri>) mApps.getAdapterItems().get(position))
|
||||
.getPayload();
|
||||
AdapterItemWithPayload<Uri> item =
|
||||
(AdapterItemWithPayload<Uri>) mApps.getAdapterItems().get(position);
|
||||
sliceView.setOnSliceActionListener((info1, s) -> {
|
||||
if (item.getPlugin() != null) {
|
||||
SearchTargetEvent searchTargetEvent = new SearchTargetEvent(
|
||||
SearchTarget.ItemType.SETTINGS_SLICE,
|
||||
SearchTargetEvent.CHILD_SELECT);
|
||||
searchTargetEvent.bundle = new Bundle();
|
||||
searchTargetEvent.bundle.putParcelable("uri", item.getPayload());
|
||||
item.getPlugin().notifySearchTargetEvent(searchTargetEvent);
|
||||
}
|
||||
});
|
||||
try {
|
||||
LiveData<Slice> liveData = SliceLiveData.fromUri(mLauncher, uri);
|
||||
LiveData<Slice> liveData = SliceLiveData.fromUri(mLauncher, item.getPayload());
|
||||
liveData.observe(this::getLifecycle, sliceView);
|
||||
sliceView.setTag(liveData);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
break;
|
||||
@@ -492,6 +546,25 @@ public class AllAppsGridAdapter extends
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewRecycled(@NonNull ViewHolder holder) {
|
||||
super.onViewRecycled(holder);
|
||||
if (!FeatureFlags.ENABLE_DEVICE_SEARCH.get()) return;
|
||||
if (holder.itemView instanceof BubbleTextView) {
|
||||
BubbleTextView icon = (BubbleTextView) holder.itemView;
|
||||
icon.setOnClickListener(mOnIconClickListener);
|
||||
icon.setOnLongClickListener(mOnIconLongClickListener);
|
||||
} else if (holder.itemView instanceof SliceView) {
|
||||
SliceView sliceView = (SliceView) holder.itemView;
|
||||
sliceView.setOnSliceActionListener(null);
|
||||
if (sliceView.getTag() instanceof LiveData) {
|
||||
LiveData sliceLiveData = (LiveData) sliceView.getTag();
|
||||
sliceLiveData.removeObservers(this::getLifecycle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onFailedToRecycleView(ViewHolder holder) {
|
||||
// Always recycle and we will reset the view when it is bound
|
||||
|
||||
Reference in New Issue
Block a user