Search in sources :

Example 1 with ExpandableItem

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

Example 2 with 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 "";
}
Also used : ExpandableItem(eu.davidea.samples.flexibleadapter.items.ExpandableItem) AbstractItem(eu.davidea.samples.flexibleadapter.items.AbstractItem) HeaderItem(eu.davidea.samples.flexibleadapter.items.HeaderItem)

Example 3 with ExpandableItem

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);
            }
        }
    }
}
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

ExpandableItem (eu.davidea.samples.flexibleadapter.items.ExpandableItem)3 SubItem (eu.davidea.samples.flexibleadapter.items.SubItem)2 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)1 IExpandable (eu.davidea.flexibleadapter.items.IExpandable)1 AbstractItem (eu.davidea.samples.flexibleadapter.items.AbstractItem)1 AnimatorExpandableItem (eu.davidea.samples.flexibleadapter.items.AnimatorExpandableItem)1 AnimatorSubItem (eu.davidea.samples.flexibleadapter.items.AnimatorSubItem)1 HeaderItem (eu.davidea.samples.flexibleadapter.items.HeaderItem)1 SimpleItem (eu.davidea.samples.flexibleadapter.items.SimpleItem)1