package com.gh.gamecenter.common.base;

import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.gh.gamecenter.common.callback.OnListClickListener;

/**
 * 目前仅提供butterknife bind方法
 *
 * @author CsHeng
 * @Date 16/06/2017
 * @Time 9:55 AM
 */

public abstract class BaseRecyclerViewHolder<T> extends RecyclerView.ViewHolder implements View.OnClickListener {

    private T mData;
    private OnListClickListener mListClickListener;

    public BaseRecyclerViewHolder(View itemView) {
        super(itemView);
    }

    /**
     * 具体的设置监听在childViewHolder 设置
     *
     * @param itemView
     * @param data              一般情况下只传列表数据
     * @param listClickListener 列表事件接口
     */
    public BaseRecyclerViewHolder(View itemView, T data, OnListClickListener listClickListener) {
        this(itemView);
        this.mData = data;
        this.mListClickListener = listClickListener;
    }

    public BaseRecyclerViewHolder(View itemView, OnListClickListener listClickListener) {
        this(itemView);
        this.mListClickListener = listClickListener;
    }

    public void setClickData(T clickData) {
        this.mData = clickData;
    }

    @Override
    public void onClick(View view) {
        try {
            mListClickListener.onListClick(view, getAdapterPosition(), mData);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
