package com.tenlionsoft.baselib.core.widget.base;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.tenlionsoft.baselib.R;
import com.tenlionsoft.baselib.core.beans.ConditionBean;
import com.tenlionsoft.baselib.core.beans.DicBean;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者: adam
 * 日期: 2021/10/20 - 11:18 上午
 * 邮箱: itgaojian@163.com
 * 描述:
 */
public class ConditionAdapter extends BaseRecyclerAdapter<ConditionBean, ConditionHolder> {
    public List<ConditionBean> mSelBeans = new ArrayList<>();

    public ConditionAdapter(Context ctx, List<ConditionBean> list) {
        super(ctx, list);
    }

    @Override
    public ConditionHolder createHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_condition_sel, parent, false);
        return new ConditionHolder(view);
    }

    @Override
    public void bindHolder(ConditionHolder holder, int i) {
        ConditionBean bean = mData.get(i);
        holder.mTvName.setText(bean.getName());
        holder.mCbCheck.setOnCheckedChangeListener(null);
        holder.mTvName.setTextColor(bean.isCheck() ? Color.parseColor("#1296db") : Color.BLACK);
        holder.mCbCheck.setChecked(bean.isCheck());
        holder.mCbCheck.setOnCheckedChangeListener((buttonView, isChecked) -> mLis.onItemCheckChange(bean, isChecked, i));
        holder.itemView.setOnClickListener(v -> mLis.onItemCheckChange(bean, !bean.isCheck(), i));
    }

    private OnItemCheckChange mLis;

    public void addOnitemCheckChange(OnItemCheckChange lis) {
        this.mLis = lis;
    }

    public interface OnItemCheckChange {
        void onItemCheckChange(ConditionBean bean, boolean isCheck, int pos);
    }
}
