package com.example.prettywallpapers.prettyadapter;

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

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

import com.bumptech.glide.Glide;
import com.example.prettywallpapers.activity.PreviewActivity;
import com.example.prettywallpapers.databinding.DiscoverRecycleViewBinding;
import com.example.prettywallpapers.list.PrettyPaper;
import com.example.prettywallpapers.myvalue.MyValues;
import com.example.prettywallpapers.room.PrettyPaperEntity;

import java.util.List;

public class DiscoverAdapter extends RecyclerView.Adapter<DiscoverAdapter.DiscoverVH> {
    private List<PrettyPaperEntity> mylist;
    private Context mycon;
    public  DiscoverAdapter(Context context, List<PrettyPaperEntity> list){
        mycon = context;
        mylist = list;
    }
    @NonNull
    @Override
    public DiscoverVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        DiscoverRecycleViewBinding discoverRecycleViewBinding = DiscoverRecycleViewBinding.inflate(LayoutInflater.from(mycon),parent,false);
        return new DiscoverVH(discoverRecycleViewBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull DiscoverVH holder, int position) {
        PrettyPaperEntity entity = mylist.get(position);
        Glide.with(mycon).load(entity.getImage())
                .into(holder.discoverbinding.discoverRecycleImage);
        holder.discoverbinding.discoverRecycleImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mycon, PreviewActivity.class);
                intent.putExtra(MyValues.PAPER_IMAGE,entity.getImage());
                mycon.startActivity(intent);
            }
        });
    }

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

    public class DiscoverVH extends RecyclerView.ViewHolder {
        private DiscoverRecycleViewBinding discoverbinding;
        public DiscoverVH(@NonNull DiscoverRecycleViewBinding itemView) {
            super(itemView.getRoot());
            discoverbinding = itemView;
        }
    }
}
