Search in sources :

Example 11 with IExpandable

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);
            }
        }
    }
}
Also used : AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) SubItem(eu.davidea.samples.flexibleadapter.items.SubItem) IExpandable(eu.davidea.flexibleadapter.items.IExpandable) ExpandableItem(eu.davidea.samples.flexibleadapter.items.ExpandableItem) SimpleItem(eu.davidea.samples.flexibleadapter.items.SimpleItem)

Aggregations

IExpandable (eu.davidea.flexibleadapter.items.IExpandable)11 SuppressLint (android.annotation.SuppressLint)5 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)1 IHeader (eu.davidea.flexibleadapter.items.IHeader)1 ISectionable (eu.davidea.flexibleadapter.items.ISectionable)1 ExpandableItem (eu.davidea.samples.flexibleadapter.items.ExpandableItem)1 SimpleItem (eu.davidea.samples.flexibleadapter.items.SimpleItem)1 SubItem (eu.davidea.samples.flexibleadapter.items.SubItem)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1