package com.datarecovery.master.module.member;

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

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

import com.datarecovery.master.databinding.ItemSuperScenesBinding;
import com.datarecovery.master.module.member.bean.SuperScenesBean;

import java.util.List;

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

    private List<SuperScenesBean> list;

    @NonNull
    @Override
    public SuperScenesAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        Context context = parent.getContext();
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        return new ViewHolder(ItemSuperScenesBinding.inflate(layoutInflater, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull SuperScenesAdapter.ViewHolder holder, int position) {
        holder.bind(list.get(position));
    }

    @SuppressLint("NotifyDataSetChanged")
    public void setData(List<SuperScenesBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {
        private final ItemSuperScenesBinding binding;

        public ViewHolder(@NonNull ItemSuperScenesBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

        public void bind(SuperScenesBean superScenesBean) {
            binding.setBean(superScenesBean);
        }
    }
}
