Remove redundant codes

This commit is contained in:
NekoInverter 2021-01-26 16:56:28 +08:00
parent d9b93c0c49
commit 0df7cbca3e
No known key found for this signature in database
GPG Key ID: 280D6CCCF95715F9
6 changed files with 23 additions and 23 deletions

View File

@ -44,11 +44,11 @@ public class BaseActivity extends AppCompatActivity {
private static final String THEME_DEFAULT = "DEFAULT"; private static final String THEME_DEFAULT = "DEFAULT";
private static final String THEME_BLACK = "BLACK"; private static final String THEME_BLACK = "BLACK";
protected static SharedPreferences preferences;
private String theme; private String theme;
protected SharedPreferences preferences;
public static boolean isBlackNightTheme() { public static boolean isBlackNightTheme() {
return App.getPreferences().getBoolean("black_dark_theme", false) || App.getPreferences().getBoolean("md2", false); return preferences.getBoolean("black_dark_theme", false) || preferences.getBoolean("md2", false);
} }
public static String getTheme(Context context) { public static String getTheme(Context context) {
@ -89,19 +89,19 @@ public class BaseActivity extends AppCompatActivity {
@StyleRes @StyleRes
private int getCustomTheme() { private int getCustomTheme() {
String baseThemeName = App.getPreferences().getBoolean("colorized_action_bar", false) && !App.getPreferences().getBoolean("md2", false) ? String baseThemeName = preferences.getBoolean("colorized_action_bar", false) && !preferences.getBoolean("md2", false) ?
"ThemeOverlay.ActionBarPrimaryColor" : "ThemeOverlay"; "ThemeOverlay.ActionBarPrimaryColor" : "ThemeOverlay";
String customThemeName; String customThemeName;
String primaryColorEntryName = "colorPrimary"; String primaryColorEntryName = "colorPrimary";
for (CustomThemeColor color : CustomThemeColors.Primary.values()) { for (CustomThemeColor color : CustomThemeColors.Primary.values()) {
if (App.getPreferences().getInt("primary_color", ContextCompat.getColor(this, R.color.colorPrimary)) if (preferences.getInt("primary_color", ContextCompat.getColor(this, R.color.colorPrimary))
== ContextCompat.getColor(this, color.getResourceId())) { == ContextCompat.getColor(this, color.getResourceId())) {
primaryColorEntryName = color.getResourceEntryName(); primaryColorEntryName = color.getResourceEntryName();
} }
} }
String accentColorEntryName = "colorAccent"; String accentColorEntryName = "colorAccent";
for (CustomThemeColor color : CustomThemeColors.Accent.values()) { for (CustomThemeColor color : CustomThemeColors.Accent.values()) {
if (App.getPreferences().getInt("accent_color", ContextCompat.getColor(this, R.color.colorAccent)) if (preferences.getInt("accent_color", ContextCompat.getColor(this, R.color.colorAccent))
== ContextCompat.getColor(this, color.getResourceId())) { == ContextCompat.getColor(this, color.getResourceId())) {
accentColorEntryName = color.getResourceEntryName(); accentColorEntryName = color.getResourceEntryName();
} }
@ -118,8 +118,8 @@ public class BaseActivity extends AppCompatActivity {
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
preferences = App.getPreferences(); preferences = App.getPreferences();
AppCompatDelegate.setDefaultNightMode(App.getPreferences().getInt("theme", -1)); AppCompatDelegate.setDefaultNightMode(preferences.getInt("theme", -1));
theme = getTheme(this) + getCustomTheme() + App.getPreferences().getBoolean("md2", false); theme = getTheme(this) + getCustomTheme() + preferences.getBoolean("md2", false);
} }
public int getThemedColor(int id) { public int getThemedColor(int id) {
@ -133,13 +133,13 @@ public class BaseActivity extends AppCompatActivity {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (!(this instanceof MainActivity)) { if (!(this instanceof MainActivity)) {
if (App.getPreferences().getBoolean("transparent_status_bar", false)) { if (preferences.getBoolean("transparent_status_bar", false)) {
getWindow().setStatusBarColor(getThemedColor(R.attr.colorActionBar)); getWindow().setStatusBarColor(getThemedColor(R.attr.colorActionBar));
} else { } else {
getWindow().setStatusBarColor(getThemedColor(R.attr.colorPrimaryDark)); getWindow().setStatusBarColor(getThemedColor(R.attr.colorPrimaryDark));
} }
} }
if (!Objects.equals(theme, getTheme(this) + getCustomTheme() + App.getPreferences().getBoolean("md2", false))) { if (!Objects.equals(theme, getTheme(this) + getCustomTheme() + preferences.getBoolean("md2", false))) {
recreate(); recreate();
} }
} }
@ -158,7 +158,7 @@ public class BaseActivity extends AppCompatActivity {
theme.applyStyle(resid, false); theme.applyStyle(resid, false);
} }
theme.applyStyle(getCustomTheme(), true); theme.applyStyle(getCustomTheme(), true);
if (App.getPreferences().getBoolean("md2", false) && !(this instanceof MainActivity)) { if (preferences.getBoolean("md2", false) && !(this instanceof MainActivity)) {
theme.applyStyle(R.style.ThemeOverlay_Md2, true); theme.applyStyle(R.style.ThemeOverlay_Md2, true);
} }
if (this instanceof MainActivity) { if (this instanceof MainActivity) {

View File

@ -14,7 +14,6 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.DividerItemDecoration;
import org.meowcat.edxposed.manager.App;
import org.meowcat.edxposed.manager.R; import org.meowcat.edxposed.manager.R;
import org.meowcat.edxposed.manager.adapters.AppAdapter; import org.meowcat.edxposed.manager.adapters.AppAdapter;
import org.meowcat.edxposed.manager.adapters.AppHelper; import org.meowcat.edxposed.manager.adapters.AppHelper;
@ -56,7 +55,7 @@ public class BlackListActivity extends BaseActivity implements AppAdapter.Callba
binding.recyclerView.setAdapter(appAdapter); binding.recyclerView.setAdapter(appAdapter);
binding.recyclerView.setLayoutManager(new LinearLayoutManagerFix(this)); binding.recyclerView.setLayoutManager(new LinearLayoutManagerFix(this));
FastScrollerBuilder fastScrollerBuilder = new FastScrollerBuilder(binding.recyclerView); FastScrollerBuilder fastScrollerBuilder = new FastScrollerBuilder(binding.recyclerView);
if (!App.getPreferences().getBoolean("md2", false)) { if (!preferences.getBoolean("md2", false)) {
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this,
DividerItemDecoration.VERTICAL); DividerItemDecoration.VERTICAL);
binding.recyclerView.addItemDecoration(dividerItemDecoration); binding.recyclerView.addItemDecoration(dividerItemDecoration);

View File

@ -52,7 +52,7 @@ public class EdDownloadActivity extends BaseActivity {
binding.tabLayout.setupWithViewPager(binding.pager); binding.tabLayout.setupWithViewPager(binding.pager);
//new JSONParser().execute(); //new JSONParser().execute();
if (!App.getPreferences().getBoolean("hide_install_warning", false)) { if (!preferences.getBoolean("hide_install_warning", false)) {
DialogInstallWarningBinding binding = DialogInstallWarningBinding.inflate(getLayoutInflater()); DialogInstallWarningBinding binding = DialogInstallWarningBinding.inflate(getLayoutInflater());
new MaterialAlertDialogBuilder(this) new MaterialAlertDialogBuilder(this)
.setTitle(R.string.install_warning_title) .setTitle(R.string.install_warning_title)
@ -60,7 +60,7 @@ public class EdDownloadActivity extends BaseActivity {
.setView(binding.getRoot()) .setView(binding.getRoot())
.setPositiveButton(android.R.string.ok, (dialog, which) -> { .setPositiveButton(android.R.string.ok, (dialog, which) -> {
if (binding.checkbox.isChecked()) if (binding.checkbox.isChecked())
App.getPreferences().edit().putBoolean("hide_install_warning", true).apply(); preferences.edit().putBoolean("hide_install_warning", true).apply();
}) })
.setCancelable(false) .setCancelable(false)
.show(); .show();

View File

@ -26,7 +26,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import org.meowcat.edxposed.manager.App;
import org.meowcat.edxposed.manager.BuildConfig; import org.meowcat.edxposed.manager.BuildConfig;
import org.meowcat.edxposed.manager.Constants; import org.meowcat.edxposed.manager.Constants;
import org.meowcat.edxposed.manager.R; import org.meowcat.edxposed.manager.R;
@ -70,7 +69,7 @@ public class LogsActivity extends BaseActivity {
} }
setupWindowInsets(binding.snackbar, binding.recyclerView); setupWindowInsets(binding.snackbar, binding.recyclerView);
if (!App.getPreferences().getBoolean("hide_logcat_warning", false)) { if (!preferences.getBoolean("hide_logcat_warning", false)) {
DialogInstallWarningBinding binding = DialogInstallWarningBinding.inflate(getLayoutInflater()); DialogInstallWarningBinding binding = DialogInstallWarningBinding.inflate(getLayoutInflater());
new MaterialAlertDialogBuilder(this) new MaterialAlertDialogBuilder(this)
.setTitle(R.string.install_warning_title) .setTitle(R.string.install_warning_title)
@ -78,7 +77,7 @@ public class LogsActivity extends BaseActivity {
.setView(binding.getRoot()) .setView(binding.getRoot())
.setPositiveButton(android.R.string.ok, (dialog, which) -> { .setPositiveButton(android.R.string.ok, (dialog, which) -> {
if (binding.checkbox.isChecked()) if (binding.checkbox.isChecked())
App.getPreferences().edit().putBoolean("hide_logcat_warning", true).apply(); preferences.edit().putBoolean("hide_logcat_warning", true).apply();
}) })
.setCancelable(false) .setCancelable(false)
.show(); .show();
@ -87,7 +86,7 @@ public class LogsActivity extends BaseActivity {
binding.recyclerView.setAdapter(adapter); binding.recyclerView.setAdapter(adapter);
layoutManager = new LinearLayoutManagerFix(this); layoutManager = new LinearLayoutManagerFix(this);
binding.recyclerView.setLayoutManager(layoutManager); binding.recyclerView.setLayoutManager(layoutManager);
if (App.getPreferences().getBoolean("disable_verbose_log", false)) { if (preferences.getBoolean("disable_verbose_log", false)) {
binding.slidingTabs.setVisibility(View.GONE); binding.slidingTabs.setVisibility(View.GONE);
} }
binding.slidingTabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { binding.slidingTabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

View File

@ -14,7 +14,6 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.DividerItemDecoration;
import org.meowcat.edxposed.manager.App;
import org.meowcat.edxposed.manager.R; import org.meowcat.edxposed.manager.R;
import org.meowcat.edxposed.manager.adapters.AppAdapter; import org.meowcat.edxposed.manager.adapters.AppAdapter;
import org.meowcat.edxposed.manager.adapters.AppHelper; import org.meowcat.edxposed.manager.adapters.AppHelper;
@ -58,7 +57,7 @@ public class ModuleScopeActivity extends BaseActivity implements AppAdapter.Call
binding.recyclerView.setAdapter(appAdapter); binding.recyclerView.setAdapter(appAdapter);
binding.recyclerView.setLayoutManager(new LinearLayoutManagerFix(this)); binding.recyclerView.setLayoutManager(new LinearLayoutManagerFix(this));
FastScrollerBuilder fastScrollerBuilder = new FastScrollerBuilder(binding.recyclerView); FastScrollerBuilder fastScrollerBuilder = new FastScrollerBuilder(binding.recyclerView);
if (!App.getPreferences().getBoolean("md2", false)) { if (!preferences.getBoolean("md2", false)) {
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this,
DividerItemDecoration.VERTICAL); DividerItemDecoration.VERTICAL);
binding.recyclerView.addItemDecoration(dividerItemDecoration); binding.recyclerView.addItemDecoration(dividerItemDecoration);

View File

@ -1,5 +1,6 @@
package org.meowcat.edxposed.manager.util; package org.meowcat.edxposed.manager.util;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -37,10 +38,12 @@ public final class ModuleUtil {
private final List<String> enabledModules; private final List<String> enabledModules;
private boolean isReloading = false; private boolean isReloading = false;
private Toast toast; private Toast toast;
private final SharedPreferences prefs;
private ModuleUtil() { private ModuleUtil() {
pm = App.getInstance().getPackageManager(); pm = App.getInstance().getPackageManager();
enabledModules = AppHelper.getEnabledModuleList(); enabledModules = AppHelper.getEnabledModuleList();
prefs = App.getPreferences();
} }
public static synchronized ModuleUtil getInstance() { public static synchronized ModuleUtil getInstance() {
@ -174,7 +177,7 @@ public final class ModuleUtil {
try { try {
Log.i(App.TAG, "ModuleUtil -> updating modules.list"); Log.i(App.TAG, "ModuleUtil -> updating modules.list");
int installedXposedVersion = Constants.getXposedApiVersion(); int installedXposedVersion = Constants.getXposedApiVersion();
if (!App.getPreferences().getBoolean("skip_xposedminversion_check", false) && installedXposedVersion <= 0 && showToast) { if (!prefs.getBoolean("skip_xposedminversion_check", false) && installedXposedVersion <= 0 && showToast) {
if (binding != null) { if (binding != null) {
Snackbar.make(binding.snackbar, R.string.notinstalled, Snackbar.LENGTH_SHORT).show(); Snackbar.make(binding.snackbar, R.string.notinstalled, Snackbar.LENGTH_SHORT).show();
} else { } else {
@ -188,7 +191,7 @@ public final class ModuleUtil {
List<InstalledModule> enabledModules = getEnabledModules(); List<InstalledModule> enabledModules = getEnabledModules();
for (InstalledModule module : enabledModules) { for (InstalledModule module : enabledModules) {
if (!App.getPreferences().getBoolean("skip_xposedminversion_check", false) && (module.minVersion > installedXposedVersion || module.minVersion < MIN_MODULE_VERSION) && showToast) { if (!prefs.getBoolean("skip_xposedminversion_check", false) && (module.minVersion > installedXposedVersion || module.minVersion < MIN_MODULE_VERSION) && showToast) {
if (binding != null) { if (binding != null) {
Snackbar.make(binding.snackbar, R.string.notinstalled, Snackbar.LENGTH_SHORT).show(); Snackbar.make(binding.snackbar, R.string.notinstalled, Snackbar.LENGTH_SHORT).show();
} else { } else {
@ -287,7 +290,7 @@ public final class ModuleUtil {
this.description = ""; this.description = "";
} else { } else {
int version = Constants.getXposedApiVersion(); int version = Constants.getXposedApiVersion();
if (version > 0 && App.getPreferences().getBoolean("skip_xposedminversion_check", false)) { if (version > 0 && prefs.getBoolean("skip_xposedminversion_check", false)) {
this.minVersion = version; this.minVersion = version;
} else { } else {
Object minVersionRaw = app.metaData.get("xposedminversion"); Object minVersionRaw = app.metaData.get("xposedminversion");