Added some documentation

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

@ -200,6 +200,20 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
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")
public static TaskListFragment instantiateWithFilterAndExtras(Filter filter, Bundle extras, Class<?> customComponent) {
Class<?> component = customComponent;
@ -226,6 +240,17 @@ public class TaskListFragment extends ListFragment implements OnScrollListener,
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
* does during the onAttach() callback

@ -17,7 +17,7 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
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) {
super(fm);
@ -31,6 +31,10 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
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
public Fragment getItem(int position) {
Filter filter = filterAdapter.getItem(position);
@ -39,6 +43,11 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
return fragment;
}
/**
* Lookup the fragment for the specified position
* @param position
* @return
*/
public Fragment lookupFragmentForPosition(int position) {
return positionToFragment.get(position);
}
@ -48,10 +57,21 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
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) {
return filterAdapter.addOrLookup(filter);
}
/**
* Get the filter at the specified position
* @param position
* @return
*/
public Filter getFilter(int position) {
return filterAdapter.getItem(position);
}
@ -63,9 +83,10 @@ public class TaskListFragmentPagerAdapter extends FragmentStatePagerAdapter impl
private Fragment getFragmentForFilter(Filter 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) {
Bundle extras;
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
*/
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
*/
public TaskListFragment getCurrentFragment() {

Loading…
Cancel
Save