package com.cooleshow.student.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.cooleshow.base.utils.GlideUtils;
import com.cooleshow.base.utils.ToastUtils;
import com.cooleshow.student.R;
import com.cooleshow.student.bean.TeachableInstrumentBean;

import java.util.List;

/**
 * 创建日期：2022/5/13 18:12
 *
 * @author Ryan
 * 类说明：
 */
public class TeachableInstrumentItemAdapter extends BaseQuickAdapter<TeachableInstrumentBean, BaseViewHolder> {

    public TeachableInstrumentItemAdapter(List<TeachableInstrumentBean> data) {
        super(R.layout.layout_teachable_instrument_item, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, TeachableInstrumentBean item) {
        if (item == null) {
            return;
        }
        ImageView iv_pic = helper.getView(R.id.iv_pic);
        ImageView im_check = helper.getView(R.id.im_check);
        TextView tv_name = helper.getView(R.id.tv_name);
        GlideUtils.INSTANCE.loadImage(getContext(), item.img, iv_pic);
        if (item.isSelect) {
            im_check.setBackgroundResource(R.drawable.icon_check_select);
        } else {
            im_check.setBackgroundResource(R.drawable.icon_check_normal);
        }
        tv_name.setText(item.name);
        iv_pic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               if (!item.isSelect){
                   if (null!=itemSelectListener){
                       itemSelectListener.select(item.id);
                   }
               }
            }
        });
    }

    public  interface ItemSelectListener{
        void select(long id);
    }
    private ItemSelectListener itemSelectListener;
    public void setItemSelectListener(ItemSelectListener itemSelectListener){
        this.itemSelectListener=itemSelectListener;
    }
}
