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.HjywInfo;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * 货架移位列表适配器
 */
public class HjywAdapter extends BaseAdapter implements View.OnClickListener {
    private List<HjywInfo.Hjyw> list;
    private Context context;
    private CallBack mCallBack;


    public HjywAdapter(List<HjywInfo.Hjyw> list, Context context, CallBack mCallBack) {
        this.list = list;
        this.context = context;
        this.mCallBack = mCallBack;
    }

    /**
     * Called when background view has been clicked.
     *
     * @param v The view that was clicked.
     */
    @Override
    public void onClick(View v) {
        mCallBack.Click(v);
    }

    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.ss_item, viewGroup, false);
            holder.tv_hj = (TextView) view.findViewById(R.id.tv_hj);
            holder.tv_ph = (TextView) view.findViewById(R.id.tv_ph);
            holder.tv_dqsl = (TextView) view.findViewById(R.id.tv_dqyl);
            holder.tv_wll = (TextView) view.findViewById(R.id.tv_wll);
            holder.tv_pch = (TextView) view.findViewById(R.id.tv_pch);
            holder.tv_hjzy = (TextView) view.findViewById(R.id.tv_hjzy);
            holder.cb = (CheckBox) view.findViewById(R.id.cb);
            view.setTag(holder);
            AutoUtils.autoSize(view);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.tv_wll.setText(list.get(i).getCurbal() + "");
        holder.tv_dqsl.setText(list.get(i).getBinnum() + "");
        holder.tv_ph.setText(list.get(i).getDescription());
        holder.tv_hj.setText(list.get(i).getItemnum());
        holder.tv_pch.setText(list.get(i).getLotnum());
        holder.tv_hjzy.setText(list.get(i).getIn6());
        holder.cb.setChecked(list.get(i).isChecked());
        holder.cb.setOnClickListener(this);
        holder.cb.setTag(i);

        return view;
    }

    static class ViewHolder {
        TextView tv_hj;//项目
        TextView tv_ph;//描述
        TextView tv_dqsl;//存放货柜
        TextView tv_wll;//数量
        TextView tv_pch;//批次号
        TextView tv_hjzy;//货架专业
        CheckBox cb;
    }
}
