Search in sources :

Example 6 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(View view, 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() != Mode.IDLE && mActionModeHelper != null) {
        boolean activate = mActionModeHelper.onClick(position);
        Log.d("Last activated position %s", mActionModeHelper.getActivatedPosition());
        return activate;
    } else {
        // Notify the active callbacks or implement a custom action onClick
        if (flexibleItem instanceof SimpleItem || flexibleItem instanceof SubItem) {
            mRecyclerView.postDelayed(() -> {
                Log.d("scroll to position=%s item=%s", position, mAdapter.getItem(position));
                int headers = mAdapter.areHeadersSticky() ? 1 : 0;
                mRecyclerView.smoothScrollToPosition(Math.max(0, position - headers));
            }, 300L);
        // //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)

Example 7 with SubItem

use of eu.davidea.samples.flexibleadapter.items.SubItem in project FlexibleAdapter by davideas.

the class DatabaseService method newExpandableSectionItem.

/*
     * Creates a special expandable item which is also a Header.
     * The subItems will have linked its parent as Header!
     */
public static ExpandableHeaderItem newExpandableSectionItem(int i) {
    ExpandableHeaderItem expandableItem = new ExpandableHeaderItem("EH" + i);
    expandableItem.setTitle("Expandable Header " + i);
    for (int j = 1; j <= SUB_ITEMS; j++) {
        SubItem subItem = new SubItem(expandableItem.getId() + "-SB" + j);
        subItem.setTitle("Sub Item " + j);
        // NOTE: In case you want to retrieve the parent, you can implement ISectionable
        // then, assign the Header: ExpandableHeaderItem instance.
        // subItem.setHeader(expandableItem);
        expandableItem.addSubItem(subItem);
    }
    return expandableItem;
}
Also used : AnimatorSubItem(eu.davidea.samples.flexibleadapter.items.AnimatorSubItem) SubItem(eu.davidea.samples.flexibleadapter.items.SubItem) ExpandableHeaderItem(eu.davidea.samples.flexibleadapter.items.ExpandableHeaderItem)

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