From 62ac52e74016d5f010e2aa09ff12aaf5c882bac2 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 17 Dec 2012 13:27:39 -0800 Subject: [PATCH] Added place in the preferences to set configuration defaults --- astrid/res/values/keys.xml | 6 ++++ astrid/res/values/strings-core.xml | 20 +++++++++--- astrid/res/xml/preferences.xml | 6 ++++ .../astrid/activity/EditPreferences.java | 32 +++++++++++++++++++ .../astrid/utility/AstridPreferenceSpec.java | 2 +- 5 files changed, 61 insertions(+), 5 deletions(-) diff --git a/astrid/res/values/keys.xml b/astrid/res/values/keys.xml index 8dbe7f287..127638102 100644 --- a/astrid/res/values/keys.xml +++ b/astrid/res/values/keys.xml @@ -271,6 +271,12 @@ taskRowPrefs fullTaskTitle + + + p_configurations + p_config_default + p_config_lite + diff --git a/astrid/res/values/strings-core.xml b/astrid/res/values/strings-core.xml index 2c3b07c4a..788b30e49 100644 --- a/astrid/res/values/strings-core.xml +++ b/astrid/res/values/strings-core.xml @@ -752,17 +752,29 @@ Get ideas to help you complete tasks - Calendar event time - End calendar events at due time - Start calendar events at due time + Calendar event time + End calendar events at due time + Start calendar events at due time Use phone layout Show featured lists + + Set configuration + Default + Astrid Lite - + + Set configuration? + + Reset preferences to the %s configuration? + + + default + + Swipe between lists diff --git a/astrid/res/xml/preferences.xml b/astrid/res/xml/preferences.xml index 49aeb7996..686de6a15 100644 --- a/astrid/res/xml/preferences.xml +++ b/astrid/res/xml/preferences.xml @@ -180,6 +180,12 @@ + + + + + diff --git a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java index a418b75c0..e9630092b 100644 --- a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java +++ b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java @@ -66,6 +66,9 @@ import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.sync.SyncProviderPreferences; import com.todoroo.astrid.ui.ContactListAdapter; import com.todoroo.astrid.ui.TaskListFragmentPager; +import com.todoroo.astrid.utility.AstridDefaultPreferenceSpec; +import com.todoroo.astrid.utility.AstridLitePreferenceSpec; +import com.todoroo.astrid.utility.AstridPreferenceSpec; import com.todoroo.astrid.utility.Constants; import com.todoroo.astrid.utility.Flags; import com.todoroo.astrid.voice.VoiceInputAssistant; @@ -121,6 +124,29 @@ public class EditPreferences extends TodorooPreferenceActivity { } } + private class SetDefaultsClickListener implements OnPreferenceClickListener { + private final AstridPreferenceSpec spec; + private final int nameId; + public SetDefaultsClickListener(AstridPreferenceSpec spec, int nameId) { + this.spec = spec; + this.nameId = nameId; + } + + @Override + public boolean onPreferenceClick(Preference preference) { + DialogUtilities.okCancelDialog(EditPreferences.this, getString(R.string.EPr_config_dialog_title), + getString(R.string.EPr_config_dialog_text, getString(nameId)), new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + spec.resetDefaults(); + setResult(RESULT_CODE_PERFORMANCE_PREF_CHANGED); + finish(); + } + }, null); + return true; + } + } + @Override public int getPreferenceResource() { return R.xml.preferences; @@ -644,6 +670,12 @@ public class EditPreferences extends TodorooPreferenceActivity { findPreference(getString(R.string.p_fontSize)).setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(RESULT_CODE_PERFORMANCE_PREF_CHANGED)); + findPreference(getString(R.string.p_config_default)).setOnPreferenceClickListener( + new SetDefaultsClickListener(new AstridDefaultPreferenceSpec(), R.string.EPr_config_dialog_default_id)); + + findPreference(getString(R.string.p_config_lite)).setOnPreferenceClickListener( + new SetDefaultsClickListener(new AstridLitePreferenceSpec(), R.string.EPr_config_lite)); + int[] menuPrefs = { R.string.p_show_menu_search, R.string.p_show_menu_friends, R.string.p_show_featured_lists, R.string.p_show_menu_sync, R.string.p_show_menu_sort, R.string.p_show_menu_addons }; diff --git a/astrid/src/com/todoroo/astrid/utility/AstridPreferenceSpec.java b/astrid/src/com/todoroo/astrid/utility/AstridPreferenceSpec.java index 209241b76..253535fb0 100644 --- a/astrid/src/com/todoroo/astrid/utility/AstridPreferenceSpec.java +++ b/astrid/src/com/todoroo/astrid/utility/AstridPreferenceSpec.java @@ -14,7 +14,7 @@ public abstract class AstridPreferenceSpec { if (ifUnset) Preferences.setIfUnset(prefs, editor, r, key, value); else - Preferences.setInt(r.getString(key), value); + Preferences.setString(r.getString(key), Integer.toString(value)); } protected static void setPreference(SharedPreferences prefs, Editor editor, Resources r, int key, boolean value, boolean ifUnset) {