package com.example.writeepc.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.writeepc.BR;
import com.example.writeepc.R;
import com.example.writeepc.been.MESInfo;
import com.example.writeepc.databinding.ItemMesInfoBinding;

import java.util.List;

public class MyMesInfoAdapter extends RecyclerView.Adapter<MyMesInfoAdapter.MyMesInfoAdapterViewHolder> {

    private Context context;
    private LayoutInflater inflater;
    private List<MESInfo> list;

    public MyMesInfoAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

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

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

    @Override
    public void onBindViewHolder(@NonNull MyMesInfoAdapterViewHolder holder, int position) {
        ItemMesInfoBinding binding = holder.getBinding();
        MESInfo mesInfo = list.get(position);
        binding.setVariable(BR.data,mesInfo);

    }

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

    class MyMesInfoAdapterViewHolder extends RecyclerView.ViewHolder {
        private ItemMesInfoBinding binding;

        public ItemMesInfoBinding getBinding() {
            return binding;
        }

        public MyMesInfoAdapterViewHolder(ItemMesInfoBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }


    }

}
