From 761862efd31ab2d70b666957fd7cc86a991b4949 Mon Sep 17 00:00:00 2001 From: mgdx Date: Tue, 25 Dec 2018 01:21:26 +0100 Subject: [PATCH] Theme Settings: - Fix trouble when apps launch for the first time - Display selected color into settings - Display msg when color change from settings --- .../peertube/activity/SettingsActivity.java | 32 ++++++++++++++++++- app/src/main/res/xml/pref_general.xml | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java b/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java index eabde7c..0cb0211 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SettingsActivity.java @@ -23,6 +23,8 @@ import static net.schueller.peertube.helper.Constants.THEME_PREF_KEY; public class SettingsActivity extends AppCompatPreferenceActivity { + private static String previousThemeColorValue = ""; + @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { @@ -33,6 +35,21 @@ public class SettingsActivity extends AppCompatPreferenceActivity { return super.onOptionsItemSelected(item); } + private static String getSelectedColor(Context context, String colorId){ + + String res = "Color not found"; + String [ ] themeArray = context.getResources().getStringArray(R.array.themeValues); + String [ ] colorArray = context.getResources().getStringArray(R.array.themeArray); + + for (int i = 0 ; i < themeArray.length ; i++){ + if (themeArray[i].equals(colorId)){ + res = colorArray[i]; + break; + } + } + return res; + } + /** * A preference value change listener that updates the preference's summary * to reflect its new value. @@ -45,6 +62,19 @@ public class SettingsActivity extends AppCompatPreferenceActivity { Toast.makeText(preference.getContext(), R.string.invalid_url, Toast.LENGTH_LONG).show(); return false; } + // Check if Theme color has change & Provide selected color + else if (preference.getKey().equals("pref_theme")) { + + stringValue = getSelectedColor(preference.getContext(), stringValue); + + if (!previousThemeColorValue.equals("") && !previousThemeColorValue.equals(stringValue)) { + Toast.makeText(preference.getContext(), R.string.pref_description_app_theme, Toast.LENGTH_LONG).show(); + } + + previousThemeColorValue = stringValue; + preference.setSummary(stringValue); + return true; + } preference.setSummary(stringValue); @@ -96,7 +126,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity { setupActionBar(); getFragmentManager().beginTransaction().replace(android.R.id.content, new GeneralPreferenceFragment()).commit(); - } /** @@ -153,6 +182,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity { // updated to reflect the new value, per the Android Design // guidelines. bindPreferenceSummaryToValue(findPreference("pref_api_base")); + bindPreferenceSummaryToValue(findPreference("pref_theme")); } @Override diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml index 3e6af98..9a964c2 100644 --- a/app/src/main/res/xml/pref_general.xml +++ b/app/src/main/res/xml/pref_general.xml @@ -20,7 +20,7 @@ android:title="@string/pref_title_app_theme" android:summary="@string/pref_description_app_theme" android:key="pref_theme" - android:defaultValue="1" + android:defaultValue="AppTheme.ORANGE" android:entries="@array/themeArray" android:entryValues="@array/themeValues" />