minor preferences tweaks

1) shorten some summaries
2) add summaries to appearance subscreen
3) move common summary functions to common parent class

// FREEBIE
This commit is contained in:
Jake McGinty 2014-12-11 22:08:04 -08:00
parent df12174458
commit 761049d6f8
4 changed files with 46 additions and 43 deletions

View File

@ -39,8 +39,8 @@
<string name="ApplicationPreferencesActivity_partial">partial</string>
<string name="ApplicationPreferencesActivity_sms">SMS</string>
<string name="ApplicationPreferencesActivity_mms">MMS</string>
<string name="ApplicationPreferencesActivity_incoming_sms">Incoming SMS</string>
<string name="ApplicationPreferencesActivity_outgoing_sms">outgoing SMS</string>
<string name="ApplicationPreferencesActivity_incoming_sms">Incoming</string>
<string name="ApplicationPreferencesActivity_outgoing_sms">outgoing</string>
<!-- DraftDatabase -->
<string name="DraftDatabase_Draft_image_snippet">(image)</string>
@ -683,8 +683,8 @@
<string name="preferences__conversation_length_limit">Conversation length limit</string>
<string name="preferences__trim_all_threads_now">Trim all threads now</string>
<string name="preferences__scan_through_all_conversation_threads_and_enforce_conversation_length_limits">Scan through all conversation threads and enforce conversation length limits</string>
<string name="preferences__light_theme">Light theme</string>
<string name="preferences__dark_theme">Dark theme</string>
<string name="preferences__light_theme">Light</string>
<string name="preferences__dark_theme">Dark</string>
<string name="preferences__appearance">Appearance</string>
<string name="preferences__theme">Theme</string>
<string name="preferences__default">Default</string>

View File

@ -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];
}
}

View File

@ -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());
}
}

View File

@ -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();