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

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

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.helper.I.MyClickListener;

import java.util.List;

/**
 * @author: liup
 * @description: 基础数据管理 - 物料管理
 * @date: 2024/5/21 16:19.
 */
public class MaterialSetAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    /**
     * 内部点击事件
     */
    private MyClickListener mListener;
    private List<BPA_MATERIAL> datas;
    private final LayoutInflater mLayoutInflater;
    public MaterialSetAdapter(@NonNull Context context, @NonNull List<BPA_MATERIAL> objects, MyClickListener listener) {
        mListener = listener;
        datas=objects;
        mLayoutInflater = LayoutInflater.from(context);
    }

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

    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, @SuppressLint("RecyclerView") int position) {
        BPA_MATERIAL bpa_material = (BPA_MATERIAL) datas.get(position);//得到当前项选中item实例
        //为每一个子项加载设定的布局
        MyLCViewHolder1 myViewHolder = (MyLCViewHolder1) holder;

        // 设置要显示的图片和文字
        myViewHolder.name.setText(bpa_material.name);
        myViewHolder.name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mListener!=null) mListener.clickListenerNew(view,position,bpa_material);
            }
        });

        myViewHolder.button_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mListener!=null) mListener.clickListenerNew(view,position,bpa_material);
            }
        });

        myViewHolder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mListener!=null) mListener.clickListenerNew(view,position,bpa_material);
            }
        });
    }

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

    public static class MyLCViewHolder1 extends RecyclerView.ViewHolder{
        TextView name ;
        RelativeLayout button ;
        RelativeLayout button_update ;

        public MyLCViewHolder1(@NonNull View view) {
            super(view);
            name = view.findViewById(R.id.name);
            button = view.findViewById(R.id.button_item);
            button_update = view.findViewById(R.id.button_update);
        }
    }
}