From 761049d6f89ad5540d7ae2f58c315526155af326 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Thu, 11 Dec 2014 22:08:04 -0800 Subject: [PATCH] minor preferences tweaks 1) shorten some summaries 2) add summaries to appearance subscreen 3) move common summary functions to common parent class // FREEBIE --- res/values/strings.xml | 8 ++--- .../AppearancePreferenceFragment.java | 29 ++++++++----------- .../ListSummaryPreferenceFragment.java | 29 +++++++++++++++++++ .../NotificationsPreferenceFragment.java | 23 +-------------- 4 files changed, 46 insertions(+), 43 deletions(-) create mode 100644 src/org/thoughtcrime/securesms/preferences/ListSummaryPreferenceFragment.java diff --git a/res/values/strings.xml b/res/values/strings.xml index 64b638dea9..b685044242 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -39,8 +39,8 @@ partial SMS MMS - Incoming SMS - outgoing SMS + Incoming + outgoing (image) @@ -683,8 +683,8 @@ Conversation length limit Trim all threads now Scan through all conversation threads and enforce conversation length limits - Light theme - Dark theme + Light + Dark Appearance Theme Default diff --git a/src/org/thoughtcrime/securesms/preferences/AppearancePreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/AppearancePreferenceFragment.java index 052a861548..23aadc7428 100644 --- a/src/org/thoughtcrime/securesms/preferences/AppearancePreferenceFragment.java +++ b/src/org/thoughtcrime/securesms/preferences/AppearancePreferenceFragment.java @@ -2,18 +2,25 @@ package org.thoughtcrime.securesms.preferences; import android.content.Context; import android.os.Bundle; -import android.support.v4.preference.PreferenceFragment; +import android.preference.ListPreference; import org.thoughtcrime.securesms.ApplicationPreferencesActivity; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.util.TextSecurePreferences; -public class AppearancePreferenceFragment extends PreferenceFragment { +import java.util.Arrays; + +public class AppearancePreferenceFragment extends ListSummaryPreferenceFragment { @Override public void onCreate(Bundle paramBundle) { super.onCreate(paramBundle); addPreferencesFromResource(R.xml.preferences_appearance); + + this.findPreference(TextSecurePreferences.THEME_PREF).setOnPreferenceChangeListener(new ListSummaryListener()); + this.findPreference(TextSecurePreferences.LANGUAGE_PREF).setOnPreferenceChangeListener(new ListSummaryListener()); + initializeListSummary((ListPreference)findPreference(TextSecurePreferences.THEME_PREF)); + initializeListSummary((ListPreference)findPreference(TextSecurePreferences.LANGUAGE_PREF)); } @Override @@ -40,22 +47,10 @@ public class AppearancePreferenceFragment extends PreferenceFragment { String[] themeEntries = context.getResources().getStringArray(R.array.pref_theme_entries); String[] themeEntryValues = context.getResources().getStringArray(R.array.pref_theme_values); - Integer langIndex = findIndexOfValue(TextSecurePreferences.getLanguage(context), languageEntryValues); - Integer themeIndex = findIndexOfValue(TextSecurePreferences.getTheme(context), themeEntryValues); + int langIndex = Arrays.asList(languageEntryValues).indexOf(TextSecurePreferences.getLanguage(context)); + int themeIndex = Arrays.asList(themeEntryValues).indexOf(TextSecurePreferences.getTheme(context)); return context.getString(R.string.preferences__theme) + ": " + themeEntries[themeIndex] + ", " + - context.getString(R.string.preferences__language) + ": " + languageEntries[langIndex]; - } - - // Copy from ListPreference - private static int findIndexOfValue(String value, CharSequence[] mEntryValues) { - if (value != null && mEntryValues != null) { - for (int i = mEntryValues.length - 1; i >= 0; i--) { - if (mEntryValues[i].equals(value)) { - return i; - } - } - } - return -1; + context.getString(R.string.preferences__language) + ": " + languageEntries[langIndex]; } } diff --git a/src/org/thoughtcrime/securesms/preferences/ListSummaryPreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/ListSummaryPreferenceFragment.java new file mode 100644 index 0000000000..d9902a34b5 --- /dev/null +++ b/src/org/thoughtcrime/securesms/preferences/ListSummaryPreferenceFragment.java @@ -0,0 +1,29 @@ +package org.thoughtcrime.securesms.preferences; + +import android.preference.ListPreference; +import android.preference.Preference; +import android.support.v4.preference.PreferenceFragment; + +import org.thoughtcrime.securesms.R; + +import java.util.Arrays; + +public abstract class ListSummaryPreferenceFragment extends PreferenceFragment { + + protected class ListSummaryListener implements Preference.OnPreferenceChangeListener { + @Override + public boolean onPreferenceChange(Preference preference, Object value) { + ListPreference listPref = (ListPreference) preference; + int entryIndex = Arrays.asList(listPref.getEntryValues()).indexOf(value); + + listPref.setSummary(entryIndex >= 0 && entryIndex < listPref.getEntries().length + ? listPref.getEntries()[entryIndex] + : getString(R.string.preferences__led_color_unknown)); + return true; + } + } + + protected void initializeListSummary(ListPreference pref) { + pref.setSummary(pref.getEntry()); + } +} diff --git a/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java b/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java index f395a5968e..d9862f85d6 100644 --- a/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java +++ b/src/org/thoughtcrime/securesms/preferences/NotificationsPreferenceFragment.java @@ -10,17 +10,13 @@ import android.preference.ListPreference; import android.preference.Preference; import android.preference.PreferenceManager; import android.preference.RingtonePreference; -import android.support.v4.preference.PreferenceFragment; import android.text.TextUtils; -import android.util.Log; import org.thoughtcrime.securesms.ApplicationPreferencesActivity; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.util.TextSecurePreferences; -import java.util.Arrays; - -public class NotificationsPreferenceFragment extends PreferenceFragment { +public class NotificationsPreferenceFragment extends ListSummaryPreferenceFragment { @Override public void onCreate(Bundle paramBundle) { @@ -48,19 +44,6 @@ public class NotificationsPreferenceFragment extends PreferenceFragment { ((ApplicationPreferencesActivity) getActivity()).getSupportActionBar().setTitle(R.string.preferences__notifications); } - private class ListSummaryListener implements Preference.OnPreferenceChangeListener { - @Override - public boolean onPreferenceChange(Preference preference, Object value) { - ListPreference listPref = (ListPreference) preference; - - final int entryIndex = Arrays.asList(listPref.getEntryValues()).indexOf(value); - listPref.setSummary(entryIndex >= 0 && entryIndex < listPref.getEntries().length - ? listPref.getEntries()[entryIndex] - : getString(R.string.preferences__led_color_unknown)); - return true; - } - } - private class RingtoneSummaryListener implements Preference.OnPreferenceChangeListener { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { @@ -79,10 +62,6 @@ public class NotificationsPreferenceFragment extends PreferenceFragment { } } - private void initializeListSummary(ListPreference pref) { - pref.setSummary(pref.getEntry()); - } - private void initializeRingtoneSummary(RingtonePreference pref) { RingtoneSummaryListener listener = (RingtoneSummaryListener) pref.getOnPreferenceChangeListener();