[app] Fix usage of filter (#520)
This commit is contained in:
parent
41fd9be898
commit
ef2845610e
|
|
@ -77,6 +77,7 @@ import org.lsposed.manager.util.ModuleUtil;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
|
@ -100,7 +101,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
|||
private final HashSet<ApplicationWithEquals> recommendedList = new HashSet<>();
|
||||
private final HashSet<ApplicationWithEquals> checkedList = new HashSet<>();
|
||||
private final List<AppInfo> searchList = new ArrayList<>();
|
||||
private List<AppInfo> showList = new ArrayList<>();
|
||||
private final List<AppInfo> showList = new ArrayList<>();
|
||||
|
||||
private final SwitchBar.OnCheckedChangeListener switchBarOnCheckedChangeListener = new SwitchBar.OnCheckedChangeListener() {
|
||||
@Override
|
||||
|
|
@ -182,7 +183,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
|||
return preferences.getBoolean("filter_system_apps", true) && (info.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
|
||||
}
|
||||
|
||||
private List<AppInfo> sortApps(List<AppInfo> list) {
|
||||
private void sortApps(List<AppInfo> list) {
|
||||
Comparator<PackageInfo> comparator = AppHelper.getAppListComparator(preferences.getInt("list_sort", 0), pm);
|
||||
Comparator<AppInfo> frameworkComparator = (a, b) -> {
|
||||
if (a.packageName.equals("android") == b.packageName.equals("android")) {
|
||||
|
|
@ -215,7 +216,6 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
|||
return 1;
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
private void checkRecommended() {
|
||||
|
|
@ -546,7 +546,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
|||
if (emptyCheckedList) {
|
||||
ConfigManager.setModuleScope(modulePackageName, checkedList);
|
||||
}
|
||||
showList = sortApps(searchList);
|
||||
sortApps(searchList);
|
||||
synchronized (dataReadyRunnable) {
|
||||
synchronized (this) {
|
||||
refreshing = false;
|
||||
|
|
@ -588,10 +588,11 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
|||
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
FilterResults filterResults = new FilterResults();
|
||||
List<AppInfo> filtered = new ArrayList<>();
|
||||
if (constraint.toString().isEmpty()) {
|
||||
showList = searchList;
|
||||
filtered.addAll(searchList);
|
||||
} else {
|
||||
ArrayList<AppInfo> filtered = new ArrayList<>();
|
||||
String filter = constraint.toString().toLowerCase();
|
||||
for (AppInfo info : searchList) {
|
||||
if (lowercaseContains(info.label.toString(), filter)
|
||||
|
|
@ -599,13 +600,17 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
|||
filtered.add(info);
|
||||
}
|
||||
}
|
||||
showList = filtered;
|
||||
}
|
||||
return null;
|
||||
filterResults.values = filtered;
|
||||
filterResults.count = filtered.size();
|
||||
return filterResults;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
showList.clear();
|
||||
//noinspection unchecked
|
||||
showList.addAll((Collection<AppInfo>) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package org.lsposed.manager.ui.activity;
|
|||
|
||||
import static android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
|
@ -68,7 +69,6 @@ import org.lsposed.manager.util.GlideApp;
|
|||
import org.lsposed.manager.util.ModuleUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -198,10 +198,10 @@ public class ModulesActivity extends ListActivity implements ModuleUtil.ModuleLi
|
|||
}
|
||||
|
||||
private class ModuleAdapter extends BaseAdapter<ModuleAdapter.ViewHolder> {
|
||||
private List<ModuleUtil.InstalledModule> fullList, showList;
|
||||
private final List<ModuleUtil.InstalledModule> searchList = new ArrayList<>();
|
||||
private List<ModuleUtil.InstalledModule> showList = new ArrayList<>();
|
||||
|
||||
ModuleAdapter() {
|
||||
fullList = showList = Collections.emptyList();
|
||||
refresh();
|
||||
}
|
||||
|
||||
|
|
@ -317,9 +317,10 @@ public class ModulesActivity extends ListActivity implements ModuleUtil.ModuleLi
|
|||
|
||||
private final Runnable reloadModules = new Runnable() {
|
||||
public void run() {
|
||||
fullList = new ArrayList<>(moduleUtil.getModules().values());
|
||||
searchList.clear();
|
||||
searchList.addAll(moduleUtil.getModules().values());
|
||||
Comparator<PackageInfo> cmp = AppHelper.getAppListComparator(0, pm);
|
||||
fullList.sort((a, b) -> {
|
||||
searchList.sort((a, b) -> {
|
||||
boolean aChecked = moduleUtil.isModuleEnabled(a.packageName);
|
||||
boolean bChecked = moduleUtil.isModuleEnabled(b.packageName);
|
||||
if (aChecked == bChecked) {
|
||||
|
|
@ -330,7 +331,6 @@ public class ModulesActivity extends ListActivity implements ModuleUtil.ModuleLi
|
|||
return 1;
|
||||
}
|
||||
});
|
||||
showList = fullList;
|
||||
String queryStr = searchView != null ? searchView.getQuery().toString() : "";
|
||||
runOnUiThread(() -> getFilter().filter(queryStr));
|
||||
}
|
||||
|
|
@ -363,25 +363,31 @@ public class ModulesActivity extends ListActivity implements ModuleUtil.ModuleLi
|
|||
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
FilterResults filterResults = new FilterResults();
|
||||
List<ModuleUtil.InstalledModule> filtered = new ArrayList<>();
|
||||
if (constraint.toString().isEmpty()) {
|
||||
showList = fullList;
|
||||
filtered.addAll(searchList);
|
||||
} else {
|
||||
ArrayList<ModuleUtil.InstalledModule> filtered = new ArrayList<>();
|
||||
String filter = constraint.toString().toLowerCase();
|
||||
for (ModuleUtil.InstalledModule info : fullList) {
|
||||
for (ModuleUtil.InstalledModule info : searchList) {
|
||||
if (lowercaseContains(info.getAppName(), filter) ||
|
||||
lowercaseContains(info.packageName, filter) ||
|
||||
lowercaseContains(info.getDescription(), filter)) {
|
||||
filtered.add(info);
|
||||
}
|
||||
}
|
||||
showList = filtered;
|
||||
}
|
||||
return null;
|
||||
filterResults.values = filtered;
|
||||
filterResults.count = filtered.size();
|
||||
return filterResults;
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
showList.clear();
|
||||
//noinspection unchecked
|
||||
showList.addAll((List<ModuleUtil.InstalledModule>) results.values);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue