FileDocCategorySizeDatePackage
ItemBridgeAdapter.javaAPI DocAndroid 5.1 API10629Thu Mar 12 22:22:56 GMT 2015android.support.v17.leanback.widget

ItemBridgeAdapter

public class ItemBridgeAdapter extends RecyclerView.Adapter
Bridge from Presenter to RecyclerView.Adapter. Public to allow use by third party presenters.

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private ObjectAdapter
mAdapter
private Wrapper
mWrapper
private PresenterSelector
mPresenterSelector
private FocusHighlightHandler
mFocusHighlight
private AdapterListener
mAdapterListener
private ArrayList
mPresenters
private ObjectAdapter.DataObserver
mDataObserver
Constructors Summary
public ItemBridgeAdapter(ObjectAdapter adapter, PresenterSelector presenterSelector)


         
        setAdapter(adapter);
        mPresenterSelector = presenterSelector;
    
public ItemBridgeAdapter(ObjectAdapter adapter)

        this(adapter, null);
    
public ItemBridgeAdapter()

    
Methods Summary
public voidclear()

        setAdapter(null);
    
public intgetItemCount()

        return mAdapter.size();
    
public longgetItemId(int position)

        return mAdapter.getId(position);
    
public intgetItemViewType(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);
            if (mAdapterListener != null) {
                mAdapterListener.onAddPresenter(presenter, type);
            }
        }
        return type;
    
public java.util.ArrayListgetPresenterMapper()

        return mPresenters;
    
public android.support.v17.leanback.widget.ItemBridgeAdapter$WrappergetWrapper()

        return mWrapper;
    
public voidonBindViewHolder(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);

        if (mAdapterListener != null) {
            mAdapterListener.onBind(viewHolder);
        }
    
public RecyclerView.ViewHolderonCreateViewHolder(android.view.ViewGroup parent, int viewType)
{@link View.OnFocusChangeListener} that assigned in {@link Presenter#onCreateViewHolder(ViewGroup)} may be chained, user should never change {@link View.OnFocusChangeListener} after that.

        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);
        if (mAdapterListener != null) {
            mAdapterListener.onCreate(viewHolder);
        }
        View presenterView = viewHolder.mHolder.view;
        if (presenterView != null) {
            viewHolder.mFocusChangeListener.mChainedListener = presenterView.getOnFocusChangeListener();
            presenterView.setOnFocusChangeListener(viewHolder.mFocusChangeListener);
        }
        if (mFocusHighlight != null) {
            mFocusHighlight.onInitializeView(view);
        }
        return viewHolder;
    
public voidonViewAttachedToWindow(RecyclerView.ViewHolder holder)

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

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

        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.mPresenter.onUnbindViewHolder(viewHolder.mHolder);

        viewHolder.mItem = null;

        if (mAdapterListener != null) {
            mAdapterListener.onUnbind(viewHolder);
        }
    
public voidsetAdapter(ObjectAdapter adapter)

        if (mAdapter != null) {
            mAdapter.unregisterObserver(mDataObserver);
        }
        mAdapter = adapter;
        if (mAdapter == null) {
            return;
        }

        mAdapter.registerObserver(mDataObserver);
        if (hasStableIds() != mAdapter.hasStableIds()) {
            setHasStableIds(mAdapter.hasStableIds());
        }
    
public voidsetAdapterListener(android.support.v17.leanback.widget.ItemBridgeAdapter$AdapterListener listener)

        mAdapterListener = listener;
    
voidsetFocusHighlight(FocusHighlightHandler listener)

        mFocusHighlight = listener;
        if (DEBUG) Log.v(TAG, "setFocusHighlight " + mFocusHighlight);
    
public voidsetPresenterMapper(java.util.ArrayList presenters)

        mPresenters = presenters;
    
public voidsetWrapper(android.support.v17.leanback.widget.ItemBridgeAdapter$Wrapper wrapper)

        mWrapper = wrapper;