package com.baoshi.swms.adapter;

import android.annotation.SuppressLint;
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.baoshi.swms.R;
import com.baoshi.swms.bean.Waybill;

import java.util.List;

/**
 * 运单列表适配器
 *
 * @author Zhendong Zhou
 * @date   2021/12/3 18:11
 */
public class WaybillDispatchList extends BaseAdapter {

    private final List<Waybill> list;
    private final Context context;

    public WaybillDispatchList(List<Waybill> list, Context context) {
        this.list = list;
        this.context = context;
    }

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

    @Override
    public Object getItem(int i) {
        return null;
    }

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

    @SuppressLint("ResourceAsColor")
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null)view = LayoutInflater.from(context).inflate(R.layout.item_waybill_item, viewGroup, false);
        Waybill waybill = list.get(i);
        TextView waybillNumber =  view.findViewById(R.id.waybill_number);
        waybillNumber.setText(waybill.getWaybillNumber());
        TextView deliverAt =  view.findViewById(R.id.deliver_at);
        deliverAt.setText(waybill.getDeliverAt());
        TextView number =  view.findViewById(R.id.number);
        number.setText((waybill.getWeight()!=null && waybill.getWeight()!=0.0) ? waybill.getWeight() +" KG" :
                ((waybill.getVolume()!=null && waybill.getVolume()!=0.0) ? waybill.getVolume()+" M³" : "暂无"));
        if (number.getText().equals("暂无"))number.setTextColor(R.color.dark_gray);
        return view;
    }
}
