package com.wd.workoffice.ui.adapter;


import android.icu.text.UFormat;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wd.workoffice.R;
import com.wd.workoffice.bean.mesBean.QualityClientBean;
import com.wd.workoffice.bean.mesBean.QualityMarkBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by flexible on 2018/8/13.
 */

public class MesQualityMarkAdapter extends BaseQuickAdapter<QualityMarkBean.ListBean, BaseViewHolder> {
    Map<Integer, Boolean> isChoose = new HashMap<>();

    public MesQualityMarkAdapter(int layoutResId, List data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, QualityMarkBean.ListBean item) {
        helper.setText(R.id.tv_name, item.getSerialNumber());
        CheckBox cbCheck = helper.getView(R.id.cb_check);
        cbCheck.setChecked(null != isChoose.get(helper.getLayoutPosition()) && isChoose.get(helper.getLayoutPosition()));
        cbCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                isChoose.put(helper.getLayoutPosition(), isChecked);
            }
        });

    }

    public String getChooseMark() {
        StringBuilder chooseMark = new StringBuilder();
        for (Map.Entry<Integer, Boolean> entry : isChoose.entrySet()) {
            if (entry.getValue())
                chooseMark.append(getData().get(entry.getKey()).getSerialNumber()).append(",");
        }
        if (chooseMark.length() > 0) {
            chooseMark.substring(0, chooseMark.length() - 1);
        }
        return chooseMark.toString();
    }
}

