From bcc695234ccee25477ecbbc724eb75f399b4cf6d Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Wed, 25 Jan 2017 13:16:50 +0800 Subject: [PATCH] Seperate Configs --- .../com/topjohnwu/magisk/AboutActivity.java | 2 +- .../java/com/topjohnwu/magisk/Global.java | 19 ++++++++++++++++++- .../com/topjohnwu/magisk/MainActivity.java | 3 +-- .../com/topjohnwu/magisk/ModulesFragment.java | 2 +- .../com/topjohnwu/magisk/ReposFragment.java | 2 +- .../topjohnwu/magisk/SettingsActivity.java | 12 ++++++------ .../com/topjohnwu/magisk/SplashActivity.java | 11 +++-------- .../topjohnwu/magisk/module/ModuleHelper.java | 2 +- .../magisk/receivers/MagiskDlReceiver.java | 2 +- .../magisk/superuser/SuReceiver.java | 1 - .../com/topjohnwu/magisk/utils/Logger.java | 10 +++++----- .../com/topjohnwu/magisk/utils/Utils.java | 4 ++-- 12 files changed, 40 insertions(+), 30 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java b/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java index f287eeb91..6b0ff4492 100644 --- a/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java @@ -46,7 +46,7 @@ public class AboutActivity extends AppCompatActivity { super.onCreate(savedInstanceState); String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", ""); Logger.dev("AboutActivity: Theme is " + theme); - if (Utils.isDarkTheme) { + if (Global.Configs.isDarkTheme) { setTheme(R.style.AppTheme_dh); } setContentView(R.layout.activity_about); diff --git a/app/src/main/java/com/topjohnwu/magisk/Global.java b/app/src/main/java/com/topjohnwu/magisk/Global.java index f42ef39a9..63257f0e0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/Global.java +++ b/app/src/main/java/com/topjohnwu/magisk/Global.java @@ -1,5 +1,10 @@ package com.topjohnwu.magisk; +import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; + +import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.ValueSortedMap; @@ -21,7 +26,7 @@ public class Global { } public static class Data { public static ValueSortedMap repoMap = new ValueSortedMap<>(); - public static ValueSortedMap moduleMap = new ValueSortedMap<>(); + public static ValueSortedMap moduleMap = new ValueSortedMap<>(); public static List blockList; } public static class Events { @@ -33,5 +38,17 @@ public class Global { public static final CallbackHandler.Event updateCheckDone = new CallbackHandler.Event(); public static final CallbackHandler.Event safetyNetDone = new CallbackHandler.Event(); } + public static class Configs { + public static boolean isDarkTheme; + public static boolean shellLogging; + public static boolean devLogging; + + public static void init(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + isDarkTheme = prefs.getString("theme", context.getString(R.string.theme_default_value)).equalsIgnoreCase(context.getString(R.string.theme_dark_value)); + devLogging = prefs.getBoolean("developer_logging", false); + shellLogging = prefs.getBoolean("shell_logging", false); + } + } } diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java index 3ce7e49db..1e1bc4fa8 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -24,7 +24,6 @@ import android.view.View; import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.Shell; -import com.topjohnwu.magisk.utils.Utils; import butterknife.BindView; import butterknife.ButterKnife; @@ -48,7 +47,7 @@ public class MainActivity extends AppCompatActivity prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - if (Utils.isDarkTheme) { + if (Global.Configs.isDarkTheme) { setTheme(R.style.AppTheme_dh); } super.onCreate(savedInstanceState); diff --git a/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java index 3439cdfec..91d448e82 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ModulesFragment.java @@ -16,10 +16,10 @@ import android.widget.TextView; import com.github.clans.fab.FloatingActionButton; import com.topjohnwu.magisk.adapters.ModulesAdapter; import com.topjohnwu.magisk.module.Module; +import com.topjohnwu.magisk.module.ModuleHelper; import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.Logger; -import com.topjohnwu.magisk.module.ModuleHelper; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java index d22fa91f7..e2df10522 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ReposFragment.java @@ -16,11 +16,11 @@ import android.widget.TextView; import com.topjohnwu.magisk.adapters.ReposAdapter; import com.topjohnwu.magisk.adapters.SimpleSectionedRecyclerViewAdapter; +import com.topjohnwu.magisk.module.ModuleHelper; import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.Logger; -import com.topjohnwu.magisk.module.ModuleHelper; import java.util.ArrayList; import java.util.List; diff --git a/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java b/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java index 0de2640dc..10101a026 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java @@ -32,7 +32,7 @@ public class SettingsActivity extends AppCompatActivity { super.onCreate(savedInstanceState); String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", ""); Logger.dev("AboutActivity: Theme is " + theme); - if (Utils.isDarkTheme) { + if (Global.Configs.isDarkTheme) { setTheme(R.style.AppTheme_dh); } @@ -101,7 +101,7 @@ public class SettingsActivity extends AppCompatActivity { return true; }); - if (Utils.isDarkTheme) { + if (Global.Configs.isDarkTheme) { themePreference.setSummary(R.string.theme_dark); } else { themePreference.setSummary(R.string.theme_default); @@ -143,8 +143,8 @@ public class SettingsActivity extends AppCompatActivity { switch (key) { case "theme": String theme = prefs.getString("theme", getString(R.string.theme_default_value)); - if (Utils.isDarkTheme != theme.equalsIgnoreCase(getString(R.string.theme_dark_value))) { - Utils.isDarkTheme = !Utils.isDarkTheme; + if (Global.Configs.isDarkTheme != theme.equalsIgnoreCase(getString(R.string.theme_dark_value))) { + Global.Configs.isDarkTheme = !Global.Configs.isDarkTheme; getActivity().recreate(); Global.Events.reloadMainActivity.trigger(); } @@ -200,10 +200,10 @@ public class SettingsActivity extends AppCompatActivity { }.exec(); break; case "developer_logging": - Logger.devLog = prefs.getBoolean("developer_logging", false); + Global.Configs.devLogging = prefs.getBoolean("developer_logging", false); break; case "shell_logging": - Logger.logShell = prefs.getBoolean("shell_logging", false); + Global.Configs.shellLogging = prefs.getBoolean("shell_logging", false); break; } diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index 97d1aa827..625f41082 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -7,7 +7,6 @@ import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; import com.topjohnwu.magisk.utils.Async; -import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Utils; public class SplashActivity extends AppCompatActivity { @@ -16,18 +15,14 @@ public class SplashActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication()); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - String theme = prefs.getString("theme", getString(R.string.theme_default_value)); - Utils.isDarkTheme = theme.equalsIgnoreCase(getString(R.string.theme_dark_value)); + Global.Configs.init(getApplicationContext()); - if (Utils.isDarkTheme) { + if (Global.Configs.isDarkTheme) { setTheme(R.style.AppTheme_dh); } - Logger.devLog = prefs.getBoolean("developer_logging", false); - Logger.logShell = prefs.getBoolean("shell_logging", false); - // Initialize prefs prefs.edit() .putBoolean("magiskhide", Utils.itemExist(false, "/magisk/.core/magiskhide/enable")) diff --git a/app/src/main/java/com/topjohnwu/magisk/module/ModuleHelper.java b/app/src/main/java/com/topjohnwu/magisk/module/ModuleHelper.java index 827e2029d..1ef42795c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/module/ModuleHelper.java +++ b/app/src/main/java/com/topjohnwu/magisk/module/ModuleHelper.java @@ -5,8 +5,8 @@ import android.content.SharedPreferences; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.Global; +import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.ValueSortedMap; diff --git a/app/src/main/java/com/topjohnwu/magisk/receivers/MagiskDlReceiver.java b/app/src/main/java/com/topjohnwu/magisk/receivers/MagiskDlReceiver.java index 21275b462..962d5d432 100644 --- a/app/src/main/java/com/topjohnwu/magisk/receivers/MagiskDlReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/receivers/MagiskDlReceiver.java @@ -2,8 +2,8 @@ package com.topjohnwu.magisk.receivers; import android.net.Uri; -import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.Global; +import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.ZipUtils; diff --git a/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java b/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java index c0fced9fd..c72de958b 100644 --- a/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java +++ b/app/src/main/java/com/topjohnwu/magisk/superuser/SuReceiver.java @@ -3,7 +3,6 @@ package com.topjohnwu.magisk.superuser; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.os.Bundle; import android.os.Process; import android.widget.Toast; diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java b/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java index 14f51ac6f..1a36f6755 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Logger.java @@ -2,20 +2,20 @@ package com.topjohnwu.magisk.utils; import android.util.Log; +import com.topjohnwu.magisk.Global; + public class Logger { public static final String TAG = "Magisk"; public static final String DEV_TAG = "Magisk: DEV"; public static final String DEBUG_TAG = "Magisk: DEBUG"; - public static boolean logShell, devLog; - public static void debug(String msg) { Log.d(DEBUG_TAG, msg); } public static void dev(String msg, Object... args) { - if (devLog) { + if (Global.Configs.devLogging) { if (args.length == 1 && args[0] instanceof Throwable) { Log.d(DEV_TAG, msg, (Throwable) args[0]); } else { @@ -25,13 +25,13 @@ public class Logger { } public static void dev(String msg) { - if (devLog) { + if (Global.Configs.devLogging) { Log.d(DEV_TAG, msg); } } public static void shell(boolean root, String msg) { - if (logShell) { + if (Global.Configs.shellLogging) { Log.d(root ? "SU" : "SH", msg); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index dce0ad31c..d6fe74ccd 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -12,6 +12,7 @@ import android.support.v4.app.ActivityCompat; import android.text.TextUtils; import android.widget.Toast; +import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.receivers.DownloadReceiver; @@ -23,7 +24,6 @@ import java.util.List; public class Utils { public static boolean isDownloading = false; - public static boolean isDarkTheme; public static boolean itemExist(String path) { return itemExist(true, path); @@ -125,7 +125,7 @@ public class Utils { } public static AlertDialog.Builder getAlertDialogBuilder(Context context) { - if (isDarkTheme) { + if (Global.Configs.isDarkTheme) { return new AlertDialog.Builder(context, R.style.AlertDialog_dh); } else { return new AlertDialog.Builder(context);