package com.ygtx.emcs.activity.adapter;

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.ygtx.emcs.R;
import com.ygtx.emcs.activity.model.StockModel;

import java.util.ArrayList;

public class StockInAdapter extends BaseAdapter {
    private ArrayList<StockModel> mList;
    private Context mContext;
    private LayoutInflater mLayoutInflater;

    public StockInAdapter(ArrayList<StockModel> 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 StockModel stockModel = mList.get(position);
        if (view == null) {
            view=mLayoutInflater.inflate(R.layout.stock_in_item,null);
            mainHolder = new MainHolder();
            mainHolder.tv_startTime = view.findViewById(R.id.tv_start_time);
            mainHolder.tv_endTime = view.findViewById(R.id.tv_end_time);
            mainHolder.tv_remark = view.findViewById(R.id.tv_remark);
            mainHolder.tv_inStockCode = view.findViewById(R.id.tv_in_stock_code);
            mainHolder.tv_operator = view.findViewById(R.id.tv_operator);
            mainHolder.tv_status = view.findViewById(R.id.tv_status);
            view.setTag(mainHolder);
        }else{
            mainHolder= (MainHolder) view.getTag();
        }
        mainHolder.tv_remark.setText(stockModel.getRemark());
        mainHolder.tv_inStockCode.setText(stockModel.getErpInstockCode());
        mainHolder.tv_operator.setText(stockModel.getCreateBy());
        mainHolder.tv_startTime.setText(stockModel.getCreateTime());
        StatusEnum status = StatusEnum.filter(stockModel.getStatus());
        mainHolder.tv_status.setText(status.text);
        return view;
    }

    static class MainHolder {
        public TextView tv_startTime;
        public TextView tv_endTime;
        public TextView tv_remark;
        public TextView tv_inStockCode;
        public TextView tv_operator;
        public TextView tv_status;
    }
}
