package com.draw.painting.test.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

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

import com.draw.painting.test.PaintingApp;
import com.draw.painting.test.R;
import com.draw.painting.test.manager.Utils;
import com.draw.painting.test.onClickListener;
import com.draw.painting.test.ui.CameraActivity;

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


    private Context mCon;
    private String dir;

    private int count = 4;
    private onClickListener listener;
    public HomeChildAdapter(Context mCon, String dirStr) {
        this.mCon = mCon;
        dir = dirStr;
    }

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

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

    @Override
    public void onBindViewHolder(@NonNull HomeVH holder, int position) {
        String filePath = dir + "/" + (position+1) + ".jpg";

        Log.d("---------tt","---------filePath="+filePath);
        Bitmap bitmap = Utils.loadImageFromAssets(mCon, filePath);
        holder.previewIm.setImageBitmap(bitmap);
        holder.cardView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener!= null){
                    listener.onClickItem(false,filePath);
                }

            }
        });


    }

    @Override
    public int getItemCount() {
        return count;
    }

    public static class HomeVH extends RecyclerView.ViewHolder {
        private ImageView previewIm;
        private CardView cardView;

        public HomeVH(@NonNull View itemView) {
            super(itemView);
            previewIm = itemView.findViewById(R.id.imPreview);
           cardView = itemView.findViewById(R.id.card);
        }


    }
}
