package com.fusi24.rfid.adapter;

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

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

import com.fusi24.rfid.data.entity.DataSite;
import com.fusi24.rfid.databinding.RowSiteBinding;

import java.util.ArrayList;
import java.util.List;

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

    private Context context;
    private List<DataSite> siteList;

    public SiteAdapter(Context context) {
        this.context = context;
        this.siteList = new ArrayList<>();
    }

    private void setSiteList(List<DataSite> siteList) {
        this.siteList = siteList;
    }

    public void updateSiteList(List<DataSite> siteList){
        setSiteList(siteList);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        private RowSiteBinding binding;

        ViewHolder(RowSiteBinding itemBinding) {
            super(itemBinding.getRoot());
            this.binding = itemBinding;
        }
    }


    @NonNull
    @Override
    public SiteAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        RowSiteBinding itemBinding = RowSiteBinding.inflate(LayoutInflater.from(context), parent, false);
        return new ViewHolder(itemBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull SiteAdapter.ViewHolder holder, int position) {

        DataSite site = siteList.get(position);
        holder.binding.tvCommon.setText(site.getName());

    }

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