Show repo loading progress by showing repos already loaded
This commit is contained in:
parent
c1a0f520f9
commit
294ad094c4
@ -15,7 +15,6 @@ import android.widget.TextView;
|
|||||||
import com.topjohnwu.magisk.adapters.ReposAdapter;
|
import com.topjohnwu.magisk.adapters.ReposAdapter;
|
||||||
import com.topjohnwu.magisk.asyncs.UpdateRepos;
|
import com.topjohnwu.magisk.asyncs.UpdateRepos;
|
||||||
import com.topjohnwu.magisk.components.Fragment;
|
import com.topjohnwu.magisk.components.Fragment;
|
||||||
import com.topjohnwu.magisk.utils.Logger;
|
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
@ -29,7 +28,7 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
|
|||||||
@BindView(R.id.empty_rv) TextView emptyRv;
|
@BindView(R.id.empty_rv) TextView emptyRv;
|
||||||
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
|
|
||||||
private ReposAdapter adapter;
|
public static ReposAdapter adapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@ -43,13 +42,11 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
|
|||||||
View view = inflater.inflate(R.layout.fragment_repos, container, false);
|
View view = inflater.inflate(R.layout.fragment_repos, container, false);
|
||||||
unbinder = ButterKnife.bind(this, view);
|
unbinder = ButterKnife.bind(this, view);
|
||||||
|
|
||||||
adapter = new ReposAdapter(getApplication().repoDB, getApplication().moduleMap);
|
|
||||||
recyclerView.setAdapter(adapter);
|
|
||||||
|
|
||||||
mSwipeRefreshLayout.setRefreshing(true);
|
mSwipeRefreshLayout.setRefreshing(true);
|
||||||
|
|
||||||
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||||
recyclerView.setVisibility(View.GONE);
|
recyclerView.setVisibility(View.VISIBLE);
|
||||||
|
emptyRv.setVisibility(View.GONE);
|
||||||
new UpdateRepos(getActivity()).exec();
|
new UpdateRepos(getActivity()).exec();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -58,11 +55,22 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
adapter = new ReposAdapter(getApplication().repoDB, getApplication().moduleMap);
|
||||||
|
recyclerView.setAdapter(adapter);
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
adapter = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTopicPublished(Topic topic) {
|
public void onTopicPublished(Topic topic) {
|
||||||
Logger.dev("ReposFragment: UI refresh triggered");
|
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
adapter.notifyDBChanged();
|
|
||||||
recyclerView.setVisibility(adapter.getItemCount() == 0 ? View.GONE : View.VISIBLE);
|
recyclerView.setVisibility(adapter.getItemCount() == 0 ? View.GONE : View.VISIBLE);
|
||||||
emptyRv.setVisibility(adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
emptyRv.setVisibility(adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ public class ReposAdapter extends SectionedAdapter<ReposAdapter.SectionHolder, R
|
|||||||
repoDB = db;
|
repoDB = db;
|
||||||
moduleMap = map;
|
moduleMap = map;
|
||||||
repoPairs = new ArrayList<>();
|
repoPairs = new ArrayList<>();
|
||||||
|
notifyDBChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import android.content.SharedPreferences;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
import com.topjohnwu.magisk.ReposFragment;
|
||||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||||
import com.topjohnwu.magisk.module.BaseModule;
|
import com.topjohnwu.magisk.module.BaseModule;
|
||||||
import com.topjohnwu.magisk.module.Repo;
|
import com.topjohnwu.magisk.module.Repo;
|
||||||
@ -45,6 +46,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
|||||||
super(context);
|
super(context);
|
||||||
prefs = getMagiskManager().prefs;
|
prefs = getMagiskManager().prefs;
|
||||||
repoDB = getMagiskManager().repoDB;
|
repoDB = getMagiskManager().repoDB;
|
||||||
|
getMagiskManager().repoLoadDone.hasPublished = false;
|
||||||
String prefsPath = context.getApplicationInfo().dataDir + "/shared_prefs";
|
String prefsPath = context.getApplicationInfo().dataDir + "/shared_prefs";
|
||||||
// Legacy data cleanup
|
// Legacy data cleanup
|
||||||
File old = new File(prefsPath, "RepoMap.xml");
|
File old = new File(prefsPath, "RepoMap.xml");
|
||||||
@ -81,6 +83,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
|||||||
}
|
}
|
||||||
if (updated) {
|
if (updated) {
|
||||||
repoDB.addRepo(repo);
|
repoDB.addRepo(repo);
|
||||||
|
publishProgress();
|
||||||
}
|
}
|
||||||
} catch (BaseModule.CacheModException ignored) {}
|
} catch (BaseModule.CacheModException ignored) {}
|
||||||
}
|
}
|
||||||
@ -154,6 +157,12 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onProgressUpdate(Void... values) {
|
||||||
|
if (ReposFragment.adapter != null)
|
||||||
|
ReposFragment.adapter.notifyDBChanged();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
Logger.dev("UpdateRepos: Loading repos");
|
Logger.dev("UpdateRepos: Loading repos");
|
||||||
|
Loading…
Reference in New Issue
Block a user