use of eu.davidea.samples.flexibleadapter.items.ExpandableHeaderItem 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);
}
});
}
use of eu.davidea.samples.flexibleadapter.items.ExpandableHeaderItem in project FlexibleAdapter by davideas.
the class DatabaseService method newExpandableSectionItem.
/*
* Creates a special expandable item which is also a Header.
* The subItems will have linked its parent as Header!
*/
public static ExpandableHeaderItem newExpandableSectionItem(int i) {
ExpandableHeaderItem expandableItem = new ExpandableHeaderItem("EH" + i);
expandableItem.setTitle("Expandable Header " + i);
for (int j = 1; j <= SUB_ITEMS; j++) {
SubItem subItem = new SubItem(expandableItem.getId() + "-SB" + j);
subItem.setTitle("Sub Item " + j);
//In this case the Header is the same parent: ExpandableHeaderItem instance
subItem.setHeader(expandableItem);
expandableItem.addSubItem(subItem);
}
return expandableItem;
}
Aggregations