public class

ItemBridgeAdapter

extends RecyclerView.Adapter

implements FacetProviderAdapter

 java.lang.Object

androidx.recyclerview.widget.RecyclerView.Adapter

↳androidx.leanback.widget.ItemBridgeAdapter

Gradle dependencies

compile group: 'androidx.leanback', name: 'leanback', version: '1.2.0-alpha04'

  • groupId: androidx.leanback
  • artifactId: leanback
  • version: 1.2.0-alpha04

Artifact androidx.leanback:leanback:1.2.0-alpha04 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.leanback:leanback com.android.support:leanback-v17

Androidx class mapping:

androidx.leanback.widget.ItemBridgeAdapter android.support.v17.leanback.widget.ItemBridgeAdapter

Overview

Bridge from Presenter to . Public to allow use by third party Presenters.

Summary

Constructors
publicItemBridgeAdapter()

publicItemBridgeAdapter(ObjectAdapter adapter)

publicItemBridgeAdapter(ObjectAdapter adapter, PresenterSelector presenterSelector)

Methods
public voidclear()

Clears the adapter.

public FacetProvidergetFacetProvider(int type)

public abstract intgetItemCount()

Returns the total number of items in the data set held by the adapter.

public longgetItemId(int position)

Return the stable ID for the item at position.

public intgetItemViewType(int position)

Return the view type of the item at position for the purposes of view recycling.

public java.util.ArrayList<Presenter>getPresenterMapper()

Returns the presenter mapper array.

public ItemBridgeAdapter.WrappergetWrapper()

Returns the ItemBridgeAdapter.Wrapper.

protected voidonAddPresenter(Presenter presenter, int type)

Called when presenter is added to Adapter.

protected voidonAttachedToWindow(ItemBridgeAdapter.ViewHolder viewHolder)

Called when ViewHolder has been attached to window.

protected voidonBind(ItemBridgeAdapter.ViewHolder viewHolder)

Called when ViewHolder has been bound to data.

public abstract voidonBindViewHolder(RecyclerView.ViewHolder holder, int position)

Called by RecyclerView to display the data at the specified position.

public voidonBindViewHolder(RecyclerView.ViewHolder holder, int position, java.util.List<java.lang.Object> payloads)

Called by RecyclerView to display the data at the specified position.

protected voidonCreate(ItemBridgeAdapter.ViewHolder viewHolder)

Called when ViewHolder is created.

public final RecyclerView.ViewHolderonCreateViewHolder(ViewGroup parent, int viewType)

that assigned in Presenter.onCreateViewHolder(ViewGroup) may be chained, user should never change after that.

protected voidonDetachedFromWindow(ItemBridgeAdapter.ViewHolder viewHolder)

Called when ViewHolder has been detached from window.

public booleanonFailedToRecycleView(RecyclerView.ViewHolder holder)

Called by the RecyclerView if a ViewHolder created by this Adapter cannot be recycled due to its transient state.

protected voidonUnbind(ItemBridgeAdapter.ViewHolder viewHolder)

Called when ViewHolder has been unbound from data.

public voidonViewAttachedToWindow(RecyclerView.ViewHolder holder)

Called when a view created by this adapter has been attached to a window.

public voidonViewDetachedFromWindow(RecyclerView.ViewHolder holder)

Called when a view created by this adapter has been detached from its window.

public voidonViewRecycled(RecyclerView.ViewHolder holder)

Called when a view created by this adapter has been recycled.

public voidsetAdapter(ObjectAdapter adapter)

Sets the ObjectAdapter.

public voidsetAdapterListener(ItemBridgeAdapter.AdapterListener listener)

Sets the AdapterListener.

public voidsetPresenter(PresenterSelector presenterSelector)

Changes Presenter that creates and binds the view.

public voidsetPresenterMapper(java.util.ArrayList<Presenter> presenters)

Sets the presenter mapper array.

public voidsetWrapper(ItemBridgeAdapter.Wrapper wrapper)

Sets the ItemBridgeAdapter.Wrapper.

from RecyclerView.Adapter<VH>bindViewHolder, createViewHolder, findRelativeAdapterPositionIn, getStateRestorationPolicy, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onDetachedFromRecyclerView, registerAdapterDataObserver, setHasStableIds, setStateRestorationPolicy, unregisterAdapterDataObserver
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public ItemBridgeAdapter(ObjectAdapter adapter, PresenterSelector presenterSelector)

public ItemBridgeAdapter(ObjectAdapter adapter)

public ItemBridgeAdapter()

Methods

public void setAdapter(ObjectAdapter adapter)

Sets the ObjectAdapter.

public void setPresenter(PresenterSelector presenterSelector)

Changes Presenter that creates and binds the view.

Parameters:

presenterSelector: Presenter that creates and binds the view.

public void setWrapper(ItemBridgeAdapter.Wrapper wrapper)

Sets the ItemBridgeAdapter.Wrapper.

public ItemBridgeAdapter.Wrapper getWrapper()

Returns the ItemBridgeAdapter.Wrapper.

public void clear()

Clears the adapter.

public void setPresenterMapper(java.util.ArrayList<Presenter> presenters)

Sets the presenter mapper array.

public java.util.ArrayList<Presenter> getPresenterMapper()

Returns the presenter mapper array.

public abstract int getItemCount()

Returns the total number of items in the data set held by the adapter.

Returns:

The total number of items in this adapter.

public int getItemViewType(int position)

Return the view type of the item at position for the purposes of view recycling.

The default implementation of this method returns 0, making the assumption of a single view type for the adapter. Unlike ListView adapters, types need not be contiguous. Consider using id resources to uniquely identify item view types.

Parameters:

position: position to query

Returns:

integer value identifying the type of the view needed to represent the item at position. Type codes need not be contiguous.

protected void onAddPresenter(Presenter presenter, int type)

Called when presenter is added to Adapter.

protected void onCreate(ItemBridgeAdapter.ViewHolder viewHolder)

Called when ViewHolder is created.

protected void onBind(ItemBridgeAdapter.ViewHolder viewHolder)

Called when ViewHolder has been bound to data.

protected void onUnbind(ItemBridgeAdapter.ViewHolder viewHolder)

Called when ViewHolder has been unbound from data.

protected void onAttachedToWindow(ItemBridgeAdapter.ViewHolder viewHolder)

Called when ViewHolder has been attached to window.

protected void onDetachedFromWindow(ItemBridgeAdapter.ViewHolder viewHolder)

Called when ViewHolder has been detached from window.

public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)

that assigned in Presenter.onCreateViewHolder(ViewGroup) may be chained, user should never change after that.

public void setAdapterListener(ItemBridgeAdapter.AdapterListener listener)

Sets the AdapterListener.

public abstract void onBindViewHolder(RecyclerView.ViewHolder holder, int position)

Called by RecyclerView to display the data at the specified position. This method should update the contents of the RecyclerView.ViewHolder.itemView to reflect the item at the given position.

Note that unlike , RecyclerView will not call this method again if the position of the item changes in the data set unless the item itself is invalidated or the new position cannot be determined. For this reason, you should only use the position parameter while acquiring the related data item inside this method and should not keep a copy of it. If you need the position of an item later on (e.g. in a click listener), use RecyclerView.ViewHolder.getBindingAdapterPosition() which will have the updated adapter position. Override RecyclerView.Adapter instead if Adapter can handle efficient partial bind.

Parameters:

holder: The ViewHolder which should be updated to represent the contents of the item at the given position in the data set.
position: The position of the item within the adapter's data set.

public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, java.util.List<java.lang.Object> payloads)

Called by RecyclerView to display the data at the specified position. This method should update the contents of the RecyclerView.ViewHolder.itemView to reflect the item at the given position.

Note that unlike , RecyclerView will not call this method again if the position of the item changes in the data set unless the item itself is invalidated or the new position cannot be determined. For this reason, you should only use the position parameter while acquiring the related data item inside this method and should not keep a copy of it. If you need the position of an item later on (e.g. in a click listener), use RecyclerView.ViewHolder.getBindingAdapterPosition() which will have the updated adapter position.

Partial bind vs full bind:

The payloads parameter is a merge list from RecyclerView.Adapter.notifyItemChanged(int, Object) or RecyclerView.Adapter.notifyItemRangeChanged(int, int, Object). If the payloads list is not empty, the ViewHolder is currently bound to old data and Adapter may run an efficient partial update using the payload info. If the payload is empty, Adapter must run a full bind. Adapter should not assume that the payload passed in notify methods will be received by onBindViewHolder(). For example when the view is not attached to the screen, the payload in notifyItemChange() will be simply dropped.

Parameters:

holder: The ViewHolder which should be updated to represent the contents of the item at the given position in the data set.
position: The position of the item within the adapter's data set.
payloads: A non-null list of merged payloads. Can be empty list if requires full update.

public void onViewRecycled(RecyclerView.ViewHolder holder)

Called when a view created by this adapter has been recycled.

A view is recycled when a RecyclerView.LayoutManager decides that it no longer needs to be attached to its parent RecyclerView. This can be because it has fallen out of visibility or a set of cached views represented by views still attached to the parent RecyclerView. If an item view has large or expensive data bound to it such as large bitmaps, this may be a good place to release those resources.

RecyclerView calls this method right before clearing ViewHolder's internal data and sending it to RecycledViewPool. This way, if ViewHolder was holding valid information before being recycled, you can call RecyclerView.ViewHolder.getBindingAdapterPosition() to get its adapter position.

Parameters:

holder: The ViewHolder for the view being recycled

public boolean onFailedToRecycleView(RecyclerView.ViewHolder holder)

Called by the RecyclerView if a ViewHolder created by this Adapter cannot be recycled due to its transient state. Upon receiving this callback, Adapter can clear the animation(s) that effect the View's transient state and return true so that the View can be recycled. Keep in mind that the View in question is already removed from the RecyclerView.

In some cases, it is acceptable to recycle a View although it has transient state. Most of the time, this is a case where the transient state will be cleared in RecyclerView.Adapter call when View is rebound to a new position. For this reason, RecyclerView leaves the decision to the Adapter and uses the return value of this method to decide whether the View should be recycled or not.

Note that when all animations are created by RecyclerView.ItemAnimator, you should never receive this callback because RecyclerView keeps those Views as children until their animations are complete. This callback is useful when children of the item views create animations which may not be easy to implement using an RecyclerView.ItemAnimator.

You should never fix this issue by calling holder.itemView.setHasTransientState(false); unless you've previously called holder.itemView.setHasTransientState(true);. Each View.setHasTransientState(true) call must be matched by a View.setHasTransientState(false) call, otherwise, the state of the View may become inconsistent. You should always prefer to end or cancel animations that are triggering the transient state instead of handling it manually.

Parameters:

holder: The ViewHolder containing the View that could not be recycled due to its transient state.

Returns:

True if the View should be recycled, false otherwise. Note that if this method returns true, RecyclerView will ignore the transient state of the View and recycle it regardless. If this method returns false, RecyclerView will check the View's transient state again before giving a final decision. Default implementation returns false.

public void onViewAttachedToWindow(RecyclerView.ViewHolder holder)

Called when a view created by this adapter has been attached to a window.

This can be used as a reasonable signal that the view is about to be seen by the user. If the adapter previously freed any resources in onViewDetachedFromWindow those resources should be restored here.

Parameters:

holder: Holder of the view being attached

public void onViewDetachedFromWindow(RecyclerView.ViewHolder holder)

Called when a view created by this adapter has been detached from its window.

Becoming detached from the window is not necessarily a permanent condition; the consumer of an Adapter's views may choose to cache views offscreen while they are not visible, attaching and detaching them as appropriate.

Parameters:

holder: Holder of the view being detached

public long getItemId(int position)

Return the stable ID for the item at position. If RecyclerView.Adapter.hasStableIds() would return false this method should return RecyclerView.NO_ID. The default implementation of this method returns RecyclerView.NO_ID.

Parameters:

position: Adapter position to query

Returns:

the stable ID of the item at position

public FacetProvider getFacetProvider(int type)

Source

/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package androidx.leanback.widget;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

/**
 * Bridge from {@link Presenter} to {@link RecyclerView.Adapter}. Public to allow use by third
 * party Presenters.
 */
public class ItemBridgeAdapter extends RecyclerView.Adapter implements FacetProviderAdapter {
    static final String TAG = "ItemBridgeAdapter";
    static final boolean DEBUG = false;

    /**
     * Interface for listening to ViewHolder operations.
     */
    public static class AdapterListener {
        public void onAddPresenter(Presenter presenter, int type) {
        }

        public void onCreate(ViewHolder viewHolder) {
        }

        public void onBind(ViewHolder viewHolder) {
        }

        public void onBind(ViewHolder viewHolder, List payloads) {
            onBind(viewHolder);
        }

        public void onUnbind(ViewHolder viewHolder) {
        }

        public void onAttachedToWindow(ViewHolder viewHolder) {
        }

        public void onDetachedFromWindow(ViewHolder viewHolder) {
        }
    }

    /**
     * Interface for wrapping a view created by a Presenter into another view.
     * The wrapper must be the immediate parent of the wrapped view.
     */
    public static abstract class Wrapper {
        public abstract View createWrapper(View root);

        public abstract void wrap(View wrapper, View wrapped);
    }

    private ObjectAdapter mAdapter;
    Wrapper mWrapper;
    private PresenterSelector mPresenterSelector;
    FocusHighlightHandler mFocusHighlight;
    private AdapterListener mAdapterListener;
    private ArrayList<Presenter> mPresenters = new ArrayList<Presenter>();

    static final class ChainingFocusChangeListener implements View.OnFocusChangeListener {
        final View.OnFocusChangeListener mChainedListener;
        boolean mHasWrapper;
        FocusHighlightHandler mFocusHighlight;

        ChainingFocusChangeListener(View.OnFocusChangeListener chainedListener,
                boolean hasWrapper, FocusHighlightHandler focusHighlight) {
            mChainedListener = chainedListener;
            mHasWrapper = hasWrapper;
            mFocusHighlight = focusHighlight;
        }

        void update(boolean hasWrapper, FocusHighlightHandler focusHighlight) {
            mHasWrapper = hasWrapper;
            mFocusHighlight = focusHighlight;
        }

        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (DEBUG) {
                Log.v(TAG, "onFocusChange " + hasFocus + " " + view
                        + " mFocusHighlight" + mFocusHighlight);
            }
            if (mHasWrapper) {
                view = (View) view.getParent();
            }
            mFocusHighlight.onItemFocused(view, hasFocus);
            if (mChainedListener != null) {
                mChainedListener.onFocusChange(view, hasFocus);
            }
        }
    }

    /**
     * ViewHolder for the ItemBridgeAdapter.
     */
    public static class ViewHolder extends RecyclerView.ViewHolder implements FacetProvider {
        final Presenter mPresenter;
        final Presenter.ViewHolder mHolder;
        Object mItem;
        Object mExtraObject;

        /**
         * Get {@link Presenter}.
         */
        public final Presenter getPresenter() {
            return mPresenter;
        }

        /**
         * Get {@link Presenter.ViewHolder}.
         */
        public final Presenter.ViewHolder getViewHolder() {
            return mHolder;
        }

        /**
         * Get currently bound object.
         */
        public final Object getItem() {
            return mItem;
        }

        /**
         * Get extra object associated with the view.  Developer can attach
         * any customized UI object in addition to {@link Presenter.ViewHolder}.
         * A typical use case is attaching an animator object.
         */
        public final Object getExtraObject() {
            return mExtraObject;
        }

        /**
         * Set extra object associated with the view.  Developer can attach
         * any customized UI object in addition to {@link Presenter.ViewHolder}.
         * A typical use case is attaching an animator object.
         */
        public void setExtraObject(Object object) {
            mExtraObject = object;
        }

        @Override
        public Object getFacet(Class<?> facetClass) {
            return mHolder.getFacet(facetClass);
        }

        ViewHolder(Presenter presenter, View view, Presenter.ViewHolder holder) {
            super(view);
            mPresenter = presenter;
            mHolder = holder;
        }
    }

    private ObjectAdapter.DataObserver mDataObserver = new ObjectAdapter.DataObserver() {
        @Override
        public void onChanged() {
            ItemBridgeAdapter.this.notifyDataSetChanged();
        }

        @Override
        public void onItemRangeChanged(int positionStart, int itemCount) {
            ItemBridgeAdapter.this.notifyItemRangeChanged(positionStart, itemCount);
        }

        @Override
        public void onItemRangeChanged(int positionStart, int itemCount, Object payload) {
            ItemBridgeAdapter.this.notifyItemRangeChanged(positionStart, itemCount, payload);
        }

        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            ItemBridgeAdapter.this.notifyItemRangeInserted(positionStart, itemCount);
        }

        @Override
        public void onItemRangeRemoved(int positionStart, int itemCount) {
            ItemBridgeAdapter.this.notifyItemRangeRemoved(positionStart, itemCount);
        }

        @Override
        public void onItemMoved(int fromPosition, int toPosition) {
            ItemBridgeAdapter.this.notifyItemMoved(fromPosition, toPosition);
        }
    };

    public ItemBridgeAdapter(ObjectAdapter adapter, PresenterSelector presenterSelector) {
        setAdapter(adapter);
        mPresenterSelector = presenterSelector;
    }

    public ItemBridgeAdapter(ObjectAdapter adapter) {
        this(adapter, null);
    }

    public ItemBridgeAdapter() {
    }

    /**
     * Sets the {@link ObjectAdapter}.
     */
    public void setAdapter(ObjectAdapter adapter) {
        if (adapter == mAdapter) {
            return;
        }
        if (mAdapter != null) {
            mAdapter.unregisterObserver(mDataObserver);
        }
        mAdapter = adapter;
        if (mAdapter == null) {
            notifyDataSetChanged();
            return;
        }

        mAdapter.registerObserver(mDataObserver);
        if (hasStableIds() != mAdapter.hasStableIds()) {
            setHasStableIds(mAdapter.hasStableIds());
        }
        notifyDataSetChanged();
    }

    /**
     * Changes Presenter that creates and binds the view.
     *
     * @param presenterSelector Presenter that creates and binds the view.
     */
    public void setPresenter(PresenterSelector presenterSelector) {
        mPresenterSelector = presenterSelector;
        notifyDataSetChanged();
    }

    /**
     * Sets the {@link Wrapper}.
     */
    public void setWrapper(Wrapper wrapper) {
        mWrapper = wrapper;
    }

    /**
     * Returns the {@link Wrapper}.
     */
    public Wrapper getWrapper() {
        return mWrapper;
    }

    void setFocusHighlight(FocusHighlightHandler listener) {
        mFocusHighlight = listener;
        if (DEBUG) Log.v(TAG, "setFocusHighlight " + mFocusHighlight);
    }

    /**
     * Clears the adapter.
     */
    public void clear() {
        setAdapter(null);
    }

    /**
     * Sets the presenter mapper array.
     */
    public void setPresenterMapper(ArrayList<Presenter> presenters) {
        mPresenters = presenters;
    }

    /**
     * Returns the presenter mapper array.
     */
    public ArrayList<Presenter> getPresenterMapper() {
        return mPresenters;
    }

    @Override
    public int getItemCount() {
        return mAdapter != null ? mAdapter.size() : 0;
    }

    @Override
    public int getItemViewType(int position) {
        PresenterSelector presenterSelector = mPresenterSelector != null
                ? mPresenterSelector : mAdapter.getPresenterSelector();
        Object item = mAdapter.get(position);
        Presenter presenter = presenterSelector.getPresenter(item);
        int type = mPresenters.indexOf(presenter);
        if (type < 0) {
            mPresenters.add(presenter);
            type = mPresenters.indexOf(presenter);
            if (DEBUG) Log.v(TAG, "getItemViewType added presenter " + presenter + " type " + type);
            onAddPresenter(presenter, type);
            if (mAdapterListener != null) {
                mAdapterListener.onAddPresenter(presenter, type);
            }
        }
        return type;
    }

    /**
     * Called when presenter is added to Adapter.
     */
    protected void onAddPresenter(Presenter presenter, int type) {
    }

    /**
     * Called when ViewHolder is created.
     */
    protected void onCreate(ViewHolder viewHolder) {
    }

    /**
     * Called when ViewHolder has been bound to data.
     */
    protected void onBind(ViewHolder viewHolder) {
    }

    /**
     * Called when ViewHolder has been unbound from data.
     */
    protected void onUnbind(ViewHolder viewHolder) {
    }

    /**
     * Called when ViewHolder has been attached to window.
     */
    protected void onAttachedToWindow(ViewHolder viewHolder) {
    }

    /**
     * Called when ViewHolder has been detached from window.
     */
    protected void onDetachedFromWindow(ViewHolder viewHolder) {
    }

    /**
     * {@link View.OnFocusChangeListener} that assigned in
     * {@link Presenter#onCreateViewHolder(ViewGroup)} may be chained, user should never change
     * {@link View.OnFocusChangeListener} after that.
     */
    @Override
    public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (DEBUG) Log.v(TAG, "onCreateViewHolder viewType " + viewType);
        Presenter presenter = mPresenters.get(viewType);
        Presenter.ViewHolder presenterVh;
        View view;
        if (mWrapper != null) {
            view = mWrapper.createWrapper(parent);
            presenterVh = presenter.onCreateViewHolder(parent);
            mWrapper.wrap(view, presenterVh.view);
        } else {
            presenterVh = presenter.onCreateViewHolder(parent);
            view = presenterVh.view;
        }
        ViewHolder viewHolder = new ViewHolder(presenter, view, presenterVh);
        onCreate(viewHolder);
        if (mAdapterListener != null) {
            mAdapterListener.onCreate(viewHolder);
        }
        View presenterView = viewHolder.mHolder.view;
        View.OnFocusChangeListener currentListener = presenterView.getOnFocusChangeListener();
        if (mFocusHighlight != null) {
            // update or create ChainingFocusChangeListener
            if (currentListener instanceof ChainingFocusChangeListener) {
                ((ChainingFocusChangeListener) currentListener).update(
                        /* hasWrapper= */ mWrapper != null, mFocusHighlight);
            } else {
                presenterView.setOnFocusChangeListener(new ChainingFocusChangeListener(
                        currentListener, /* hasWrapper= */ mWrapper != null, mFocusHighlight));
            }
            mFocusHighlight.onInitializeView(view);
        } else {
            // restore chained listener
            if (currentListener instanceof ChainingFocusChangeListener) {
                presenterView.setOnFocusChangeListener(
                        ((ChainingFocusChangeListener) currentListener).mChainedListener);
            }
        }
        return viewHolder;
    }

    /**
     * Sets the AdapterListener.
     */
    public void setAdapterListener(AdapterListener listener) {
        mAdapterListener = listener;
    }

    @Override
    public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (DEBUG) Log.v(TAG, "onBindViewHolder position " + position);
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.mItem = mAdapter.get(position);

        viewHolder.mPresenter.onBindViewHolder(viewHolder.mHolder, viewHolder.mItem);

        onBind(viewHolder);
        if (mAdapterListener != null) {
            mAdapterListener.onBind(viewHolder);
        }
    }

    @Override
    @SuppressWarnings("unchecked")
    public final  void onBindViewHolder(RecyclerView.ViewHolder holder, int position,
            List payloads) {
        if (DEBUG) Log.v(TAG, "onBindViewHolder position " + position);
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.mItem = mAdapter.get(position);

        viewHolder.mPresenter.onBindViewHolder(viewHolder.mHolder, viewHolder.mItem, payloads);

        onBind(viewHolder);
        if (mAdapterListener != null) {
            mAdapterListener.onBind(viewHolder, payloads);
        }
    }

    @Override
    public final void onViewRecycled(RecyclerView.ViewHolder holder) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.mPresenter.onUnbindViewHolder(viewHolder.mHolder);
        onUnbind(viewHolder);
        if (mAdapterListener != null) {
            mAdapterListener.onUnbind(viewHolder);
        }
        viewHolder.mItem = null;
    }

    @Override
    public final boolean onFailedToRecycleView(RecyclerView.ViewHolder holder) {
        onViewRecycled(holder);
        return false;
    }

    @Override
    public final void onViewAttachedToWindow(RecyclerView.ViewHolder holder) {
        ViewHolder viewHolder = (ViewHolder) holder;
        onAttachedToWindow(viewHolder);
        if (mAdapterListener != null) {
            mAdapterListener.onAttachedToWindow(viewHolder);
        }
        viewHolder.mPresenter.onViewAttachedToWindow(viewHolder.mHolder);
    }

    @Override
    public final void onViewDetachedFromWindow(RecyclerView.ViewHolder holder) {
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.mPresenter.onViewDetachedFromWindow(viewHolder.mHolder);
        onDetachedFromWindow(viewHolder);
        if (mAdapterListener != null) {
            mAdapterListener.onDetachedFromWindow(viewHolder);
        }
    }

    @Override
    public long getItemId(int position) {
        return mAdapter.getId(position);
    }

    @Override
    public FacetProvider getFacetProvider(int type) {
        return mPresenters.get(type);
    }
}