use of eu.davidea.samples.flexibleadapter.items.SubItem in project FlexibleAdapter by davideas.
the class MainActivity method onItemClick.
/* ========================================================================
* FLEXIBLE ADAPTER LISTENERS IMPLEMENTATION
* Listeners implementation are in MainActivity to easily reuse the common
* components like SwipeToRefresh, ActionMode, NavigationView, etc...
* ======================================================================== */
@Override
public boolean onItemClick(View view, int position) {
IFlexible flexibleItem = mAdapter.getItem(position);
if (flexibleItem instanceof OverallItem) {
OverallItem overallItem = (OverallItem) flexibleItem;
MenuItem menuItem = mNavigationView.getMenu().findItem(overallItem.getId());
onNavigationItemSelected(menuItem);
return false;
}
// Action on elements are allowed if Mode is IDLE, otherwise selection has priority
if (mAdapter.getMode() != Mode.IDLE && mActionModeHelper != null) {
boolean activate = mActionModeHelper.onClick(position);
Log.d("Last activated position %s", mActionModeHelper.getActivatedPosition());
return activate;
} else {
// Notify the active callbacks or implement a custom action onClick
if (flexibleItem instanceof SimpleItem || flexibleItem instanceof SubItem) {
mRecyclerView.postDelayed(() -> {
Log.d("scroll to position=%s item=%s", position, mAdapter.getItem(position));
int headers = mAdapter.areHeadersSticky() ? 1 : 0;
mRecyclerView.smoothScrollToPosition(Math.max(0, position - headers));
}, 300L);
// //TODO FOR YOU: call your custom Action on item click
// String title = extractTitleFrom(flexibleItem);
// EditItemDialog.newInstance(title, position).show(getFragmentManager(), EditItemDialog.TAG);
}
return false;
}
}
use of eu.davidea.samples.flexibleadapter.items.SubItem 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);
// NOTE: In case you want to retrieve the parent, you can implement ISectionable
// then, assign the Header: ExpandableHeaderItem instance.
// subItem.setHeader(expandableItem);
expandableItem.addSubItem(subItem);
}
return expandableItem;
}
Aggregations