From 0df7cbca3e9fbd852b921c009468458b2c2e8199 Mon Sep 17 00:00:00 2001 From: NekoInverter <7741672-NekoInverter@users.noreply.gitlab.com> Date: Tue, 26 Jan 2021 16:56:28 +0800 Subject: [PATCH] Remove redundant codes --- .../manager/ui/activity/BaseActivity.java | 20 +++++++++---------- .../ui/activity/BlackListActivity.java | 3 +-- .../ui/activity/EdDownloadActivity.java | 4 ++-- .../manager/ui/activity/LogsActivity.java | 7 +++---- .../ui/activity/ModuleScopeActivity.java | 3 +-- .../edxposed/manager/util/ModuleUtil.java | 9 ++++++--- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/BaseActivity.java b/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/BaseActivity.java index c7957e35..a8ea5412 100644 --- a/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/BaseActivity.java +++ b/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/BaseActivity.java @@ -44,11 +44,11 @@ public class BaseActivity extends AppCompatActivity { private static final String THEME_DEFAULT = "DEFAULT"; private static final String THEME_BLACK = "BLACK"; + protected static SharedPreferences preferences; private String theme; - protected SharedPreferences preferences; 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) { @@ -89,19 +89,19 @@ public class BaseActivity extends AppCompatActivity { @StyleRes 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"; String customThemeName; String primaryColorEntryName = "colorPrimary"; 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())) { primaryColorEntryName = color.getResourceEntryName(); } } String accentColorEntryName = "colorAccent"; 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())) { accentColorEntryName = color.getResourceEntryName(); } @@ -118,8 +118,8 @@ public class BaseActivity extends AppCompatActivity { public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); preferences = App.getPreferences(); - AppCompatDelegate.setDefaultNightMode(App.getPreferences().getInt("theme", -1)); - theme = getTheme(this) + getCustomTheme() + App.getPreferences().getBoolean("md2", false); + AppCompatDelegate.setDefaultNightMode(preferences.getInt("theme", -1)); + theme = getTheme(this) + getCustomTheme() + preferences.getBoolean("md2", false); } public int getThemedColor(int id) { @@ -133,13 +133,13 @@ public class BaseActivity extends AppCompatActivity { protected void onResume() { super.onResume(); 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)); } else { 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(); } } @@ -158,7 +158,7 @@ public class BaseActivity extends AppCompatActivity { theme.applyStyle(resid, false); } 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); } if (this instanceof MainActivity) { diff --git a/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/BlackListActivity.java b/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/BlackListActivity.java index 911f9ab5..79a5e764 100644 --- a/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/BlackListActivity.java +++ b/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/BlackListActivity.java @@ -14,7 +14,6 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.SearchView; import androidx.recyclerview.widget.DividerItemDecoration; -import org.meowcat.edxposed.manager.App; import org.meowcat.edxposed.manager.R; import org.meowcat.edxposed.manager.adapters.AppAdapter; 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.setLayoutManager(new LinearLayoutManagerFix(this)); FastScrollerBuilder fastScrollerBuilder = new FastScrollerBuilder(binding.recyclerView); - if (!App.getPreferences().getBoolean("md2", false)) { + if (!preferences.getBoolean("md2", false)) { DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL); binding.recyclerView.addItemDecoration(dividerItemDecoration); diff --git a/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/EdDownloadActivity.java b/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/EdDownloadActivity.java index 320e4510..54548a1b 100644 --- a/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/EdDownloadActivity.java +++ b/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/EdDownloadActivity.java @@ -52,7 +52,7 @@ public class EdDownloadActivity extends BaseActivity { binding.tabLayout.setupWithViewPager(binding.pager); //new JSONParser().execute(); - if (!App.getPreferences().getBoolean("hide_install_warning", false)) { + if (!preferences.getBoolean("hide_install_warning", false)) { DialogInstallWarningBinding binding = DialogInstallWarningBinding.inflate(getLayoutInflater()); new MaterialAlertDialogBuilder(this) .setTitle(R.string.install_warning_title) @@ -60,7 +60,7 @@ public class EdDownloadActivity extends BaseActivity { .setView(binding.getRoot()) .setPositiveButton(android.R.string.ok, (dialog, which) -> { if (binding.checkbox.isChecked()) - App.getPreferences().edit().putBoolean("hide_install_warning", true).apply(); + preferences.edit().putBoolean("hide_install_warning", true).apply(); }) .setCancelable(false) .show(); diff --git a/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/LogsActivity.java b/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/LogsActivity.java index e9320f5a..85af7aa6 100644 --- a/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/LogsActivity.java +++ b/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/LogsActivity.java @@ -26,7 +26,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; import com.google.android.material.tabs.TabLayout; -import org.meowcat.edxposed.manager.App; import org.meowcat.edxposed.manager.BuildConfig; import org.meowcat.edxposed.manager.Constants; import org.meowcat.edxposed.manager.R; @@ -70,7 +69,7 @@ public class LogsActivity extends BaseActivity { } 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()); new MaterialAlertDialogBuilder(this) .setTitle(R.string.install_warning_title) @@ -78,7 +77,7 @@ public class LogsActivity extends BaseActivity { .setView(binding.getRoot()) .setPositiveButton(android.R.string.ok, (dialog, which) -> { if (binding.checkbox.isChecked()) - App.getPreferences().edit().putBoolean("hide_logcat_warning", true).apply(); + preferences.edit().putBoolean("hide_logcat_warning", true).apply(); }) .setCancelable(false) .show(); @@ -87,7 +86,7 @@ public class LogsActivity extends BaseActivity { binding.recyclerView.setAdapter(adapter); layoutManager = new LinearLayoutManagerFix(this); 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.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { diff --git a/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/ModuleScopeActivity.java b/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/ModuleScopeActivity.java index 78064f3b..6d5e454a 100644 --- a/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/ModuleScopeActivity.java +++ b/app/src/main/java/org/meowcat/edxposed/manager/ui/activity/ModuleScopeActivity.java @@ -14,7 +14,6 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.SearchView; import androidx.recyclerview.widget.DividerItemDecoration; -import org.meowcat.edxposed.manager.App; import org.meowcat.edxposed.manager.R; import org.meowcat.edxposed.manager.adapters.AppAdapter; 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.setLayoutManager(new LinearLayoutManagerFix(this)); FastScrollerBuilder fastScrollerBuilder = new FastScrollerBuilder(binding.recyclerView); - if (!App.getPreferences().getBoolean("md2", false)) { + if (!preferences.getBoolean("md2", false)) { DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL); binding.recyclerView.addItemDecoration(dividerItemDecoration); diff --git a/app/src/main/java/org/meowcat/edxposed/manager/util/ModuleUtil.java b/app/src/main/java/org/meowcat/edxposed/manager/util/ModuleUtil.java index 07ef530b..dd8d57a5 100644 --- a/app/src/main/java/org/meowcat/edxposed/manager/util/ModuleUtil.java +++ b/app/src/main/java/org/meowcat/edxposed/manager/util/ModuleUtil.java @@ -1,5 +1,6 @@ package org.meowcat.edxposed.manager.util; +import android.content.SharedPreferences; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; @@ -37,10 +38,12 @@ public final class ModuleUtil { private final List enabledModules; private boolean isReloading = false; private Toast toast; + private final SharedPreferences prefs; private ModuleUtil() { pm = App.getInstance().getPackageManager(); enabledModules = AppHelper.getEnabledModuleList(); + prefs = App.getPreferences(); } public static synchronized ModuleUtil getInstance() { @@ -174,7 +177,7 @@ public final class ModuleUtil { try { Log.i(App.TAG, "ModuleUtil -> updating modules.list"); 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) { Snackbar.make(binding.snackbar, R.string.notinstalled, Snackbar.LENGTH_SHORT).show(); } else { @@ -188,7 +191,7 @@ public final class ModuleUtil { List enabledModules = getEnabledModules(); 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) { Snackbar.make(binding.snackbar, R.string.notinstalled, Snackbar.LENGTH_SHORT).show(); } else { @@ -287,7 +290,7 @@ public final class ModuleUtil { this.description = ""; } else { 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; } else { Object minVersionRaw = app.metaData.get("xposedminversion");