From f0ff251bdaced1dfd5f8147c996bfb0c74c3700a Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Wed, 27 Jun 2012 16:33:59 -0700 Subject: [PATCH] Refresh the main menu after sync, only show featured lists when necessary --- .../todoroo/astrid/actfm/sync/ActFmSyncService.java | 3 +++ astrid/res/values/keys.xml | 3 +++ .../todoroo/astrid/activity/TaskListActivity.java | 2 +- .../todoroo/astrid/activity/TaskListFragment.java | 4 +++- .../src/com/todoroo/astrid/ui/MainMenuPopover.java | 7 ++++--- .../todoroo/astrid/utility/AstridPreferences.java | 12 ++++++++++++ 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index 0d2dd8f9a..4747b17c7 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -842,6 +842,9 @@ public final class ActFmSyncService { JSONObject result = actFmInvoker.invoke("featured_lists", "token", token, "modified_after", serverTime); JSONArray featuredLists = result.getJSONArray("list"); + if (featuredLists.length() > 0) + Preferences.setBoolean(R.string.p_show_featured_lists, true); + for (int i = 0; i < featuredLists.length(); i++) { JSONObject featObject = featuredLists.getJSONObject(i); actFmDataService.saveFeaturedList(featObject); diff --git a/astrid/res/values/keys.xml b/astrid/res/values/keys.xml index 5347a322a..1f4b21be2 100644 --- a/astrid/res/values/keys.xml +++ b/astrid/res/values/keys.xml @@ -51,6 +51,9 @@ show_friends_view + + + show_featured_lists third_party_addons diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index d04ea1b2d..bc9688c23 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -695,7 +695,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener getIntent().putExtra(FILTER_MODE, mode); } - private void refreshMainMenu() { + public void refreshMainMenu() { mainMenuPopover.refreshFixedItems(); TypedValue tv = new TypedValue(); getTheme().resolveAttribute(filterModeSpec.getMainMenuIconAttr(), tv, false); diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index 7cc0cc1fc..710d48176 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -696,12 +696,14 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, || !AstridApiConstants.BROADCAST_EVENT_REFRESH.equals(intent.getAction())) return; - Activity activity = getActivity(); + final Activity activity = getActivity(); if (activity != null) { activity.runOnUiThread(new Runnable() { @Override public void run() { refresh(); + if (activity instanceof TaskListActivity) + ((TaskListActivity) activity).refreshMainMenu(); } }); } diff --git a/astrid/src/com/todoroo/astrid/ui/MainMenuPopover.java b/astrid/src/com/todoroo/astrid/ui/MainMenuPopover.java index 566619310..c06efc866 100644 --- a/astrid/src/com/todoroo/astrid/ui/MainMenuPopover.java +++ b/astrid/src/com/todoroo/astrid/ui/MainMenuPopover.java @@ -111,9 +111,10 @@ public class MainMenuPopover extends FragmentPopover implements InterceptTouchLi ThemeService.getDrawable(R.drawable.icn_menu_friends, themeFlags), MAIN_MENU_ITEM_FRIENDS, null, topFixed); - addMenuItem(R.string.TLA_menu_featured_lists, - ThemeService.getDrawable(R.drawable.icn_featured_lists, themeFlags), - MAIN_MENU_ITEM_FEATURED_LISTS, null, topFixed); + if (Preferences.getBoolean(R.string.p_show_featured_lists, false)) + addMenuItem(R.string.TLA_menu_featured_lists, + ThemeService.getDrawable(R.drawable.icn_featured_lists, themeFlags), + MAIN_MENU_ITEM_FEATURED_LISTS, null, topFixed); addMenuItem(R.string.TLA_menu_search, ThemeService.getDrawable(R.drawable.icn_menu_search, themeFlags), diff --git a/astrid/src/com/todoroo/astrid/utility/AstridPreferences.java b/astrid/src/com/todoroo/astrid/utility/AstridPreferences.java index f69221f68..1bb3f2928 100644 --- a/astrid/src/com/todoroo/astrid/utility/AstridPreferences.java +++ b/astrid/src/com/todoroo/astrid/utility/AstridPreferences.java @@ -8,10 +8,12 @@ import android.content.res.Resources; import com.timsu.astrid.R; import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.ContextManager; +import com.todoroo.andlib.sql.Functions; import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.core.PluginServices; +import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.User; import com.todoroo.astrid.service.ThemeService; @@ -76,6 +78,16 @@ public class AstridPreferences { } Preferences.setBoolean(R.string.p_show_friends_view, showFriends); + boolean showFeaturedLists = false; + TodorooCursor featLists = PluginServices.getTagDataService().query(Query.select(TagData.ID) + .where(Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_FEATURED).gt(0)).limit(1)); + try { + showFeaturedLists = featLists.getCount() > 0; + } finally { + featLists.close(); + } + Preferences.setBoolean(R.string.p_show_featured_lists, showFeaturedLists); + editor.commit(); }