package com.ahamed.sample.common.binder;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;
import com.ahamed.multiviewadapter.SelectableBinder;
import com.ahamed.multiviewadapter.SelectableViewHolder;
import com.ahamed.sample.R;
import com.ahamed.sample.common.model.GridItem;

public class GridItemBinder extends SelectableBinder<GridItem, GridItemBinder.ItemViewHolder> {

  @Override public ItemViewHolder create(LayoutInflater layoutInflater, ViewGroup parent) {
    return new ItemViewHolder(layoutInflater.inflate(R.layout.item_grid, parent, false));
  }

  @Override public void bind(ItemViewHolder holder, GridItem item, boolean isSelected) {
    holder.itemView.setBackgroundColor(item.getColor());
    holder.ivIcon.setImageResource(item.getDrawable());
    if (isSelected) {
      holder.ivSelectionIndicator.setVisibility(View.VISIBLE);
    } else {
      holder.ivSelectionIndicator.setVisibility(View.GONE);
    }
  }

  @Override public boolean canBindData(Object item) {
    return item instanceof GridItem;
  }

  static class ItemViewHolder extends SelectableViewHolder<GridItem> {

    private ImageView ivIcon;
    private ImageView ivSelectionIndicator;
    private View itemView;

    ItemViewHolder(View itemView) {
      super(itemView);
      ivSelectionIndicator = (ImageView) itemView.findViewById(R.id.iv_selection_indicator);
      ivIcon = (ImageView) itemView.findViewById(R.id.iv_icon);
      this.itemView = itemView;

      setItemClickListener(new OnItemClickListener<GridItem>() {
        @Override public void onItemClick(View view, GridItem item) {
          Toast.makeText(view.getContext(), item.getData(), Toast.LENGTH_SHORT).show();
        }
      });
    }
  }
}
@@ -225,29 +225,27 @@
 adapter.
-SelectableBin
+BaseViewHol
 der;%0Aimp
@@ -276,33 +276,23 @@
 adapter.
-SelectableViewHol
+ItemBin
 der;%0Aimp
@@ -401,26 +401,20 @@
 extends 
-Selectable
+Item
 Binder%3CG
@@ -712,28 +712,8 @@
 item
-, boolean isSelected
 ) %7B%0A
@@ -837,18 +837,29 @@
 if (
-is
+holder.isItem
 Selected
 ) %7B%0A
@@ -854,16 +854,18 @@
 Selected
+()
 ) %7B%0A    
@@ -1145,17 +1145,11 @@
 nds 
-Selectabl
+Bas
 eVie
@@ -1651,24 +1651,24 @@
 tem item) %7B%0A
-
           To
@@ -1762,16 +1762,243 @@
      %7D);
+%0A%0A      setItemLongClickListener(new OnItemLongClickListener%3CGridItem%3E() %7B%0A        @Override public boolean onItemLongClick(View view, GridItem item) %7B%0A          toggleItemSelection();%0A          return true;%0A        %7D%0A      %7D);
 %0A    %7D%0A 

Switch from deprecated methods in sample app