package com.sketch.art.trace.adapter;

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

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

import com.sketch.art.trace.databinding.ListChildLayoutBinding;
import com.sketch.art.trace.listener.OnMyClickListener;
import com.sketch.art.trace.tools.ComManager;

import java.util.List;

public class AdapterChild extends RecyclerView.Adapter<AdapterChild.ChildVH> {


    private Context mCon;
    private List<String> data;

    private OnMyClickListener listener;


    public void setListener(OnMyClickListener listener) {
        this.listener = listener;
    }

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

    }


    @NonNull
    @Override
    public ChildVH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {


        return new ChildVH( ListChildLayoutBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false));
    }

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

        String name = data.get(position);
      ComManager.loadImageFromAssets(mCon, name, holder.binding.imPreview, bitmap -> {

      });
//        holder.binding.imPreview.setImageBitmap(bitmap);
        holder.binding.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClickItem(1, name);
                }
            }
        });



    }

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

    public static class ChildVH extends RecyclerView.ViewHolder {


        private ListChildLayoutBinding binding;


        public ChildVH(@NonNull ListChildLayoutBinding itemView) {
            super(itemView.getRoot());
            binding = itemView;
        }


    }
}
