Refactor filter list toggling to support multiple modes

pull/14/head
Sam Bosley 13 years ago
parent 91935162ab
commit 8912fa0491

@ -50,6 +50,7 @@ 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.FeaturedListActivity; import com.todoroo.astrid.tags.reusable.FeaturedListActivity;
import com.todoroo.astrid.tags.reusable.FeaturedListFragment;
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;
@ -69,7 +70,10 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
public static final String OPEN_TASK = "openTask"; //$NON-NLS-1$ public static final String OPEN_TASK = "openTask"; //$NON-NLS-1$
private static final String PEOPLE_VIEW = "peopleView"; //$NON-NLS-1$ private static final String FILTER_MODE = "filterMode"; //$NON-NLS-1$
private static final int FILTER_MODE_NORMAL = 0;
private static final int FILTER_MODE_PEOPLE = 1;
private static final int FILTER_MODE_FEATURED = 2;
@Autowired private ABTestEventReportingService abTestEventReportingService; @Autowired private ABTestEventReportingService abTestEventReportingService;
@ -78,6 +82,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
private TextView lists; private TextView lists;
private ImageView mainMenu; private ImageView mainMenu;
private Button commentsButton; private Button commentsButton;
private int filterMode;
private TaskListFragmentPager tlfPager; private TaskListFragmentPager tlfPager;
private TaskListFragmentPagerAdapter tlfPagerAdapter; private TaskListFragmentPagerAdapter tlfPagerAdapter;
@ -251,6 +256,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
protected void initializeFragments(ActionBar actionBar) { protected void initializeFragments(ActionBar actionBar) {
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);
if (filterFragment != null) { if (filterFragment != null) {
actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false);
@ -267,12 +273,8 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
} }
} }
boolean peopleView = getIntent().getBooleanExtra(PEOPLE_VIEW, false);
Class<? extends FilterListFragment> filterFragmentClass =
peopleView ? PeopleListFragment.class : FilterListFragment.class;
setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT,
R.id.filterlist_fragment_container, filterFragmentClass, false, false); R.id.filterlist_fragment_container, getFilterFragmentClass(filterMode), false, false);
} else { } else {
fragmentLayout = LAYOUT_SINGLE; fragmentLayout = LAYOUT_SINGLE;
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
@ -320,7 +322,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
}); });
if (isTablet) if (isTablet)
setupMainMenuForPeopleViewState(getIntent().getBooleanExtra(PEOPLE_VIEW, false)); refreshMainMenuForFilterMode(filterMode);
} }
private void setupPopoverWithFragment(FragmentPopover popover, Fragment frag, LayoutParams params) { private void setupPopoverWithFragment(FragmentPopover popover, Fragment frag, LayoutParams params) {
@ -635,21 +637,25 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
TaskListFragment tlf = getTaskListFragment(); TaskListFragment tlf = getTaskListFragment();
switch (item) { switch (item) {
case MainMenuPopover.MAIN_MENU_ITEM_LISTS: case MainMenuPopover.MAIN_MENU_ITEM_LISTS:
if (fragmentLayout == LAYOUT_SINGLE) if (fragmentLayout == LAYOUT_SINGLE || filterMode == FILTER_MODE_NORMAL)
listsNav.performClick(); listsNav.performClick();
else else
togglePeopleView(); setFilterMode(FILTER_MODE_NORMAL);
return; return;
case MainMenuPopover.MAIN_MENU_ITEM_SEARCH: case MainMenuPopover.MAIN_MENU_ITEM_SEARCH:
onSearchRequested(); onSearchRequested();
return; return;
case MainMenuPopover.MAIN_MENU_ITEM_FEATURED_LISTS: case MainMenuPopover.MAIN_MENU_ITEM_FEATURED_LISTS:
Intent featured = new Intent(this, FeaturedListActivity.class); if (fragmentLayout != LAYOUT_SINGLE) {
startActivity(featured); setFilterMode(FILTER_MODE_FEATURED);
} else {
Intent featured = new Intent(this, FeaturedListActivity.class);
startActivity(featured);
}
return; return;
case MainMenuPopover.MAIN_MENU_ITEM_FRIENDS: case MainMenuPopover.MAIN_MENU_ITEM_FRIENDS:
if (fragmentLayout != LAYOUT_SINGLE) { if (fragmentLayout != LAYOUT_SINGLE) {
togglePeopleView(); setFilterMode(FILTER_MODE_PEOPLE);
} else { } else {
Intent peopleIntent = new Intent(this, PeopleViewActivity.class); Intent peopleIntent = new Intent(this, PeopleViewActivity.class);
startActivity(peopleIntent); startActivity(peopleIntent);
@ -666,27 +672,28 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
tlf.handleOptionsMenuItemSelected(item, customIntent); tlf.handleOptionsMenuItemSelected(item, customIntent);
} }
private void togglePeopleView() { private Class<? extends FilterListFragment> getFilterFragmentClass(int mode) {
FilterListFragment flf = getFilterListFragment(); switch (mode) {
boolean peopleMode = !(flf instanceof PeopleListFragment); case FILTER_MODE_PEOPLE:
if (peopleMode) return PeopleListFragment.class;
setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, R.id.filterlist_fragment_container, case FILTER_MODE_FEATURED:
PeopleListFragment.class, false, true); return FeaturedListFragment.class;
else case FILTER_MODE_NORMAL:
setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, default:
R.id.filterlist_fragment_container, FilterListFragment.class, false, true); return FilterListFragment.class;
}
setupMainMenuForPeopleViewState(peopleMode);
getIntent().putExtra(PEOPLE_VIEW, peopleMode);
} }
private void setupMainMenuForPeopleViewState(boolean inPeopleMode) { private void setFilterMode(int mode) {
mainMenuPopover.setFixedItemVisibility(0, inPeopleMode ? View.VISIBLE : View.GONE, true); filterMode = mode;
mainMenuPopover.setFixedItemVisibility(1, inPeopleMode ? View.GONE : View.VISIBLE, true); setupFragment(FilterListFragment.TAG_FILTERLIST_FRAGMENT, R.id.filterlist_fragment_container,
getFilterFragmentClass(mode), false, true);
refreshMainMenuForFilterMode(mode);
getIntent().putExtra(FILTER_MODE, mode);
}
TypedValue tv = new TypedValue(); private void refreshMainMenuForFilterMode(int filterMode) {
getTheme().resolveAttribute(inPeopleMode ? R.attr.asPeopleMenu : R.attr.asMainMenu, tv, false); // TODO: IMPLEMENT ME!
mainMenu.setImageResource(tv.data);
} }
public MainMenuPopover getMainMenuPopover() { public MainMenuPopover getMainMenuPopover() {

Loading…
Cancel
Save