mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-25 10:57:39 +00:00
Fix repo loading UI logic
This commit is contained in:
parent
d5408d1f09
commit
c9d3e20aef
@ -159,8 +159,8 @@ public class MagiskFragment extends Fragment
|
||||
|
||||
safetyNetStatusText.setText(R.string.safetyNet_check_text);
|
||||
|
||||
mm.safetyNetDone.hasPublished = false;
|
||||
mm.updateCheckDone.hasPublished = false;
|
||||
mm.safetyNetDone.reset();
|
||||
mm.updateCheckDone.reset();
|
||||
mm.remoteMagiskVersionString = null;
|
||||
mm.remoteMagiskVersionCode = -1;
|
||||
collapse();
|
||||
@ -176,11 +176,11 @@ public class MagiskFragment extends Fragment
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTopicPublished(Topic topic, Object result) {
|
||||
public void onTopicPublished(Topic topic) {
|
||||
if (topic == mm.updateCheckDone) {
|
||||
updateCheckUI();
|
||||
} else if (topic == mm.safetyNetDone) {
|
||||
updateSafetyNetUI((int) result);
|
||||
updateSafetyNetUI((int) topic.getResults()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTopicPublished(Topic topic, Object result) {
|
||||
public void onTopicPublished(Topic topic) {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
appAdapter.filter(lastFilter);
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ public class MainActivity extends Activity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTopicPublished(Topic topic, Object result) {
|
||||
public void onTopicPublished(Topic topic) {
|
||||
recreate();
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class ModulesFragment extends Fragment implements Topic.Subscriber {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTopicPublished(Topic topic, Object result) {
|
||||
public void onTopicPublished(Topic topic) {
|
||||
updateUI();
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ import butterknife.Unbinder;
|
||||
public class ReposFragment extends Fragment implements Topic.Subscriber {
|
||||
|
||||
private Unbinder unbinder;
|
||||
private MagiskManager mm;
|
||||
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
||||
@BindView(R.id.empty_rv) TextView emptyRv;
|
||||
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
@ -44,8 +45,9 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_repos, container, false);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
mm = getApplication();
|
||||
|
||||
mSwipeRefreshLayout.setRefreshing(true);
|
||||
mSwipeRefreshLayout.setRefreshing(mm.repoLoadDone.isPending());
|
||||
|
||||
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||
recyclerView.setVisibility(View.VISIBLE);
|
||||
@ -60,7 +62,7 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
adapter = new ReposAdapter(getApplication().repoDB, getApplication().moduleMap);
|
||||
adapter = new ReposAdapter(mm.repoDB, mm.moduleMap);
|
||||
recyclerView.setAdapter(adapter);
|
||||
super.onResume();
|
||||
}
|
||||
@ -72,7 +74,7 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTopicPublished(Topic topic, Object result) {
|
||||
public void onTopicPublished(Topic topic) {
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
recyclerView.setVisibility(adapter.getItemCount() == 0 ? View.GONE : View.VISIBLE);
|
||||
emptyRv.setVisibility(adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
@ -80,7 +82,7 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
|
||||
|
||||
@Override
|
||||
public Topic[] getSubscription() {
|
||||
return new Topic[] { getApplication().repoLoadDone };
|
||||
return new Topic[] { mm.repoLoadDone };
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -103,7 +105,6 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
MagiskManager mm = getApplication();
|
||||
if (item.getItemId() == R.id.repo_sort) {
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.sorting_order)
|
||||
|
@ -69,7 +69,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTopicPublished(Topic topic, Object result) {
|
||||
public void onTopicPublished(Topic topic) {
|
||||
recreate();
|
||||
}
|
||||
|
||||
@ -311,7 +311,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTopicPublished(Topic topic, Object result) {
|
||||
public void onTopicPublished(Topic topic) {
|
||||
setLocalePreference((ListPreference) findPreference(Const.Key.LOCALE));
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
||||
MagiskManager mm = MagiskManager.get();
|
||||
prefs = mm.prefs;
|
||||
repoDB = mm.repoDB;
|
||||
mm.repoLoadDone.hasPublished = false;
|
||||
mm.repoLoadDone.reset();
|
||||
// Legacy data cleanup
|
||||
File old = new File(mm.getApplicationInfo().dataDir + "/shared_prefs", "RepoMap.xml");
|
||||
if (old.exists() || prefs.getString("repomap", null) != null) {
|
||||
@ -160,6 +160,11 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
||||
ReposFragment.adapter.notifyDBChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
MagiskManager.get().repoLoadDone.setPending();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
etags = new ArrayList<>(Arrays.asList(prefs.getString(Const.Key.ETAG_KEY, "").split(",")));
|
||||
|
@ -7,8 +7,13 @@ import java.util.List;
|
||||
|
||||
public class Topic {
|
||||
|
||||
public boolean hasPublished = false;
|
||||
private static final int NON_INIT = 0;
|
||||
private static final int PENDING = 1;
|
||||
private static final int PUBLISHED = 2;
|
||||
|
||||
private int state = NON_INIT;
|
||||
private List<WeakReference<Subscriber>> subscribers;
|
||||
private Object[] results;
|
||||
|
||||
public void subscribe(Subscriber sub) {
|
||||
if (subscribers == null) {
|
||||
@ -30,29 +35,47 @@ public class Topic {
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
state = NON_INIT;
|
||||
results = null;
|
||||
}
|
||||
|
||||
public boolean isPublished() {
|
||||
return state == PUBLISHED;
|
||||
}
|
||||
|
||||
public void publish() {
|
||||
publish(true, null);
|
||||
publish(true);
|
||||
}
|
||||
|
||||
public void publish(boolean record) {
|
||||
publish(record, null);
|
||||
}
|
||||
|
||||
public void publish(boolean record, Object result) {
|
||||
hasPublished = record;
|
||||
public void publish(boolean record, Object... results) {
|
||||
if (record)
|
||||
state = PUBLISHED;
|
||||
this.results = results;
|
||||
if (subscribers != null) {
|
||||
for (WeakReference<Subscriber> subscriber : subscribers) {
|
||||
if (subscriber.get() != null)
|
||||
subscriber.get().onTopicPublished(this, result);
|
||||
subscriber.get().onTopicPublished(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object[] getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public boolean isPending() {
|
||||
return state == PENDING;
|
||||
}
|
||||
|
||||
public void setPending() {
|
||||
state = PENDING;
|
||||
}
|
||||
|
||||
public interface Subscriber {
|
||||
default void subscribeTopics() {
|
||||
for (Topic topic : getSubscription()) {
|
||||
if (topic.hasPublished) {
|
||||
if (topic.isPublished()) {
|
||||
onTopicPublished(topic);
|
||||
}
|
||||
topic.subscribe(this);
|
||||
@ -63,13 +86,7 @@ public class Topic {
|
||||
event.unsubscribe(this);
|
||||
}
|
||||
}
|
||||
default void onTopicPublished() {
|
||||
onTopicPublished(null, null);
|
||||
}
|
||||
default void onTopicPublished(Topic topic) {
|
||||
onTopicPublished(topic, null);
|
||||
}
|
||||
void onTopicPublished(Topic topic, Object result);
|
||||
void onTopicPublished(Topic topic);
|
||||
Topic[] getSubscription();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user