Don't crash when switching to subtasks mode

pull/14/head
Sam Bosley 14 years ago
parent 86fbeeba08
commit c6d32ea3fa

@ -208,7 +208,7 @@ public class TaskListActivity extends AstridActivity implements MainMenuListener
@Override @Override
public void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Bundle extras, Class<?> customTaskList) { public void setupTasklistFragmentWithFilterAndCustomTaskList(Filter filter, Bundle extras, Class<?> customTaskList) {
if (fragmentLayout == LAYOUT_SINGLE) { if (fragmentLayout == LAYOUT_SINGLE) {
tlfPager.showFilter(filter); tlfPager.showFilterWithCustomTaskList(filter, customTaskList);
} else { } else {
super.setupTasklistFragmentWithFilterAndCustomTaskList(filter, extras, customTaskList); super.setupTasklistFragmentWithFilterAndCustomTaskList(filter, extras, customTaskList);
} }

@ -1202,10 +1202,10 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
protected void toggleDragDrop(boolean newState) { protected void toggleDragDrop(boolean newState) {
if(newState) if(newState)
((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(null, ((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(filter,
extras, SubtasksListFragment.class); extras, SubtasksListFragment.class);
else else
((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(null, ((AstridActivity)getActivity()).setupTasklistFragmentWithFilterAndCustomTaskList(filter,
extras, TaskListFragment.class); extras, TaskListFragment.class);
} }

@ -16,6 +16,7 @@ import com.todoroo.astrid.api.FilterWithCustomIntent;
public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter implements FilterDataSourceChangedListener { public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter implements FilterDataSourceChangedListener {
private final HashMap<Integer, Fragment> positionToFragment; private final HashMap<Integer, Fragment> positionToFragment;
private final HashMap<Filter, Class<?>> customTaskLists;
private final FilterAdapter filterAdapter; // Shares an adapter instance with the filter list fragment 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; this.filterAdapter = filterAdapter;
filterAdapter.setDataSourceChangedListener(this); filterAdapter.setDataSourceChangedListener(this);
positionToFragment = new HashMap<Integer, Fragment>(); positionToFragment = new HashMap<Integer, Fragment>();
customTaskLists = new HashMap<Filter, Class<?>>();
} }
@Override @Override
@ -81,9 +83,21 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
return filterAdapter.getCount(); 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) { private Fragment getFragmentForFilter(Filter filter) {
Bundle extras = getExtrasForFilter(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 // Constructs extras corresponding to the specified filter that can be used as arguments to the fragment

@ -31,6 +31,12 @@ public class TaskListFragmentPager extends ViewPager {
showFilter(adapter.addOrLookup(f)); 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 * Show the filter at the supplied index, with animation
* @param index * @param index

Loading…
Cancel
Save