package cn.net.caoyao.cpzshandset.adapter;

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

import java.util.List;

import cn.net.caoyao.cpzshandset.R;
import cn.net.caoyao.cpzshandset.bean.PiCiBean;

public class PiCiListAdapter extends RecyclerView.Adapter {
    List<PiCiBean.DataBean> list;
    Context context;

    public PiCiListAdapter( List<PiCiBean.DataBean> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_pici, null);
        MyVIewHolder myVIewHolder=new MyVIewHolder(inflate);
        return myVIewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int i) {
        MyVIewHolder holder1=(MyVIewHolder) viewHolder;
        //批次code
        final String productBatchCode = list.get(i).getProductBatchCode();
        String productBatchType = list.get(i).getProductBatchType();
        //批次id
        final long id = list.get(i).getId();
        //产品name
        final String productName = list.get(i).getProductName();
        //产品id
        final long productId = list.get(i).getProductId();
        holder1.tv_pici_name.setText(productBatchCode+" ("+productBatchType+")");
        holder1.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onClick(i);
//                Intent intent = new Intent(context, ActivateConfigActivity.class);
//                intent.putExtra("id_pici",id);
//                intent.putExtra("id_product",productId);
//                intent.putExtra("name_pici",productBatchCode);
//                intent.putExtra("name_product",productName);
//                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
    class MyVIewHolder extends RecyclerView.ViewHolder {
        TextView tv_pici_name;
        public MyVIewHolder(View itemView) {
            super(itemView);
            tv_pici_name = itemView.findViewById(R.id.tv_pici_name);

        }
    }
    private JieKou listener;
    public interface JieKou{
        void onClick(int pos);
    }
    public void onClick(JieKou listener1){
        this.listener=listener1;
    }
}
