package com.navinfo.outdoor.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

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

import com.bumptech.glide.Glide;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.room.ChargingPileEntity;

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

public class ChargingPileAdapter extends RecyclerView.Adapter<ChargingPileAdapter.ViewHolder> {
    private Context context;
    private List<ChargingPileEntity> chargingPileEntities=new ArrayList<>();

    public ChargingPileAdapter(Context context) {
        this.context = context;
    }

    public List<ChargingPileEntity> getChargingPileEntities() {
        return chargingPileEntities;
    }

    public void setChargingPileEntities(List<ChargingPileEntity> chargingPileEntities) {
        this.chargingPileEntities.addAll(chargingPileEntities);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_charging_pile, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        ChargingPileEntity chargingPileEntity = chargingPileEntities.get(position);
        holder.textView.setText(chargingPileEntity.getName());
        holder.rlItem.setBackgroundColor(Color.parseColor("#BDBDBD"));
        holder.itemView.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View v) {
            if (onLickItem!=null){
                onLickItem.item(chargingPileEntity);
            }
           }
       });
    }

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

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        RelativeLayout rlItem;
        TextView textView;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView=itemView.findViewById(R.id.image);
            rlItem=itemView.findViewById(R.id.rl_item);
            textView=itemView.findViewById(R.id.tv_text);
        }
    }
    onLickItem onLickItem;

    public void setOnLickItem(ChargingPileAdapter.onLickItem onLickItem) {
        this.onLickItem = onLickItem;
    }

    public interface onLickItem{
        void item( ChargingPileEntity chargingPileEntity );
    }
}
