Search in sources :

Example 1 with OverallItem

use of eu.davidea.samples.flexibleadapter.items.OverallItem 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)

Example 2 with OverallItem

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

the class OverallAdapter method onBindViewHolder.

/**
	 * METHOD A - NEW! Via Model objects. In this case you don't need to implement this method!
	 * METHOD B - You override and implement this method as you prefer (don't call super).
	 *
	 * Using Method B, some methods need to be called by the user, see bottom of this method!
	 */
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List payload) {
    int viewType = getItemViewType(position);
    Context context = holder.itemView.getContext();
    if (viewType == R.layout.recycler_scrollable_usecase_item) {
        ScrollableUseCaseItem item = (ScrollableUseCaseItem) getItem(position);
        ScrollableUseCaseItem.UCViewHolder vHolder = (ScrollableUseCaseItem.UCViewHolder) holder;
        assert item != null;
        DrawableUtils.setBackgroundCompat(holder.itemView, DrawableUtils.getRippleDrawable(DrawableUtils.getColorDrawable(context.getResources().getColor(R.color.material_color_blue_grey_50)), DrawableUtils.getColorControlHighlight(context)));
        vHolder.mTitle.setText(Utils.fromHtmlCompat(item.getTitle()));
        vHolder.mSubtitle.setText(Utils.fromHtmlCompat(item.getSubtitle()));
        //Support for StaggeredGridLayoutManager
        if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
            ((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(true);
            Log.d("LayoutItem", "LayoutItem configured fullSpan for StaggeredGridLayout");
        }
    } else if (viewType == R.layout.recycler_scrollable_layout_item) {
        ScrollableLayoutItem item = (ScrollableLayoutItem) getItem(position);
        ScrollableLayoutItem.LayoutViewHolder vHolder = (ScrollableLayoutItem.LayoutViewHolder) holder;
        assert item != null;
        //For marquee
        vHolder.mTitle.setSelected(true);
        vHolder.mTitle.setText(item.getTitle());
        vHolder.mSubtitle.setText(item.getSubtitle());
        //Support for StaggeredGridLayoutManager
        if (holder.itemView.getLayoutParams() instanceof StaggeredGridLayoutManager.LayoutParams) {
            ((StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams()).setFullSpan(true);
            Log.d("LayoutItem", "LayoutItem configured fullSpan for StaggeredGridLayout");
        }
    } else if (viewType == R.layout.recycler_overall_item) {
        OverallItem item = (OverallItem) getItem(position);
        OverallItem.LabelViewHolder vHolder = (OverallItem.LabelViewHolder) holder;
        assert item != null;
        if (item.getTitle() != null) {
            vHolder.mTitle.setText(item.getTitle());
            vHolder.mTitle.setEnabled(isEnabled(position));
        }
        if (item.getDescription() != null) {
            vHolder.mSubtitle.setText(Utils.fromHtmlCompat(item.getDescription()));
            vHolder.mSubtitle.setEnabled(isEnabled(position));
        }
        if (item.getIcon() != null) {
            vHolder.mIcon.setImageDrawable(item.getIcon());
        }
    }
    // IMPORTANT!!!
    // With method B, animateView() needs to be called by the user!
    // With method A, the call is handled by the Adapter
    animateView(holder, position);
// Same concept for EndlessScrolling and View activation:
// - onLoadMore(position);
// - holder.itemView.setActivated(isSelected(position));
}
Also used : Context(android.content.Context) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) OverallItem(eu.davidea.samples.flexibleadapter.items.OverallItem) ScrollableUseCaseItem(eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem) ScrollableLayoutItem(eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem)

Example 3 with OverallItem

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

the class DatabaseService method createOverallDatabase.

/*
	 * List of CardView as entry list, showing the functionality of the library.
	 * It also shows how adapter animation can be configured.
	 */
//TODO: Review the description of all examples
//TODO: Add ScrollableUseCaseItem header for each database
public void createOverallDatabase(Resources resources) {
    databaseType = DatabaseType.OVERALL;
    mItems.clear();
    mItems.add(new OverallItem(R.id.nav_selection_modes, resources.getString(R.string.selection_modes)).withDescription(resources.getString(R.string.selection_modes_description)).withIcon(resources.getDrawable(R.drawable.ic_select_all_grey600_24dp)));
    mItems.add(new OverallItem(R.id.nav_filter, resources.getString(R.string.filter)).withDescription(resources.getString(R.string.filter_description)).withIcon(resources.getDrawable(R.drawable.ic_filter_outline_grey600_24dp)));
    mItems.add(new OverallItem(R.id.nav_animator, resources.getString(R.string.animator)).withDescription(resources.getString(R.string.animator_description)).withIcon(resources.getDrawable(R.drawable.ic_animation_grey600_24dp)));
    mItems.add(new OverallItem(R.id.nav_headers_and_sections, resources.getString(R.string.headers_sections)).withDescription(resources.getString(R.string.headers_sections_description)).withIcon(resources.getDrawable(R.drawable.ic_sections_grey600_24dp)));
    mItems.add(new OverallItem(R.id.nav_expandable_sections, resources.getString(R.string.expandable_sections)).withDescription(resources.getString(R.string.expandable_sections_description)).withIcon(resources.getDrawable(R.drawable.ic_expandable_grey_600_24dp)));
    mItems.add(new OverallItem(R.id.nav_multi_level_expandable, resources.getString(R.string.multi_level_expandable)).withDescription(resources.getString(R.string.multi_level_expandable_description)).withIcon(resources.getDrawable(R.drawable.ic_expandable_grey_600_24dp)));
    mItems.add(new OverallItem(R.id.nav_endless_scrolling, resources.getString(R.string.endless_scrolling)).withDescription(resources.getString(R.string.endless_scrolling_description)).withIcon(resources.getDrawable(R.drawable.ic_playlist_play_grey600_24dp)));
    //Special Use Cases
    mItems.add(new OverallItem(R.id.nav_instagram_headers, resources.getString(R.string.instagram_headers)).withDescription(resources.getString(R.string.instagram_headers_description)).withIcon(resources.getDrawable(R.drawable.ic_instagram_grey600_24dp)));
    mItems.add(new OverallItem(R.id.nav_model_holders, resources.getString(R.string.model_holders)).withDescription(resources.getString(R.string.model_holders_description)).withIcon(resources.getDrawable(R.drawable.ic_select_inverse_grey600_24dp)));
    mItems.add(new OverallItem(R.id.nav_staggered, resources.getString(R.string.staggered_layout)).withDescription(resources.getString(R.string.staggered_description)).withIcon(resources.getDrawable(R.drawable.ic_dashboard_grey600_24dp)));
    mItems.add(new OverallItem(R.id.nav_viewpager, resources.getString(R.string.viewpager)).withDescription(resources.getString(R.string.viewpager_description)).withIcon(resources.getDrawable(R.drawable.ic_view_carousel_grey600_24dp)));
}
Also used : OverallItem(eu.davidea.samples.flexibleadapter.items.OverallItem)

Aggregations

OverallItem (eu.davidea.samples.flexibleadapter.items.OverallItem)3 Context (android.content.Context)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 MenuItem (android.view.MenuItem)1 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)1 ScrollableLayoutItem (eu.davidea.samples.flexibleadapter.items.ScrollableLayoutItem)1 ScrollableUseCaseItem (eu.davidea.samples.flexibleadapter.items.ScrollableUseCaseItem)1 SimpleItem (eu.davidea.samples.flexibleadapter.items.SimpleItem)1 SubItem (eu.davidea.samples.flexibleadapter.items.SubItem)1