From 76ac2d53d5da3150c8fbedecc1bd6e933b09fad6 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 9 Aug 2012 13:35:01 -0700 Subject: [PATCH] First pass at a migration for asserting the hide until section always exists --- astrid/res/values/keys.xml | 17 ++------- astrid/res/values/strings-core.xml | 2 + .../astrid/activity/BeastModePreferences.java | 38 +++++++++++++++++++ .../astrid/service/StartupService.java | 3 ++ 4 files changed, 46 insertions(+), 14 deletions(-) diff --git a/astrid/res/values/keys.xml b/astrid/res/values/keys.xml index 5347a322a..7a7bad1b2 100644 --- a/astrid/res/values/keys.xml +++ b/astrid/res/values/keys.xml @@ -408,25 +408,12 @@ @string/TEA_control_lists @string/TEA_control_notes @string/TEA_control_files + @string/TEA_control_hidden_section @string/TEA_control_reminders @string/TEA_control_timer @string/TEA_control_share - - @string/TEA_control_title - @string/TEA_control_who - @string/TEA_control_when - @string/TEA_control_more_section - @string/TEA_control_importance - @string/TEA_control_lists - @string/TEA_control_notes - @string/TEA_control_files - @string/TEA_control_reminders - @string/TEA_control_timer - @string/TEA_control_share - - TEA_ctrl_title_pref TEA_ctrl_who_pref TEA_ctrl_when_pref @@ -436,6 +423,7 @@ TEA_ctrl_lists_pref TEA_ctrl_notes_pref TEA_ctrl_files_pref + TEA_ctrl_hide_section_pref TEA_ctrl_reminders_pref TEA_ctrl_timer_pref TEA_ctrl_share_pref @@ -448,6 +436,7 @@ @string/TEA_ctrl_lists_pref @string/TEA_ctrl_notes_pref @string/TEA_ctrl_files_pref + @string/TEA_ctrl_hide_section_pref @string/TEA_ctrl_reminders_pref @string/TEA_ctrl_timer_pref @string/TEA_ctrl_share_pref diff --git a/astrid/res/values/strings-core.xml b/astrid/res/values/strings-core.xml index a15b55d1c..c8301d1b5 100644 --- a/astrid/res/values/strings-core.xml +++ b/astrid/res/values/strings-core.xml @@ -448,6 +448,8 @@ Share With Friends + ----Hide Always---- + Show in my list diff --git a/astrid/src/com/todoroo/astrid/activity/BeastModePreferences.java b/astrid/src/com/todoroo/astrid/activity/BeastModePreferences.java index 6dd689ee4..dd2f6669d 100644 --- a/astrid/src/com/todoroo/astrid/activity/BeastModePreferences.java +++ b/astrid/src/com/todoroo/astrid/activity/BeastModePreferences.java @@ -12,6 +12,7 @@ import android.app.ListActivity; import android.content.Context; import android.content.res.Resources; import android.os.Bundle; +import android.text.TextUtils; import android.view.MotionEvent; import android.view.View; import android.view.View.OnTouchListener; @@ -36,8 +37,45 @@ public class BeastModePreferences extends ListActivity { public static final String BEAST_MODE_PREF_ITEM_SEPARATOR = ";"; //$NON-NLS-1$ + private static final String BEAST_MODE_ASSERTED_HIDE_ALWAYS = "asserted_hide_always"; //$NON-NLS-1$ + private HashMap prefsToDescriptions; + /** + * Migration for existing users to assert that the "hide always" section divider exists in the preferences. + * Knowing that this section will always be in the constructed list of controls simplifies the logic a bit. + * @param c + */ + public static void assertHideUntilSectionExists(Context c, long latestSetVersion) { + if (latestSetVersion == 0) + Preferences.setBoolean(BEAST_MODE_ASSERTED_HIDE_ALWAYS, true); + + if (Preferences.getBoolean(BEAST_MODE_ASSERTED_HIDE_ALWAYS, false)) + return; + + String order = Preferences.getStringValue(BEAST_MODE_ORDER_PREF); + String hideSectionPref = c.getString(R.string.TEA_ctrl_hide_section_pref); + if (TextUtils.isEmpty(order)) { + // create preference and stick hide always at the end of it + String[] items = c.getResources().getStringArray(R.array.TEA_control_sets_prefs); + StringBuilder builder = new StringBuilder(); + for (String item : items) { + if (item.equals(hideSectionPref)) + continue; + builder.append(item); + builder.append(BEAST_MODE_PREF_ITEM_SEPARATOR); + } + + builder.append(hideSectionPref); + builder.append(BEAST_MODE_PREF_ITEM_SEPARATOR); + } else if (!order.contains(hideSectionPref)) { + order += (hideSectionPref + BEAST_MODE_PREF_ITEM_SEPARATOR); + } + Preferences.setString(BEAST_MODE_ORDER_PREF, order); + + Preferences.setBoolean(BEAST_MODE_ASSERTED_HIDE_ALWAYS, true); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/astrid/src/com/todoroo/astrid/service/StartupService.java b/astrid/src/com/todoroo/astrid/service/StartupService.java index d7ad8a81a..63244802b 100644 --- a/astrid/src/com/todoroo/astrid/service/StartupService.java +++ b/astrid/src/com/todoroo/astrid/service/StartupService.java @@ -37,6 +37,7 @@ import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; import com.todoroo.astrid.actfm.sync.ActFmSyncService; +import com.todoroo.astrid.activity.BeastModePreferences; import com.todoroo.astrid.backup.BackupConstants; import com.todoroo.astrid.backup.BackupService; import com.todoroo.astrid.backup.TasksXmlImporter; @@ -154,6 +155,8 @@ public class StartupService { Preferences.setLong(AstridPreferences.P_FIRST_LAUNCH, 0); } + BeastModePreferences.assertHideUntilSectionExists(context, latestSetVersion); + int version = 0; String versionName = "0"; //$NON-NLS-1$ try {