package com.example.administrator.zhapp.adapter;

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

import com.example.administrator.zhapp.R;
import com.example.administrator.zhapp.contans.Contans;
import com.example.administrator.zhapp.entity.SbdjInfo;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * 设备点检适配器
 */

public class SbdjAdapter extends BaseAdapter {

    private Context mContext;
    private List<SbdjInfo> list;

    public SbdjAdapter(Context context, List<SbdjInfo> list) {
        mContext = context;
        this.list = list;
    }

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

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

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.sbdj_item, parent, false);
            holder.tv_jcnr = (TextView) convertView.findViewById(R.id.tv_jcnr);
            holder.tv_pl = (TextView) convertView.findViewById(R.id.tv_pl);
            holder.tv_zt = (TextView) convertView.findViewById(R.id.tv_zt);
            holder.tv_zy = (TextView) convertView.findViewById(R.id.tv_zy);
            convertView.setTag(holder);
            AutoUtils.autoSize(convertView);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tv_zy.setText(list.get(position).getZy());
        holder.tv_jcnr.setText(list.get(position).getJcnr());
        holder.tv_pl.setText(list.get(position).getPl());

        switch (list.get(position).getZt()) {
            case Contans.SBXJZT_WWC:
                holder.tv_zt.setText("未检查");
                break;
            case Contans.SBXJZT_ZC:
                holder.tv_zt.setText("合格");
                holder.tv_zt.setTextColor(Color.BLUE);
                break;
            case Contans.SBXJZT_BZC:
                holder.tv_zt.setText("不合格");
                holder.tv_zt.setTextColor(Color.RED);
                break;
        }


        return convertView;
    }


    static class ViewHolder {
        TextView tv_zt;
        TextView tv_jcnr;
        TextView tv_zy;
        TextView tv_pl;
    }
}
