package com.e16din.simplerecycler.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;

import com.e16din.handyholder.AlreadyBox;
import com.e16din.handyholder.holder.HandyHolder;
import com.e16din.handyholder.listeners.click.OnClickListener;
import com.e16din.handyholder.listeners.click.OnViewsClickListener;
import com.e16din.handyholder.wrapper.Handy;

import java.util.List;

@SuppressWarnings("unused")//remove it to see unused warnings
public abstract class SimpleHandyHolderAdapter<HOLDER extends RecyclerView.ViewHolder, MODEL>
        extends SimpleClickAdapter<HOLDER, MODEL> {

    public SimpleHandyHolderAdapter(@NonNull Context context, @NonNull List<MODEL> items) {
        super(context, items);
    }

    public SimpleHandyHolderAdapter(@NonNull Context context) {
        super(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, final int viewType) {
        if (viewType == TYPE_INSERTION) {
            return super.onCreateViewHolder(parent, viewType);
        }// else


        final Handy<MODEL> handy = new Handy<MODEL>(this, parent) {
            @Override
            public RecyclerView.ViewHolder newHolder(ViewGroup viewGroup) {
                return newViewHolder(viewGroup, viewType);
            }
        };

        if (handy.set().holder() instanceof HandyHolder) {
            HandyHolder h = (HandyHolder) handy.set().holder();
            if (!h.set().isAlreadyInited()) {
                updateHandyHolderSettings(h.set());
            }

            return h;
        }// else

        updateHandyHolderSettings(handy.set());
        return handy.set().init();
    }

    private void updateHandyHolderSettings(AlreadyBox set) {
        if (!set.isAlreadySetAsyncInflating()) {
            set.asyncInflating(isAsyncInflating());
        }

        if (!set.isAlreadySetRippleEffect()) {
            set.rippleEffect(isRippleEffect());
        }

        //click listeners
        if (mOnItemClickListener != null) {
            set.clickListener(mOnItemClickListener);
        }

        if (mOnItemViewsClickListener != null) {
            if (mClickableViewsArray != null)
                set.setViewsClickListener(mClickableViewsArray, mOnItemViewsClickListener);
            if (mClickableViewsList != null)
                set.setViewsClickListener(mClickableViewsList, mOnItemViewsClickListener);
        }
    }


    public void setOnItemClickListener(OnClickListener<MODEL> listener) {
        mOnItemClickListener = listener;
    }


    public void setOnItemViewsClickListener(List<Integer> clickableViews, OnViewsClickListener<MODEL> listener) {
        mClickableViewsList = clickableViews;
        mOnItemViewsClickListener = listener;
    }

    public void setOnItemViewsClickListener(int[] clickableViews, OnViewsClickListener<MODEL> listener) {
        mClickableViewsArray = clickableViews;
        mOnItemViewsClickListener = listener;
    }


    public OnClickListener<MODEL> getOnItemClickListener() {
        return mOnItemClickListener;
    }


    public OnViewsClickListener<MODEL> getOnViewsClickListener() {
        return mOnItemViewsClickListener;
    }


    public List<Integer> getClickableViewsList() {
        return mClickableViewsList;
    }
}

@@ -287,139 +287,8 @@
 er;%0A
-import com.e16din.handyholder.listeners.click.OnClickListener;%0Aimport com.e16din.handyholder.listeners.click.OnViewsClickListener;%0A
 impo
@@ -2392,867 +2392,6 @@
   %7D%0A
-%0A%0A    public void setOnItemClickListener(OnClickListener%3CMODEL%3E listener) %7B%0A        mOnItemClickListener = listener;%0A    %7D%0A%0A%0A    public void setOnItemViewsClickListener(List%3CInteger%3E clickableViews, OnViewsClickListener%3CMODEL%3E listener) %7B%0A        mClickableViewsList = clickableViews;%0A        mOnItemViewsClickListener = listener;%0A    %7D%0A%0A    public void setOnItemViewsClickListener(int%5B%5D clickableViews, OnViewsClickListener%3CMODEL%3E listener) %7B%0A        mClickableViewsArray = clickableViews;%0A        mOnItemViewsClickListener = listener;%0A    %7D%0A%0A%0A    public OnClickListener%3CMODEL%3E getOnItemClickListener() %7B%0A        return mOnItemClickListener;%0A    %7D%0A%0A%0A    public OnViewsClickListener%3CMODEL%3E getOnViewsClickListener() %7B%0A        return mOnItemViewsClickListener;%0A    %7D%0A%0A%0A    public List%3CInteger%3E getClickableViewsList() %7B%0A        return mClickableViewsList;%0A    %7D%0A
 %7D%0A

Remove unused methods.