package lib.morkim.mfw.ui.lists;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

public abstract class ListAdapter<M extends ListItemModel, VH extends ListItemHolder> extends RecyclerView.Adapter<VH> {

	protected LayoutInflater layoutInflater;

//	protected ViewHelper textViewHelper;

	protected List<M> listModel;

	public ListAdapter() {

	}

	public ListAdapter(List<M> listModel) {
		this.listModel = listModel;
	}

	@Override
	public VH onCreateViewHolder(ViewGroup parent, int viewType) {

		View v = LayoutInflater.from(parent.getContext()).inflate(layoutId(), parent, false);

		return holdView(v, 0);
	}

	@Override
	public void onBindViewHolder(VH holder, int position) {

		bindView(holder, position);
	}

//	@Override
//	public View getView(int position, View convertView, ViewGroup parent) {
//
//		ListItemHolder holder = null;
//
//		// item = listModel.get(position);
//
//		if (convertView == null) {
//
//			convertView = inflateLayout(null, position);
//			setViewHelper(convertView);
//
//			// init ui elements
//			holder = holdView(convertView, position);
//
//			// save holder
//			convertView.setTag(holder);
//
//		} else {
//
//			// use saved holder if already recycled
//			holder = (ListItemHolder) convertView.getTag();
//		}
//
//		// bind data to viewable holder
//		bindView(convertView, holder, position);
//
//		return convertView;
//	}

	protected abstract int layoutId();

	protected abstract VH holdView(View convertView,
								   int position);

	protected abstract void bindView(VH holder, int position);

//	protected void setViewHelper(View view) {
//
//		textViewHelper = new ViewHelper(context, view);
//	}

	public void updateData(List<M> listModel) {

		this.listModel = listModel;

		notifyDataSetChanged();
	}

	@Override
	public int getItemCount() {

		if (listModel != null)
			return listModel.size();

		return 0;
	}

	public M getItem(int position) {

		if (listModel != null)
			return listModel.get(position);

		return null;
	}

	@Override
	public long getItemId(int position) {

		return 0;
	}

	public boolean isEnabled(int position) {

		if (listModel != null)
			return listModel.get(position).isEnabled;

		return false;
	}
}

@@ -330,108 +330,72 @@
 ed L
-ayoutInflater layoutInflater
+ist%3CM%3E listModel
 ;%0A%0A
-//
 %09pr
-otected ViewHelper textViewHelper;%0A%0A%09protected List%3CM%3E listModel
+ivate View.OnClickListener onClickListener
 ;%0A%0A%09
@@ -538,16 +538,22 @@
 wHolder(
+final 
 ViewGrou
@@ -666,16 +666,57 @@
  false);
+%0A%09%09v.setOnClickListener(onClickListener);
 %0A%0A%09%09retu
@@ -845,666 +845,8 @@
 %09%7D%0A%0A
-//%09@Override%0A//%09public View getView(int position, View convertView, ViewGroup parent) %7B%0A//%0A//%09%09ListItemHolder holder = null;%0A//%0A//%09%09// item = listModel.get(position);%0A//%0A//%09%09if (convertView == null) %7B%0A//%0A//%09%09%09convertView = inflateLayout(null, position);%0A//%09%09%09setViewHelper(convertView);%0A//%0A//%09%09%09// init ui elements%0A//%09%09%09holder = holdView(convertView, position);%0A//%0A//%09%09%09// save holder%0A//%09%09%09convertView.setTag(holder);%0A//%0A//%09%09%7D else %7B%0A//%0A//%09%09%09// use saved holder if already recycled%0A//%09%09%09holder = (ListItemHolder) convertView.getTag();%0A//%09%09%7D%0A//%0A//%09%09// bind data to viewable holder%0A//%09%09bindView(convertView, holder, position);%0A//%0A//%09%09return convertView;%0A//%09%7D%0A%0A
 %09pro
@@ -931,19 +931,8 @@
 iew,
-%0A%09%09%09%09%09%09%09%09  
  int
@@ -1009,114 +1009,8 @@
 );%0A%0A
-//%09protected void setViewHelper(View view) %7B%0A//%0A//%09%09textViewHelper = new ViewHelper(context, view);%0A//%09%7D%0A%0A
 %09pub
@@ -1537,11 +1537,129 @@
 alse;%0A%09%7D
+%0A%0A%09public void setOnClickListener(View.OnClickListener onClickListener) %7B%0A%09%09this.onClickListener = onClickListener;%0A%09%7D
 %0A%7D%0A

Add a click listener setter to list adapter