Search in sources :

Example 1 with HeaderItem

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

the class DatabaseService method newHeader.

/*---------------*/
/* ITEM CREATION */
/*---------------*/
/*
	 * Creates a Header item.
	 */
public static HeaderItem newHeader(int i) {
    HeaderItem header = new HeaderItem("H" + i);
    header.setTitle("Header " + i);
    //header is hidden and un-selectable by default!
    return header;
}
Also used : 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)

Example 2 with HeaderItem

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

the class DatabaseService method createHeadersSectionsDatabase.

/*
	 * List of Simple Items with Header attached. Only Simple Items will be added to the list.
	 */
public void createHeadersSectionsDatabase(int size, int headers) {
    databaseType = DatabaseType.HEADERS_SECTIONS;
    HeaderItem header = null;
    mItems.clear();
    int lastHeaderId = 0;
    for (int i = 0; i < size; i++) {
        header = i % Math.round(size / headers) == 0 ? newHeader(++lastHeaderId) : header;
        mItems.add(newSimpleItem(i + 1, header));
    }
}
Also used : 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)

Example 3 with HeaderItem

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

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

Example 5 with HeaderItem

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

the class FragmentViewPager method createList.

private List<IFlexible> createList(int size, int headers) {
    HeaderItem header = null;
    List<IFlexible> items = new ArrayList<>();
    int lastHeaderId = 0;
    for (int i = 0; i < size; i++) {
        header = i % Math.round(size / headers) == 0 ? DatabaseService.newHeader(++lastHeaderId) : header;
        items.add(DatabaseService.newSimpleItem(i + 1, header));
    }
    return items;
}
Also used : ArrayList(java.util.ArrayList) IFlexible(eu.davidea.flexibleadapter.items.IFlexible) HeaderItem(eu.davidea.samples.flexibleadapter.items.HeaderItem)

Aggregations

HeaderItem (eu.davidea.samples.flexibleadapter.items.HeaderItem)5 AbstractItem (eu.davidea.samples.flexibleadapter.items.AbstractItem)2 ExpandableHeaderItem (eu.davidea.samples.flexibleadapter.items.ExpandableHeaderItem)2 InstagramHeaderItem (eu.davidea.samples.flexibleadapter.items.InstagramHeaderItem)2 StaggeredHeaderItem (eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem)2 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)1 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)1 ExpandableItem (eu.davidea.samples.flexibleadapter.items.ExpandableItem)1 ArrayList (java.util.ArrayList)1