package com.test.basd.smartjunkcleaner.activity.photocompress.photo;

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

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

import com.bumptech.glide.Glide;
import com.test.basd.smartjunkcleaner.R;

import java.util.List;

public class GalleryAdapter extends RecyclerView.Adapter<GalleryAdapter.GalleryViewHolder> {
    private Context context;


    private int index = 0;

    public void setPos(int index) {
        this.index = index;
    }

    private List<PhotoBean> list;

    public GalleryAdapter(Context context, List<PhotoBean> list) {
        this.context = context;
        this.list = list;
    }

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

    @Override
    public void onBindViewHolder(@NonNull GalleryViewHolder holder, int position) {
        if (position < list.size()) {
            PhotoBean bean = list.get(position);
            Glide.with(holder.itemView.getContext()).load(bean.getSrc()).into((ImageView) holder.itemView);
        }
    }

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

    public static class GalleryViewHolder extends RecyclerView.ViewHolder {

        public GalleryViewHolder(@NonNull View itemView) {
            super(itemView);
        }
    }
}