From c6d32ea3fa5e247e22b0de06a9c857b02894a004 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 2 Mar 2012 13:57:15 -0800 Subject: [PATCH] Don't crash when switching to subtasks mode --- .../astrid/activity/TaskListActivity.java | 2 +- .../astrid/activity/TaskListFragment.java | 4 ++-- .../adapter/TaskListFragmentPagerAdapter.java | 16 +++++++++++++++- .../todoroo/astrid/ui/TaskListFragmentPager.java | 6 ++++++ 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java index 00512a349..4c7470614 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListActivity.java @@ -208,7 +208,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener @Override public void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Bundle extras, Class customTaskList) { if (fragmentLayout == LAYOUT_SINGLE) { - tlfPager.showFilter(filter); + tlfPager.showFilterWithCustomTaskList(filter, customTaskList); } else { super.setupTasklistFragmentWithFilterAndCustomTaskList(filter, extras, customTaskList); } diff --git a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java index c261c1afe..d20ab0888 100644 --- a/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskListFragment.java @@ -1202,10 +1202,10 @@ public class TaskListFragment extends ListFragment implements OnScrollListener, protected void toggleDragDrop(boolean newState) { if(newState) - ((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(null, + ((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(filter, extras, SubtasksListFragment.class); else - ((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(null, + ((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(filter, extras, TaskListFragment.class); } diff --git a/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java b/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java index 8ac8bfae8..2d2936b70 100644 --- a/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/TaskListFragmentPagerAdapter.java @@ -16,6 +16,7 @@ import com.todoroo.astrid.api.FilterWithCustomIntent; public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter implements FilterDataSourceChangedListener { private final HashMap positionToFragment; + private final HashMap> customTaskLists; private final FilterAdapter filterAdapter; // Shares an adapter instance with the filter list fragment @@ -24,6 +25,7 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl this.filterAdapter = filterAdapter; filterAdapter.setDataSourceChangedListener(this); positionToFragment = new HashMap(); + customTaskLists = new HashMap>(); } @Override @@ -81,9 +83,21 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl return filterAdapter.getCount(); } + public void setCustomTaskListForFilter(Filter f, Class customTaskList) { + customTaskLists.put(f, customTaskList); + notifyDataSetChanged(); + } + + public void clearCustomTaskListForFilter(Filter f) { + customTaskLists.remove(f); + } + private Fragment getFragmentForFilter(Filter filter) { Bundle extras = getExtrasForFilter(filter); - return TaskListFragment.instantiateWithFilterAndExtras(filter, extras); + Class customList = customTaskLists.get(filter); + if (customList == null) + customList = TaskListFragment.class; + return TaskListFragment.instantiateWithFilterAndExtras(filter, extras, customList); } // Constructs extras corresponding to the specified filter that can be used as arguments to the fragment diff --git a/astrid/src/com/todoroo/astrid/ui/TaskListFragmentPager.java b/astrid/src/com/todoroo/astrid/ui/TaskListFragmentPager.java index 49b2ba36b..407871fb8 100644 --- a/astrid/src/com/todoroo/astrid/ui/TaskListFragmentPager.java +++ b/astrid/src/com/todoroo/astrid/ui/TaskListFragmentPager.java @@ -31,6 +31,12 @@ public class TaskListFragmentPager extends ViewPager { showFilter(adapter.addOrLookup(f)); } + public void showFilterWithCustomTaskList(Filter f, Class customTaskList) { + TaskListFragmentPagerAdapter adapter = (TaskListFragmentPagerAdapter) getAdapter(); + adapter.setCustomTaskListForFilter(f, customTaskList); + showFilter(adapter.addOrLookup(f)); + } + /** * Show the filter at the supplied index, with animation * @param index