package com.example.jinyu_rfid.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

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

import com.example.jinyu_rfid.BR;
import com.example.jinyu_rfid.R;
import com.example.jinyu_rfid.been.ConfigurationData;
import com.example.jinyu_rfid.been.ConfigurationTable;
import com.example.jinyu_rfid.callback.ItemClickCall;
import com.example.jinyu_rfid.databinding.ItemConfigurationBinding;

import java.util.List;

/**
 * @author wanghao
 * @date 2024/5/17  15:35
 */
public class ConfigurationTableAdapter extends RecyclerView.Adapter<ConfigurationTableAdapter.MyViewHolder> {
    private Context context;
    private LayoutInflater inflater;

    private List<ConfigurationData> list;
    public ConfigurationTableAdapter(Context context) {
        this.context = context;

        inflater=LayoutInflater.from(context);
    }

    public void setList(List<ConfigurationData> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemConfigurationBinding binding= DataBindingUtil.inflate(inflater, R.layout.item_configuration,parent,false);
        return new MyViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
        var item = list.get(position);
        holder.binding.setVariable(BR.item,item);
        holder.binding.executePendingBindings();
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
       private   ItemConfigurationBinding binding;

        public MyViewHolder(ItemConfigurationBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }


    }

}
