Search in sources :

Example 1 with StaggeredHeaderItem

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

the class FragmentStaggeredLayout method performFabAction.

@Override
public void performFabAction() {
    //Simulate changing status
    StaggeredItemStatus status = StaggeredItemStatus.values()[new Random().nextInt(StaggeredItemStatus.values().length - 1)];
    StaggeredHeaderItem headerItem = DatabaseService.getInstance().getHeaderByStatus(status);
    int scrollTo;
    //   if not yet visible.
    if (mAdapter.getItemCountOfTypes(R.layout.recycler_staggered_item) >= 15) {
        //FAB Action: Move Item
        scrollTo = moveItem(status, headerItem);
    } else // ADD ITEM TO SECTION
    // - Useful only to add new items of every type
    // - Comparator object should sort the Section (in the eventuality the header is hidden)
    //   and the Item into the Section (see the Class ItemComparatorByGroup for an
    //   example of implementation).
    // - The relative header will be automatically displayed too if not yet visible.
    // - if you already know the relative index of the new item, then call the correct
    //   method without the Comparator object.
    {
        // FAB Action: Add Item
        scrollTo = addItem(status, headerItem);
    }
    // Show to the user the result of the addition/changes
    smoothScrollTo(scrollTo, headerItem);
    refreshItem(scrollTo);
    clearEmptySections();
}
Also used : StaggeredHeaderItem(eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem) Random(java.util.Random) StaggeredItemStatus(eu.davidea.samples.flexibleadapter.items.StaggeredItemStatus)

Example 2 with StaggeredHeaderItem

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

the class DatabaseService method createStaggeredDatabase.

/*
	 * List of CardView items
	 */
public void createStaggeredDatabase(Context context) {
    databaseType = DatabaseType.LAYOUT_STAGGERED;
    mItems.clear();
    if (headers == null) {
        headers = new HashMap<StaggeredItemStatus, StaggeredHeaderItem>();
        headers.put(StaggeredItemStatus.A, new StaggeredHeaderItem(0, context.getString(StaggeredItemStatus.A.getResId())));
        headers.put(StaggeredItemStatus.B, new StaggeredHeaderItem(1, context.getString(StaggeredItemStatus.B.getResId())));
        headers.put(StaggeredItemStatus.C, new StaggeredHeaderItem(2, context.getString(StaggeredItemStatus.C.getResId())));
        headers.put(StaggeredItemStatus.D, new StaggeredHeaderItem(3, context.getString(StaggeredItemStatus.D.getResId())));
        headers.put(StaggeredItemStatus.E, new StaggeredHeaderItem(4, context.getString(StaggeredItemStatus.E.getResId())));
    }
    for (int i = 0; i < 15; i++) {
        mItems.add(newStaggeredItem(i + 1, getHeaderByStatus(StaggeredItemStatus.C)));
    }
    createMergedItems();
}
Also used : StaggeredHeaderItem(eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem) StaggeredItemStatus(eu.davidea.samples.flexibleadapter.items.StaggeredItemStatus)

Example 3 with StaggeredHeaderItem

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

the class DatabaseService method resetItems.

public void resetItems() {
    List<StaggeredItem> mergedItems = new ArrayList<>();
    for (AbstractFlexibleItem item : mItems) {
        if (item instanceof StaggeredItem) {
            StaggeredItem staggeredItem = (StaggeredItem) item;
            staggeredItem.setStatus(StaggeredItemStatus.C);
            staggeredItem.setHeader(headers.get(StaggeredItemStatus.C));
            mergedItems.addAll(staggeredItem.splitAllItems());
        }
    }
    for (StaggeredHeaderItem header : headers.values()) {
        header.setHidden(true);
    }
    mItems.addAll(mergedItems);
    Collections.sort(mItems, new ItemComparatorById());
    createMergedItems();
}
Also used : StaggeredHeaderItem(eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem) AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) ArrayList(java.util.ArrayList) StaggeredItem(eu.davidea.samples.flexibleadapter.items.StaggeredItem)

Aggregations

StaggeredHeaderItem (eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem)3 StaggeredItemStatus (eu.davidea.samples.flexibleadapter.items.StaggeredItemStatus)2 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)1 StaggeredItem (eu.davidea.samples.flexibleadapter.items.StaggeredItem)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1