From ef2e02098d12b8449f6f6031ef76f75c760d4f0e Mon Sep 17 00:00:00 2001 From: tonymanou Date: Wed, 4 Jan 2017 23:11:09 +0100 Subject: [PATCH] Use untranslatable string when storing theme This fixes #30 --- app/src/main/java/com/topjohnwu/magisk/AboutActivity.java | 5 +++-- app/src/main/java/com/topjohnwu/magisk/MainActivity.java | 3 ++- app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java | 4 ++-- app/src/main/java/com/topjohnwu/magisk/SplashActivity.java | 2 +- app/src/main/java/com/topjohnwu/magisk/utils/Utils.java | 4 ++++ app/src/main/java/com/topjohnwu/magisk/utils/WebWindow.java | 2 +- app/src/main/res/values/arrays.xml | 4 ++++ app/src/main/res/values/strings.xml | 4 ++++ app/src/main/res/xml/app_settings.xml | 4 ++-- 9 files changed, 23 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java b/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java index 9314ef79c..8a8245543 100644 --- a/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/AboutActivity.java @@ -18,6 +18,7 @@ import android.view.WindowManager; import android.widget.TextView; import com.topjohnwu.magisk.utils.Logger; +import com.topjohnwu.magisk.utils.Utils; import java.io.IOException; import java.io.InputStream; @@ -45,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 (theme.equals("Dark")) { + if (Utils.isDarkTheme(theme, this)) { setTheme(R.style.AppTheme_dh); } setContentView(R.layout.activity_about); @@ -76,7 +77,7 @@ public class AboutActivity extends AppCompatActivity { } appChangelog.removeSummary(); - if (theme.equals("Dark")) { + if (Utils.isDarkTheme(theme, this)) { builder = new AlertDialog.Builder(this, R.style.AlertDialog_dh); } else { builder = new AlertDialog.Builder(this); diff --git a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java index 267604ab3..20cdb11cf 100644 --- a/app/src/main/java/com/topjohnwu/magisk/MainActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/MainActivity.java @@ -27,6 +27,7 @@ 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; import butterknife.BindView; import butterknife.ButterKnife; @@ -55,7 +56,7 @@ public class MainActivity extends AppCompatActivity String theme = prefs.getString("theme", ""); Logger.dev("MainActivity: Theme is " + theme); - if (theme.equals("Dark")) { + if (Utils.isDarkTheme(theme, this)) { setTheme(R.style.AppTheme_dh); alertBuilder = new AlertDialog.Builder(this, R.style.AlertDialog_dh); } else { diff --git a/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java b/app/src/main/java/com/topjohnwu/magisk/SettingsActivity.java index b657e6937..e19eb6a01 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 (theme.equals("Dark")) { + if (Utils.isDarkTheme(theme, this)) { setTheme(R.style.AppTheme_dh); } @@ -123,7 +123,7 @@ public class SettingsActivity extends AppCompatActivity { String theme = prefs.getString(key, ""); themePreference.setSummary(theme); - if (theme.equals("Dark")) { + if (Utils.isDarkTheme(theme, getActivity())) { 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 468d9c18f..a6113fb04 100644 --- a/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java +++ b/app/src/main/java/com/topjohnwu/magisk/SplashActivity.java @@ -17,7 +17,7 @@ public class SplashActivity extends AppCompatActivity { super.onCreate(savedInstanceState); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplication()); - if (prefs.getString("theme", "").equals("Dark")) { + if (Utils.isDarkTheme(prefs.getString("theme", null), this)) { setTheme(R.style.AppTheme_dh); } 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 399ebbf88..d42fb5f4c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -164,6 +164,10 @@ 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 class ByteArrayInOutStream extends ByteArrayOutputStream { public ByteArrayInputStream getInputStream() { ByteArrayInputStream in = new ByteArrayInputStream(buf, 0, count); 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 30d7e4633..e2c716135 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/WebWindow.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/WebWindow.java @@ -14,7 +14,7 @@ public class WebWindow { public WebWindow(String title, String url, Context context) { AlertDialog.Builder alert; String theme = PreferenceManager.getDefaultSharedPreferences(context).getString("theme", ""); - if (theme.equals("Dark")) { + if (Utils.isDarkTheme(theme, context)) { alert = new AlertDialog.Builder(context, R.style.AlertDialog_dh); } else { alert = new AlertDialog.Builder(context); diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 1f10d557a..801f99d9a 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -4,4 +4,8 @@ "Default" "Dark" + + @string/theme_default_value + @string/theme_dark_value + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 99bad1219..1c2e79b24 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -130,4 +130,8 @@ Reboot to apply settings + + default + dark + diff --git a/app/src/main/res/xml/app_settings.xml b/app/src/main/res/xml/app_settings.xml index 9b49dea74..2a2c0a83d 100644 --- a/app/src/main/res/xml/app_settings.xml +++ b/app/src/main/res/xml/app_settings.xml @@ -8,9 +8,9 @@ android:key="theme" android:title="@string/settings_theme_title" android:summary="@string/settings_theme_summary" - android:defaultValue="Default" + android:defaultValue="@string/theme_default_value" android:entries="@array/themes" - android:entryValues="@array/themes"/> + android:entryValues="@array/themes_values"/>