Finished implementing filter mode specs for all three filter modes

pull/14/head
Sam Bosley 13 years ago
parent f1cffcc704
commit 7cb1a40923

@ -2,6 +2,7 @@ package com.todoroo.astrid.people;
import android.content.Context; import android.content.Context;
import com.timsu.astrid.R;
import com.todoroo.astrid.activity.FilterListFragment; import com.todoroo.astrid.activity.FilterListFragment;
import com.todoroo.astrid.activity.FilterModeSpec; import com.todoroo.astrid.activity.FilterModeSpec;
import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.activity.TaskListFragment;
@ -45,6 +46,11 @@ public class PeopleFilterMode implements FilterModeSpec {
return FORBIDDEN_MENU_ITEMS; return FORBIDDEN_MENU_ITEMS;
} }
@Override
public int getMainMenuIconAttr() {
return R.attr.asPeopleMenu;
}
private static final int[] FORBIDDEN_MENU_ITEMS = { private static final int[] FORBIDDEN_MENU_ITEMS = {
TaskListFragment.MENU_NEW_FILTER_ID, TaskListFragment.MENU_NEW_FILTER_ID,
TaskListFragment.MENU_ADDONS_ID, TaskListFragment.MENU_ADDONS_ID,

@ -60,7 +60,7 @@ public class TagFilterExposer extends BroadcastReceiver implements AstridFilterE
private static final String TAG = "tag"; //$NON-NLS-1$ private static final String TAG = "tag"; //$NON-NLS-1$
@Autowired TagDataService tagDataService; @Autowired protected TagDataService tagDataService;
@Autowired GtasksPreferenceService gtasksPreferenceService; @Autowired GtasksPreferenceService gtasksPreferenceService;
protected boolean addUntaggedFilter = true; protected boolean addUntaggedFilter = true;

@ -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<? extends FilterListFragment> 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);
}
}

@ -8,8 +8,11 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.sql.Criterion; 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.andlib.sql.QueryTemplate;
import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.actfm.TagViewFragment;
import com.todoroo.astrid.api.AstridApiConstants; 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.FilterListItem;
import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.api.FilterWithUpdate; import com.todoroo.astrid.api.FilterWithUpdate;
import com.todoroo.astrid.core.PluginServices;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.TagData;
import com.todoroo.astrid.data.TaskApiDao.TaskCriteria; import com.todoroo.astrid.data.TaskApiDao.TaskCriteria;
import com.todoroo.astrid.tags.TagFilterExposer; import com.todoroo.astrid.tags.TagFilterExposer;
import com.todoroo.astrid.tags.TagService; import com.todoroo.astrid.tags.TagService;
@ -59,6 +64,26 @@ public class FeaturedListFilterExposer extends TagFilterExposer {
return filter; return filter;
} }
public static Filter getDefaultFilter() {
TodorooCursor<TagData> 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 @Override
protected Filter constructFilter(Context context, Tag tag) { protected Filter constructFilter(Context context, Tag tag) {
return filterFromFeaturedList(tag, TaskCriteria.activeAndVisible()); return filterFromFeaturedList(tag, TaskCriteria.activeAndVisible());

@ -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<? extends FilterListFragment> 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) {
//
}
}

@ -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<? extends FilterListFragment> 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) {
//
}
}

@ -11,6 +11,7 @@ public interface FilterModeSpec {
public int[] getForbiddenMenuItems(); public int[] getForbiddenMenuItems();
public Class<? extends FilterListFragment> getFilterListClass(); public Class<? extends FilterListFragment> getFilterListClass();
public Filter getDefaultFilter(Context context); public Filter getDefaultFilter(Context context);
public int getMainMenuIconAttr();
public void onFilterItemClickedCallback(FilterListItem item); public void onFilterItemClickedCallback(FilterListItem item);
} }

@ -39,17 +39,15 @@ import com.todoroo.astrid.adapter.TaskListFragmentPagerAdapter;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.core.CoreFilterExposer;
import com.todoroo.astrid.core.CustomFilterExposer; import com.todoroo.astrid.core.CustomFilterExposer;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.people.PeopleFilterMode; import com.todoroo.astrid.people.PeopleFilterMode;
import com.todoroo.astrid.people.PeopleListFragment;
import com.todoroo.astrid.service.StatisticsConstants; import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.StatisticsService;
import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.service.abtesting.ABTestEventReportingService; import com.todoroo.astrid.service.abtesting.ABTestEventReportingService;
import com.todoroo.astrid.tags.TagService; 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.DateChangedAlerts;
import com.todoroo.astrid.ui.FragmentPopover; import com.todoroo.astrid.ui.FragmentPopover;
import com.todoroo.astrid.ui.MainMenuPopover; import com.todoroo.astrid.ui.MainMenuPopover;
@ -223,7 +221,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
} }
protected Filter getDefaultFilter() { protected Filter getDefaultFilter() {
return CoreFilterExposer.buildInboxFilter(getResources()); return filterModeSpec.getDefaultFilter(this);
} }
private boolean swipeIsEnabled() { private boolean swipeIsEnabled() {
@ -257,6 +255,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
View filterFragment = findViewById(R.id.filterlist_fragment_container); View filterFragment = findViewById(R.id.filterlist_fragment_container);
View editFragment = findViewById(R.id.taskedit_fragment_container); View editFragment = findViewById(R.id.taskedit_fragment_container);
filterMode = getIntent().getIntExtra(FILTER_MODE, FILTER_MODE_NORMAL); filterMode = getIntent().getIntExtra(FILTER_MODE, FILTER_MODE_NORMAL);
updateFilterModeSpec(filterMode);
if (filterFragment != null) { if (filterFragment != null) {
actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false);
@ -274,14 +273,14 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
} }
setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT,
R.id.filterlist_fragment_container, getFilterFragmentClass(filterMode), false, false); R.id.filterlist_fragment_container, filterModeSpec.getFilterListClass(), false, false);
} else { } else {
fragmentLayout = LAYOUT_SINGLE; fragmentLayout = LAYOUT_SINGLE;
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
listsNav.setOnClickListener(popupMenuClickListener); listsNav.setOnClickListener(popupMenuClickListener);
createListsPopover(); createListsPopover();
setupPopoverWithFilterList((FilterListFragment) setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, 0, 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); tlf.handleOptionsMenuItemSelected(item, customIntent);
} }
private Class<? extends FilterListFragment> 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) { private void setFilterMode(int mode) {
filterMode = mode; filterMode = mode;
filterModeSpec = getFilterModeSpec(); updateFilterModeSpec(mode);
mainMenuPopover.refreshFixedItems();
refreshMainMenu();
if (fragmentLayout == LAYOUT_SINGLE) { if (fragmentLayout == LAYOUT_SINGLE) {
createListsPopover(); createListsPopover();
setupPopoverWithFilterList((FilterListFragment) setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, 0, setupPopoverWithFilterList((FilterListFragment) setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, 0,
getFilterFragmentClass(filterMode), true, true)); filterModeSpec.getFilterListClass(), true, true));
listsNav.performClick();
} else { } else {
setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, R.id.filterlist_fragment_container, 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); getIntent().putExtra(FILTER_MODE, mode);
} }
private FilterModeSpec getFilterModeSpec() { private void refreshMainMenu() {
switch(filterMode) { 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: case FILTER_MODE_PEOPLE:
return new PeopleFilterMode(); filterModeSpec = new PeopleFilterMode();
break;
case FILTER_MODE_FEATURED:
filterModeSpec = new FeaturedListFilterMode();
break;
case FILTER_MODE_NORMAL:
default: default:
return null; filterModeSpec = new DefaultFilterMode();
} }
} }

Loading…
Cancel
Save