package com.bjzc.zjyxdxj.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.bjzc.zjyxdxj.DBModel.Zjrwdata;
import com.bjzc.zjyxdxj.R;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;


/**
 * 下载计划适配器
 */
public class ZjdscAdapter extends BaseAdapter {

    private Context context;
    private List<Zjrwdata> list;
    private CallBack mCallBack;

    public ZjdscAdapter(Context context, List<Zjrwdata> list, CallBack mCallBack) {
        this.context = context;
        this.list = list;
        this.mCallBack = mCallBack;
    }

    public interface CallBack {
        void Click(View view);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {

        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.sczjdrw_item, viewGroup, false);
            holder.zjd_cb = view.findViewById(R.id.zjd_cb);
            holder.tv_zjd = view.findViewById(R.id.tv_zjd);
            holder.tv_yjzj = view.findViewById(R.id.tv_yjzj);

            view.setTag(holder);
            AutoUtils.autoSize(view);
        } else {
            holder = (ViewHolder) view.getTag();
        }


        holder.zjd_cb.setChecked(list.get(i).isChecked());

        holder.tv_zjd.setText(list.get(i).getTitle() + "-" + list.get(i).getName() + "-" + list.get(i).getProusername());

        holder.tv_yjzj.setText(list.get(i).getCountPercent());


        holder.zjd_cb.setTag(i);
        holder.zjd_cb.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mCallBack.Click(view);
            }
        });
        return view;
    }

    static class ViewHolder {
        CheckBox zjd_cb;
        TextView tv_zjd;
        TextView tv_yjzj;

    }
}
