From c538daf22afe514922a7ca0b431da9071a6b2daa Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 20 Aug 2012 11:20:01 -0700 Subject: [PATCH] Sync should occur after turning on featured lists preference --- .../todoroo/astrid/core/LabsPreferences.java | 31 ++++++++++++------- .../astrid/activity/EditPreferences.java | 10 ++++-- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/core/LabsPreferences.java b/astrid/plugin-src/com/todoroo/astrid/core/LabsPreferences.java index 61ab3680a..acb37155f 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/LabsPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/LabsPreferences.java @@ -24,22 +24,32 @@ public class LabsPreferences extends TodorooPreferenceActivity { return R.xml.preferences_labs; } - public static final int PERFORMANCE_SETTING_CHANGED = 3; + public static final int RESULT_TLA_NEEDS_REFRESH = 3; + public static final int RESULT_NEEDS_SYNC = 4; + + private class SetResultOnPreferenceChangeListener implements OnPreferenceChangeListener { + private final int resultCode; + public SetResultOnPreferenceChangeListener(int resultCode) { + this.resultCode = resultCode; + } - private final OnPreferenceChangeListener settingChangedListener = new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference p, Object newValue) { - setResult(PERFORMANCE_SETTING_CHANGED); + setResult(resultCode); updatePreferences(p, newValue); return true; } - }; + } @Override public void onCreate(android.os.Bundle savedInstanceState) { super.onCreate(savedInstanceState); - EditPreferences.removeForbiddenPreferences(getPreferenceScreen(), getResources()); + + if (!AndroidUtilities.isTabletSized(this)) { + PreferenceScreen screen = getPreferenceScreen(); + screen.removePreference(screen.findPreference(getString(R.string.p_force_phone_layout))); + } } @Override @@ -48,7 +58,7 @@ public class LabsPreferences extends TodorooPreferenceActivity { String key = preference.getKey(); if (r.getString(R.string.p_swipe_lists_performance_key).equals(key)) { - preference.setOnPreferenceChangeListener(settingChangedListener); + preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(RESULT_TLA_NEEDS_REFRESH)); int index = 0; if(value instanceof String && !TextUtils.isEmpty((String)value)) @@ -76,12 +86,9 @@ public class LabsPreferences extends TodorooPreferenceActivity { screen.removePreference(preference); } } else if (r.getString(R.string.p_force_phone_layout).equals(key)) { - if (!AndroidUtilities.isTabletSized(this)) { - PreferenceScreen screen = getPreferenceScreen(); - screen.removePreference(preference); - } else { - preference.setOnPreferenceChangeListener(settingChangedListener); - } + preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(RESULT_TLA_NEEDS_REFRESH)); + } else if (r.getString(R.string.p_show_featured_lists_labs).equals(key)) { + preference.setOnPreferenceChangeListener(new SetResultOnPreferenceChangeListener(RESULT_NEEDS_SYNC)); } } diff --git a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java index 75fd2e6f5..a6e516438 100644 --- a/astrid/src/com/todoroo/astrid/activity/EditPreferences.java +++ b/astrid/src/com/todoroo/astrid/activity/EditPreferences.java @@ -85,7 +85,7 @@ public class EditPreferences extends TodorooPreferenceActivity { private static final int POWER_PACK_PREFERENCE = 5; private static final int REQUEST_CODE_SYNC = 0; - private static final int REQUEST_CODE_PERFORMANCE = 1; + private static final int REQUEST_CODE_LABS = 1; private static final int REQUEST_CODE_FILES_DIR = 2; public static final int RESULT_CODE_THEME_CHANGED = 1; @@ -253,7 +253,7 @@ public class EditPreferences extends TodorooPreferenceActivity { private static final HashMap, Integer> PREFERENCE_REQUEST_CODES = new HashMap, Integer>(); static { PREFERENCE_REQUEST_CODES.put(SyncProviderPreferences.class, REQUEST_CODE_SYNC); - PREFERENCE_REQUEST_CODES.put(LabsPreferences.class, REQUEST_CODE_PERFORMANCE); + PREFERENCE_REQUEST_CODES.put(LabsPreferences.class, REQUEST_CODE_LABS); } private void addPluginPreferences(PreferenceScreen screen) { @@ -494,9 +494,13 @@ public class EditPreferences extends TodorooPreferenceActivity { setResult(SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE); finish(); return; - } else if (requestCode == REQUEST_CODE_PERFORMANCE && resultCode == LabsPreferences.PERFORMANCE_SETTING_CHANGED) { + } else if (requestCode == REQUEST_CODE_LABS && resultCode == LabsPreferences.RESULT_TLA_NEEDS_REFRESH) { setResult(RESULT_CODE_PERFORMANCE_PREF_CHANGED); return; + } else if (requestCode == REQUEST_CODE_LABS && resultCode == LabsPreferences.RESULT_NEEDS_SYNC) { + if (Preferences.getBoolean(R.string.p_show_featured_lists_labs, false)) + setResult(SyncProviderPreferences.RESULT_CODE_SYNCHRONIZE); + return; } else if (requestCode == REQUEST_CODE_FILES_DIR && resultCode == RESULT_OK) { if (data != null) { String dir = data.getStringExtra(FileExplore.RESULT_DIR_SELECTED);