package com.philisense.rdgo.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.philisense.rdgo.R;
import com.philisense.rdgo.bean.response.BoxInfoBean;
import com.philisense.rdgo.bean.response.OrderDetailBean;
import com.philisense.rdgo.databinding.ItemDistrbutionBinding;
import com.philisense.rdgo.databinding.ItemOutReplaceBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by shaop on 2018/1/5.
 */

public class distributionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<OrderDetailBean.DataBean> dataArray;
    private Context context;

    public distributionAdapter(Context context) {
        this.context = context;
        dataArray = new ArrayList<>();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemDistrbutionBinding mBindHeader = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_distrbution, parent, false);
        return new distributionAdapter.OrderViewHolder(mBindHeader.getRoot());
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        OrderViewHolder lineViewHolder = (OrderViewHolder) holder;

        String orderID = dataArray.get(position).getOrderId();

        lineViewHolder.itemOrderBinding.name.setText("名字："+dataArray.get(position).getTransport());
        lineViewHolder.itemOrderBinding.number.setText("单号："+orderID);
        lineViewHolder.itemOrderBinding.orderSend.setText("始地："+dataArray.get(position).getSendPlace());
        lineViewHolder.itemOrderBinding.orderReceiv.setText("终地："+dataArray.get(position).getRcvPlace());
//




        lineViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                monItemClickListener.onClick(orderID);

            }
        });

        lineViewHolder.itemOrderBinding.itemDelte.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                monItemClickListener.delte(position);
            }
        });


    }

    public interface OnItemClickListener{
        void onClick(String orderId);
        void delte(int postion);
    }
    public OnItemClickListener monItemClickListener;
    public void setOnClickListener(OnItemClickListener onClickListener){
        this.monItemClickListener=onClickListener;
    }


    @Override
    public int getItemCount() {
        return dataArray.size();
    }

    /**
     * 添加数据
     *
     * @param data 数据
     */
    public void insertData(List<OrderDetailBean.DataBean> data) {

    }

    /**
     * 初始化数据
     *
     * @param data 数据
     */
    public void setData(List<OrderDetailBean.DataBean> data) {
        dataArray = data;
        notifyDataSetChanged();
    }

    private class OrderViewHolder extends RecyclerView.ViewHolder {

        ItemDistrbutionBinding itemOrderBinding;

        OrderViewHolder(View view) {
            super(view);
            itemOrderBinding = DataBindingUtil.getBinding(view);
        }

    }
}

