Rename callbackevents to topic/subscribers
This commit is contained in:
parent
2ecbca303b
commit
8e7b8825f5
@ -31,8 +31,8 @@ import com.topjohnwu.magisk.components.AlertDialogBuilder;
|
|||||||
import com.topjohnwu.magisk.components.Fragment;
|
import com.topjohnwu.magisk.components.Fragment;
|
||||||
import com.topjohnwu.magisk.components.SnackbarMaker;
|
import com.topjohnwu.magisk.components.SnackbarMaker;
|
||||||
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
||||||
import com.topjohnwu.magisk.utils.CallbackEvent;
|
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -49,7 +49,7 @@ import butterknife.OnClick;
|
|||||||
import butterknife.Unbinder;
|
import butterknife.Unbinder;
|
||||||
|
|
||||||
public class MagiskFragment extends Fragment
|
public class MagiskFragment extends Fragment
|
||||||
implements CallbackEvent.Listener, SwipeRefreshLayout.OnRefreshListener {
|
implements Topic.Subscriber, SwipeRefreshLayout.OnRefreshListener {
|
||||||
|
|
||||||
public static final String SHOW_DIALOG = "dialog";
|
public static final String SHOW_DIALOG = "dialog";
|
||||||
|
|
||||||
@ -268,8 +268,8 @@ public class MagiskFragment extends Fragment
|
|||||||
|
|
||||||
safetyNetStatusText.setText(R.string.safetyNet_check_text);
|
safetyNetStatusText.setText(R.string.safetyNet_check_text);
|
||||||
|
|
||||||
magiskManager.safetyNetDone.isTriggered = false;
|
magiskManager.safetyNetDone.hasPublished = false;
|
||||||
magiskManager.updateCheckDone.isTriggered = false;
|
magiskManager.updateCheckDone.hasPublished = false;
|
||||||
magiskManager.remoteMagiskVersionString = null;
|
magiskManager.remoteMagiskVersionString = null;
|
||||||
magiskManager.remoteMagiskVersionCode = -1;
|
magiskManager.remoteMagiskVersionCode = -1;
|
||||||
collapse();
|
collapse();
|
||||||
@ -283,17 +283,17 @@ public class MagiskFragment extends Fragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent event) {
|
public void onTopicPublished(Topic topic) {
|
||||||
if (event == magiskManager.updateCheckDone) {
|
if (topic == magiskManager.updateCheckDone) {
|
||||||
updateCheckUI();
|
updateCheckUI();
|
||||||
} else if (event == magiskManager.safetyNetDone) {
|
} else if (topic == magiskManager.safetyNetDone) {
|
||||||
updateSafetyNetUI();
|
updateSafetyNetUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallbackEvent[] getRegisterEvents() {
|
public Topic[] getSubscription() {
|
||||||
return new CallbackEvent[] { magiskManager.updateCheckDone, magiskManager.safetyNetDone };
|
return new Topic[] { magiskManager.updateCheckDone, magiskManager.safetyNetDone };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -13,13 +13,13 @@ import android.widget.SearchView;
|
|||||||
|
|
||||||
import com.topjohnwu.magisk.adapters.ApplicationAdapter;
|
import com.topjohnwu.magisk.adapters.ApplicationAdapter;
|
||||||
import com.topjohnwu.magisk.components.Fragment;
|
import com.topjohnwu.magisk.components.Fragment;
|
||||||
import com.topjohnwu.magisk.utils.CallbackEvent;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.Unbinder;
|
import butterknife.Unbinder;
|
||||||
|
|
||||||
public class MagiskHideFragment extends Fragment implements CallbackEvent.Listener {
|
public class MagiskHideFragment extends Fragment implements Topic.Subscriber {
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
@ -84,13 +84,13 @@ public class MagiskHideFragment extends Fragment implements CallbackEvent.Listen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent event) {
|
public void onTopicPublished(Topic topic) {
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
appAdapter.filter(lastFilter);
|
appAdapter.filter(lastFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallbackEvent[] getRegisterEvents() {
|
public Topic[] getSubscription() {
|
||||||
return new CallbackEvent[] { getApplication().magiskHideDone };
|
return new Topic[] { getApplication().magiskHideDone };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@ import com.topjohnwu.magisk.asyncs.ParallelTask;
|
|||||||
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
import com.topjohnwu.magisk.database.RepoDatabaseHelper;
|
||||||
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
||||||
import com.topjohnwu.magisk.module.Module;
|
import com.topjohnwu.magisk.module.Module;
|
||||||
import com.topjohnwu.magisk.utils.CallbackEvent;
|
|
||||||
import com.topjohnwu.magisk.utils.SafetyNetHelper;
|
import com.topjohnwu.magisk.utils.SafetyNetHelper;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -43,14 +43,14 @@ public class MagiskManager extends Application {
|
|||||||
public static final String BUSYBOX_ARM = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.1/busybox-arm";
|
public static final String BUSYBOX_ARM = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.1/busybox-arm";
|
||||||
public static final String BUSYBOX_X86 = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.1/busybox-x86";
|
public static final String BUSYBOX_X86 = "https://github.com/topjohnwu/ndk-busybox/releases/download/1.27.1/busybox-x86";
|
||||||
|
|
||||||
// Events
|
// Topics
|
||||||
public final CallbackEvent magiskHideDone = new CallbackEvent();
|
public final Topic magiskHideDone = new Topic();
|
||||||
public final CallbackEvent reloadActivity = new CallbackEvent();
|
public final Topic reloadActivity = new Topic();
|
||||||
public final CallbackEvent moduleLoadDone = new CallbackEvent();
|
public final Topic moduleLoadDone = new Topic();
|
||||||
public final CallbackEvent repoLoadDone = new CallbackEvent();
|
public final Topic repoLoadDone = new Topic();
|
||||||
public final CallbackEvent updateCheckDone = new CallbackEvent();
|
public final Topic updateCheckDone = new Topic();
|
||||||
public final CallbackEvent safetyNetDone = new CallbackEvent();
|
public final Topic safetyNetDone = new Topic();
|
||||||
public final CallbackEvent localeDone = new CallbackEvent();
|
public final Topic localeDone = new Topic();
|
||||||
|
|
||||||
// Info
|
// Info
|
||||||
public String magiskVersionString;
|
public String magiskVersionString;
|
||||||
@ -113,7 +113,7 @@ public class MagiskManager extends Application {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void aVoid) {
|
protected void onPostExecute(Void aVoid) {
|
||||||
getMagiskManager().localeDone.trigger();
|
getMagiskManager().localeDone.publish();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,15 +20,15 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.utils.CallbackEvent;
|
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class MainActivity extends Activity
|
public class MainActivity extends Activity
|
||||||
implements NavigationView.OnNavigationItemSelectedListener, CallbackEvent.Listener {
|
implements NavigationView.OnNavigationItemSelectedListener, Topic.Subscriber {
|
||||||
|
|
||||||
private final Handler mDrawerHandler = new Handler();
|
private final Handler mDrawerHandler = new Handler();
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
@ -110,13 +110,13 @@ public class MainActivity extends Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent event) {
|
public void onTopicPublished(Topic topic) {
|
||||||
recreate();
|
recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallbackEvent[] getRegisterEvents() {
|
public Topic[] getSubscription() {
|
||||||
return new CallbackEvent[] { getApplicationContext().reloadActivity };
|
return new Topic[] { getApplicationContext().reloadActivity };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkHideSection() {
|
public void checkHideSection() {
|
||||||
|
@ -16,8 +16,8 @@ import com.topjohnwu.magisk.adapters.ModulesAdapter;
|
|||||||
import com.topjohnwu.magisk.asyncs.LoadModules;
|
import com.topjohnwu.magisk.asyncs.LoadModules;
|
||||||
import com.topjohnwu.magisk.components.Fragment;
|
import com.topjohnwu.magisk.components.Fragment;
|
||||||
import com.topjohnwu.magisk.module.Module;
|
import com.topjohnwu.magisk.module.Module;
|
||||||
import com.topjohnwu.magisk.utils.CallbackEvent;
|
|
||||||
import com.topjohnwu.magisk.utils.Logger;
|
import com.topjohnwu.magisk.utils.Logger;
|
||||||
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -26,7 +26,7 @@ import butterknife.BindView;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.Unbinder;
|
import butterknife.Unbinder;
|
||||||
|
|
||||||
public class ModulesFragment extends Fragment implements CallbackEvent.Listener {
|
public class ModulesFragment extends Fragment implements Topic.Subscriber {
|
||||||
|
|
||||||
private static final int FETCH_ZIP_CODE = 2;
|
private static final int FETCH_ZIP_CODE = 2;
|
||||||
|
|
||||||
@ -73,14 +73,14 @@ public class ModulesFragment extends Fragment implements CallbackEvent.Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent event) {
|
public void onTopicPublished(Topic topic) {
|
||||||
Logger.dev("ModulesFragment: UI refresh triggered");
|
Logger.dev("ModulesFragment: UI refresh triggered");
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallbackEvent[] getRegisterEvents() {
|
public Topic[] getSubscription() {
|
||||||
return new CallbackEvent[] { getApplication().moduleLoadDone };
|
return new Topic[] { getApplication().moduleLoadDone };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,14 +15,14 @@ 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.CallbackEvent;
|
|
||||||
import com.topjohnwu.magisk.utils.Logger;
|
import com.topjohnwu.magisk.utils.Logger;
|
||||||
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
|
|
||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.Unbinder;
|
import butterknife.Unbinder;
|
||||||
|
|
||||||
public class ReposFragment extends Fragment implements CallbackEvent.Listener {
|
public class ReposFragment extends Fragment implements Topic.Subscriber {
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
||||||
@ -59,7 +59,7 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent event) {
|
public void onTopicPublished(Topic topic) {
|
||||||
Logger.dev("ReposFragment: UI refresh triggered");
|
Logger.dev("ReposFragment: UI refresh triggered");
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
adapter.notifyDBChanged();
|
adapter.notifyDBChanged();
|
||||||
@ -68,8 +68,8 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallbackEvent[] getRegisterEvents() {
|
public Topic[] getSubscription() {
|
||||||
return new CallbackEvent[] { getApplication().repoLoadDone };
|
return new Topic[] { getApplication().repoLoadDone };
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,9 +15,9 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import com.topjohnwu.magisk.components.Activity;
|
import com.topjohnwu.magisk.components.Activity;
|
||||||
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
||||||
import com.topjohnwu.magisk.utils.CallbackEvent;
|
|
||||||
import com.topjohnwu.magisk.utils.Logger;
|
import com.topjohnwu.magisk.utils.Logger;
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -25,7 +25,7 @@ import java.util.Locale;
|
|||||||
import butterknife.BindView;
|
import butterknife.BindView;
|
||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class SettingsActivity extends Activity implements CallbackEvent.Listener {
|
public class SettingsActivity extends Activity implements Topic.Subscriber {
|
||||||
|
|
||||||
@BindView(R.id.toolbar) Toolbar toolbar;
|
@BindView(R.id.toolbar) Toolbar toolbar;
|
||||||
|
|
||||||
@ -58,18 +58,18 @@ public class SettingsActivity extends Activity implements CallbackEvent.Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent event) {
|
public void onTopicPublished(Topic topic) {
|
||||||
recreate();
|
recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallbackEvent[] getRegisterEvents() {
|
public Topic[] getSubscription() {
|
||||||
return new CallbackEvent[] { getApplicationContext().reloadActivity };
|
return new Topic[] { getApplicationContext().reloadActivity };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class SettingsFragment extends PreferenceFragment
|
public static class SettingsFragment extends PreferenceFragment
|
||||||
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
||||||
CallbackEvent.Listener {
|
Topic.Subscriber {
|
||||||
|
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
private PreferenceScreen prefScreen;
|
private PreferenceScreen prefScreen;
|
||||||
@ -162,13 +162,13 @@ public class SettingsActivity extends Activity implements CallbackEvent.Listener
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
registerEvents();
|
subscribeTopics();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
prefs.unregisterOnSharedPreferenceChangeListener(this);
|
prefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
unregisterEvents();
|
unsubscribeTopics();
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,7 +182,7 @@ public class SettingsActivity extends Activity implements CallbackEvent.Listener
|
|||||||
enabled = prefs.getBoolean("dark_theme", false);
|
enabled = prefs.getBoolean("dark_theme", false);
|
||||||
if (magiskManager.isDarkTheme != enabled) {
|
if (magiskManager.isDarkTheme != enabled) {
|
||||||
magiskManager.isDarkTheme = enabled;
|
magiskManager.isDarkTheme = enabled;
|
||||||
magiskManager.reloadActivity.trigger(false);
|
magiskManager.reloadActivity.publish(false);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "disable":
|
case "disable":
|
||||||
@ -243,7 +243,7 @@ public class SettingsActivity extends Activity implements CallbackEvent.Listener
|
|||||||
break;
|
break;
|
||||||
case "locale":
|
case "locale":
|
||||||
magiskManager.setLocale();
|
magiskManager.setLocale();
|
||||||
magiskManager.reloadActivity.trigger(false);
|
magiskManager.reloadActivity.publish(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
setSummary();
|
setSummary();
|
||||||
@ -265,13 +265,13 @@ public class SettingsActivity extends Activity implements CallbackEvent.Listener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent event) {
|
public void onTopicPublished(Topic topic) {
|
||||||
setLocalePreference((ListPreference) findPreference("locale"));
|
setLocalePreference((ListPreference) findPreference("locale"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CallbackEvent[] getRegisterEvents() {
|
public Topic[] getSubscription() {
|
||||||
return new CallbackEvent[] { magiskManager.localeDone };
|
return new Topic[] { magiskManager.localeDone };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +16,8 @@ import android.widget.TextView;
|
|||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
import com.topjohnwu.magisk.asyncs.ParallelTask;
|
||||||
import com.topjohnwu.magisk.components.SnackbarMaker;
|
import com.topjohnwu.magisk.components.SnackbarMaker;
|
||||||
import com.topjohnwu.magisk.utils.CallbackEvent;
|
|
||||||
import com.topjohnwu.magisk.utils.Shell;
|
import com.topjohnwu.magisk.utils.Shell;
|
||||||
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -46,7 +46,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
private List<String> mHideList;
|
private List<String> mHideList;
|
||||||
private PackageManager pm;
|
private PackageManager pm;
|
||||||
private ApplicationFilter filter;
|
private ApplicationFilter filter;
|
||||||
private CallbackEvent magiskHideDone;
|
private Topic magiskHideDone;
|
||||||
private Shell shell;
|
private Shell shell;
|
||||||
|
|
||||||
public ApplicationAdapter(Context context) {
|
public ApplicationAdapter(Context context) {
|
||||||
@ -169,7 +169,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Void v) {
|
||||||
magiskHideDone.trigger(false);
|
magiskHideDone.publish(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class CheckUpdates extends ParallelTask<Void, Void, Void> {
|
|||||||
Utils.showMagiskUpdate(magiskManager);
|
Utils.showMagiskUpdate(magiskManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
magiskManager.updateCheckDone.trigger();
|
magiskManager.updateCheckDone.publish();
|
||||||
super.onPostExecute(v);
|
super.onPostExecute(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public class LoadModules extends ParallelTask<Void, Void, Void> {
|
|||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Void v) {
|
||||||
MagiskManager magiskManager = getMagiskManager();
|
MagiskManager magiskManager = getMagiskManager();
|
||||||
if (magiskManager == null) return;
|
if (magiskManager == null) return;
|
||||||
magiskManager.moduleLoadDone.trigger();
|
magiskManager.moduleLoadDone.publish();
|
||||||
super.onPostExecute(v);
|
super.onPostExecute(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,7 +186,7 @@ public class UpdateRepos extends ParallelTask<Void, Void, Void> {
|
|||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Void v) {
|
||||||
MagiskManager magiskManager = getMagiskManager();
|
MagiskManager magiskManager = getMagiskManager();
|
||||||
if (magiskManager == null) return;
|
if (magiskManager == null) return;
|
||||||
magiskManager.repoLoadDone.trigger();
|
magiskManager.repoLoadDone.publish();
|
||||||
super.onPostExecute(v);
|
super.onPostExecute(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import android.view.WindowManager;
|
|||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.utils.CallbackEvent;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
|
|
||||||
public class Activity extends AppCompatActivity {
|
public class Activity extends AppCompatActivity {
|
||||||
|
|
||||||
@ -22,15 +22,15 @@ public class Activity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
if (this instanceof CallbackEvent.Listener) {
|
if (this instanceof Topic.Subscriber) {
|
||||||
((CallbackEvent.Listener) this).registerEvents();
|
((Topic.Subscriber) this).subscribeTopics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
if (this instanceof CallbackEvent.Listener) {
|
if (this instanceof Topic.Subscriber) {
|
||||||
((CallbackEvent.Listener) this).unregisterEvents();
|
((Topic.Subscriber) this).unsubscribeTopics();
|
||||||
}
|
}
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package com.topjohnwu.magisk.components;
|
package com.topjohnwu.magisk.components;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
import com.topjohnwu.magisk.utils.CallbackEvent;
|
import com.topjohnwu.magisk.utils.Topic;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
|
|
||||||
public class Fragment extends android.support.v4.app.Fragment {
|
public class Fragment extends android.support.v4.app.Fragment {
|
||||||
@ -13,15 +13,15 @@ public class Fragment extends android.support.v4.app.Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (this instanceof CallbackEvent.Listener) {
|
if (this instanceof Topic.Subscriber) {
|
||||||
((CallbackEvent.Listener) this).registerEvents();
|
((Topic.Subscriber) this).subscribeTopics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
if (this instanceof CallbackEvent.Listener) {
|
if (this instanceof Topic.Subscriber) {
|
||||||
((CallbackEvent.Listener) this).unregisterEvents();
|
((Topic.Subscriber) this).unsubscribeTopics();
|
||||||
}
|
}
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
@ -1,68 +0,0 @@
|
|||||||
package com.topjohnwu.magisk.utils;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CallbackEvent {
|
|
||||||
|
|
||||||
public boolean isTriggered = false;
|
|
||||||
private List<WeakReference<Listener>> listeners;
|
|
||||||
|
|
||||||
public void register(Listener l) {
|
|
||||||
if (listeners == null) {
|
|
||||||
listeners = new LinkedList<>();
|
|
||||||
}
|
|
||||||
listeners.add(new WeakReference<>(l));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unregister() {
|
|
||||||
listeners = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void unregister(Listener l) {
|
|
||||||
for (Iterator<WeakReference<Listener>> i = listeners.iterator(); i.hasNext();) {
|
|
||||||
WeakReference<Listener> listener = i.next();
|
|
||||||
if (listener.get() == null || listener.get() == l) {
|
|
||||||
i.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void trigger() {
|
|
||||||
trigger(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void trigger(boolean b) {
|
|
||||||
isTriggered = b;
|
|
||||||
if (listeners != null) {
|
|
||||||
for (WeakReference<Listener> listener : listeners) {
|
|
||||||
if (listener.get() != null)
|
|
||||||
listener.get().onTrigger(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public interface Listener {
|
|
||||||
default void registerEvents() {
|
|
||||||
for (CallbackEvent event : getRegisterEvents()) {
|
|
||||||
if (event.isTriggered) {
|
|
||||||
onTrigger(event);
|
|
||||||
}
|
|
||||||
event.register(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default void unregisterEvents() {
|
|
||||||
for (CallbackEvent event : getRegisterEvents()) {
|
|
||||||
event.unregister(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
default void onTrigger() {
|
|
||||||
onTrigger(null);
|
|
||||||
}
|
|
||||||
void onTrigger(CallbackEvent event);
|
|
||||||
CallbackEvent[] getRegisterEvents();
|
|
||||||
}
|
|
||||||
}
|
|
68
app/src/main/java/com/topjohnwu/magisk/utils/Topic.java
Normal file
68
app/src/main/java/com/topjohnwu/magisk/utils/Topic.java
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package com.topjohnwu.magisk.utils;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Topic {
|
||||||
|
|
||||||
|
public boolean hasPublished = false;
|
||||||
|
private List<WeakReference<Subscriber>> subscribers;
|
||||||
|
|
||||||
|
public void subscribe(Subscriber sub) {
|
||||||
|
if (subscribers == null) {
|
||||||
|
subscribers = new LinkedList<>();
|
||||||
|
}
|
||||||
|
subscribers.add(new WeakReference<>(sub));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsubscribe() {
|
||||||
|
subscribers = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void unsubscribe(Subscriber sub) {
|
||||||
|
for (Iterator<WeakReference<Subscriber>> i = subscribers.iterator(); i.hasNext();) {
|
||||||
|
WeakReference<Subscriber> subscriber = i.next();
|
||||||
|
if (subscriber.get() == null || subscriber.get() == sub) {
|
||||||
|
i.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void publish() {
|
||||||
|
publish(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void publish(boolean b) {
|
||||||
|
hasPublished = b;
|
||||||
|
if (subscribers != null) {
|
||||||
|
for (WeakReference<Subscriber> subscriber : subscribers) {
|
||||||
|
if (subscriber.get() != null)
|
||||||
|
subscriber.get().onTopicPublished(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public interface Subscriber {
|
||||||
|
default void subscribeTopics() {
|
||||||
|
for (Topic topic : getSubscription()) {
|
||||||
|
if (topic.hasPublished) {
|
||||||
|
onTopicPublished(topic);
|
||||||
|
}
|
||||||
|
topic.subscribe(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default void unsubscribeTopics() {
|
||||||
|
for (Topic event : getSubscription()) {
|
||||||
|
event.unsubscribe(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default void onTopicPublished() {
|
||||||
|
onTopicPublished(null);
|
||||||
|
}
|
||||||
|
void onTopicPublished(Topic topic);
|
||||||
|
Topic[] getSubscription();
|
||||||
|
}
|
||||||
|
}
|
@ -140,7 +140,7 @@ public class Utils {
|
|||||||
@Override
|
@Override
|
||||||
public void handleResults(Result result) {
|
public void handleResults(Result result) {
|
||||||
getMagiskManager(mActivity).SNCheckResult = result;
|
getMagiskManager(mActivity).SNCheckResult = result;
|
||||||
getMagiskManager(mActivity).safetyNetDone.trigger();
|
getMagiskManager(mActivity).safetyNetDone.publish();
|
||||||
}
|
}
|
||||||
}.requestTest();
|
}.requestTest();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user