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