use of eu.davidea.flexibleadapter.items.IExpandable 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