From 1cf21f057f6e56b8d51206d92dcdf26cc45e9f13 Mon Sep 17 00:00:00 2001 From: Gregor Santner Date: Tue, 25 Oct 2016 23:04:16 +0200 Subject: [PATCH] Fixes #95 --- .../activity/SettingsActivity.java | 35 ++++++++++--------- .../diaspora_android/data/AppSettings.java | 16 ++++++--- .../ui/ThemedColorPickerPreference.java | 24 ++++++++++--- .../res/xml/preferences__sub_debugging.xml | 2 +- 4 files changed, 50 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java b/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java index 74ef19ee..009585d0 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/activity/SettingsActivity.java @@ -143,24 +143,25 @@ public class SettingsActivity extends ThemedActivity { @Override public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) { if(isAdded() && preference.hasKey()) { - DiasporaUrlHelper diasporaUrlHelper = new DiasporaUrlHelper(((App)getActivity().getApplication()).getSettings()); + AppSettings settings = ((App)getActivity().getApplication()).getSettings(); + DiasporaUrlHelper diasporaUrlHelper = new DiasporaUrlHelper(settings); String key = preference.getKey(); /** Sub-Categories */ - if(key.equals(getString(R.string.pref_key__cat_themes))) { + if(settings.isKeyEqual(key,R.string.pref_key__cat_themes)) { ((SettingsActivity) getActivity()).showFragment(SettingsFragmentThemes.TAG, true); return true; - } else if (key.equals(getString(R.string.pref_key__cat_nav_slider))) { + } else if (settings.isKeyEqual(key,R.string.pref_key__cat_nav_slider)) { ((SettingsActivity) getActivity()).showFragment(SettingsFragmentNavSlider.TAG, true); return true; - } else if (key.equals(getString(R.string.pref_key__cat_proxy))) { + } else if (settings.isKeyEqual(key,R.string.pref_key__cat_proxy)) { ((SettingsActivity)getActivity()).showFragment(SettingsFragmentProxy.TAG, true); return true; - } else if (key.equals(getString(R.string.pref_key__cat_debugging))) { + } else if (settings.isKeyEqual(key,R.string.pref_key__cat_debugging)) { ((SettingsActivity)getActivity()).showFragment(SettingsFragmentDebugging.TAG, true); return true; } /** Network */ - else if (key.equals(getString(R.string.pref_key__clear_cache))) { + else if (settings.isKeyEqual(key,R.string.pref_key__clear_cache)) { Intent intent = new Intent(getActivity(), MainActivity.class); intent.setAction(MainActivity.ACTION_CLEAR_CACHE); startActivity(intent); @@ -168,28 +169,28 @@ public class SettingsActivity extends ThemedActivity { return true; } /** Pod Settings */ - if (key.equals(getString(R.string.pref_key__personal_settings))) { + if (settings.isKeyEqual(key,R.string.pref_key__personal_settings)) { Intent intent = new Intent(getActivity(), MainActivity.class); intent.setAction(MainActivity.ACTION_OPEN_URL); intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getPersonalSettingsUrl()); startActivity(intent); getActivity().finish(); return true; - } else if (key.equals(getString(R.string.pref_key__manage_tags))) { + } else if (settings.isKeyEqual(key,R.string.pref_key__manage_tags)) { Intent intent = new Intent(getActivity(), MainActivity.class); intent.setAction(MainActivity.ACTION_OPEN_URL); intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageTagsUrl()); startActivity(intent); getActivity().finish(); return true; - } else if (key.equals(getString(R.string.pref_key__manage_contacts))) { + } else if (settings.isKeyEqual(key,R.string.pref_key__manage_contacts)) { Intent intent = new Intent(getActivity(), MainActivity.class); intent.setAction(MainActivity.ACTION_OPEN_URL); intent.putExtra(MainActivity.URL_MESSAGE, diasporaUrlHelper.getManageContactsUrl()); startActivity(intent); getActivity().finish(); return true; - } else if (key.equals(getString(R.string.pref_key__change_account))) { + } else if (settings.isKeyEqual(key,R.string.pref_key__change_account)) { new AlertDialog.Builder(getActivity()) .setTitle(getString(R.string.confirmation)) .setMessage(getString(R.string.pref_warning__change_account)) @@ -348,9 +349,9 @@ public class SettingsActivity extends ThemedActivity { public void updateSummaries() { if(isAdded()) { - AppSettings appSettings = ((App) getActivity().getApplication()).getSettings(); - findPreference(getString(R.string.pref_key__http_proxy_host)).setSummary(appSettings.getProxyHttpHost()); - findPreference(getString(R.string.pref_key__http_proxy_port)).setSummary(Integer.toString(appSettings.getProxyHttpPort())); + AppSettings settings = ((App) getActivity().getApplication()).getSettings(); + findPreference(settings.getKey(R.string.pref_key__http_proxy_host)).setSummary(settings.getProxyHttpHost()); + findPreference(settings.getKey(R.string.pref_key__http_proxy_port)).setSummary(Integer.toString(settings.getProxyHttpPort())); } } @@ -359,7 +360,7 @@ public class SettingsActivity extends ThemedActivity { if (isAdded() && preference.hasKey()) { AppSettings appSettings = ((App) getActivity().getApplication()).getSettings(); String key = preference.getKey(); - if(key.equals(getString(R.string.pref_key__http_proxy_load_tor_preset))) { + if(appSettings.isKeyEqual(key, R.string.pref_key__http_proxy_load_tor_preset)) { appSettings.setProxyHttpHost("127.0.0.1"); appSettings.setProxyHttpPort(8118); return true; @@ -374,10 +375,10 @@ public class SettingsActivity extends ThemedActivity { } @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if(isAdded()) { - if (s.equals(getString(R.string.pref_key__http_proxy_host)) || - s.equals(getString(R.string.pref_key__http_proxy_port))) { + if (key.equals(getString(R.string.pref_key__http_proxy_host)) || + key.equals(getString(R.string.pref_key__http_proxy_port))) { updateSummaries(); } } diff --git a/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java b/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java index dd24f4ca..95fd79fe 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/data/AppSettings.java @@ -54,6 +54,14 @@ public class AppSettings { prefApp.edit().clear().apply(); } + public String getKey(int stringKeyRessourceId){ + return context.getString(stringKeyRessourceId); + } + + public boolean isKeyEqual(String key, int stringKeyRessourceId){ + return key.equals(getKey(stringKeyRessourceId)); + } + private void setString(SharedPreferences pref, int keyRessourceId, String value) { pref.edit().putString(context.getString(keyRessourceId), value).apply(); } @@ -95,6 +103,10 @@ public class AppSettings { return pref.getInt(context.getString(ressourceId), defaultValue); } + public int getColor(SharedPreferences pref, String key, int defaultColor) { + return pref.getInt(key, defaultColor); + } + /* // Setters & Getters @@ -384,8 +396,4 @@ public class AppSettings { public boolean isExtendedNotificationsActivated() { return getBoolean(prefApp, R.string.pref_key__extended_notifications, false); } - - public int getColor(String key) { - return prefApp.getInt(key, context.getResources().getColor(R.color.primary)); - } } \ No newline at end of file diff --git a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedColorPickerPreference.java b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedColorPickerPreference.java index 90861128..9ec3efa0 100644 --- a/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedColorPickerPreference.java +++ b/app/src/main/java/com/github/dfa/diaspora_android/ui/ThemedColorPickerPreference.java @@ -8,7 +8,9 @@ import android.util.AttributeSet; import android.view.View; import android.widget.ImageView; +import com.github.dfa.diaspora_android.R; import com.github.dfa.diaspora_android.data.AppSettings; +import com.github.dfa.diaspora_android.util.Helpers; /** * Preference that shows selected Color in a circle @@ -17,14 +19,17 @@ import com.github.dfa.diaspora_android.data.AppSettings; public class ThemedColorPickerPreference extends Preference implements Themeable { protected ImageView colorPreview; + @SuppressWarnings("unused") public ThemedColorPickerPreference(Context context) { super(context); } + @SuppressWarnings("unused") public ThemedColorPickerPreference(Context context, AttributeSet attrs) { super(context, attrs); } + @SuppressWarnings("unused") public ThemedColorPickerPreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); @@ -39,12 +44,21 @@ public class ThemedColorPickerPreference extends Preference implements Themeable @Override public void setColors() { - AppSettings appSettings = new AppSettings(getContext()); - if(colorPreview != null) { - Drawable circle = colorPreview.getDrawable(); - if(circle != null) { - circle.setColorFilter(appSettings.getColor(getKey()), PorterDuff.Mode.SRC_ATOP); + Drawable circle; + if (colorPreview != null && (circle = colorPreview.getDrawable()) != null) { + Context c = getContext(); + AppSettings appSettings = new AppSettings(getContext()); + String key = getKey(); + + int color = Helpers.getColorFromRessource(c, R.color.primary); + if ((appSettings.isKeyEqual(key, R.string.pref_key__primary_color_shade))) { + color = appSettings.getPrimaryColor(); + } else if ((appSettings.isKeyEqual(key, R.string.pref_key__accent_color_shade))) { + color = appSettings.getAccentColor(); + } else { + color = appSettings.getColor(getSharedPreferences(), key, color); } + circle.setColorFilter(color, PorterDuff.Mode.SRC_ATOP); } } } diff --git a/app/src/main/res/xml/preferences__sub_debugging.xml b/app/src/main/res/xml/preferences__sub_debugging.xml index 63414f8e..91145231 100644 --- a/app/src/main/res/xml/preferences__sub_debugging.xml +++ b/app/src/main/res/xml/preferences__sub_debugging.xml @@ -9,7 +9,7 @@ android:key="@string/pref_key__logging_enabled" android:title="@string/pref_title__logging_enabled"/>