Search in sources :

Example 1 with StaggeredItemStatus

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

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

Aggregations

StaggeredHeaderItem (eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem)2 StaggeredItemStatus (eu.davidea.samples.flexibleadapter.items.StaggeredItemStatus)2 Random (java.util.Random)1