use of eu.davidea.flexibleadapter.items.ISectionable in project FlexibleAdapter by davideas.
the class FragmentHeadersSections method onParameterSelected.
@Override
public void onParameterSelected(int itemType, int referencePosition, int childPosition) {
if (referencePosition < 0)
return;
int scrollTo, id;
IHeader referenceHeader = getReferenceList().get(referencePosition);
Log.d(TAG, "Adding New Item: ItemType=" + itemType + " referencePosition=" + referencePosition + " childPosition=" + childPosition);
switch(itemType) {
case //Expandable
1:
id = mAdapter.getItemCountOfTypes(R.layout.recycler_expandable_item) + 1;
ISectionable sectionableExpandable = DatabaseService.newExpandableItem(id, referenceHeader);
mAdapter.addItemToSection(sectionableExpandable, referenceHeader, childPosition);
scrollTo = mAdapter.getGlobalPositionOf(referenceHeader);
break;
case //Expandable Header
2:
id = mAdapter.getItemCountOfTypes(R.layout.recycler_expandable_header_item) + 1;
ExpandableHeaderItem expandableHeader = DatabaseService.newExpandableSectionItem(id);
expandableHeader.setExpanded(false);
mAdapter.addSection(expandableHeader, referenceHeader);
scrollTo = mAdapter.getGlobalPositionOf(expandableHeader);
break;
case //Header
3:
id = mAdapter.getItemCountOfTypes(R.layout.recycler_header_item) + 1;
IHeader header = DatabaseService.newHeader(id);
mAdapter.addSection(header, referenceHeader);
scrollTo = mAdapter.getGlobalPositionOf(header);
break;
default:
//case 0 = Simple Item
id = mAdapter.getItemCountOfTypes(R.layout.recycler_expandable_item) + 1;
ISectionable sectionable = DatabaseService.newSimpleItem(id, referenceHeader);
mAdapter.addItemToSection(sectionable, referenceHeader, childPosition);
scrollTo = mAdapter.getGlobalPositionOf(referenceHeader);
}
// With Sticky Headers enabled, this seems necessary to give
// time at the RV to be in correct state before scrolling
final int scrollToFinal = scrollTo;
mRecyclerView.post(new Runnable() {
@Override
public void run() {
mRecyclerView.smoothScrollToPosition(scrollToFinal);
}
});
}
Aggregations