Skip to content

Commit

Permalink
Shade: Use AllAppsStore instead of AppsList for search results
Browse files Browse the repository at this point in the history
  • Loading branch information
amirzaidi committed Mar 10, 2020
1 parent aeba41a commit f451b50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 18 additions & 6 deletions shade/src/amirz/shade/hidden/HiddenAppsSearchAlgorithm.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
package amirz.shade.hidden;

import android.content.Context;
import android.os.Process;

import com.android.launcher3.AppInfo;
import com.android.launcher3.R;
import com.android.launcher3.allapps.AppInfoComparator;
import com.android.launcher3.allapps.search.AllAppsSearchBarController;
import com.android.launcher3.allapps.search.DefaultAppSearchAlgorithm;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ItemInfoMatcher;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

public class HiddenAppsSearchAlgorithm extends DefaultAppSearchAlgorithm {
private final Context mContext;
private final List<AppInfo> mApps;
private final AppInfoComparator mAppNameComparator;
private final Collection<AppInfo> mApps;
private final String mKeyGlobal;
private final String mKeyTranslated;

public HiddenAppsSearchAlgorithm(Context context, List<AppInfo> apps) {
super(apps);
public HiddenAppsSearchAlgorithm(Context context, Collection<AppInfo> apps) {
super(Collections.emptyList());
mContext = context;
mAppNameComparator = new AppInfoComparator(context);
mApps = apps;
mKeyGlobal = context.getString(R.string.search_hidden_global).toLowerCase();
mKeyTranslated = context.getString(R.string.search_hidden).toLowerCase();
Expand All @@ -43,14 +50,19 @@ private ArrayList<ComponentKey> getTitleMatchResult(String query, boolean showHi
// Do an intersection of the words in the query and each title, and filter out all the
// apps that don't match all of the words in the query.
final String queryTextLower = query.toLowerCase();
final ArrayList<ComponentKey> result = new ArrayList<>();
final List<AppInfo> result = new ArrayList<>();
StringMatcher matcher = StringMatcher.getInstance();
for (AppInfo info : mApps) {
if (matches(info, queryTextLower, matcher) || (showHidden
&& HiddenAppsDatabase.isHidden(mContext, info.componentName, info.user))) {
result.add(info.toComponentKey());
result.add(info);
}
}
return result;
Collections.sort(result, mAppNameComparator);
ArrayList<ComponentKey> resultKeys = new ArrayList<>();
for (AppInfo appInfo : result) {
resultKeys.add(appInfo.toComponentKey());
}
return resultKeys;
}
}
2 changes: 1 addition & 1 deletion shade/src/amirz/shade/search/AllAppsQsb.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void initialize(AllAppsContainerView appsView) {
mAppsView = appsView;
mFallbackSearchView = findViewById(R.id.fallback_search_view);
mSearchBarController.initialize(
new HiddenAppsSearchAlgorithm(mLauncher, mApps.getApps()),
new HiddenAppsSearchAlgorithm(mLauncher, appsView.getAppsStore().getApps()),
mFallbackSearchView, mLauncher, this);

appsView.setRecyclerViewVerticalFadingEdgeEnabled(true);
Expand Down

0 comments on commit f451b50

Please sign in to comment.