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.holder.HandyHolder;
import com.e16din.handyholder.listeners.click.OnClickListener;
import com.e16din.handyholder.listeners.click.OnViewsClickListener;
import com.e16din.handyholder.wrapper.SimpleHandy;

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, int viewType) {
        switch (viewType) {
            case TYPE_INSERTION:
                return super.onCreateViewHolder(parent, viewType);
        }//else

        final RecyclerView.ViewHolder holder = super.onCreateViewHolder(parent, viewType);

        if (isInflatedHandyHolder(holder)) return holder;

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

        handy.asyncInflating(isAsyncInflating());
        handy.rippleEffect(isRippleEffect());

        //click listeners
        if (mOnItemClickListener != null) {
            handy.clickListener(mOnItemClickListener);
        }
        if (mOnItemViewsClickListener != null) {
            if (mClickableViewsArray != null)
                handy.setViewsClickListener(mClickableViewsArray, mOnItemViewsClickListener);
            if (mClickableViewsList != null)
                handy.setViewsClickListener(mClickableViewsList, mOnItemViewsClickListener);
        }

        return handy.init();
    }

    private boolean isInflatedHandyHolder(RecyclerView.ViewHolder holder) {
        if (holder instanceof HandyHolder) {
            HandyHolder h = (HandyHolder) holder;
            if (h.isInflated()) {//already inited
                return true;
            }
        }
        return false;
    }

    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;
    }
}

@@ -195,58 +195,8 @@
 p;%0A%0A
-import com.e16din.handyholder.holder.HandyHolder;%0A
 impo
@@ -246,32 +246,32 @@
 nClickListener;%0A
+
 import com.e16di
@@ -917,16 +917,22 @@
  parent,
+ final
  int vie
@@ -952,14 +952,10 @@
     
-switch
+if
  (vi
@@ -964,28 +964,11 @@
 Type
-) %7B%0A            case
+ ==
  TYP
@@ -982,14 +982,12 @@
 TION
-:%0A    
+) %7B%0A
     
@@ -1060,163 +1060,13 @@
  %7D//
+ 
 else
-%0A%0A        final RecyclerView.ViewHolder holder = super.onCreateViewHolder(parent, viewType);%0A%0A        if (isInflatedHandyHolder(holder)) return holder;
 %0A%0A  
@@ -1264,22 +1264,50 @@
  return 
-holder
+newViewHolder(viewGroup, viewType)
 ;%0A      
@@ -1936,310 +1936,8 @@
  %7D%0A%0A
-    private boolean isInflatedHandyHolder(RecyclerView.ViewHolder holder) %7B%0A        if (holder instanceof HandyHolder) %7B%0A            HandyHolder h = (HandyHolder) holder;%0A            if (h.isInflated()) %7B//already inited%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D%0A
 %0A   

Update onCreateViewHolder logic.