use of eu.davidea.samples.flexibleadapter.items.SubItem in project FlexibleAdapter by davideas.
the class DatabaseService method newExpandableLevelItem.
/*
* Creates a special expandable item which has another level of expandable.
* IMPORTANT: Give different IDs to each child and override getExpansionLevel()!
*/
private ExpandableLevel0Item newExpandableLevelItem(int i) {
// ExpandableLevel0Item is an expandable with Level=0
ExpandableLevel0Item expandableItem = new ExpandableLevel0Item("EI" + i);
expandableItem.setTitle("Expandable Two-Levels " + i);
for (int j = 1; j <= SUB_ITEMS; j++) {
// ExpandableLevel1Item is an expandable as well with Level=1
ExpandableLevel1Item expSubItem = new ExpandableLevel1Item(expandableItem.getId() + "-EII" + j);
expSubItem.setTitle("Expandable Sub Item " + j);
for (int k = 1; k <= 3; k++) {
SubItem subItem = new SubItem(expSubItem.getId() + "-SB" + k);
subItem.setTitle("Simple Sub Item " + k);
expSubItem.addSubItem(subItem);
}
expandableItem.addSubItem(expSubItem);
}
return expandableItem;
}
use of eu.davidea.samples.flexibleadapter.items.SubItem in project FlexibleAdapter by davideas.
the class DatabaseService method newExpandableItem.
/*
* Creates a normal expandable item with some subItems.
* The expandable has a Header linked.
*/
public static ExpandableItem newExpandableItem(int i, IHeader header) {
// Items are expandable because they implements IExpandable
ExpandableItem expandableItem = new ExpandableItem("E" + i, (HeaderItem) header);
expandableItem.setTitle("Expandable Item " + i);
// SubItems are not expandable by default, but they might be if extends/implements IExpandable
for (int j = 1; j <= SUB_ITEMS; j++) {
SubItem subItem = new SubItem(expandableItem.getId() + "-SB" + j);
subItem.setTitle("Sub Item " + j);
expandableItem.addSubItem(subItem);
}
return expandableItem;
}
use of eu.davidea.samples.flexibleadapter.items.SubItem in project FlexibleAdapter by davideas.
the class MainActivity method onActionConfirmed.
@Override
public void onActionConfirmed(@UndoHelper.Action int action, int event) {
if (action == UndoHelper.Action.UPDATE) {
mAdapter.removeItems(mAdapter.getUndoPositions());
}
// Disable Refreshing
mRefreshHandler.sendEmptyMessage(REFRESH_STOP);
// Removing items from Database. Example:
for (AbstractFlexibleItem adapterItem : mAdapter.getDeletedItems()) {
// NEW! You can take advantage of AutoMap and differentiate logic by viewType using "switch" statement
switch(adapterItem.getLayoutRes()) {
case R.layout.recycler_sub_item:
SubItem subItem = (SubItem) adapterItem;
DatabaseService.getInstance().removeSubItem(mAdapter.getExpandableOfDeletedChild(subItem), subItem);
Log.d("Confirm removed %s", subItem);
break;
case R.layout.recycler_simple_item:
case R.layout.recycler_expandable_item:
DatabaseService.getInstance().removeItem(adapterItem);
Log.d("Confirm removed %s", adapterItem);
break;
}
}
}
use of eu.davidea.samples.flexibleadapter.items.SubItem in project FlexibleAdapter by davideas.
the class MainActivity method onDeleteConfirmed.
@Override
public void onDeleteConfirmed(int action) {
// Disable Refreshing
mSwipeRefreshLayout.setRefreshing(false);
// Removing items from Database. Example:
for (AbstractFlexibleItem adapterItem : mAdapter.getDeletedItems()) {
try {
// NEW! You can take advantage of AutoMap and differentiate logic by viewType using "switch" statement
switch(adapterItem.getLayoutRes()) {
case R.layout.recycler_sub_item:
SubItem subItem = (SubItem) adapterItem;
DatabaseService.getInstance().removeSubItem(mAdapter.getExpandableOfDeletedChild(subItem), subItem);
Log.d(TAG, "Confirm removed " + subItem.getTitle());
break;
case R.layout.recycler_expandable_item:
DatabaseService.getInstance().removeItem(adapterItem);
Log.d(TAG, "Confirm removed " + adapterItem);
break;
}
} catch (IllegalStateException e) {
// AutoMap is disabled, fallback to if-else with "instanceof" statement
if (adapterItem instanceof SubItem) {
// SubItem
SubItem subItem = (SubItem) adapterItem;
IExpandable expandable = mAdapter.getExpandableOf(subItem);
DatabaseService.getInstance().removeSubItem(expandable, subItem);
Log.d(TAG, "Confirm removed " + subItem.getTitle());
} else if (adapterItem instanceof SimpleItem || adapterItem instanceof ExpandableItem) {
DatabaseService.getInstance().removeItem(adapterItem);
Log.d(TAG, "Confirm removed " + adapterItem);
}
}
}
}
use of eu.davidea.samples.flexibleadapter.items.SubItem in project FlexibleAdapter by davideas.
the class MainActivity method onItemClick.
/* ========================================================================
* FLEXIBLE ADAPTER LISTENERS IMPLEMENTATION
* Listeners implementation are in MainActivity to easily reuse the common
* components like SwipeToRefresh, ActionMode, NavigationView, etc...
* ======================================================================== */
@Override
public boolean onItemClick(int position) {
IFlexible flexibleItem = mAdapter.getItem(position);
if (flexibleItem instanceof OverallItem) {
OverallItem overallItem = (OverallItem) flexibleItem;
MenuItem menuItem = mNavigationView.getMenu().findItem(overallItem.getId());
onNavigationItemSelected(menuItem);
return false;
}
// Action on elements are allowed if Mode is IDLE, otherwise selection has priority
if (mAdapter.getMode() != SelectableAdapter.MODE_IDLE && mActionModeHelper != null) {
boolean activate = mActionModeHelper.onClick(position);
Log.d(TAG, "Last activated position " + mActionModeHelper.getActivatedPosition());
return activate;
} else {
// Notify the active callbacks or implement a custom action onClick
if (flexibleItem instanceof SimpleItem || flexibleItem instanceof SubItem) {
//TODO FOR YOU: call your custom Action on item click
String title = extractTitleFrom(flexibleItem);
EditItemDialog.newInstance(title, position).show(getFragmentManager(), EditItemDialog.TAG);
}
return false;
}
}
Aggregations