Set summary to value of list preference

pull/253/head
Alex Baker 9 years ago
parent c29efa18fd
commit 7c4bc038ff

@ -5,7 +5,6 @@
*/
package com.todoroo.astrid.core;
import android.content.SharedPreferences.Editor;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.ListPreference;
@ -44,20 +43,12 @@ public class DefaultsPreferences extends InjectingPreferenceActivity {
addPreferencesFromResource(R.xml.preferences_defaults);
initCalendarsPreference((ListPreference) findPreference(getString(R.string.gcal_p_default)));
initListPreference(R.string.p_default_urgency_key, R.array.EPr_default_urgency,
R.array.EPr_default_urgency_values);
initListPreference(R.string.p_default_importance_key, R.array.EPr_default_importance,
R.array.EPr_default_importance_values);
initListPreference(R.string.p_default_hideUntil_key, R.array.EPr_default_hideUntil,
R.array.EPr_default_hideUntil_values);
initListPreference(R.string.p_default_reminders_key, R.array.EPr_default_reminders,
R.array.EPr_default_reminders_values);
initListPreference(R.string.p_default_reminders_mode_key, R.array.EPr_default_reminders_mode,
R.array.EPr_default_reminders_mode_values);
initListPreference(R.string.p_rmd_default_random_hours, R.array.EPr_reminder_random,
R.array.EPr_reminder_random_hours);
Preference defaultCalendarPref = findPreference(getString(R.string.gcal_p_default));
try {
initCalendarsPreference((ListPreference) defaultCalendarPref);
} catch(Exception e) {
log.error(e.getMessage(), e);
}
}
private void setCalendarSummary(Object value) {
@ -67,39 +58,6 @@ public class DefaultsPreferences extends InjectingPreferenceActivity {
listPreference.setSummary(setting);
}
private void initListPreference(int key, final int keyArray, final int valueArray) {
Preference preference = findPreference(getString(key));
preference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
updateTaskListPreference(preference, newValue, keyArray, valueArray);
return true;
}
});
updateTaskListPreference(preference, ((ListPreference) preference).getValue(), keyArray, valueArray);
}
private void updateTaskListPreference(Preference preference, Object value, int keyArray, int valueArray) {
Resources r = getResources();
int index = AndroidUtilities.indexOf(r.getStringArray(valueArray), value);
if(index == -1) {
// force the zeroth index
index = 0;
Editor editor = preference.getEditor();
editor.putString(preference.getKey(), r.getStringArray(valueArray)[0]);
editor.commit();
}
String setting = r.getStringArray(keyArray)[index];
preference.setSummary(setting);
// if user changed the value, refresh task defaults
if(!AndroidUtilities.equals(value, preferences.getStringValue(preference.getKey()))) {
Editor editor = preferences.getPrefs().edit();
editor.putString(preference.getKey(), (String)value);
editor.commit();
}
}
/**
* Appends all user-modifiable calendars to listPreference.
*

@ -12,10 +12,8 @@ import android.preference.Preference;
import android.view.View;
import android.view.ViewGroup;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
import com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider;
import com.todoroo.astrid.utility.TodorooPreferenceActivity;
import org.tasks.R;
@ -28,7 +26,6 @@ import static org.tasks.date.DateTimeUtils.newDate;
public class GtasksPreferences extends TodorooPreferenceActivity {
@Inject GtasksPreferenceService gtasksPreferenceService;
@Inject GtasksSyncV2Provider gtasksSyncV2Provider;
@Inject BackgroundScheduler backgroundScheduler;
private void startSync() {
@ -101,22 +98,11 @@ public class GtasksPreferences extends TodorooPreferenceActivity {
@Override
public void updatePreferences(Preference preference, Object value) {
// interval
if (getString(R.string.gtasks_GPr_interval_key).equals(preference.getKey())) {
updateSyncInterval(preference, value);
} else if (getString(R.string.sync_SPr_status_key).equals(preference.getKey())) {
if (getString(R.string.sync_SPr_status_key).equals(preference.getKey())) {
updateStatus(preference);
}
}
private void updateSyncInterval(Preference preference, Object value) {
int index = AndroidUtilities.indexOf(getResources().getStringArray(R.array.sync_SPr_interval_values), value);
if (index == -1) {
index = 0;
}
preference.setSummary(getResources().getStringArray(R.array.sync_SPr_interval_entries)[index]);
}
private void updateStatus(Preference preference) {
boolean loggedIn = gtasksPreferenceService.isLoggedIn();
String status;

@ -31,4 +31,10 @@ public class MultilineListPreference extends ListPreference {
}
MultilineHelper.makeMultiline(view);
}
@Override
public void setValue(String value) {
super.setValue(value);
setSummary(getEntry());
}
}

@ -431,9 +431,6 @@
<!-- slide 32a: Preference: Show confirmation for smart reminders -->
<string name="EPr_showSmartConfirmation_title">Show confirmation for smart reminders</string>
<!-- slide 34g: Preference: Task List Font Size Description -->
<string name="EPr_fontSize_desc">Font size on the main listing page</string>
<!-- Edit screen preference category -->
<string name="EPr_edit_screen_options">Edit screen options</string>

@ -14,7 +14,6 @@
android:entries="@array/EPr_font_size"
android:entryValues="@array/EPr_font_size"
android:key="@string/p_fontSize"
android:summary="@string/EPr_fontSize_desc"
android:title="@string/EPr_fontSize_title"
android:defaultValue="16"/>

Loading…
Cancel
Save