package com.cooleshow.teacher.adapter;

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.teacher.R;
import com.cooleshow.teacher.bean.TeachableInstrumentBean;

import java.util.List;

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

    private OnItemSelectedListener mSelectedListener;

    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(view -> {
            if(mSelectedListener!=null){
                mSelectedListener.select(item, helper.getAbsoluteAdapterPosition());
            }
        });
    }

    public void setSelectedListener(OnItemSelectedListener selectedListener) {
        mSelectedListener = selectedListener;
    }

    public interface OnItemSelectedListener {
        void select(TeachableInstrumentBean isSelect, int absoluteAdapterPosition);
    }
}
