package com.bonait.bnframework.modules.home.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.db.mode.BPA_MATERIAL;
import com.bonait.bnframework.common.db.res.ResMaterilas;
import com.bonait.bnframework.common.helper.I.MyClickListener;

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


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

    private final LayoutInflater mLayoutInflater;

    private Context context;

    List<BPA_MATERIAL> Data = new ArrayList<>();

    MyClickListener Click=null;

    public newneatril_adapter(Context context, List<BPA_MATERIAL> data,MyClickListener _Click) {
        this.context = context;

        mLayoutInflater = LayoutInflater.from(context);
        Data = data;
        Click=_Click;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = mLayoutInflater.inflate(R.layout.new_meatril_click, parent, false);
        return new MyLCViewHolder1(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        try {
            if (holder instanceof MyLCViewHolder1) {

                BPA_MATERIAL goods = (BPA_MATERIAL) Data.get(position);
                MyLCViewHolder1 myViewHolder = (MyLCViewHolder1) holder;
                myViewHolder.button_select.setText(goods.name);
                //按钮点击
                myViewHolder.button_select.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Click.clickListener(view,goods);
                    }
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

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

    public static class MyLCViewHolder1 extends RecyclerView.ViewHolder {
        Button button_select;

        public MyLCViewHolder1(View view) {
            super(view);
            button_select = view.findViewById(R.id.button_select);
        }
    }
}