package com.example.administrator.zhapp.BaseListViewAdapter;

import android.content.Context;

import com.example.administrator.zhapp.BaseListViewAdapter.base.ItemViewDelegate;

import java.util.List;

/**
 * 万能适配器
 *
 * @param <T>
 */
public abstract class CommonAdapter<T> extends MultiItemTypeAdapter<T> {

    public CommonAdapter(Context context, final int layoutId, List<T> datas) {
        super(context, datas);

        addItemViewDelegate(new ItemViewDelegate<T>() {
            @Override
            public int getItemViewLayoutId() {
                return layoutId;
            }

            @Override
            public boolean isForViewType(T item, int position) {
                return true;
            }

            @Override
            public void convert(ViewHolder holder, T t, int position) {
                CommonAdapter.this.convert(holder, t, position);
            }
        });
    }
    protected abstract void convert(ViewHolder viewHolder, T item, int position);

    public void  setNewData(List<T> datas){
        mDatas = datas;
        notifyDataSetChanged();
    }
}
