From 7cb1a40923a64bac51d5e7cd2651e7d7a91d0184 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Wed, 27 Jun 2012 12:00:13 -0700 Subject: [PATCH] Finished implementing filter mode specs for all three filter modes --- .../astrid/people/PeopleFilterMode.java | 6 ++ .../todoroo/astrid/tags/TagFilterExposer.java | 2 +- .../tags/reusable/FeaturedListActivity.java | 39 ------------- .../reusable/FeaturedListFilterExposer.java | 25 ++++++++ .../tags/reusable/FeaturedListFilterMode.java | 53 +++++++++++++++++ .../astrid/activity/DefaultFilterMode.java | 37 ++++++++++++ .../astrid/activity/FilterModeSpec.java | 1 + .../astrid/activity/TaskListActivity.java | 57 ++++++++++--------- 8 files changed, 153 insertions(+), 67 deletions(-) delete mode 100644 astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListActivity.java create mode 100644 astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListFilterMode.java create mode 100644 astrid/src/com/todoroo/astrid/activity/DefaultFilterMode.java diff --git a/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterMode.java b/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterMode.java index c14e60c7c..8828eacfa 100644 --- a/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterMode.java +++ b/astrid/plugin-src/com/todoroo/astrid/people/PeopleFilterMode.java @@ -2,6 +2,7 @@ package com.todoroo.astrid.people; import android.content.Context; +import com.timsu.astrid.R; import com.todoroo.astrid.activity.FilterListFragment; import com.todoroo.astrid.activity.FilterModeSpec; import com.todoroo.astrid.activity.TaskListFragment; @@ -45,6 +46,11 @@ public class PeopleFilterMode implements FilterModeSpec { return FORBIDDEN_MENU_ITEMS; } + @Override + public int getMainMenuIconAttr() { + return R.attr.asPeopleMenu; + } + private static final int[] FORBIDDEN_MENU_ITEMS = { TaskListFragment.MENU_NEW_FILTER_ID, TaskListFragment.MENU_ADDONS_ID, diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/TagFilterExposer.java b/astrid/plugin-src/com/todoroo/astrid/tags/TagFilterExposer.java index f3d9d4dd9..d32a24e77 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/TagFilterExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/TagFilterExposer.java @@ -60,7 +60,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE private static final String TAG = "tag"; //$NON-NLS-1$ - @Autowired TagDataService tagDataService; + @Autowired protected TagDataService tagDataService; @Autowired GtasksPreferenceService gtasksPreferenceService; protected boolean addUntaggedFilter = true; diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListActivity.java b/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListActivity.java deleted file mode 100644 index 6205c8b0d..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListActivity.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.todoroo.astrid.tags.reusable; - -import android.content.Intent; - -import com.todoroo.andlib.utility.AndroidUtilities; -import com.todoroo.astrid.activity.FilterListFragment; -import com.todoroo.astrid.activity.TaskListActivity; -import com.todoroo.astrid.activity.TaskListFragment; -import com.todoroo.astrid.ui.MainMenuPopover; - -public class FeaturedListActivity extends TaskListActivity { - - @Override - protected Class getFilterListClass() { - return FeaturedListFragment.class; - } - - - public static final int[] FORBIDDEN_MENU_ITEMS = { - TaskListFragment.MENU_NEW_FILTER_ID, - TaskListFragment.MENU_ADDONS_ID, - MainMenuPopover.MAIN_MENU_ITEM_FEATURED_LISTS, - }; - - @Override - public boolean shouldAddMenuItem(int itemId) { - return AndroidUtilities.indexOf(FORBIDDEN_MENU_ITEMS, itemId) < 0; - } - - @Override - public void mainMenuItemSelected(int item, Intent customIntent) { - if (item == MainMenuPopover.MAIN_MENU_ITEM_LISTS) { - finish(); - return; - } - - super.mainMenuItemSelected(item, customIntent); - } -} diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListFilterExposer.java b/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListFilterExposer.java index 56b78992d..1677931d2 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListFilterExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListFilterExposer.java @@ -8,8 +8,11 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; +import com.todoroo.andlib.data.TodorooCursor; import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.sql.Criterion; +import com.todoroo.andlib.sql.Functions; +import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.QueryTemplate; import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.api.AstridApiConstants; @@ -17,7 +20,9 @@ import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.api.FilterWithUpdate; +import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.data.Metadata; +import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.data.TaskApiDao.TaskCriteria; import com.todoroo.astrid.tags.TagFilterExposer; import com.todoroo.astrid.tags.TagService; @@ -59,6 +64,26 @@ public class FeaturedListFilterExposer extends TagFilterExposer { return filter; } + public static Filter getDefaultFilter() { + TodorooCursor firstFilter = PluginServices.getTagDataService() + .query(Query.select(TagData.PROPERTIES) + .where(Criterion.and( + Functions.bitwiseAnd(TagData.FLAGS, TagData.FLAG_FEATURED).gt(0), + TagData.DELETION_DATE.eq(0))).limit(1)); + try { + if (firstFilter.getCount() > 0) { + firstFilter.moveToFirst(); + TagData tagData = new TagData(firstFilter); + Tag tag = new Tag(tagData); + return filterFromFeaturedList(tag, TaskCriteria.activeAndVisible()); + } else { + return null; + } + } finally { + firstFilter.close(); + } + } + @Override protected Filter constructFilter(Context context, Tag tag) { return filterFromFeaturedList(tag, TaskCriteria.activeAndVisible()); diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListFilterMode.java b/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListFilterMode.java new file mode 100644 index 000000000..17b88d631 --- /dev/null +++ b/astrid/plugin-src/com/todoroo/astrid/tags/reusable/FeaturedListFilterMode.java @@ -0,0 +1,53 @@ +package com.todoroo.astrid.tags.reusable; + +import android.content.Context; + +import com.timsu.astrid.R; +import com.todoroo.astrid.activity.FilterListFragment; +import com.todoroo.astrid.activity.FilterModeSpec; +import com.todoroo.astrid.activity.TaskListFragment; +import com.todoroo.astrid.api.Filter; +import com.todoroo.astrid.api.FilterListItem; +import com.todoroo.astrid.core.CoreFilterExposer; +import com.todoroo.astrid.ui.MainMenuPopover; + +public class FeaturedListFilterMode implements FilterModeSpec { + + @Override + public int[] getForbiddenMenuItems() { + return FORBIDDEN_MENU_ITEMS; + } + + private static final int[] FORBIDDEN_MENU_ITEMS = { + TaskListFragment.MENU_NEW_FILTER_ID, + TaskListFragment.MENU_ADDONS_ID, + MainMenuPopover.MAIN_MENU_ITEM_FEATURED_LISTS + }; + + @Override + public Class getFilterListClass() { + return FeaturedListFragment.class; + } + + @Override + public Filter getDefaultFilter(Context context) { + Filter defaultFilter = FeaturedListFilterExposer.getDefaultFilter(); + if (defaultFilter == null) + return CoreFilterExposer.buildInboxFilter(context.getResources()); + else + return defaultFilter; + } + + @Override + public int getMainMenuIconAttr() { + return R.attr.asMainMenu; + } + + @Override + public void onFilterItemClickedCallback(FilterListItem item) { + // + } + + + +} diff --git a/astrid/src/com/todoroo/astrid/activity/DefaultFilterMode.java b/astrid/src/com/todoroo/astrid/activity/DefaultFilterMode.java new file mode 100644 index 000000000..7a0c68155 --- /dev/null +++ b/astrid/src/com/todoroo/astrid/activity/DefaultFilterMode.java @@ -0,0 +1,37 @@ +package com.todoroo.astrid.activity; + +import android.content.Context; + +import com.timsu.astrid.R; +import com.todoroo.astrid.api.Filter; +import com.todoroo.astrid.api.FilterListItem; +import com.todoroo.astrid.core.CoreFilterExposer; + +public class DefaultFilterMode implements FilterModeSpec { + + @Override + public int[] getForbiddenMenuItems() { + return new int[0]; + } + + @Override + public Class getFilterListClass() { + return FilterListFragment.class; + } + + @Override + public Filter getDefaultFilter(Context context) { + return CoreFilterExposer.buildInboxFilter(context.getResources()); + } + + @Override + public int getMainMenuIconAttr() { + return R.attr.asMainMenu; + } + + @Override + public void onFilterItemClickedCallback(FilterListItem item) { + // + } + +} diff --git a/astrid/src/com/todoroo/astrid/activity/FilterModeSpec.java b/astrid/src/com/todoroo/astrid/activity/FilterModeSpec.java index 256d2a754..396c5fd8a 100644 --- a/astrid/src/com/todoroo/astrid/activity/FilterModeSpec.java +++ b/astrid/src/com/todoroo/astrid/activity/FilterModeSpec.java @@ -11,6 +11,7 @@ public interface FilterModeSpec { public int[] getForbiddenMenuItems(); public Class getFilterListClass(); public Filter getDefaultFilter(Context context); + public int getMainMenuIconAttr(); public void onFilterItemClickedCallback(FilterListItem item); } diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index 81e91b103..9eba6baf0 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -39,17 +39,15 @@ import com.todoroo.astrid.adapter.TaskListFragmentPagerAdapter; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.FilterListItem; -import com.todoroo.astrid.core.CoreFilterExposer; import com.todoroo.astrid.core.CustomFilterExposer; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.people.PeopleFilterMode; -import com.todoroo.astrid.people.PeopleListFragment; import com.todoroo.astrid.service.StatisticsConstants; import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.service.abtesting.ABTestEventReportingService; import com.todoroo.astrid.tags.TagService; -import com.todoroo.astrid.tags.reusable.FeaturedListFragment; +import com.todoroo.astrid.tags.reusable.FeaturedListFilterMode; import com.todoroo.astrid.ui.DateChangedAlerts; import com.todoroo.astrid.ui.FragmentPopover; import com.todoroo.astrid.ui.MainMenuPopover; @@ -223,7 +221,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener } protected Filter getDefaultFilter() { - return CoreFilterExposer.buildInboxFilter(getResources()); + return filterModeSpec.getDefaultFilter(this); } private boolean swipeIsEnabled() { @@ -257,6 +255,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener View filterFragment = findViewById(R.id.filterlist_fragment_container); View editFragment = findViewById(R.id.taskedit_fragment_container); filterMode = getIntent().getIntExtra(FILTER_MODE, FILTER_MODE_NORMAL); + updateFilterModeSpec(filterMode); if (filterFragment != null) { actionBar.setDisplayHomeAsUpEnabled(false); @@ -274,14 +273,14 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener } setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, - R.id.filterlist_fragment_container, getFilterFragmentClass(filterMode), false, false); + R.id.filterlist_fragment_container, filterModeSpec.getFilterListClass(), false, false); } else { fragmentLayout = LAYOUT_SINGLE; actionBar.setDisplayHomeAsUpEnabled(true); listsNav.setOnClickListener(popupMenuClickListener); createListsPopover(); setupPopoverWithFilterList((FilterListFragment) setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, 0, - getFilterFragmentClass(filterMode), true, false)); + filterModeSpec.getFilterListClass(), true, false)); } } @@ -664,40 +663,44 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener tlf.handleOptionsMenuItemSelected(item, customIntent); } - private Class getFilterFragmentClass(int mode) { - switch (mode) { - case FILTER_MODE_PEOPLE: - return PeopleListFragment.class; - case FILTER_MODE_FEATURED: - return FeaturedListFragment.class; - case FILTER_MODE_NORMAL: - default: - return FilterListFragment.class; - } - } - private void setFilterMode(int mode) { filterMode = mode; - filterModeSpec = getFilterModeSpec(); - mainMenuPopover.refreshFixedItems(); + updateFilterModeSpec(mode); + + refreshMainMenu(); if (fragmentLayout == LAYOUT_SINGLE) { createListsPopover(); setupPopoverWithFilterList((FilterListFragment) setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, 0, - getFilterFragmentClass(filterMode), true, true)); - listsNav.performClick(); + filterModeSpec.getFilterListClass(), true, true)); } else { setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, R.id.filterlist_fragment_container, - getFilterFragmentClass(mode), false, true); + filterModeSpec.getFilterListClass(), false, true); } + + onFilterItemClicked(getDefaultFilter()); + if (fragmentLayout == LAYOUT_SINGLE) + listsNav.performClick(); getIntent().putExtra(FILTER_MODE, mode); } - private FilterModeSpec getFilterModeSpec() { - switch(filterMode) { + private void refreshMainMenu() { + mainMenuPopover.refreshFixedItems(); + TypedValue tv = new TypedValue(); + getTheme().resolveAttribute(filterModeSpec.getMainMenuIconAttr(), tv, false); + mainMenu.setImageResource(tv.data); + } + + private void updateFilterModeSpec(int mode) { + switch(mode) { case FILTER_MODE_PEOPLE: - return new PeopleFilterMode(); + filterModeSpec = new PeopleFilterMode(); + break; + case FILTER_MODE_FEATURED: + filterModeSpec = new FeaturedListFilterMode(); + break; + case FILTER_MODE_NORMAL: default: - return null; + filterModeSpec = new DefaultFilterMode(); } }