package com.ar.drawing.assistant.paint.tooladapter;

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

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

import com.ar.drawing.assistant.paint.databinding.ItListBinding;
import com.ar.drawing.assistant.paint.ui_activity.ActPreview;
import com.ar.drawing.assistant.paint.utils.Common;
import com.ar.drawing.assistant.paint.utils.MyApp;

import java.util.List;

public class AdList extends RecyclerView.Adapter<AdList.HomeVH> {


    private Context mCon;
    private List<String> data;



    public AdList(Context mCon, List<String> bitmapList) {
        this.mCon = mCon;
        data = bitmapList;
    }



    @NonNull
    @Override
    public HomeVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItListBinding inflate = ItListBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
        return new HomeVH(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull HomeVH holder, int position) {

        String name = data.get(position);
        Bitmap bitmap = Common.loadImageFromAssets(mCon, name);
        holder.binding.imPreview.setImageBitmap(bitmap);

        holder.binding.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mCon, ActPreview.class);
                intent.putExtra(MyApp.Key_Camera, name);
                mCon.startActivity(intent);
            }
        });


    }

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

    public static class HomeVH extends RecyclerView.ViewHolder {
        private ItListBinding binding;




        public HomeVH(@NonNull ItListBinding itemView) {
            super(itemView.getRoot());
            binding = itemView;
        }


    }
}
