package com.qhclh.ytzh.work.scan;

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

import com.qhclh.ytzh.R;
import com.qhclh.ytzh.bean.ScanBean;

import java.util.List;

/**
 * Created by 青花瓷 on 2017/11/30.
 */
///< 扫一扫
public class ScanAdapter extends BaseAdapter {

    private Context context;
    private List<ScanBean> list;
    private LayoutInflater layoutInflater;

    public ScanAdapter(Context context, List<ScanBean> list) {
        this.context = context;
        this.list = list;
        layoutInflater = LayoutInflater.from(context);
    }

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

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

    @Override
    public long getItemId(int i) {
        return list.get(i).getId();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        ScanBean message = list.get(i);
        if (view == null){
            view = layoutInflater.inflate(R.layout.item_infos,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.infos_carname = view.findViewById(R.id.infos_carname);
            viewHolder.infos_driver = view.findViewById(R.id.infos_driver);
            viewHolder.infos_phone = view.findViewById(R.id.infos_phone);
            viewHolder.infos_batch = view.findViewById(R.id.infos_batch);
            viewHolder.infos_addrs = view.findViewById(R.id.infos_addrs);
            viewHolder.infos_time = view.findViewById(R.id.infos_time);
            viewHolder.infos_number = view.findViewById(R.id.infos_number);
            viewHolder.infos_immune = view.findViewById(R.id.infos_immune);
            viewHolder.infos_uniformity = view.findViewById(R.id.infos_uniformity);
            viewHolder.infos_startime = view.findViewById(R.id.infos_startime);
            viewHolder.infos_endtime = view.findViewById(R.id.infos_endtime);

            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.infos_carname.setText(message.getInfos_carname());
        viewHolder.infos_driver.setText(message.getInfos_driver());
        viewHolder.infos_phone.setText(message.getInfos_phone());
        viewHolder.infos_batch.setText(message.getInfos_batch());
        viewHolder.infos_addrs.setText(message.getInfos_addrs());
        viewHolder.infos_time.setText(message.getInfos_time());
        viewHolder.infos_number.setText(message.getInfos_number());
        viewHolder.infos_immune.setText(message.getInfos_immune());
        viewHolder.infos_uniformity.setText(message.getInfos_uniformity());
        viewHolder.infos_startime.setText(message.getInfos_startime());
        viewHolder.infos_endtime.setText(message.getInfos_endtime());

        return view;
    }

    private class ViewHolder{
        private TextView infos_carname;
        private TextView infos_driver;
        private TextView infos_phone;
        private TextView infos_batch;
        private TextView infos_addrs;
        private TextView infos_time;
        private TextView infos_number;
        private TextView infos_immune;
        private TextView infos_uniformity;
        private TextView infos_startime;
        private TextView infos_endtime;
    }
}
