Search in sources :

Example 1 with AbstractItem

use of eu.davidea.samples.flexibleadapter.items.AbstractItem in project FlexibleAdapter by davideas.

the class DatabaseService method updateNewItems.

/**
 * This demonstrates that new content of existing items are really rebound and
 * notified with CHANGE Payload in the Adapter list when refreshed.
 */
public void updateNewItems() {
    IHeader header = null;
    for (IFlexible iFlexible : mItems) {
        if (iFlexible instanceof AbstractItem) {
            AbstractItem item = (AbstractItem) iFlexible;
            item.increaseUpdates();
        }
        if (iFlexible instanceof ISectionable) {
            IHeader newHeader = ((ISectionable) iFlexible).getHeader();
            if (newHeader instanceof HeaderItem && !newHeader.equals(header)) {
                header = newHeader;
                HeaderItem headerItem = (HeaderItem) header;
                headerItem.increaseUpdates();
            }
        }
    }
}
Also used : IHeader(eu.davidea.flexibleadapter.items.IHeader) IFlexible(eu.davidea.flexibleadapter.items.IFlexible) AbstractItem(eu.davidea.samples.flexibleadapter.items.AbstractItem) InstagramHeaderItem(eu.davidea.samples.flexibleadapter.items.InstagramHeaderItem) StaggeredHeaderItem(eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem) ExpandableHeaderItem(eu.davidea.samples.flexibleadapter.items.ExpandableHeaderItem) HeaderItem(eu.davidea.samples.flexibleadapter.items.HeaderItem) ISectionable(eu.davidea.flexibleadapter.items.ISectionable)

Example 2 with AbstractItem

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

use of eu.davidea.samples.flexibleadapter.items.AbstractItem in project FlexibleAdapter by davideas.

the class MainActivity method onTitleModified.

/* ===============================================================
	 * DIALOG LISTENER IMPLEMENTATION (For the example of onItemClick)
	 * =============================================================== */
@Override
public void onTitleModified(int position, String newTitle) {
    AbstractFlexibleItem abstractItem = mAdapter.getItem(position);
    assert abstractItem != null;
    if (abstractItem instanceof AbstractItem) {
        AbstractItem exampleItem = (AbstractItem) abstractItem;
        exampleItem.setTitle(newTitle);
    } else if (abstractItem instanceof HeaderItem) {
        HeaderItem headerItem = (HeaderItem) abstractItem;
        headerItem.setTitle(newTitle);
    }
    mAdapter.updateItem(position, abstractItem, null);
}
Also used : AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) AbstractItem(eu.davidea.samples.flexibleadapter.items.AbstractItem) HeaderItem(eu.davidea.samples.flexibleadapter.items.HeaderItem)

Aggregations

AbstractItem (eu.davidea.samples.flexibleadapter.items.AbstractItem)3 HeaderItem (eu.davidea.samples.flexibleadapter.items.HeaderItem)3 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)1 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)1 IHeader (eu.davidea.flexibleadapter.items.IHeader)1 ISectionable (eu.davidea.flexibleadapter.items.ISectionable)1 ExpandableHeaderItem (eu.davidea.samples.flexibleadapter.items.ExpandableHeaderItem)1 ExpandableItem (eu.davidea.samples.flexibleadapter.items.ExpandableItem)1 InstagramHeaderItem (eu.davidea.samples.flexibleadapter.items.InstagramHeaderItem)1 StaggeredHeaderItem (eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem)1