Search in sources :

Example 1 with SubItem

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;
}
Also used : AnimatorSubItem(eu.davidea.samples.flexibleadapter.items.AnimatorSubItem) SubItem(eu.davidea.samples.flexibleadapter.items.SubItem) ExpandableLevel0Item(eu.davidea.samples.flexibleadapter.items.ExpandableLevel0Item) ExpandableLevel1Item(eu.davidea.samples.flexibleadapter.items.ExpandableLevel1Item)

Example 2 with SubItem

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;
}
Also used : AnimatorSubItem(eu.davidea.samples.flexibleadapter.items.AnimatorSubItem) SubItem(eu.davidea.samples.flexibleadapter.items.SubItem) ExpandableItem(eu.davidea.samples.flexibleadapter.items.ExpandableItem) AnimatorExpandableItem(eu.davidea.samples.flexibleadapter.items.AnimatorExpandableItem)

Example 3 with SubItem

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;
        }
    }
}
Also used : AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) SubItem(eu.davidea.samples.flexibleadapter.items.SubItem)

Example 4 with SubItem

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);
            }
        }
    }
}
Also used : AbstractFlexibleItem(eu.davidea.flexibleadapter.items.AbstractFlexibleItem) SubItem(eu.davidea.samples.flexibleadapter.items.SubItem) IExpandable(eu.davidea.flexibleadapter.items.IExpandable) ExpandableItem(eu.davidea.samples.flexibleadapter.items.ExpandableItem) SimpleItem(eu.davidea.samples.flexibleadapter.items.SimpleItem)

Example 5 with SubItem

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;
    }
}
Also used : SubItem(eu.davidea.samples.flexibleadapter.items.SubItem) IFlexible(eu.davidea.flexibleadapter.items.IFlexible) MenuItem(android.view.MenuItem) SimpleItem(eu.davidea.samples.flexibleadapter.items.SimpleItem) OverallItem(eu.davidea.samples.flexibleadapter.items.OverallItem)

Aggregations

SubItem (eu.davidea.samples.flexibleadapter.items.SubItem)7 AnimatorSubItem (eu.davidea.samples.flexibleadapter.items.AnimatorSubItem)3 SimpleItem (eu.davidea.samples.flexibleadapter.items.SimpleItem)3 MenuItem (android.view.MenuItem)2 AbstractFlexibleItem (eu.davidea.flexibleadapter.items.AbstractFlexibleItem)2 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)2 ExpandableItem (eu.davidea.samples.flexibleadapter.items.ExpandableItem)2 OverallItem (eu.davidea.samples.flexibleadapter.items.OverallItem)2 IExpandable (eu.davidea.flexibleadapter.items.IExpandable)1 AnimatorExpandableItem (eu.davidea.samples.flexibleadapter.items.AnimatorExpandableItem)1 ExpandableHeaderItem (eu.davidea.samples.flexibleadapter.items.ExpandableHeaderItem)1 ExpandableLevel0Item (eu.davidea.samples.flexibleadapter.items.ExpandableLevel0Item)1 ExpandableLevel1Item (eu.davidea.samples.flexibleadapter.items.ExpandableLevel1Item)1