set rv items and notify change in the same thread (#1595)
to avoid inconsistency
This commit is contained in:
parent
8a53627b43
commit
a3fb878f46
|
|
@ -219,8 +219,9 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
|
|||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private void setLoaded(boolean loaded) {
|
||||
private void setLoaded(List<AppInfo> list, boolean loaded) {
|
||||
fragment.runOnUiThread(() -> {
|
||||
if (list != null) showList = list;
|
||||
isLoaded = loaded;
|
||||
notifyDataSetChanged();
|
||||
});
|
||||
|
|
@ -466,7 +467,7 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
|
|||
}
|
||||
|
||||
public void refresh(boolean force) {
|
||||
setLoaded(false);
|
||||
setLoaded(null, false);
|
||||
enabled = moduleUtil.isModuleEnabled(module.packageName);
|
||||
fragment.binding.masterSwitch.setOnCheckedChangeListener(null);
|
||||
fragment.binding.masterSwitch.setChecked(enabled);
|
||||
|
|
@ -606,8 +607,7 @@ public class ScopeAdapter extends EmptyStateRecyclerView.EmptyStateAdapter<Scope
|
|||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
//noinspection unchecked
|
||||
showList = (List<AppInfo>) results.values;
|
||||
setLoaded(true);
|
||||
setLoaded((List<AppInfo>) results.values, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ import androidx.annotation.Nullable;
|
|||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.navigation.NavOptions;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
|
@ -668,7 +667,7 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
|
|||
|
||||
public void fullRefresh() {
|
||||
runAsync(() -> {
|
||||
setLoaded(false);
|
||||
setLoaded(null, false);
|
||||
moduleUtil.reloadInstalledModules();
|
||||
refresh();
|
||||
});
|
||||
|
|
@ -678,7 +677,7 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
|
|||
var modules = moduleUtil.getModules();
|
||||
if (modules == null) return;
|
||||
Comparator<PackageInfo> cmp = AppHelper.getAppListComparator(0, pm);
|
||||
setLoaded(false);
|
||||
setLoaded(null, false);
|
||||
var tmpList = new ArrayList<ModuleUtil.InstalledModule>();
|
||||
modules.values().parallelStream()
|
||||
.sorted((a, b) -> {
|
||||
|
|
@ -719,8 +718,9 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
|
|||
};
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private void setLoaded(boolean loaded) {
|
||||
private void setLoaded(List<ModuleUtil.InstalledModule> list, boolean loaded) {
|
||||
runOnUiThread(() -> {
|
||||
if (list != null) showList = list;
|
||||
isLoaded = loaded;
|
||||
notifyDataSetChanged();
|
||||
});
|
||||
|
|
@ -778,8 +778,7 @@ public class ModulesFragment extends BaseFragment implements ModuleUtil.ModuleLi
|
|||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
//noinspection unchecked
|
||||
showList = (List<ModuleUtil.InstalledModule>) results.values;
|
||||
setLoaded(true);
|
||||
setLoaded((List<ModuleUtil.InstalledModule>) results.values, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.lsposed.manager.ui.fragment;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -325,14 +326,18 @@ public class RepoFragment extends BaseFragment implements RepoLoader.RepoListene
|
|||
return showList.size();
|
||||
}
|
||||
|
||||
private void setLoaded(boolean isLoaded) {
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
private void setLoaded(List<OnlineModule> list, boolean isLoaded) {
|
||||
runOnUiThread(() -> {
|
||||
showList = list;
|
||||
this.isLoaded = isLoaded;
|
||||
runOnUiThread(this::notifyDataSetChanged);
|
||||
notifyDataSetChanged();
|
||||
});
|
||||
}
|
||||
|
||||
public void setData(Collection<OnlineModule> modules) {
|
||||
if (modules == null) return;
|
||||
setLoaded(false);
|
||||
setLoaded(null, false);
|
||||
int sort = App.getPreferences().getInt("repo_sort", 0);
|
||||
boolean upgradableFirst = App.getPreferences().getBoolean("upgradable_first", true);
|
||||
ConcurrentHashMap<String, Boolean> upgradable = new ConcurrentHashMap<>();
|
||||
|
|
@ -356,7 +361,7 @@ public class RepoFragment extends BaseFragment implements RepoLoader.RepoListene
|
|||
|
||||
public void fullRefresh() {
|
||||
runAsync(() -> {
|
||||
setLoaded(false);
|
||||
setLoaded(null, false);
|
||||
repoLoader.loadRemoteData();
|
||||
refresh();
|
||||
});
|
||||
|
|
@ -422,8 +427,7 @@ public class RepoFragment extends BaseFragment implements RepoLoader.RepoListene
|
|||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
//noinspection unchecked
|
||||
showList = (List<OnlineModule>) results.values;
|
||||
setLoaded(true);
|
||||
setLoaded((List<OnlineModule>) results.values, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.lsposed.manager.ui.fragment;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Color;
|
||||
|
|
@ -356,23 +357,28 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.RepoLis
|
|||
runAsync(this::loadItems);
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
public void loadItems() {
|
||||
var channels = resources.getStringArray(R.array.update_channel_values);
|
||||
var channel = App.getPreferences().getString("update_channel", channels[0]);
|
||||
var releases = module.getReleases();
|
||||
List<Release> tmpList;
|
||||
if (channel.equals(channels[0])) {
|
||||
this.items = releases.parallelStream().filter(t -> {
|
||||
tmpList = releases.parallelStream().filter(t -> {
|
||||
if (t.getIsPrerelease()) return false;
|
||||
var name = t.getName().toLowerCase(LocaleDelegate.getDefaultLocale());
|
||||
return !name.startsWith("snapshot") && !name.startsWith("nightly");
|
||||
}).collect(Collectors.toList());
|
||||
} else if (channel.equals(channels[1])) {
|
||||
this.items = releases.parallelStream().filter(t -> {
|
||||
tmpList = releases.parallelStream().filter(t -> {
|
||||
var name = t.getName().toLowerCase(LocaleDelegate.getDefaultLocale());
|
||||
return !name.startsWith("snapshot") && !name.startsWith("nightly");
|
||||
}).collect(Collectors.toList());
|
||||
} else this.items = releases;
|
||||
runOnUiThread(this::notifyDataSetChanged);
|
||||
} else tmpList = releases;
|
||||
runOnUiThread(() -> {
|
||||
items = tmpList;
|
||||
notifyDataSetChanged();
|
||||
});
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
|
|||
Loading…
Reference in New Issue