package com.sketch.ar.artdrawing.allImageList

import android.content.Context
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.net.toUri
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.Target
import com.sketch.ar.artdrawing.R
import com.sketch.ar.artdrawing.databinding.AdapterAllListBinding
import com.sketch.ar.artdrawing.utils.BaseAdapter
import com.sketch.ar.artdrawing.utils.CommonUtils

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

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


    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val itemHolder  = holder as VHolder<AdapterAllListBinding>
        data[position].let {
            val filePath = "$category/$it"

            val uri = "file:///android_asset/$filePath".toUri()
            itemHolder.vb.mainImage.let {
                Glide.with(mContext)
                    .asBitmap()
                    .load(uri)
                    .override(Target.SIZE_ORIGINAL)
                    .into(it)
            }

            itemHolder.vb.mainImage.setOnClickListener {
                clickAction(filePath)
            }
        }


    }


}