package com.example.mynotepad.MenuFeatures.Pics.Gallery;

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

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

import com.example.mynotepad.R;

import java.util.ArrayList;

public class GalleryAdaptor extends RecyclerView.Adapter<GalleryAdaptor.GalleryViewHolder> {
    private ArrayList<MyGalleryPic> picsUrlAndTxt;
    private Context context;

    public GalleryAdaptor(ArrayList<MyGalleryPic> picsUrlAndTxt, Context context) {
        this.picsUrlAndTxt = picsUrlAndTxt;
        this.context = context;
    }

    @NonNull
    @Override
    public GalleryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom_gallery_item, parent, false);
        return new GalleryViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GalleryViewHolder holder, int position) {
        holder.textView.setText(picsUrlAndTxt.get(position).getText());
        System.out.println(picsUrlAndTxt.get(position).getUrl() + "                                         !!!!!");
        holder.imageView.setImageBitmap(BitmapFactory.decodeFile(picsUrlAndTxt.get(position).getUrl()));
    }

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

    public class GalleryViewHolder extends RecyclerView.ViewHolder {
        TextView textView;
        ImageView imageView;

        public GalleryViewHolder(@NonNull View itemView) {
            super(itemView);
            textView = itemView.findViewById(R.id.tv_gallery);
            imageView = itemView.findViewById(R.id.img_gallery);
        }
    }
}
