Improve static data management
This commit is contained in:
parent
bfec381933
commit
b9495cd1bb
@ -2,6 +2,7 @@ package com.topjohnwu.magisk;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.SparseArray;
|
||||
|
||||
@ -16,9 +17,6 @@ import java.util.List;
|
||||
|
||||
public class Global {
|
||||
|
||||
public static class Constant {
|
||||
// No global constants now
|
||||
}
|
||||
public static class Info {
|
||||
public static double magiskVersion;
|
||||
public static String magiskVersionString = "(none)";
|
||||
@ -34,6 +32,15 @@ public class Global {
|
||||
public static ValueSortedMap<String, Repo> repoMap;
|
||||
public static ValueSortedMap<String, Module> moduleMap;
|
||||
public static List<String> blockList;
|
||||
public static List<ApplicationInfo> appList;
|
||||
public static List<String> magiskHideList;
|
||||
public static void clear() {
|
||||
repoMap = null;
|
||||
moduleMap = null;
|
||||
blockList = null;
|
||||
appList = null;
|
||||
magiskHideList = null;
|
||||
}
|
||||
}
|
||||
public static class Events {
|
||||
public static final CallbackHandler.Event blockDetectionDone = new CallbackHandler.Event();
|
||||
|
@ -106,8 +106,7 @@ public class MagiskHideFragment extends Fragment implements CallbackHandler.Even
|
||||
@Override
|
||||
public void onTrigger(CallbackHandler.Event event) {
|
||||
Logger.dev("MagiskHideFragment: UI refresh");
|
||||
Async.LoadApps.Result result = (Async.LoadApps.Result) event.getResult();
|
||||
appAdapter.setLists(result.listApps, result.hideList);
|
||||
appAdapter.setLists(Global.Data.appList, Global.Data.magiskHideList);
|
||||
mSwipeRefreshLayout.setRefreshing(false);
|
||||
if (!TextUtils.isEmpty(lastFilter)) {
|
||||
appAdapter.filter(lastFilter);
|
||||
|
@ -87,9 +87,8 @@ public class MainActivity extends AppCompatActivity
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
CallbackHandler.register(Global.Events.updateCheckDone, this);
|
||||
if (Global.Events.updateCheckDone.isTriggered) {
|
||||
if (Global.Events.updateCheckDone.isTriggered)
|
||||
onTrigger(Global.Events.updateCheckDone);
|
||||
}
|
||||
checkHideSection();
|
||||
}
|
||||
|
||||
@ -102,17 +101,18 @@ public class MainActivity extends AppCompatActivity
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
CallbackHandler.unRegister(Global.Events.reloadMainActivity, this);
|
||||
// Let garbage collector remove them
|
||||
Global.Data.clear();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (drawer.isDrawerOpen(navigationView)) {
|
||||
if (drawer.isDrawerOpen(navigationView))
|
||||
drawer.closeDrawer(navigationView);
|
||||
} else {
|
||||
else
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) {
|
||||
|
@ -114,7 +114,7 @@ public class Async {
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoadApps extends RootTask<Void, Void, LoadApps.Result> {
|
||||
public static class LoadApps extends RootTask<Void, Void, Void> {
|
||||
|
||||
private PackageManager pm;
|
||||
|
||||
@ -123,33 +123,22 @@ public class Async {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Result doInBackground(Void... voids) {
|
||||
List<ApplicationInfo> listApps = pm.getInstalledApplications(PackageManager.GET_META_DATA);
|
||||
for (Iterator<ApplicationInfo> i = listApps.iterator(); i.hasNext(); ) {
|
||||
protected Void doInBackground(Void... voids) {
|
||||
Global.Data.appList = pm.getInstalledApplications(0);
|
||||
for (Iterator<ApplicationInfo> i = Global.Data.appList.iterator(); i.hasNext(); ) {
|
||||
ApplicationInfo info = i.next();
|
||||
if (ApplicationAdapter.BLACKLIST.contains(info.packageName) || !info.enabled)
|
||||
i.remove();
|
||||
}
|
||||
Collections.sort(listApps, (a, b) -> a.loadLabel(pm).toString().toLowerCase()
|
||||
Collections.sort(Global.Data.appList, (a, b) -> a.loadLabel(pm).toString().toLowerCase()
|
||||
.compareTo(b.loadLabel(pm).toString().toLowerCase()));
|
||||
List<String> hideList = Shell.su(Async.MAGISK_HIDE_PATH + "list");
|
||||
return new Result(listApps, hideList);
|
||||
Global.Data.magiskHideList = Shell.su(Async.MAGISK_HIDE_PATH + "list");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Result result) {
|
||||
Global.Events.packageLoadDone.trigger(result);
|
||||
}
|
||||
|
||||
public static class Result {
|
||||
|
||||
public final List<ApplicationInfo> listApps;
|
||||
public final List<String> hideList;
|
||||
|
||||
Result(List<ApplicationInfo> listApps, List<String> hideList) {
|
||||
this.listApps = listApps;
|
||||
this.hideList = hideList;
|
||||
}
|
||||
protected void onPostExecute(Void v) {
|
||||
Global.Events.packageLoadDone.trigger();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user