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.databinding.ItemOutReplaceBinding;

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

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

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

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

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

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

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

        String boxId = dataArray.get(position).getBoxId();
        lineViewHolder.itemOrderBinding.itemBox.setText(boxId);
        String name=dataArray.get(position).getName();
        lineViewHolder.itemOrderBinding.itemBoxname.setText(name);

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

            }
        });

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




    }

    public interface OnItemClickListener{
        void onClick();
        void btnOnClick(int postion, String boxId);
    }
    public OnItemClickListener monItemClickListener;
    public void setOnClickListener(OnItemClickListener onClickListener){
        this.monItemClickListener=onClickListener;
    }


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

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

    }

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

    private class OrderViewHolder extends RecyclerView.ViewHolder {

        ItemOutReplaceBinding itemOrderBinding;

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

    }
}

