package com.example.jinyu_rfid.adapter;

import android.content.Context;
import android.view.LayoutInflater;
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.ReadTyreNoResult;
import com.example.jinyu_rfid.databinding.ItemConfigurationBinding;
import com.example.jinyu_rfid.databinding.ItemResultBinding;

import java.util.List;

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

    private List<ReadTyreNoResult> list;
    public ResultAdapter(Context context) {
        this.context = context;

        inflater=LayoutInflater.from(context);
    }

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

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemResultBinding binding= DataBindingUtil.inflate(inflater, R.layout.item_result,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   ItemResultBinding binding;

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


    }

}
