package com.zxhy.solarmasterace.tools

import android.net.Uri
import android.view.ViewGroup
import coil.load
import coil.transform.RoundedCornersTransformation
import com.zxhy.solarmasterace.R
import com.zxhy.solarmasterace.adapter.CommonAdapter
import com.zxhy.solarmasterace.adapter.ItemCardImage85ViewHolder
import com.zxhy.solarmasterace.quicktools.getFilePathByUri
import com.zxhy.solarmasterace.quicktools.inflate

class RecentImageAdapter(
    val clickItem: ((uri: Uri) -> Unit)? = null
) : CommonAdapter<ItemCardImage85ViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemCardImage85ViewHolder {
        return ItemCardImage85ViewHolder(R.layout.item_card_image_85.inflate(parent))
    }

    override fun onBindViewHolder(holder: ItemCardImage85ViewHolder, position: Int) {
        val data = fileList[position]
        holder.binding.apply {
            iv.load(data.uri) {
                transformations(RoundedCornersTransformation())
            }
            iv.setOnClickListener {
                clickItem?.invoke(data.uri)
            }
        }
    }

}