use of eu.davidea.samples.flexibleadapter.items.ExpandableItem in project FlexibleAdapter by davideas.
the class DatabaseService method newExpandableItem.
/*
* Creates a normal expandable item with some subItems.
* The expandable has a Header linked.
*/
public static ExpandableItem newExpandableItem(int i, IHeader header) {
// Items are expandable because they implements IExpandable
ExpandableItem expandableItem = new ExpandableItem("E" + i, (HeaderItem) header);
expandableItem.setTitle("Expandable Item " + i);
// SubItems are not expandable by default, but they might be if extends/implements IExpandable
for (int j = 1; j <= SUB_ITEMS; j++) {
SubItem subItem = new SubItem(expandableItem.getId() + "-SB" + j);
subItem.setTitle("Sub Item " + j);
expandableItem.addSubItem(subItem);
}
return expandableItem;
}
use of eu.davidea.samples.flexibleadapter.items.ExpandableItem in project FlexibleAdapter by davideas.
the class MainActivity method extractTitleFrom.
private String extractTitleFrom(IFlexible flexibleItem) {
if (flexibleItem instanceof AbstractItem) {
AbstractItem exampleItem = (AbstractItem) flexibleItem;
String title = exampleItem.getTitle();
if (exampleItem instanceof ExpandableItem) {
ExpandableItem expandableItem = (ExpandableItem) flexibleItem;
if (expandableItem.getSubItems() != null) {
title += "(+" + expandableItem.getSubItems().size() + ")";
}
}
return title;
} else if (flexibleItem instanceof HeaderItem) {
HeaderItem headerItem = (HeaderItem) flexibleItem;
return headerItem.getTitle();
}
// We already covered all situations with instanceof
return "";
}
use of eu.davidea.samples.flexibleadapter.items.ExpandableItem in project FlexibleAdapter by davideas.
the class MainActivity method onDeleteConfirmed.
@Override
public void onDeleteConfirmed(int action) {
// Disable Refreshing
mSwipeRefreshLayout.setRefreshing(false);
// Removing items from Database. Example:
for (AbstractFlexibleItem adapterItem : mAdapter.getDeletedItems()) {
try {
// NEW! You can take advantage of AutoMap and differentiate logic by viewType using "switch" statement
switch(adapterItem.getLayoutRes()) {
case R.layout.recycler_sub_item:
SubItem subItem = (SubItem) adapterItem;
DatabaseService.getInstance().removeSubItem(mAdapter.getExpandableOfDeletedChild(subItem), subItem);
Log.d(TAG, "Confirm removed " + subItem.getTitle());
break;
case R.layout.recycler_expandable_item:
DatabaseService.getInstance().removeItem(adapterItem);
Log.d(TAG, "Confirm removed " + adapterItem);
break;
}
} catch (IllegalStateException e) {
// AutoMap is disabled, fallback to if-else with "instanceof" statement
if (adapterItem instanceof SubItem) {
// SubItem
SubItem subItem = (SubItem) adapterItem;
IExpandable expandable = mAdapter.getExpandableOf(subItem);
DatabaseService.getInstance().removeSubItem(expandable, subItem);
Log.d(TAG, "Confirm removed " + subItem.getTitle());
} else if (adapterItem instanceof SimpleItem || adapterItem instanceof ExpandableItem) {
DatabaseService.getInstance().removeItem(adapterItem);
Log.d(TAG, "Confirm removed " + adapterItem);
}
}
}
}
Aggregations