[app] Fix race condition (#636)
This commit is contained in:
parent
c1bed35bcf
commit
c3765d4266
|
|
@ -86,6 +86,7 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
|
|
||||||
import rikka.core.res.ResourcesKt;
|
import rikka.core.res.ResourcesKt;
|
||||||
import rikka.widget.switchbar.SwitchBar;
|
import rikka.widget.switchbar.SwitchBar;
|
||||||
|
|
@ -104,7 +105,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
|
|
||||||
private final HashSet<ApplicationWithEquals> recommendedList = new HashSet<>();
|
private final HashSet<ApplicationWithEquals> recommendedList = new HashSet<>();
|
||||||
private final HashSet<ApplicationWithEquals> checkedList = new HashSet<>();
|
private final HashSet<ApplicationWithEquals> checkedList = new HashSet<>();
|
||||||
private final List<AppInfo> searchList = new ArrayList<>();
|
private final ConcurrentLinkedQueue<AppInfo> searchList = new ConcurrentLinkedQueue<>();
|
||||||
private final List<AppInfo> showList = new ArrayList<>();
|
private final List<AppInfo> showList = new ArrayList<>();
|
||||||
|
|
||||||
private final SwitchBar.OnCheckedChangeListener switchBarOnCheckedChangeListener = new SwitchBar.OnCheckedChangeListener() {
|
private final SwitchBar.OnCheckedChangeListener switchBarOnCheckedChangeListener = new SwitchBar.OnCheckedChangeListener() {
|
||||||
|
|
@ -504,8 +505,7 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
List<PackageInfo> appList = AppHelper.getAppList((Boolean) msg.obj);
|
List<PackageInfo> appList = AppHelper.getAppList((Boolean) msg.obj);
|
||||||
checkedList.clear();
|
checkedList.clear();
|
||||||
recommendedList.clear();
|
recommendedList.clear();
|
||||||
searchList.clear();
|
var tmpList = new ArrayList<AppInfo>();
|
||||||
|
|
||||||
checkedList.addAll(ConfigManager.getModuleScope(module.packageName));
|
checkedList.addAll(ConfigManager.getModuleScope(module.packageName));
|
||||||
HashSet<ApplicationWithEquals> installedList = new HashSet<>();
|
HashSet<ApplicationWithEquals> installedList = new HashSet<>();
|
||||||
List<String> scopeList = module.getScopeList();
|
List<String> scopeList = module.getScopeList();
|
||||||
|
|
@ -537,13 +537,15 @@ public class ScopeAdapter extends RecyclerView.Adapter<ScopeAdapter.ViewHolder>
|
||||||
appInfo.application = application;
|
appInfo.application = application;
|
||||||
appInfo.packageName = info.packageName;
|
appInfo.packageName = info.packageName;
|
||||||
appInfo.applicationInfo = info.applicationInfo;
|
appInfo.applicationInfo = info.applicationInfo;
|
||||||
searchList.add(appInfo);
|
tmpList.add(appInfo);
|
||||||
}
|
}
|
||||||
checkedList.retainAll(installedList);
|
checkedList.retainAll(installedList);
|
||||||
if (emptyCheckedList) {
|
if (emptyCheckedList) {
|
||||||
ConfigManager.setModuleScope(module.packageName, checkedList);
|
ConfigManager.setModuleScope(module.packageName, checkedList);
|
||||||
}
|
}
|
||||||
sortApps(searchList);
|
sortApps(tmpList);
|
||||||
|
searchList.clear();
|
||||||
|
searchList.addAll(tmpList);
|
||||||
synchronized (dataReadyRunnable) {
|
synchronized (dataReadyRunnable) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
refreshing = false;
|
refreshing = false;
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
|
@ -403,7 +404,7 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ModuleAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<ModuleAdapter.ViewHolder> implements Filterable {
|
private class ModuleAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<ModuleAdapter.ViewHolder> implements Filterable {
|
||||||
private final List<ModuleUtil.InstalledModule> searchList = new ArrayList<>();
|
private final ConcurrentLinkedQueue<ModuleUtil.InstalledModule> searchList = new ConcurrentLinkedQueue<>();
|
||||||
private final List<ModuleUtil.InstalledModule> showList = new ArrayList<>();
|
private final List<ModuleUtil.InstalledModule> showList = new ArrayList<>();
|
||||||
private final int userId;
|
private final int userId;
|
||||||
private final UserHandle userHandle;
|
private final UserHandle userHandle;
|
||||||
|
|
@ -578,10 +579,9 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
|
|
||||||
private final Runnable reloadModules = new Runnable() {
|
private final Runnable reloadModules = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
searchList.clear();
|
var tmpList = moduleUtil.getModules().values().stream().filter(module -> module.userId == userId).filter(customFilter).collect(Collectors.toCollection(ArrayList::new));
|
||||||
searchList.addAll(moduleUtil.getModules().values().stream().filter(module -> module.userId == userId).filter(customFilter).collect(Collectors.toList()));
|
|
||||||
Comparator<PackageInfo> cmp = AppHelper.getAppListComparator(0, pm);
|
Comparator<PackageInfo> cmp = AppHelper.getAppListComparator(0, pm);
|
||||||
searchList.sort((a, b) -> {
|
tmpList.sort((a, b) -> {
|
||||||
boolean aChecked = moduleUtil.isModuleEnabled(a.packageName);
|
boolean aChecked = moduleUtil.isModuleEnabled(a.packageName);
|
||||||
boolean bChecked = moduleUtil.isModuleEnabled(b.packageName);
|
boolean bChecked = moduleUtil.isModuleEnabled(b.packageName);
|
||||||
if (aChecked == bChecked) {
|
if (aChecked == bChecked) {
|
||||||
|
|
@ -592,6 +592,8 @@ public class ModulesActivity extends BaseActivity implements ModuleUtil.ModuleLi
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
searchList.clear();
|
||||||
|
searchList.addAll(tmpList);
|
||||||
String queryStr = searchView != null ? searchView.getQuery().toString() : "";
|
String queryStr = searchView != null ? searchView.getQuery().toString() : "";
|
||||||
runOnUiThread(() -> getFilter().filter(queryStr));
|
runOnUiThread(() -> getFilter().filter(queryStr));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue