package com.qhclh.ytzh.work.tablepoultry;

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

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

import java.util.List;

/**
 * Created by 青花瓷 on 2017/12/11.
 */

public class XFactryAdapter extends BaseAdapter{
    private Context context;
    private List<TablePBean> list;
    private LayoutInflater layoutInflater;

    public XFactryAdapter(Context context, List<TablePBean> 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).getBreedFactory_id();
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        TablePBean message = list.get(i);

        if (view == null){
            view = layoutInflater.inflate(R.layout.item_tablep,viewGroup,false);
            viewHolder = new ViewHolder();
            viewHolder.tab_breedFactory_name = view.findViewById(R.id.tab_breedFactory_name);
            viewHolder.tab_days1 = view.findViewById(R.id.tab_days1);
            viewHolder.tab_dienub1 = view.findViewById(R.id.tab_dienub1);
            viewHolder.tab_obs1 = view.findViewById(R.id.tab_obs1);
            viewHolder.tab_days2 = view.findViewById(R.id.tab_days2);
            viewHolder.tab_dienub2 = view.findViewById(R.id.tab_dienub2);
            viewHolder.tab_obs2 = view.findViewById(R.id.tab_obs2);
            viewHolder.ll_tb1 = view.findViewById(R.id.ll_tb1);
            viewHolder.ll_tb2 = view.findViewById(R.id.ll_tb2);

            viewHolder.tab_days3 = view.findViewById(R.id.tab_days3);
            viewHolder.tab_dienub3 = view.findViewById(R.id.tab_dienub3);
            viewHolder.tab_obs3 = view.findViewById(R.id.tab_obs3);
            viewHolder.ll_tb3 = view.findViewById(R.id.ll_tb3);

            viewHolder.tab_days4 = view.findViewById(R.id.tab_days4);
            viewHolder.tab_dienub4 = view.findViewById(R.id.tab_dienub4);
            viewHolder.tab_obs4 = view.findViewById(R.id.tab_obs4);
            viewHolder.ll_tb4 = view.findViewById(R.id.ll_tb4);

            viewHolder.tab_days5 = view.findViewById(R.id.tab_days5);
            viewHolder.tab_dienub5 = view.findViewById(R.id.tab_dienub5);
            viewHolder.tab_obs5 = view.findViewById(R.id.tab_obs5);
            viewHolder.ll_tb5 = view.findViewById(R.id.ll_tb5);

            viewHolder.tab_days6 = view.findViewById(R.id.tab_days6);
            viewHolder.tab_dienub6 = view.findViewById(R.id.tab_dienub6);
            viewHolder.tab_obs6 = view.findViewById(R.id.tab_obs6);
            viewHolder.ll_tb6 = view.findViewById(R.id.ll_tb6);

            viewHolder.tab_days7 = view.findViewById(R.id.tab_days7);
            viewHolder.tab_dienub7 = view.findViewById(R.id.tab_dienub7);
            viewHolder.tab_obs7 = view.findViewById(R.id.tab_obs7);
            viewHolder.ll_tb7 = view.findViewById(R.id.ll_tb7);

            viewHolder.view_v1 = view.findViewById(R.id.view_v1);
            viewHolder.view_v2 = view.findViewById(R.id.view_v2);
            viewHolder.view_v3 = view.findViewById(R.id.view_v3);
            viewHolder.view_v4 = view.findViewById(R.id.view_v4);
            viewHolder.view_v5 = view.findViewById(R.id.view_v5);
            viewHolder.view_v6 = view.findViewById(R.id.view_v6);
            viewHolder.view_v7 = view.findViewById(R.id.view_v7);

            viewHolder.tab_chenghuolv1 = view.findViewById(R.id.tab_chenghuolv1);
            viewHolder.tab_chenghuolv2 = view.findViewById(R.id.tab_chenghuolv2);
            viewHolder.tab_chenghuolv3 = view.findViewById(R.id.tab_chenghuolv3);
            viewHolder.tab_chenghuolv4 = view.findViewById(R.id.tab_chenghuolv4);
            viewHolder.tab_chenghuolv5 = view.findViewById(R.id.tab_chenghuolv5);
            viewHolder.tab_chenghuolv6 = view.findViewById(R.id.tab_chenghuolv6);
            viewHolder.tab_chenghuolv7 = view.findViewById(R.id.tab_chenghuolv7);

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

        viewHolder.tab_breedFactory_name.setText("场:  "+message.getBreedFactory_name());
        if (message.getDetailses().getDays1()!=null) {
            viewHolder.ll_tb1.setVisibility(View.VISIBLE);
            viewHolder.view_v1.setVisibility(View.VISIBLE);
            viewHolder.tab_days1.setText("日龄1:" + message.getDetailses().getDays1());
            viewHolder.tab_chenghuolv1.setText("成活率:"+message.getDetailses().getChenghuolv1());
            viewHolder.tab_dienub1.setText("死亡:" + message.getDetailses().getDienumber1());
            viewHolder.tab_obs1.setText("淘汰:" + message.getDetailses().getObs1());
        }

        if (message.getDetailses().getDays2()!=null) {
            viewHolder.ll_tb2.setVisibility(View.VISIBLE);
            viewHolder.view_v2.setVisibility(View.VISIBLE);
            viewHolder.tab_days2.setText("日龄2:" + message.getDetailses().getDays2());
            viewHolder.tab_chenghuolv2.setText("成活率:"+message.getDetailses().getChenghuolv2());
            viewHolder.tab_dienub2.setText("死亡:" + message.getDetailses().getDienumber2());
            viewHolder.tab_obs2.setText("淘汰:" + message.getDetailses().getObs2());
        }

        if (message.getDetailses().getDays3()!=null) {
            viewHolder.ll_tb3.setVisibility(View.VISIBLE);
            viewHolder.view_v3.setVisibility(View.VISIBLE);
            viewHolder.tab_days3.setText("日龄3:" + message.getDetailses().getDays3());
            viewHolder.tab_chenghuolv3.setText("成活率:"+message.getDetailses().getChenghuolv3());
            viewHolder.tab_dienub3.setText("死亡:" + message.getDetailses().getDienumber3());
            viewHolder.tab_obs3.setText("淘汰:" + message.getDetailses().getObs3());
        }

        if (message.getDetailses().getDays4()!=null) {
            viewHolder.ll_tb4.setVisibility(View.VISIBLE);
            viewHolder.view_v4.setVisibility(View.VISIBLE);
            viewHolder.tab_days4.setText("日龄4:" + message.getDetailses().getDays4());
            viewHolder.tab_chenghuolv4.setText("成活率:"+message.getDetailses().getChenghuolv4());
            viewHolder.tab_dienub4.setText("死亡:" + message.getDetailses().getDienumber4());
            viewHolder.tab_obs4.setText("淘汰:" + message.getDetailses().getObs4());
        }

        if (message.getDetailses().getDays5()!=null) {
            viewHolder.ll_tb5.setVisibility(View.VISIBLE);
            viewHolder.view_v5.setVisibility(View.VISIBLE);
            viewHolder.tab_days5.setText("日龄5:" + message.getDetailses().getDays5());
            viewHolder.tab_chenghuolv5.setText("成活率:"+message.getDetailses().getChenghuolv5());
            viewHolder.tab_dienub5.setText("死亡:" + message.getDetailses().getDienumber5());
            viewHolder.tab_obs5.setText("淘汰:" + message.getDetailses().getObs5());
        }

        if (message.getDetailses().getDays6()!=null) {
            viewHolder.ll_tb6.setVisibility(View.VISIBLE);
            viewHolder.view_v6.setVisibility(View.VISIBLE);
            viewHolder.tab_days6.setText("日龄6:" + message.getDetailses().getDays6());
            viewHolder.tab_chenghuolv6.setText("成活率:"+message.getDetailses().getChenghuolv6());
            viewHolder.tab_dienub6.setText("死亡:" + message.getDetailses().getDienumber6());
            viewHolder.tab_obs6.setText("淘汰:" + message.getDetailses().getObs6());
        }
        if (message.getDetailses().getDays7()!=null) {
            viewHolder.ll_tb7.setVisibility(View.VISIBLE);
            viewHolder.view_v7.setVisibility(View.VISIBLE);
            viewHolder.tab_days7.setText("日龄7:" + message.getDetailses().getDays7());
            viewHolder.tab_chenghuolv7.setText("成活率:"+message.getDetailses().getChenghuolv7());
            viewHolder.tab_dienub7.setText("死亡:" + message.getDetailses().getDienumber7());
            viewHolder.tab_obs7.setText("淘汰:" + message.getDetailses().getObs7());
        }



        return view;
    }

    private class ViewHolder {
        private TextView tab_breedFactory_name;
        private TextView tab_days1;
        private TextView tab_dienub1;
        private TextView tab_obs1;
        private TextView tab_days2;
        private TextView tab_dienub2;
        private TextView tab_obs2;
        private LinearLayout ll_tb1;
        private LinearLayout ll_tb2;
        private TextView tab_days3;
        private TextView tab_dienub3;
        private TextView tab_obs3;
        private LinearLayout ll_tb3;

        private TextView tab_days4;
        private TextView tab_dienub4;
        private TextView tab_obs4;
        private LinearLayout ll_tb4;

        private TextView tab_days5;
        private TextView tab_dienub5;
        private TextView tab_obs5;
        private LinearLayout ll_tb5;

        private TextView tab_days6;
        private TextView tab_dienub6;
        private TextView tab_obs6;
        private LinearLayout ll_tb6;

        private TextView tab_days7;
        private TextView tab_dienub7;
        private TextView tab_obs7;
        private LinearLayout ll_tb7;

        private TextView view_v1;
        private TextView view_v2;
        private TextView view_v3;
        private TextView view_v4;
        private TextView view_v5;
        private TextView view_v6;
        private TextView view_v7;

        private TextView tab_chenghuolv1;
        private TextView tab_chenghuolv2;
        private TextView tab_chenghuolv3;
        private TextView tab_chenghuolv4;
        private TextView tab_chenghuolv5;
        private TextView tab_chenghuolv6;
        private TextView tab_chenghuolv7;

    }
}
