Added some documentation

pull/14/head
Sam Bosley 14 years ago
parent 661ccf5696
commit 1593c28042

@ -200,6 +200,20 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
AstridDependencyInjector.initialize(); AstridDependencyInjector.initialize();
} }
/**
* Instantiates and returns an instance of TaskListFragment (or some subclass). Custom types of
* TaskListFragment can be created, with the following precedence:
*
* --If the filter is of type {@link FilterWithCustomIntent}, the task list type it specifies will be used
* --Otherwise, the specified customComponent will be used
*
* See also: instantiateWithFilterAndExtras(Filter, Bundle) which uses TaskListFragment as the default
* custom component.
* @param filter
* @param extras
* @param customComponent
* @return
*/
@SuppressWarnings("nls") @SuppressWarnings("nls")
public static TaskListFragment instantiateWithFilterAndExtras(Filter filter, Bundle extras, Class<?> customComponent) { public static TaskListFragment instantiateWithFilterAndExtras(Filter filter, Bundle extras, Class<?> customComponent) {
Class<?> component = customComponent; Class<?> component = customComponent;
@ -226,6 +240,17 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
return newFragment; return newFragment;
} }
/**
* Convenience method for calling instantiateWithFilterAndExtras(Filter, Bundle, Class<?>) with
* TaskListFragment as the default component
* @param filter
* @param extras
* @return
*/
public static TaskListFragment instantiateWithFilterAndExtras(Filter filter, Bundle extras) {
return instantiateWithFilterAndExtras(filter, extras, TaskListFragment.class);
}
/** /**
* Container Activity must implement this interface and we ensure that it * Container Activity must implement this interface and we ensure that it
* does during the onAttach() callback * does during the onAttach() callback

@ -17,7 +17,7 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
private final HashMap<Integer, Fragment> positionToFragment; private final HashMap<Integer, Fragment> positionToFragment;
private final FilterAdapter filterAdapter; private final FilterAdapter filterAdapter; // Shares an adapter instance as the filter list fragment
public TaskListFragmentPagerAdapter(FragmentManager fm, FilterAdapter filterAdapter) { public TaskListFragmentPagerAdapter(FragmentManager fm, FilterAdapter filterAdapter) {
super(fm); super(fm);
@ -31,6 +31,10 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
notifyDataSetChanged(); notifyDataSetChanged();
} }
/**
* Instantiates and returns a fragment for the filter at the specified position.
* Also maps the position to the fragment in a cache for later lookup
*/
@Override @Override
public Fragment getItem(int position) { public Fragment getItem(int position) {
Filter filter = filterAdapter.getItem(position); Filter filter = filterAdapter.getItem(position);
@ -39,6 +43,11 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
return fragment; return fragment;
} }
/**
* Lookup the fragment for the specified position
* @param position
* @return
*/
public Fragment lookupFragmentForPosition(int position) { public Fragment lookupFragmentForPosition(int position) {
return positionToFragment.get(position); return positionToFragment.get(position);
} }
@ -48,10 +57,21 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
return filterAdapter.getItem(position).title; return filterAdapter.getItem(position).title;
} }
/**
* Adds the specified filter to the data source if it doesn't exist,
* returning the position of that filter regardless
* @param filter
* @return
*/
public int addOrLookup(Filter filter) { public int addOrLookup(Filter filter) {
return filterAdapter.addOrLookup(filter); return filterAdapter.addOrLookup(filter);
} }
/**
* Get the filter at the specified position
* @param position
* @return
*/
public Filter getFilter(int position) { public Filter getFilter(int position) {
return filterAdapter.getItem(position); return filterAdapter.getItem(position);
} }
@ -63,9 +83,10 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
private Fragment getFragmentForFilter(Filter filter) { private Fragment getFragmentForFilter(Filter filter) {
Bundle extras = getExtrasForFilter(filter); Bundle extras = getExtrasForFilter(filter);
return TaskListFragment.instantiateWithFilterAndExtras(filter, extras, TaskListFragment.class); return TaskListFragment.instantiateWithFilterAndExtras(filter, extras);
} }
// Constructs extras corresponding to the specified filter that can be used as arguments to the fragment
private Bundle getExtrasForFilter(Filter filter) { private Bundle getExtrasForFilter(Filter filter) {
Bundle extras; Bundle extras;
if (filter instanceof FilterWithCustomIntent) { if (filter instanceof FilterWithCustomIntent) {

@ -32,7 +32,7 @@ public class TaskListFragmentPager extends ViewPager {
} }
/** /**
* Show the filter at the supplied index * Show the filter at the supplied index, with animation
* @param index * @param index
*/ */
public void showFilter(int index) { public void showFilter(int index) {
@ -40,7 +40,7 @@ public class TaskListFragmentPager extends ViewPager {
} }
/** /**
* Returns a reference to the currently showing fragment * Returns the currently showing fragment
* @return * @return
*/ */
public TaskListFragment getCurrentFragment() { public TaskListFragment getCurrentFragment() {

Loading…
Cancel
Save