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