package com.qy.agv.activity.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.qy.agv.R;
import com.qy.agv.activity.appEnum.StatusEnum;
import com.qy.agv.activity.model.OrderTaskModel;
import com.qy.agv.activity.model.TaskModel;

import java.util.ArrayList;

public class HomeListViewAdapter extends BaseAdapter {
    private ArrayList<OrderTaskModel> mList;
    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public HomeListViewAdapter(ArrayList<OrderTaskModel> list, Context context) {
        this.mList=list;
        this.mContext=context;
        this.mLayoutInflater=LayoutInflater.from(context);
    }


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

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

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


    @Override
    public View getView(int position, View view, ViewGroup parent) {
        MainHolder mainHolder = null;
        final OrderTaskModel orderTaskModel = mList.get(position);
        if (view == null) {
            view=mLayoutInflater.inflate(R.layout.item_home_listview,null);
            mainHolder = new MainHolder();
            mainHolder.tv_task_code = view.findViewById(R.id.tv_task_code);
            mainHolder.tv_task_name = view.findViewById(R.id.tv_task_name);
            mainHolder.tv_start_point = view.findViewById(R.id.tv_start_point);
            mainHolder.tv_end_point = view.findViewById(R.id.tv_end_point);
            mainHolder.tv_create_time = view.findViewById(R.id.tv_create_time);
            mainHolder.tv_status = view.findViewById(R.id.tv_status);
            mainHolder.tv_remark = view.findViewById(R.id.tv_remark);
            view.setTag(mainHolder);
        }else{
            mainHolder= (MainHolder) view.getTag();
        }
        mainHolder.tv_task_code.setText(orderTaskModel.getTaskCode());
        mainHolder.tv_task_name.setText(orderTaskModel.getTaskName());
        mainHolder.tv_start_point.setText(orderTaskModel.getFromAreaName());
        mainHolder.tv_end_point.setText(orderTaskModel.getToAreaName());
        mainHolder.tv_create_time.setText(orderTaskModel.getCreateTime());
        StatusEnum status = StatusEnum.filter(orderTaskModel.getStatus());
        mainHolder.tv_status.setText(status.getText());
        if(orderTaskModel.getStatus() == 1){
            mainHolder.tv_status.setTextColor(Color.BLUE);
        }else if(orderTaskModel.getStatus() == 2){
            mainHolder.tv_status.setTextColor(Color.parseColor("#ff00ff"));
        }else if(orderTaskModel.getStatus() == 3){
            mainHolder.tv_status.setTextColor(Color.GREEN);
        }else if(orderTaskModel.getStatus() == 4){
            mainHolder.tv_status.setTextColor(Color.RED);
        }else{
            mainHolder.tv_status.setTextColor(Color.DKGRAY);
        }
        mainHolder.tv_remark.setText(orderTaskModel.getRemark());
        return view;
    }

    static class MainHolder {
        public TextView tv_task_code;
        public TextView tv_task_name;
        public TextView tv_start_point;
        public TextView tv_end_point;
        public TextView tv_create_time;
        public TextView tv_status;
        public TextView tv_remark;
    }

}
