From dc860d726494e1e28c369b745f53120403f1de96 Mon Sep 17 00:00:00 2001
From: k3b <1374583+k3b@users.noreply.github.com>
Date: Wed, 29 Jan 2020 23:22:49 +0100
Subject: [PATCH] #162: Fixed Merge Error from themePreference. Recreate
Settings after theme change
---
app/src/main/java/de/k3b/android/GuiUtil.java | 11 ++-
.../androFotoFinder/SettingsActivity.java | 98 ++++---------------
app/src/main/res/values/arrays.xml | 4 +-
app/src/main/res/values/strings.xml | 7 +-
app/src/main/res/xml/preferences.xml | 2 +-
5 files changed, 34 insertions(+), 88 deletions(-)
diff --git a/app/src/main/java/de/k3b/android/GuiUtil.java b/app/src/main/java/de/k3b/android/GuiUtil.java
index c5ecc647..a72aa62d 100644
--- a/app/src/main/java/de/k3b/android/GuiUtil.java
+++ b/app/src/main/java/de/k3b/android/GuiUtil.java
@@ -30,6 +30,9 @@
* gui utils
*/
public class GuiUtil {
+
+ public static final String PREF_KEY_USER_THEME = "user_theme";
+
public static String getAppVersionName(final Context context) {
try {
@@ -41,7 +44,7 @@ public static String getAppVersionName(final Context context) {
return null;
}
public static void setTheme(Activity act) {
- final String theme = PreferenceManager.getDefaultSharedPreferences(act).getString("user_theme", "Light");
+ final String theme = getTheme(act);
switch (theme) {
case "Light":
act.setTheme(R.style.AppTheme_Light);
@@ -50,7 +53,11 @@ public static void setTheme(Activity act) {
act.setTheme(R.style.AppTheme_Dark);
break;
default:
- throw new RuntimeException("Invalid theme selected");
+ throw new RuntimeException("Invalid theme '" + theme+ "' selected");
}
}
+
+ public static String getTheme(Context context) {
+ return PreferenceManager.getDefaultSharedPreferences(context).getString(PREF_KEY_USER_THEME, "Light");
+ }
}
diff --git a/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java b/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java
index ef32f405..d464273d 100644
--- a/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java
+++ b/app/src/main/java/de/k3b/android/androFotoFinder/SettingsActivity.java
@@ -59,6 +59,7 @@ public class SettingsActivity extends PreferenceActivity {
private SharedPreferences prefsInstance = null;
private ListPreference defaultLocalePreference; // #21: Support to change locale at runtime
private ListPreference mediaUpdateStrategyPreference;
+ private ListPreference themePreference; // #21: Support to change locale at runtime
private int INSTALL_REQUEST_CODE = 1927;
@@ -95,6 +96,15 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
});
+ themePreference = (ListPreference) findPreference(GuiUtil.PREF_KEY_USER_THEME);
+ themePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ setUserTheme((String) newValue);
+ LocalizedActivity.recreate(SettingsActivity.this);
+ return true; // change is allowed
+ }
+ });
mediaUpdateStrategyPreference =
(ListPreference) findPreference("mediaUpdateStrategy");
mediaUpdateStrategyPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@@ -133,12 +143,6 @@ public boolean onPreferenceClick(Preference preference) {
updateSummary();
}
- @Override
- public void onPause() {
- prefs2Global(this);
- super.onPause();
- }
-
public static void global2Prefs(Context context) {
fixDefaults(context, null, null);
@@ -302,79 +306,6 @@ public void onPause() {
super.onPause();
}
- @Override
- protected void onCreate(final Bundle savedInstanceState) {
- LocalizedActivity.fixLocale(this); // #21: Support to change locale at runtime
- super.onCreate(savedInstanceState);
-
- if (Global.debugEnabled) {
- // todo create junit integration tests with arabic locale from this.
- StringFormatResourceTests.test(this);
- }
-
- final Intent intent = getIntent();
- if (Global.debugEnabled && (intent != null)) {
- Log.d(Global.LOG_CONTEXT, "SettingsActivity onCreate " + intent.toUri(Intent.URI_INTENT_SCHEME));
- }
-
- this.addPreferencesFromResource(R.xml.preferences);
- if (Global.allow_emulate_ao10) {
- this.addPreferencesFromResource(R.xml.preferences_ao10_test);
- }
- prefsInstance = PreferenceManager
- .getDefaultSharedPreferences(this);
- global2Prefs(this.getApplication());
-
- // #21: Support to change locale at runtime
- defaultLocalePreference =
- (ListPreference) findPreference(Global.PREF_KEY_USER_LOCALE);
- defaultLocalePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- setLanguage((String) newValue);
- LocalizedActivity.recreate(SettingsActivity.this);
- return true; // change is allowed
- }
- });
-
- mediaUpdateStrategyPreference =
- (ListPreference) findPreference("mediaUpdateStrategy");
- mediaUpdateStrategyPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- LibGlobal.mediaUpdateStrategy = (String) newValue;
- setPref(LibGlobal.mediaUpdateStrategy, mediaUpdateStrategyPreference, R.array.pref_media_update_strategy_names);
- return true;
- }
- });
- setPref(LibGlobal.mediaUpdateStrategy, mediaUpdateStrategyPreference, R.array.pref_media_update_strategy_names);
-
- findPreference("debugClearLog").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- onDebugClearLogCat();
- return false; // donot close
- }
- });
- findPreference("debugSaveLog").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- onDebugSaveLogCat();
- return false; // donot close
- }
- });
- findPreference("translate").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- onTranslate();
- return false; // donot close
- }
- });
-
- // #21: Support to change locale at runtime
- updateSummary();
- }
-
private static void fixDefaults(Context context, File previousCacheRoot, File previousMapsForgeDir) {
boolean mustSave = false;
@@ -483,12 +414,19 @@ public static void showActivity(Activity parent) {
private void updateSummary() {
final String languageKey = prefsInstance.getString(Global.PREF_KEY_USER_LOCALE, "");
setLanguage(languageKey);
+
+ setUserTheme(GuiUtil.getTheme(this));
AboutDialogPreference about =
(AboutDialogPreference) findPreference("about");
about.setTitle(AboutDialogPreference.getAboutTitle(this));
}
- // #21: Support to change locale at runtime
+ private void setUserTheme(String newValue) {
+ setPref(GuiUtil.PREF_KEY_USER_THEME, this.themePreference, R.array.pref_themes_names);
+ }
+
+
+ // #21: Support to change locale at runtime
private void setLanguage(String languageKey) {
setPref(languageKey, defaultLocalePreference, R.array.pref_locale_names);
}
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index b94b265b..5582d55b 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -80,8 +80,8 @@
- 00000
-
- - Light
+
+ - Lgiht
- Dark
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 48089b39..58fe7b5b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -275,14 +275,15 @@ You can undo hiding by calling the mediascanner from gallery-menu."
When:
- Theme
- Holo light
- Holo dark
+ Theme
+ Holo light
+ Holo dark
+
(Re)Load Media Database
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index d4133589..d1a50912 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -38,7 +38,7 @@ this program. If not, see