diff --git a/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java b/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java index 8a8245543..6da59e7a4 100644 --- a/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java @@ -1,12 +1,12 @@ package com.topjohnwu.magisk; +import android.app.AlertDialog; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.support.v7.app.ActionBar; -import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.text.Html; @@ -39,14 +39,13 @@ public class AboutActivity extends AppCompatActivity { @BindView(R.id.app_source_code) AboutCardRow appSourceCode; @BindView(R.id.support_thread) AboutCardRow supportThread; @BindView(R.id.donation) AboutCardRow donation; - private AlertDialog.Builder builder; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); String theme = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("theme", ""); Logger.dev("AboutActivity: Theme is " + theme); - if (Utils.isDarkTheme(theme, this)) { + if (Utils.isDarkTheme) { setTheme(R.style.AppTheme_dh); } setContentView(R.layout.activity_about); @@ -77,11 +76,6 @@ public class AboutActivity extends AppCompatActivity { } appChangelog.removeSummary(); - if (Utils.isDarkTheme(theme, this)) { - builder = new AlertDialog.Builder(this, R.style.AlertDialog_dh); - } else { - builder = new AlertDialog.Builder(this); - } if (changes == null) { appChangelog.setVisibility(View.GONE); } else { @@ -92,13 +86,11 @@ public class AboutActivity extends AppCompatActivity { result = Html.fromHtml(changes); } appChangelog.setOnClickListener(v -> { - AlertDialog d = builder + AlertDialog d = Utils.getAlertDialogBuilder(this) .setTitle(R.string.app_changelog) .setMessage(result) .setPositiveButton(android.R.string.ok, null) - .create(); - - d.show(); + .show(); //noinspection ConstantConditions ((TextView) d.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); @@ -113,7 +105,7 @@ public class AboutActivity extends AppCompatActivity { } else { result = Html.fromHtml(getString(R.string.app_developers_)); } - AlertDialog d = builder + AlertDialog d = Utils.getAlertDialogBuilder(this) .setTitle(R.string.app_developers) .setMessage(result) .setPositiveButton(android.R.string.ok, null) diff --git a/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java b/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java index f93a2cd93..891a6a93c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/InstallFragment.java @@ -53,7 +53,7 @@ public class InstallFragment extends Fragment implements CallbackHandler.EventLi } String filename = "Magisk-v" + StatusFragment.remoteMagiskVersion + ".zip"; String finalBootImage = bootImage; - MainActivity.alertBuilder + Utils.getAlertDialogBuilder(getActivity()) .setTitle(getString(R.string.repo_install_title, getString(R.string.magisk))) .setMessage(getString(R.string.repo_install_msg, filename)) .setCancelable(true) diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java index ddae5aceb..13524865f 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -1,7 +1,6 @@ package com.topjohnwu.magisk; import android.Manifest; -import android.app.AlertDialog; import android.app.Fragment; import android.app.FragmentTransaction; import android.content.Intent; @@ -25,7 +24,6 @@ import android.view.MenuItem; import android.view.View; import com.topjohnwu.magisk.utils.CallbackHandler; -import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Utils; @@ -35,8 +33,6 @@ import butterknife.ButterKnife; public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, CallbackHandler.EventListener { - public static AlertDialog.Builder alertBuilder = null; - private static final String SELECTED_ITEM_ID = "SELECTED_ITEM_ID"; private final Handler mDrawerHandler = new Handler(); @@ -54,13 +50,8 @@ public class MainActivity extends AppCompatActivity prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); - String theme = prefs.getString("theme", ""); - Logger.dev("MainActivity: Theme is " + theme); - if (Utils.isDarkTheme(theme, this)) { + if (Utils.isDarkTheme) { setTheme(R.style.AppTheme_dh); - alertBuilder = new AlertDialog.Builder(this, R.style.AlertDialog_dh); - } else { - alertBuilder = new AlertDialog.Builder(this); } super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); @@ -116,7 +107,6 @@ public class MainActivity extends AppCompatActivity protected void onDestroy() { super.onDestroy(); CallbackHandler.unRegister(StatusFragment.updateCheckDone, this); - alertBuilder = null; } @Override diff --git a/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java b/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java index e19eb6a01..2a4c50a21 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java @@ -30,7 +30,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(theme, this)) { + if (Utils.isDarkTheme) { setTheme(R.style.AppTheme_dh); } @@ -120,10 +120,11 @@ public class SettingsActivity extends AppCompatActivity { switch (key) { case "theme": - String theme = prefs.getString(key, ""); + String theme = prefs.getString("theme", getString(R.string.theme_default_value)); + Utils.isDarkTheme = theme.equalsIgnoreCase(getString(R.string.theme_dark_value)); themePreference.setSummary(theme); - if (Utils.isDarkTheme(theme, getActivity())) { + if (Utils.isDarkTheme) { getActivity().getApplication().setTheme(R.style.AppTheme_dh); } else { getActivity().getApplication().setTheme(R.style.AppTheme); diff --git a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java index a631b0abb..97d1aa827 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -17,7 +17,11 @@ public class SplashActivity extends AppCompatActivity { super.onCreate(savedInstanceState); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication()); - if (Utils.isDarkTheme(prefs.getString("theme", null), this)) { + + String theme = prefs.getString("theme", getString(R.string.theme_default_value)); + Utils.isDarkTheme = theme.equalsIgnoreCase(getString(R.string.theme_dark_value)); + + if (Utils.isDarkTheme) { setTheme(R.style.AppTheme_dh); } diff --git a/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java b/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java index 3230a043e..12245066a 100644 --- a/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/StatusFragment.java @@ -3,8 +3,6 @@ package com.topjohnwu.magisk; import android.app.AlertDialog; import android.app.Fragment; import android.app.FragmentTransaction; -import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Bundle; @@ -21,6 +19,7 @@ import com.topjohnwu.magisk.utils.Async; import com.topjohnwu.magisk.utils.CallbackHandler; import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Shell; +import com.topjohnwu.magisk.utils.Utils; import java.util.List; @@ -108,7 +107,8 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis }); if (magiskVersion < 0 && Shell.rootAccess() && !noDialog) { - MainActivity.alertBuilder + noDialog = true; + Utils.getAlertDialogBuilder(getActivity()) .setTitle(R.string.no_magisk_title) .setMessage(R.string.no_magisk_msg) .setCancelable(true) @@ -120,7 +120,7 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis transaction.replace(R.id.content_frame, new InstallFragment(), "install").commit(); } catch (IllegalStateException ignored) {} }) - .setNegativeButton(R.string.no_thanks, (dialogInterface, i) -> noDialog = true) + .setNegativeButton(R.string.no_thanks, null) .show(); } @@ -240,7 +240,7 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis magiskCheckUpdatesProgress.setVisibility(View.GONE); mSwipeRefreshLayout.setRefreshing(false); - updateMagisk = MainActivity.alertBuilder + updateMagisk = Utils.getAlertDialogBuilder(getActivity()) .setTitle(R.string.magisk_update_title) .setMessage(getString(R.string.magisk_update_message, remoteMagiskVersion)) .setCancelable(true) @@ -255,12 +255,13 @@ public class StatusFragment extends Fragment implements CallbackHandler.EventLis .setNeutralButton(R.string.check_release_notes, (dialog, which) -> { getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(releaseNoteLink))); }) - .setNegativeButton(R.string.no_thanks, (dialogInterface, i) -> noDialog = true) + .setNegativeButton(R.string.no_thanks, null) .create(); if (magiskVersion < remoteMagiskVersion && Shell.rootAccess()) { magiskStatusContainer.setOnClickListener(view -> updateMagisk.show()); if (!noDialog) { + noDialog = true; updateMagisk.show(); } } diff --git a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java b/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java index d1525b474..62218368e 100644 --- a/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java +++ b/app/src/main/java/com/topjohnwu/magisk/adapters/ReposAdapter.java @@ -17,7 +17,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import com.topjohnwu.magisk.MainActivity; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.module.Repo; import com.topjohnwu.magisk.receivers.RepoDlReceiver; @@ -99,7 +98,7 @@ public class ReposAdapter extends RecyclerView.Adapter }); holder.updateImage.setOnClickListener(view -> { String filename = repo.getName() + "-" + repo.getVersion() + ".zip"; - MainActivity.alertBuilder + Utils.getAlertDialogBuilder(mContext) .setTitle(mContext.getString(R.string.repo_install_title, repo.getName())) .setMessage(mContext.getString(R.string.repo_install_msg, filename)) .setCancelable(true) diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java index 8b3bed545..445f39e74 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Async.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Async.java @@ -13,7 +13,6 @@ import android.widget.Toast; import com.topjohnwu.magisk.InstallFragment; import com.topjohnwu.magisk.MagiskHideFragment; -import com.topjohnwu.magisk.MainActivity; import com.topjohnwu.magisk.ModulesFragment; import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.ReposFragment; @@ -292,7 +291,7 @@ public class Async { StatusFragment.updateCheckDone.trigger(); new LoadModules().exec(); - MainActivity.alertBuilder + Utils.getAlertDialogBuilder(mContext) .setTitle(R.string.reboot_title) .setMessage(R.string.reboot_msg) .setPositiveButton(R.string.reboot, (dialogInterface1, i) -> Shell.sh("su -c reboot")) 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 d42fb5f4c..334f2a882 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -1,6 +1,7 @@ package com.topjohnwu.magisk.utils; import android.Manifest; +import android.app.AlertDialog; import android.app.DownloadManager; import android.content.Context; import android.content.IntentFilter; @@ -34,6 +35,7 @@ import javax.crypto.spec.DESKeySpec; public class Utils { public static boolean isDownloading = false; + public static boolean isDarkTheme; private static final String cryptoPass = "MagiskRox666"; private static final String secret = "GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus"; @@ -164,8 +166,12 @@ public class Utils { return null; } - public static boolean isDarkTheme(String theme, Context resources) { - return theme != null && theme.equalsIgnoreCase(resources.getString(R.string.theme_dark_value)); + public static AlertDialog.Builder getAlertDialogBuilder(Context context) { + if (isDarkTheme) { + return new AlertDialog.Builder(context, R.style.AlertDialog_dh); + } else { + return new AlertDialog.Builder(context); + } } public static class ByteArrayInOutStream extends ByteArrayOutputStream { diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/WebWindow.java b/app/src/main/java/com/topjohnwu/magisk/utils/WebWindow.java index e2c716135..f58568023 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/WebWindow.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/WebWindow.java @@ -1,24 +1,15 @@ package com.topjohnwu.magisk.utils; +import android.app.AlertDialog; import android.content.Context; -import android.preference.PreferenceManager; -import android.support.v7.app.AlertDialog; import android.webkit.WebResourceRequest; import android.webkit.WebView; import android.webkit.WebViewClient; -import com.topjohnwu.magisk.R; - public class WebWindow { public WebWindow(String title, String url, Context context) { - AlertDialog.Builder alert; - String theme = PreferenceManager.getDefaultSharedPreferences(context).getString("theme", ""); - if (Utils.isDarkTheme(theme, context)) { - alert = new AlertDialog.Builder(context, R.style.AlertDialog_dh); - } else { - alert = new AlertDialog.Builder(context); - } + AlertDialog.Builder alert = Utils.getAlertDialogBuilder(context); alert.setTitle(title); Logger.dev("WebView: URL = " + url); diff --git a/app/src/main/res/layout/install_fragment.xml b/app/src/main/res/layout/install_fragment.xml index 1348d3de6..11ce7f8ca 100644 --- a/app/src/main/res/layout/install_fragment.xml +++ b/app/src/main/res/layout/install_fragment.xml @@ -21,7 +21,7 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" - android:padding="15dp"> + android:padding="5dp">