package com.drawing.drawsketch.all

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.drawing.drawsketch.App
import com.drawing.drawsketch.BaseAdapter
import com.drawing.drawsketch.Utils
import com.drawing.drawsketch.databinding.CategoryAllAdapterBinding
import com.drawing.drawsketch.databinding.MainAdapterBinding
import java.io.IOException
import kotlin.math.min

class CategoryAllAdapter(var category:String,context: Context,var clickAction:(filePath:String)->Unit):BaseAdapter<String,CategoryAllAdapterBinding>(context) {
    override fun getViewBinding(parent: ViewGroup?): CategoryAllAdapterBinding {

       return  CategoryAllAdapterBinding.inflate(
           LayoutInflater.from(parent?.context),
           parent,
           false
       )
    }


    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val itemHolder  = holder as VHolder<CategoryAllAdapterBinding>
        data[position].let {
            val filePath = "$category/$it"
         Utils.loadImage(mContext, filePath,Utils.dpToPx(60f),Utils.dpToPx(140f)){
             itemHolder.vb.mainImage.setImageBitmap(it)
         }
            itemHolder.vb.mainImage.setOnClickListener {
                clickAction(filePath)
            }
        }


    }


}