mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-01-12 07:53:36 +00:00
Proper callback to trigger UI update
This commit is contained in:
parent
0e0240c4ab
commit
cf17e21ad3
@ -27,7 +27,7 @@ android {
|
|||||||
|
|
||||||
productFlavors {
|
productFlavors {
|
||||||
full {
|
full {
|
||||||
versionCode 131
|
versionCode 132
|
||||||
versionName "5.8.3"
|
versionName "5.8.3"
|
||||||
}
|
}
|
||||||
stub {
|
stub {
|
||||||
|
@ -34,7 +34,7 @@ public class ReposFragment extends BaseFragment 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;
|
||||||
|
|
||||||
public static ReposAdapter adapter;
|
private ReposAdapter adapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
@ -62,12 +62,6 @@ public class ReposFragment extends BaseFragment implements Topic.Subscriber {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
super.onPause();
|
|
||||||
adapter = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getSubscribedTopics() {
|
public int[] getSubscribedTopics() {
|
||||||
return new int[] {Topic.MODULE_LOAD_DONE, Topic.REPO_LOAD_DONE};
|
return new int[] {Topic.MODULE_LOAD_DONE, Topic.REPO_LOAD_DONE};
|
||||||
@ -77,12 +71,12 @@ public class ReposFragment extends BaseFragment implements Topic.Subscriber {
|
|||||||
public void onPublish(int topic, Object[] result) {
|
public void onPublish(int topic, Object[] result) {
|
||||||
if (topic == Topic.MODULE_LOAD_DONE) {
|
if (topic == Topic.MODULE_LOAD_DONE) {
|
||||||
adapter = new ReposAdapter(mm.repoDB, (Map<String, Module>) result[0]);
|
adapter = new ReposAdapter(mm.repoDB, (Map<String, Module>) result[0]);
|
||||||
|
mm.repoDB.registerAdapter(adapter);
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
recyclerView.setVisibility(View.VISIBLE);
|
recyclerView.setVisibility(View.VISIBLE);
|
||||||
emptyRv.setVisibility(View.GONE);
|
emptyRv.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
if (Topic.isPublished(getSubscribedTopics())) {
|
if (Topic.isPublished(getSubscribedTopics())) {
|
||||||
adapter.notifyDBChanged();
|
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
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);
|
||||||
@ -125,6 +119,7 @@ public class ReposFragment extends BaseFragment implements Topic.Subscriber {
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
mm.repoDB.unregisterAdapter();
|
||||||
unbinder.unbind();
|
unbinder.unbind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import android.os.AsyncTask;
|
|||||||
import com.topjohnwu.magisk.Const;
|
import com.topjohnwu.magisk.Const;
|
||||||
import com.topjohnwu.magisk.Data;
|
import com.topjohnwu.magisk.Data;
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.ReposFragment;
|
|
||||||
import com.topjohnwu.magisk.container.Repo;
|
import com.topjohnwu.magisk.container.Repo;
|
||||||
import com.topjohnwu.magisk.utils.Logger;
|
import com.topjohnwu.magisk.utils.Logger;
|
||||||
import com.topjohnwu.magisk.utils.Topic;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
@ -80,10 +79,6 @@ public class UpdateRepos {
|
|||||||
set.remove(id);
|
set.remove(id);
|
||||||
repo.update(date);
|
repo.update(date);
|
||||||
mm.repoDB.addRepo(repo);
|
mm.repoDB.addRepo(repo);
|
||||||
Data.mainHandler.post(() -> {
|
|
||||||
if (ReposFragment.adapter != null)
|
|
||||||
ReposFragment.adapter.notifyDBChanged();
|
|
||||||
});
|
|
||||||
} catch (Repo.IllegalRepoException e) {
|
} catch (Repo.IllegalRepoException e) {
|
||||||
Logger.debug(e.getMessage());
|
Logger.debug(e.getMessage());
|
||||||
mm.repoDB.removeRepo(id);
|
mm.repoDB.removeRepo(id);
|
||||||
|
@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||||||
import com.topjohnwu.magisk.Const;
|
import com.topjohnwu.magisk.Const;
|
||||||
import com.topjohnwu.magisk.Data;
|
import com.topjohnwu.magisk.Data;
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
|
import com.topjohnwu.magisk.adapters.ReposAdapter;
|
||||||
import com.topjohnwu.magisk.container.Repo;
|
import com.topjohnwu.magisk.container.Repo;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -20,6 +21,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
private MagiskManager mm;
|
private MagiskManager mm;
|
||||||
|
private ReposAdapter adapter;
|
||||||
|
|
||||||
public RepoDatabaseHelper(Context context) {
|
public RepoDatabaseHelper(Context context) {
|
||||||
super(context, "repo.db", null, DATABASE_VER);
|
super(context, "repo.db", null, DATABASE_VER);
|
||||||
@ -63,15 +65,18 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
public void clearRepo() {
|
public void clearRepo() {
|
||||||
mDb.delete(TABLE_NAME, null, null);
|
mDb.delete(TABLE_NAME, null, null);
|
||||||
|
notifyAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void removeRepo(String id) {
|
public void removeRepo(String id) {
|
||||||
mDb.delete(TABLE_NAME, "id=?", new String[] { id });
|
mDb.delete(TABLE_NAME, "id=?", new String[] { id });
|
||||||
|
notifyAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRepo(Repo repo) {
|
public void removeRepo(Repo repo) {
|
||||||
mDb.delete(TABLE_NAME, "repo_name=?", new String[] { repo.getRepoName() });
|
mDb.delete(TABLE_NAME, "repo_name=?", new String[] { repo.getRepoName() });
|
||||||
|
notifyAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeRepo(Iterable<String> list) {
|
public void removeRepo(Iterable<String> list) {
|
||||||
@ -79,10 +84,12 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
if (id == null) continue;
|
if (id == null) continue;
|
||||||
mDb.delete(TABLE_NAME, "id=?", new String[] { id });
|
mDb.delete(TABLE_NAME, "id=?", new String[] { id });
|
||||||
}
|
}
|
||||||
|
notifyAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addRepo(Repo repo) {
|
public void addRepo(Repo repo) {
|
||||||
mDb.replace(TABLE_NAME, null, repo.getContentValues());
|
mDb.replace(TABLE_NAME, null, repo.getContentValues());
|
||||||
|
notifyAdapter();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Repo getRepo(String id) {
|
public Repo getRepo(String id) {
|
||||||
@ -121,4 +128,18 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
return set;
|
return set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void registerAdapter(ReposAdapter a) {
|
||||||
|
adapter = a;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unregisterAdapter() {
|
||||||
|
adapter = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyAdapter() {
|
||||||
|
if (adapter != null) {
|
||||||
|
Data.mainHandler.post(adapter::notifyDBChanged);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user