package com.example.administrator.zhapp.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.example.administrator.zhapp.R;
import com.example.administrator.zhapp.entity.WlffInfo;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * 已接收列表适配器
 */
public class WlffAdapter extends BaseAdapter {

    private Context context;
    private List<WlffInfo.Wlff> infos;
    private CallBack mCallBack;

    public WlffAdapter(List<WlffInfo.Wlff> infos, Context context, CallBack callBack) {
        this.infos = infos;
        this.context = context;
        this.mCallBack = callBack;
    }

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

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

    @Override
    public Object getItem(int i) {
        return infos.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.receive_list, viewGroup, false);
            //view.findViewById(R.id.ll).setVisibility(View.GONE);
            holder.tv_ylsl = (TextView) view.findViewById(R.id.tv_kjs);
            holder.tv_project = (TextView) view.findViewById(R.id.tv_project);
            holder.tv_shelves = (TextView) view.findViewById(R.id.tv_shelves);
            holder.tv_count = (TextView) view.findViewById(R.id.tv_count);
            holder.ch = (CheckBox) view.findViewById(R.id.cb_isprint);
            holder.tv_describe = (TextView) view.findViewById(R.id.tv_describe);
            holder.tv_attr = (TextView) view.findViewById(R.id.tv_attr);
            view.setTag(holder);
            AutoUtils.autoSize(view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.tv_project.setText(infos.get(i).getItemnum());
        holder.tv_shelves.setText(infos.get(i).getDescription());
        holder.tv_count.setText(infos.get(i).getItemqty());
        holder.tv_describe.setText(infos.get(i).getRestype());
        holder.ch.setChecked(infos.get(i).isPrint());
        holder.tv_attr.setText(infos.get(i).getIn6());
        holder.tv_ylsl.setText(infos.get(i).getWonum());
        holder.ch.setTag(i);
        holder.ch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                mCallBack.onClick(view);
            }
        });
        return view;
    }

    static class ViewHolder {
        TextView tv_project;//库存项目
        TextView tv_shelves;//描述
        TextView tv_count;//接收数量
        TextView tv_describe;//单位
        CheckBox ch;
        TextView tv_attr;//专业属性
        TextView tv_ylsl;//已领数量
    }
}
