Remove boilderplate

This commit is contained in:
topjohnwu 2018-08-01 14:30:59 +08:00
parent 8574a14ed2
commit a2544768a0
19 changed files with 20 additions and 49 deletions

View File

@ -45,8 +45,6 @@ public class MagiskFragment extends Fragment
implements SwipeRefreshLayout.OnRefreshListener, ExpandableView, Topic.Subscriber {
private Container expandableContainer = new Container();
private MagiskManager mm;
private Unbinder unbinder;
private static boolean shownDialog = false;
@ -140,8 +138,6 @@ public class MagiskFragment extends Fragment
unbinder = ButterKnife.bind(this, v);
requireActivity().setTitle(R.string.magisk);
mm = getApplication();
expandableContainer.expandLayout = expandLayout;
setupExpandable();

View File

@ -42,9 +42,6 @@ public class MainActivity extends Activity
@Override
protected void onCreate(final Bundle savedInstanceState) {
MagiskManager mm = getMagiskManager();
if (!mm.hasInit) {
Intent intent = new Intent(this, SplashActivity.class);
String section = getIntent().getStringExtra(Const.Key.OPEN_SECTION);
@ -121,7 +118,6 @@ public class MainActivity extends Activity
}
public void checkHideSection() {
MagiskManager mm = getMagiskManager();
Menu menu = navigationView.getMenu();
menu.findItem(R.id.magiskhide).setVisible(
Shell.rootAccess() && Data.magiskVersionCode >= Const.MAGISK_VER.UNIFIED

View File

@ -130,7 +130,7 @@ public class ModulesFragment extends Fragment implements Topic.Subscriber {
private void updateUI() {
listModules.clear();
listModules.addAll(getApplication().moduleMap.values());
listModules.addAll(mm.moduleMap.values());
if (listModules.size() == 0) {
emptyRv.setVisibility(View.VISIBLE);
recyclerView.setVisibility(View.GONE);

View File

@ -26,7 +26,6 @@ import butterknife.Unbinder;
public class ReposFragment extends Fragment implements Topic.Subscriber {
private Unbinder unbinder;
private MagiskManager mm;
@BindView(R.id.recyclerView) RecyclerView recyclerView;
@BindView(R.id.empty_rv) TextView emptyRv;
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
@ -44,7 +43,6 @@ public class ReposFragment extends Fragment implements Topic.Subscriber {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_repos, container, false);
unbinder = ButterKnife.bind(this, view);
mm = getApplication();
mSwipeRefreshLayout.setRefreshing(true);

View File

@ -97,7 +97,7 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.app_settings, rootKey);
mm = Utils.getMagiskManager(getActivity());
mm = Data.MM();
prefs = mm.prefs;
prefScreen = getPreferenceScreen();
@ -126,10 +126,10 @@ public class SettingsActivity extends Activity implements Topic.Subscriber {
updateChannel.setOnPreferenceChangeListener((pref, o) -> {
Data.updateChannel = Integer.parseInt((String) o);
if (Data.updateChannel == Const.Value.CUSTOM_CHANNEL) {
View v = LayoutInflater.from(getActivity()).inflate(R.layout.custom_channel_dialog, null);
View v = LayoutInflater.from(requireActivity()).inflate(R.layout.custom_channel_dialog, null);
EditText url = v.findViewById(R.id.custom_url);
url.setText(mm.prefs.getString(Const.Key.CUSTOM_CHANNEL, ""));
new AlertDialog.Builder(getActivity())
new AlertDialog.Builder(requireActivity())
.setTitle(R.string.settings_update_custom)
.setView(v)
.setPositiveButton(R.string.ok, (d, i) ->

View File

@ -23,7 +23,6 @@ public class SplashActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MagiskManager mm = getMagiskManager();
// Force create a shell if not created yet
boolean root = Shell.rootAccess();

View File

@ -24,7 +24,6 @@ public class SuLogFragment extends Fragment {
@BindView(R.id.recyclerView) RecyclerView recyclerView;
private Unbinder unbinder;
private MagiskManager mm;
private SuLogAdapter adapter;
@Override
@ -45,7 +44,6 @@ public class SuLogFragment extends Fragment {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_su_log, container, false);
unbinder = ButterKnife.bind(this, v);
mm = getApplication();
adapter = new SuLogAdapter(mm.mDB);
recyclerView.setAdapter(adapter);

View File

@ -23,7 +23,6 @@ public class SuperuserFragment extends Fragment {
private Unbinder unbinder;
private PackageManager pm;
private MagiskManager mm;
@BindView(R.id.recyclerView) RecyclerView recyclerView;
@BindView(R.id.empty_rv) TextView emptyRv;
@ -34,14 +33,13 @@ public class SuperuserFragment extends Fragment {
unbinder = ButterKnife.bind(this, view);
pm = getActivity().getPackageManager();
mm = getApplication();
return view;
}
@Override
public void onStart() {
super.onStart();
getActivity().setTitle(getString(R.string.superuser));
requireActivity().setTitle(getString(R.string.superuser));
}
@Override

View File

@ -19,6 +19,7 @@ public abstract class FlavorActivity extends AppCompatActivity implements Topic.
private ActivityResultListener activityResultListener;
static int[] EMPTY_INT_ARRAY = new int[0];
public MagiskManager mm;
@Override
protected void attachBaseContext(Context base) {
@ -26,6 +27,7 @@ public abstract class FlavorActivity extends AppCompatActivity implements Topic.
Configuration config = base.getResources().getConfiguration();
config.setLocale(LocaleManager.locale);
applyOverrideConfiguration(config);
mm = Data.MM();
}
@Override
@ -38,10 +40,6 @@ public abstract class FlavorActivity extends AppCompatActivity implements Topic.
return -1;
}
public MagiskManager getMagiskManager() {
return (MagiskManager) super.getApplication();
}
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

View File

@ -2,14 +2,16 @@ package com.topjohnwu.magisk.components;
import android.content.Intent;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Topic;
import com.topjohnwu.magisk.utils.Utils;
public class Fragment extends android.support.v4.app.Fragment implements Topic.AutoSubscriber {
public MagiskManager getApplication() {
return Utils.getMagiskManager(getActivity());
public MagiskManager mm;
public Fragment() {
mm = Data.MM();
}
@Override

View File

@ -10,7 +10,6 @@ import android.widget.Toast;
import com.topjohnwu.magisk.Const;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.FlashActivity;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.receivers.DownloadReceiver;
import com.topjohnwu.magisk.utils.Download;
@ -22,7 +21,6 @@ class InstallMethodDialog extends AlertDialog.Builder {
InstallMethodDialog(Activity activity, List<String> options, String filename) {
super(activity);
MagiskManager mm = Utils.getMagiskManager(activity);
setTitle(R.string.select_method);
setItems(options.toArray(new String [0]), (dialog, idx) -> {
Intent intent;

View File

@ -18,7 +18,7 @@ import java.util.List;
public class MagiskInstallDialog extends CustomAlertDialog {
public MagiskInstallDialog(Activity activity) {
super(activity);
MagiskManager mm = Utils.getMagiskManager(activity);
MagiskManager mm = Data.MM();
String filename = Utils.fmt("Magisk-v%s(%d).zip",
Data.remoteMagiskVersionString, Data.remoteMagiskVersionCode);
setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.magisk)));

View File

@ -17,7 +17,7 @@ public class ManagerInstallDialog extends CustomAlertDialog {
public ManagerInstallDialog(@NonNull Activity activity) {
super(activity);
MagiskManager mm = Utils.getMagiskManager(activity);
MagiskManager mm = Data.MM();
String filename = Utils.fmt("MagiskManager-v%s(%d).apk",
Data.remoteManagerVersionString, Data.remoteManagerVersionCode);
setTitle(mm.getString(R.string.repo_install_title, mm.getString(R.string.app_name)));

View File

@ -15,13 +15,12 @@ import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.RestoreImages;
import com.topjohnwu.magisk.receivers.DownloadReceiver;
import com.topjohnwu.magisk.utils.Download;
import com.topjohnwu.magisk.utils.Utils;
public class UninstallDialog extends CustomAlertDialog {
public UninstallDialog(@NonNull Activity activity) {
super(activity);
MagiskManager mm = Utils.getMagiskManager(activity);
MagiskManager mm = Data.MM();
setTitle(R.string.uninstall_magisk_title);
setMessage(R.string.uninstall_magisk_msg);
setNeutralButton(R.string.restore_img, (d, i) -> new RestoreImages(activity).exec());

View File

@ -9,7 +9,6 @@ import com.topjohnwu.magisk.Const;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.container.Repo;
import com.topjohnwu.magisk.utils.Utils;
import java.util.HashSet;
import java.util.Set;
@ -24,7 +23,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
public RepoDatabaseHelper(Context context) {
super(context, "repo.db", null, DATABASE_VER);
mm = Utils.getMagiskManager(context);
mm = Data.MM();
mDb = getWritableDatabase();
// Remove outdated repos

View File

@ -5,14 +5,14 @@ import android.content.Context;
import android.content.Intent;
import com.topjohnwu.magisk.Const;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell;
public class PackageReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
MagiskManager mm = Utils.getMagiskManager(context);
MagiskManager mm = Data.MM();
String pkg = intent.getData().getEncodedSchemeSpecificPart();

View File

@ -14,7 +14,6 @@ import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.SplashActivity;
import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.superuser.Shell;
import java.util.ArrayList;
@ -23,7 +22,7 @@ public class ShortcutReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
MagiskManager mm = Utils.getMagiskManager(context);
MagiskManager mm = Data.MM();
ShortcutManager manager = context.getSystemService(ShortcutManager.class);
manager.setDynamicShortcuts(getShortCuts(mm));
}

View File

@ -21,13 +21,11 @@ import android.widget.TextView;
import com.topjohnwu.magisk.Const;
import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.asyncs.ParallelTask;
import com.topjohnwu.magisk.components.Activity;
import com.topjohnwu.magisk.container.Policy;
import com.topjohnwu.magisk.utils.FingerprintHelper;
import com.topjohnwu.magisk.utils.Utils;
import java.io.DataInputStream;
import java.io.IOException;
@ -50,7 +48,6 @@ public class RequestActivity extends Activity {
private String socketPath;
private LocalSocket socket;
private PackageManager pm;
private MagiskManager mm;
private boolean hasTimeout;
private Policy policy;
@ -68,7 +65,6 @@ public class RequestActivity extends Activity {
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
pm = getPackageManager();
mm = Utils.getMagiskManager(this);
mm.mDB.clearOutdated();
Intent intent = getIntent();

View File

@ -27,10 +27,6 @@ public class Utils {
return getPrefsInt(prefs, key, 0);
}
public static MagiskManager getMagiskManager(Context context) {
return (MagiskManager) context.getApplicationContext();
}
public static String getNameFromUri(Context context, Uri uri) {
String name = null;
try (Cursor c = context.getContentResolver().query(uri, null, null, null, null)) {
@ -50,8 +46,7 @@ public class Utils {
}
public static int dpInPx(int dp) {
Context context = Data.MM();
float scale = context.getResources().getDisplayMetrics().density;
float scale = Data.MM().getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5);
}