package com.audio.record.screen.test.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.audio.record.screen.test.activity.ImageViewActivity
import com.audio.record.screen.test.activity.PlayActivity
import com.audio.record.screen.test.base.BaseAdapter
import com.audio.record.screen.test.data.ImageInfo
import com.audio.record.screen.test.data.VideoInfo
import com.audio.record.screen.test.databinding.AdapterImageInfoBinding
import com.audio.record.screen.test.databinding.AdapterVideoInfoBinding
import com.audio.record.screen.test.tool.Common

class ImageInfoAdapter(
    context: Context,
    var showNew: Boolean,
    private var click: (cropRatio: String) -> Unit
) :
    BaseAdapter<ImageInfo, AdapterImageInfoBinding>(context) {
    override fun getViewBinding(parent: ViewGroup?): AdapterImageInfoBinding {
        return AdapterImageInfoBinding.inflate(LayoutInflater.from(parent!!.context), parent, false)
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        val itemHolder: VHolder<AdapterImageInfoBinding> = holder as VHolder<AdapterImageInfoBinding>
        val item = data[position]

        itemHolder.vb.run {
            tvNew.isVisible = (showNew && position == 0)
            image.setImageBitmap(item.thumbnail)

            root.setOnClickListener {
                mContext.startActivity(Intent(mContext, ImageViewActivity::class.java).apply {
                    putExtra(ImageViewActivity.KEY_URI, item.uri)
                    putExtra(ImageViewActivity.KEY_name,item.displayName)
                })
            }
        }
    }
}