Search in sources :

Example 6 with FlexibleViewHolder

use of eu.davidea.viewholders.FlexibleViewHolder in project FlexibleAdapter by davideas.

the class FlexibleAdapter method addListener.

/**
 * Initializes the listener(s) of this Adapter.
 * <p>This method is automatically called from the Constructor.</p>
 *
 * @param listener the object(s) instance(s) of any listener
 * @return this Adapter, so the call can be chained
 * @see #removeListener(Object)
 * @since 5.0.0-b6
 */
@CallSuper
public FlexibleAdapter<T> addListener(Object listener) {
    if (listener == null) {
        log.e("Invalid listener class: null");
        return this;
    }
    log.i("Adding listener class %s as:", getClassName(listener));
    if (listener instanceof OnItemClickListener) {
        log.i("- OnItemClickListener");
        mItemClickListener = (OnItemClickListener) listener;
        for (FlexibleViewHolder holder : getAllBoundViewHolders()) {
            holder.getContentView().setOnClickListener(holder);
        }
    }
    if (listener instanceof OnItemLongClickListener) {
        log.i("- OnItemLongClickListener");
        mItemLongClickListener = (OnItemLongClickListener) listener;
        // Restore the event
        for (FlexibleViewHolder holder : getAllBoundViewHolders()) {
            holder.getContentView().setOnLongClickListener(holder);
        }
    }
    if (listener instanceof OnItemMoveListener) {
        log.i("- OnItemMoveListener");
        mItemMoveListener = (OnItemMoveListener) listener;
    }
    if (listener instanceof OnItemSwipeListener) {
        log.i("- OnItemSwipeListener");
        mItemSwipeListener = (OnItemSwipeListener) listener;
    }
    if (listener instanceof OnDeleteCompleteListener) {
        log.i("- OnDeleteCompleteListener");
        mDeleteCompleteListener = (OnDeleteCompleteListener) listener;
    }
    if (listener instanceof OnStickyHeaderChangeListener) {
        log.i("- OnStickyHeaderChangeListener");
        mStickyHeaderChangeListener = (OnStickyHeaderChangeListener) listener;
    }
    if (listener instanceof OnUpdateListener) {
        log.i("- OnUpdateListener");
        mUpdateListener = (OnUpdateListener) listener;
        mUpdateListener.onUpdateEmptyView(getMainItemCount());
    }
    if (listener instanceof OnFilterListener) {
        log.i("- OnFilterListener");
        mFilterListener = (OnFilterListener) listener;
    }
    return this;
}
Also used : FlexibleViewHolder(eu.davidea.viewholders.FlexibleViewHolder) CallSuper(androidx.annotation.CallSuper)

Aggregations

FlexibleViewHolder (eu.davidea.viewholders.FlexibleViewHolder)6 CallSuper (androidx.annotation.CallSuper)2 Animator (android.animation.Animator)1 AnimatorSet (android.animation.AnimatorSet)1 View (android.view.View)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 ArrayList (java.util.ArrayList)1