Seperate Configs

This commit is contained in:
topjohnwu 2017-01-25 13:16:50 +08:00
parent ad16a6fc1b
commit bcc695234c
12 changed files with 40 additions and 30 deletions

View File

@ -46,7 +46,7 @@ public class AboutActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", ""); String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "");
Logger.dev("AboutActivity: Theme is " + theme); Logger.dev("AboutActivity: Theme is " + theme);
if (Utils.isDarkTheme) { if (Global.Configs.isDarkTheme) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
} }
setContentView(R.layout.activity_about); setContentView(R.layout.activity_about);

View File

@ -1,5 +1,10 @@
package com.topjohnwu.magisk; 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.module.Repo;
import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.CallbackHandler;
import com.topjohnwu.magisk.utils.ValueSortedMap; import com.topjohnwu.magisk.utils.ValueSortedMap;
@ -21,7 +26,7 @@ public class Global {
} }
public static class Data { public static class Data {
public static ValueSortedMap<String, Repo> repoMap = new ValueSortedMap<>(); public static ValueSortedMap<String, Repo> repoMap = new ValueSortedMap<>();
public static ValueSortedMap<String, com.topjohnwu.magisk.module.Module> moduleMap = new ValueSortedMap<>(); public static ValueSortedMap<String, Module> moduleMap = new ValueSortedMap<>();
public static List<String> blockList; public static List<String> blockList;
} }
public static class Events { 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 updateCheckDone = new CallbackHandler.Event();
public static final CallbackHandler.Event safetyNetDone = 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);
}
}
} }

View File

@ -24,7 +24,6 @@ import android.view.View;
import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.CallbackHandler;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.Utils;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
@ -48,7 +47,7 @@ public class MainActivity extends AppCompatActivity
prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
if (Utils.isDarkTheme) { if (Global.Configs.isDarkTheme) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
} }
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);

View File

@ -16,10 +16,10 @@ import android.widget.TextView;
import com.github.clans.fab.FloatingActionButton; import com.github.clans.fab.FloatingActionButton;
import com.topjohnwu.magisk.adapters.ModulesAdapter; import com.topjohnwu.magisk.adapters.ModulesAdapter;
import com.topjohnwu.magisk.module.Module; import com.topjohnwu.magisk.module.Module;
import com.topjohnwu.magisk.module.ModuleHelper;
import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.CallbackHandler;
import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.module.ModuleHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -16,11 +16,11 @@ import android.widget.TextView;
import com.topjohnwu.magisk.adapters.ReposAdapter; import com.topjohnwu.magisk.adapters.ReposAdapter;
import com.topjohnwu.magisk.adapters.SimpleSectionedRecyclerViewAdapter; import com.topjohnwu.magisk.adapters.SimpleSectionedRecyclerViewAdapter;
import com.topjohnwu.magisk.module.ModuleHelper;
import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.module.Repo;
import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.CallbackHandler;
import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.module.ModuleHelper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -32,7 +32,7 @@ public class SettingsActivity extends AppCompatActivity {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", ""); String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", "");
Logger.dev("AboutActivity: Theme is " + theme); Logger.dev("AboutActivity: Theme is " + theme);
if (Utils.isDarkTheme) { if (Global.Configs.isDarkTheme) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
} }
@ -101,7 +101,7 @@ public class SettingsActivity extends AppCompatActivity {
return true; return true;
}); });
if (Utils.isDarkTheme) { if (Global.Configs.isDarkTheme) {
themePreference.setSummary(R.string.theme_dark); themePreference.setSummary(R.string.theme_dark);
} else { } else {
themePreference.setSummary(R.string.theme_default); themePreference.setSummary(R.string.theme_default);
@ -143,8 +143,8 @@ public class SettingsActivity extends AppCompatActivity {
switch (key) { switch (key) {
case "theme": case "theme":
String theme = prefs.getString("theme", getString(R.string.theme_default_value)); String theme = prefs.getString("theme", getString(R.string.theme_default_value));
if (Utils.isDarkTheme != theme.equalsIgnoreCase(getString(R.string.theme_dark_value))) { if (Global.Configs.isDarkTheme != theme.equalsIgnoreCase(getString(R.string.theme_dark_value))) {
Utils.isDarkTheme = !Utils.isDarkTheme; Global.Configs.isDarkTheme = !Global.Configs.isDarkTheme;
getActivity().recreate(); getActivity().recreate();
Global.Events.reloadMainActivity.trigger(); Global.Events.reloadMainActivity.trigger();
} }
@ -200,10 +200,10 @@ public class SettingsActivity extends AppCompatActivity {
}.exec(); }.exec();
break; break;
case "developer_logging": case "developer_logging":
Logger.devLog = prefs.getBoolean("developer_logging", false); Global.Configs.devLogging = prefs.getBoolean("developer_logging", false);
break; break;
case "shell_logging": case "shell_logging":
Logger.logShell = prefs.getBoolean("shell_logging", false); Global.Configs.shellLogging = prefs.getBoolean("shell_logging", false);
break; break;
} }

View File

@ -7,7 +7,6 @@ import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
public class SplashActivity extends AppCompatActivity { public class SplashActivity extends AppCompatActivity {
@ -16,18 +15,14 @@ public class SplashActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(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)); Global.Configs.init(getApplicationContext());
Utils.isDarkTheme = theme.equalsIgnoreCase(getString(R.string.theme_dark_value));
if (Utils.isDarkTheme) { if (Global.Configs.isDarkTheme) {
setTheme(R.style.AppTheme_dh); setTheme(R.style.AppTheme_dh);
} }
Logger.devLog = prefs.getBoolean("developer_logging", false);
Logger.logShell = prefs.getBoolean("shell_logging", false);
// Initialize prefs // Initialize prefs
prefs.edit() prefs.edit()
.putBoolean("magiskhide", Utils.itemExist(false, "/magisk/.core/magiskhide/enable")) .putBoolean("magiskhide", Utils.itemExist(false, "/magisk/.core/magiskhide/enable"))

View File

@ -5,8 +5,8 @@ import android.content.SharedPreferences;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Logger;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
import com.topjohnwu.magisk.utils.ValueSortedMap; import com.topjohnwu.magisk.utils.ValueSortedMap;

View File

@ -2,8 +2,8 @@ package com.topjohnwu.magisk.receivers;
import android.net.Uri; import android.net.Uri;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.Global; import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.Async;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import com.topjohnwu.magisk.utils.ZipUtils; import com.topjohnwu.magisk.utils.ZipUtils;

View File

@ -3,7 +3,6 @@ package com.topjohnwu.magisk.superuser;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle;
import android.os.Process; import android.os.Process;
import android.widget.Toast; import android.widget.Toast;

View File

@ -2,20 +2,20 @@ package com.topjohnwu.magisk.utils;
import android.util.Log; import android.util.Log;
import com.topjohnwu.magisk.Global;
public class Logger { public class Logger {
public static final String TAG = "Magisk"; public static final String TAG = "Magisk";
public static final String DEV_TAG = "Magisk: DEV"; public static final String DEV_TAG = "Magisk: DEV";
public static final String DEBUG_TAG = "Magisk: DEBUG"; public static final String DEBUG_TAG = "Magisk: DEBUG";
public static boolean logShell, devLog;
public static void debug(String msg) { public static void debug(String msg) {
Log.d(DEBUG_TAG, msg); Log.d(DEBUG_TAG, msg);
} }
public static void dev(String msg, Object... args) { public static void dev(String msg, Object... args) {
if (devLog) { if (Global.Configs.devLogging) {
if (args.length == 1 && args[0] instanceof Throwable) { if (args.length == 1 && args[0] instanceof Throwable) {
Log.d(DEV_TAG, msg, (Throwable) args[0]); Log.d(DEV_TAG, msg, (Throwable) args[0]);
} else { } else {
@ -25,13 +25,13 @@ public class Logger {
} }
public static void dev(String msg) { public static void dev(String msg) {
if (devLog) { if (Global.Configs.devLogging) {
Log.d(DEV_TAG, msg); Log.d(DEV_TAG, msg);
} }
} }
public static void shell(boolean root, String msg) { public static void shell(boolean root, String msg) {
if (logShell) { if (Global.Configs.shellLogging) {
Log.d(root ? "SU" : "SH", msg); Log.d(root ? "SU" : "SH", msg);
} }
} }

View File

@ -12,6 +12,7 @@ import android.support.v4.app.ActivityCompat;
import android.text.TextUtils; import android.text.TextUtils;
import android.widget.Toast; import android.widget.Toast;
import com.topjohnwu.magisk.Global;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.receivers.DownloadReceiver; import com.topjohnwu.magisk.receivers.DownloadReceiver;
@ -23,7 +24,6 @@ import java.util.List;
public class Utils { public class Utils {
public static boolean isDownloading = false; public static boolean isDownloading = false;
public static boolean isDarkTheme;
public static boolean itemExist(String path) { public static boolean itemExist(String path) {
return itemExist(true, path); return itemExist(true, path);
@ -125,7 +125,7 @@ public class Utils {
} }
public static AlertDialog.Builder getAlertDialogBuilder(Context context) { public static AlertDialog.Builder getAlertDialogBuilder(Context context) {
if (isDarkTheme) { if (Global.Configs.isDarkTheme) {
return new AlertDialog.Builder(context, R.style.AlertDialog_dh); return new AlertDialog.Builder(context, R.style.AlertDialog_dh);
} else { } else {
return new AlertDialog.Builder(context); return new AlertDialog.Builder(context);