mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-26 22:37:39 +00:00
Update CallbackEvents
This commit is contained in:
parent
bd6585765e
commit
36124ddca4
@ -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<Void>, SwipeRefreshLayout.OnRefreshListener {
|
implements CallbackEvent.Listener, SwipeRefreshLayout.OnRefreshListener {
|
||||||
|
|
||||||
public static final String SHOW_DIALOG = "dialog";
|
public static final String SHOW_DIALOG = "dialog";
|
||||||
|
|
||||||
@ -253,6 +253,8 @@ public class MagiskFragment extends Fragment
|
|||||||
if (getArguments() != null && getArguments().getBoolean(SHOW_DIALOG))
|
if (getArguments() != null && getArguments().getBoolean(SHOW_DIALOG))
|
||||||
install();
|
install();
|
||||||
|
|
||||||
|
getActivity().setTitle(R.string.magisk);
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -281,7 +283,7 @@ public class MagiskFragment extends Fragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent<Void> event) {
|
public void onTrigger(CallbackEvent event) {
|
||||||
if (event == magiskManager.updateCheckDone) {
|
if (event == magiskManager.updateCheckDone) {
|
||||||
updateCheckUI();
|
updateCheckUI();
|
||||||
} else if (event == magiskManager.safetyNetDone) {
|
} else if (event == magiskManager.safetyNetDone) {
|
||||||
@ -290,23 +292,8 @@ public class MagiskFragment extends Fragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public CallbackEvent[] getRegisterEvents() {
|
||||||
super.onStart();
|
return new CallbackEvent[] { magiskManager.updateCheckDone, magiskManager.safetyNetDone };
|
||||||
// Manual trigger if already done
|
|
||||||
if (magiskManager.updateCheckDone.isTriggered)
|
|
||||||
updateCheckUI();
|
|
||||||
if (magiskManager.safetyNetDone.isTriggered)
|
|
||||||
updateSafetyNetUI();
|
|
||||||
magiskManager.updateCheckDone.register(this);
|
|
||||||
magiskManager.safetyNetDone.register(this);
|
|
||||||
getActivity().setTitle(R.string.magisk);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
magiskManager.updateCheckDone.unRegister(this);
|
|
||||||
magiskManager.safetyNetDone.unRegister(this);
|
|
||||||
super.onStop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,7 +2,6 @@ package com.topjohnwu.magisk;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
|
||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@ -15,13 +14,12 @@ 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.CallbackEvent;
|
||||||
import com.topjohnwu.magisk.utils.Logger;
|
|
||||||
|
|
||||||
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<Void> {
|
public class MagiskHideFragment extends Fragment implements CallbackEvent.Listener {
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||||
@ -67,29 +65,18 @@ public class MagiskHideFragment extends Fragment implements CallbackEvent.Listen
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
getActivity().setTitle(R.string.magiskhide);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.menu_magiskhide, menu);
|
inflater.inflate(R.menu.menu_magiskhide, menu);
|
||||||
SearchView search = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.app_search));
|
SearchView search = (SearchView) menu.findItem(R.id.app_search).getActionView();
|
||||||
search.setOnQueryTextListener(searchListener);
|
search.setOnQueryTextListener(searchListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
getActivity().setTitle(R.string.magiskhide);
|
|
||||||
getApplication().magiskHideDone.register(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
getApplication().magiskHideDone.unRegister(this);
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
@ -97,9 +84,13 @@ public class MagiskHideFragment extends Fragment implements CallbackEvent.Listen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent<Void> event) {
|
public void onTrigger(CallbackEvent event) {
|
||||||
Logger.dev("MagiskHideFragment: UI refresh");
|
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
appAdapter.filter(lastFilter);
|
appAdapter.filter(lastFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CallbackEvent[] getRegisterEvents() {
|
||||||
|
return new CallbackEvent[] { getApplication().magiskHideDone };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ 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.CallbackEvent;
|
||||||
import com.topjohnwu.magisk.utils.Logger;
|
|
||||||
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.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
@ -44,13 +43,13 @@ public class MagiskManager extends Application {
|
|||||||
public static final String NOTIFICATION_CHANNEL = "magisk_update_notice";
|
public static final String NOTIFICATION_CHANNEL = "magisk_update_notice";
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
public final CallbackEvent<Void> magiskHideDone = new CallbackEvent<>();
|
public final CallbackEvent magiskHideDone = new CallbackEvent();
|
||||||
public final CallbackEvent<Void> reloadMainActivity = new CallbackEvent<>();
|
public final CallbackEvent reloadMainActivity = new CallbackEvent();
|
||||||
public final CallbackEvent<Void> moduleLoadDone = new CallbackEvent<>();
|
public final CallbackEvent moduleLoadDone = new CallbackEvent();
|
||||||
public final CallbackEvent<Void> repoLoadDone = new CallbackEvent<>();
|
public final CallbackEvent repoLoadDone = new CallbackEvent();
|
||||||
public final CallbackEvent<Void> updateCheckDone = new CallbackEvent<>();
|
public final CallbackEvent updateCheckDone = new CallbackEvent();
|
||||||
public final CallbackEvent<Void> safetyNetDone = new CallbackEvent<>();
|
public final CallbackEvent safetyNetDone = new CallbackEvent();
|
||||||
public final CallbackEvent<Void> localeDone = new CallbackEvent<>();
|
public final CallbackEvent localeDone = new CallbackEvent();
|
||||||
|
|
||||||
// Info
|
// Info
|
||||||
public String magiskVersionString;
|
public String magiskVersionString;
|
||||||
|
@ -28,7 +28,7 @@ import butterknife.BindView;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
|
|
||||||
public class MainActivity extends Activity
|
public class MainActivity extends Activity
|
||||||
implements NavigationView.OnNavigationItemSelectedListener, CallbackEvent.Listener<Void> {
|
implements NavigationView.OnNavigationItemSelectedListener, CallbackEvent.Listener {
|
||||||
|
|
||||||
private final Handler mDrawerHandler = new Handler();
|
private final Handler mDrawerHandler = new Handler();
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
@ -81,7 +81,6 @@ public class MainActivity extends Activity
|
|||||||
navigate(getIntent().getStringExtra(MagiskManager.INTENT_SECTION));
|
navigate(getIntent().getStringExtra(MagiskManager.INTENT_SECTION));
|
||||||
|
|
||||||
navigationView.setNavigationItemSelectedListener(this);
|
navigationView.setNavigationItemSelectedListener(this);
|
||||||
getApplicationContext().reloadMainActivity.register(this);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,12 +90,6 @@ public class MainActivity extends Activity
|
|||||||
checkHideSection();
|
checkHideSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
getApplicationContext().reloadMainActivity.unRegister(this);
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (drawer.isDrawerOpen(navigationView)) {
|
if (drawer.isDrawerOpen(navigationView)) {
|
||||||
@ -117,10 +110,15 @@ public class MainActivity extends Activity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent<Void> event) {
|
public void onTrigger(CallbackEvent event) {
|
||||||
recreate();
|
recreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CallbackEvent[] getRegisterEvents() {
|
||||||
|
return new CallbackEvent[] { getApplicationContext().reloadMainActivity };
|
||||||
|
}
|
||||||
|
|
||||||
public void checkHideSection() {
|
public void checkHideSection() {
|
||||||
Menu menu = navigationView.getMenu();
|
Menu menu = navigationView.getMenu();
|
||||||
menu.findItem(R.id.magiskhide).setVisible(
|
menu.findItem(R.id.magiskhide).setVisible(
|
||||||
|
@ -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<Void> {
|
public class ModulesFragment extends Fragment implements CallbackEvent.Listener {
|
||||||
|
|
||||||
private static final int FETCH_ZIP_CODE = 2;
|
private static final int FETCH_ZIP_CODE = 2;
|
||||||
|
|
||||||
@ -67,19 +67,22 @@ public class ModulesFragment extends Fragment implements CallbackEvent.Listener<
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (getApplication().moduleLoadDone.isTriggered) {
|
getActivity().setTitle(R.string.modules);
|
||||||
updateUI();
|
|
||||||
}
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent<Void> event) {
|
public void onTrigger(CallbackEvent event) {
|
||||||
Logger.dev("ModulesFragment: UI refresh triggered");
|
Logger.dev("ModulesFragment: UI refresh triggered");
|
||||||
updateUI();
|
updateUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CallbackEvent[] getRegisterEvents() {
|
||||||
|
return new CallbackEvent[] { getApplication().moduleLoadDone };
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == FETCH_ZIP_CODE && resultCode == Activity.RESULT_OK && data != null) {
|
if (requestCode == FETCH_ZIP_CODE && resultCode == Activity.RESULT_OK && data != null) {
|
||||||
@ -88,20 +91,6 @@ public class ModulesFragment extends Fragment implements CallbackEvent.Listener<
|
|||||||
intent.setData(data.getData()).putExtra("ACTION", "flash");
|
intent.setData(data.getData()).putExtra("ACTION", "flash");
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
getApplication().moduleLoadDone.register(this);
|
|
||||||
getActivity().setTitle(R.string.modules);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
getApplication().moduleLoadDone.unRegister(this);
|
|
||||||
super.onStop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,7 +22,7 @@ import butterknife.BindView;
|
|||||||
import butterknife.ButterKnife;
|
import butterknife.ButterKnife;
|
||||||
import butterknife.Unbinder;
|
import butterknife.Unbinder;
|
||||||
|
|
||||||
public class ReposFragment extends Fragment implements CallbackEvent.Listener<Void> {
|
public class ReposFragment extends Fragment implements CallbackEvent.Listener {
|
||||||
|
|
||||||
private Unbinder unbinder;
|
private Unbinder unbinder;
|
||||||
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
||||||
@ -53,15 +53,13 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener<Vo
|
|||||||
new UpdateRepos(getActivity()).exec();
|
new UpdateRepos(getActivity()).exec();
|
||||||
});
|
});
|
||||||
|
|
||||||
if (getApplication().repoLoadDone.isTriggered) {
|
getActivity().setTitle(R.string.downloads);
|
||||||
onTrigger(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent<Void> event) {
|
public void onTrigger(CallbackEvent event) {
|
||||||
Logger.dev("ReposFragment: UI refresh triggered");
|
Logger.dev("ReposFragment: UI refresh triggered");
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
adapter.notifyDBChanged();
|
adapter.notifyDBChanged();
|
||||||
@ -69,6 +67,11 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener<Vo
|
|||||||
emptyRv.setVisibility(adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
emptyRv.setVisibility(adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CallbackEvent[] getRegisterEvents() {
|
||||||
|
return new CallbackEvent[] { getApplication().repoLoadDone };
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.menu_repo, menu);
|
inflater.inflate(R.menu.menu_repo, menu);
|
||||||
@ -87,19 +90,6 @@ public class ReposFragment extends Fragment implements CallbackEvent.Listener<Vo
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
getApplication().repoLoadDone.register(this);
|
|
||||||
getActivity().setTitle(R.string.downloads);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
getApplication().repoLoadDone.unRegister(this);
|
|
||||||
super.onStop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
|
@ -59,7 +59,7 @@ public class SettingsActivity extends Activity {
|
|||||||
|
|
||||||
public static class SettingsFragment extends PreferenceFragment
|
public static class SettingsFragment extends PreferenceFragment
|
||||||
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
implements SharedPreferences.OnSharedPreferenceChangeListener,
|
||||||
CallbackEvent.Listener<Void>{
|
CallbackEvent.Listener {
|
||||||
|
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
private PreferenceScreen prefScreen;
|
private PreferenceScreen prefScreen;
|
||||||
@ -149,16 +149,14 @@ public class SettingsActivity extends Activity {
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
magiskManager.localeDone.register(this);
|
registerEvents();
|
||||||
if (magiskManager.localeDone.isTriggered)
|
|
||||||
onTrigger(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
super.onPause();
|
|
||||||
prefs.unregisterOnSharedPreferenceChangeListener(this);
|
prefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||||
magiskManager.localeDone.unRegister(this);
|
unregisterEvents();
|
||||||
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -171,7 +169,7 @@ public class SettingsActivity extends Activity {
|
|||||||
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.reloadMainActivity.trigger();
|
magiskManager.reloadMainActivity.trigger(false);
|
||||||
getActivity().recreate();
|
getActivity().recreate();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -233,7 +231,7 @@ public class SettingsActivity extends Activity {
|
|||||||
break;
|
break;
|
||||||
case "locale":
|
case "locale":
|
||||||
magiskManager.setLocale();
|
magiskManager.setLocale();
|
||||||
magiskManager.reloadMainActivity.trigger();
|
magiskManager.reloadMainActivity.trigger(false);
|
||||||
getActivity().recreate();
|
getActivity().recreate();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -256,7 +254,7 @@ public class SettingsActivity extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackEvent<Void> event) {
|
public void onTrigger(CallbackEvent event) {
|
||||||
ListPreference language = setLocalePreference(null);
|
ListPreference language = setLocalePreference(null);
|
||||||
language.setOnPreferenceClickListener((pref) -> {
|
language.setOnPreferenceClickListener((pref) -> {
|
||||||
setLocalePreference((ListPreference) pref);
|
setLocalePreference((ListPreference) pref);
|
||||||
@ -264,6 +262,11 @@ public class SettingsActivity extends Activity {
|
|||||||
});
|
});
|
||||||
generalCatagory.addPreference(language);
|
generalCatagory.addPreference(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CallbackEvent[] getRegisterEvents() {
|
||||||
|
return new CallbackEvent[] { magiskManager.localeDone };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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<Void> magiskHideDone;
|
private CallbackEvent magiskHideDone;
|
||||||
private Shell shell;
|
private Shell shell;
|
||||||
|
|
||||||
public ApplicationAdapter(Context context) {
|
public ApplicationAdapter(Context context) {
|
||||||
@ -176,7 +176,7 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Void v) {
|
protected void onPostExecute(Void v) {
|
||||||
magiskHideDone.trigger();
|
magiskHideDone.trigger(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package com.topjohnwu.magisk.components;
|
package com.topjohnwu.magisk.components;
|
||||||
|
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.view.WindowManager;
|
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.Utils;
|
import com.topjohnwu.magisk.utils.CallbackEvent;
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class Activity extends AppCompatActivity {
|
public class Activity extends AppCompatActivity {
|
||||||
|
|
||||||
@ -19,6 +19,22 @@ public class Activity extends AppCompatActivity {
|
|||||||
applyOverrideConfiguration(configuration);
|
applyOverrideConfiguration(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
if (this instanceof CallbackEvent.Listener) {
|
||||||
|
((CallbackEvent.Listener) this).registerEvents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDestroy() {
|
||||||
|
if (this instanceof CallbackEvent.Listener) {
|
||||||
|
((CallbackEvent.Listener) this).unregisterEvents();
|
||||||
|
}
|
||||||
|
super.onDestroy();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MagiskManager getApplicationContext() {
|
public MagiskManager getApplicationContext() {
|
||||||
return (MagiskManager) super.getApplicationContext();
|
return (MagiskManager) super.getApplicationContext();
|
||||||
|
@ -1,6 +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.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 {
|
||||||
@ -9,4 +10,19 @@ public class Fragment extends android.support.v4.app.Fragment {
|
|||||||
return Utils.getMagiskManager(getActivity());
|
return Utils.getMagiskManager(getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
if (this instanceof CallbackEvent.Listener) {
|
||||||
|
((CallbackEvent.Listener) this).registerEvents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
if (this instanceof CallbackEvent.Listener) {
|
||||||
|
((CallbackEvent.Listener) this).unregisterEvents();
|
||||||
|
}
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import com.topjohnwu.magisk.MagiskManager;
|
|||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class SuLogEntry implements Parcelable {
|
public class SuLogEntry implements Parcelable {
|
||||||
|
|
||||||
|
@ -1,32 +1,29 @@
|
|||||||
package com.topjohnwu.magisk.utils;
|
package com.topjohnwu.magisk.utils;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class CallbackEvent<Result> {
|
public class CallbackEvent {
|
||||||
|
|
||||||
public boolean isTriggered = false;
|
public boolean isTriggered = false;
|
||||||
private Result result;
|
private List<WeakReference<Listener>> listeners;
|
||||||
private List<WeakReference<Listener<Result>>> listeners;
|
|
||||||
|
|
||||||
public void register(Listener<Result> l) {
|
public void register(Listener l) {
|
||||||
if (listeners == null) {
|
if (listeners == null) {
|
||||||
listeners = new LinkedList<>();
|
listeners = new LinkedList<>();
|
||||||
}
|
}
|
||||||
listeners.add(new WeakReference<>(l));
|
listeners.add(new WeakReference<>(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unRegister() {
|
public void unregister() {
|
||||||
listeners = null;
|
listeners = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unRegister(Listener<Result> l) {
|
public void unregister(Listener l) {
|
||||||
for (Iterator<WeakReference<Listener<Result>>> i = listeners.iterator(); i.hasNext();) {
|
for (Iterator<WeakReference<Listener>> i = listeners.iterator(); i.hasNext();) {
|
||||||
WeakReference<Listener<Result>> listener = i.next();
|
WeakReference<Listener> listener = i.next();
|
||||||
if (listener.get() == null || listener.get() == l) {
|
if (listener.get() == null || listener.get() == l) {
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
@ -34,25 +31,38 @@ public class CallbackEvent<Result> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void trigger() {
|
public void trigger() {
|
||||||
trigger(null);
|
trigger(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trigger(Result r) {
|
public void trigger(boolean b) {
|
||||||
result = r;
|
isTriggered = b;
|
||||||
isTriggered = true;
|
|
||||||
if (listeners != null) {
|
if (listeners != null) {
|
||||||
for (WeakReference<Listener<Result>> listener : listeners) {
|
for (WeakReference<Listener> listener : listeners) {
|
||||||
if (listener.get() != null)
|
if (listener.get() != null)
|
||||||
listener.get().onTrigger(this);
|
listener.get().onTrigger(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result getResult() {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface Listener<R> {
|
public interface Listener {
|
||||||
void onTrigger(CallbackEvent<R> event);
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,14 +11,12 @@ import android.content.IntentFilter;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.OpenableColumns;
|
import android.provider.OpenableColumns;
|
||||||
import android.support.annotation.IdRes;
|
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
@ -26,7 +24,6 @@ import android.support.v4.app.FragmentActivity;
|
|||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.support.v7.app.NotificationCompat;
|
import android.support.v7.app.NotificationCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.DisplayMetrics;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.topjohnwu.magisk.MagiskManager;
|
import com.topjohnwu.magisk.MagiskManager;
|
||||||
@ -40,7 +37,6 @@ import com.topjohnwu.magisk.receivers.ManagerUpdate;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user