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