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.PlayActivity
import com.audio.record.screen.test.base.BaseAdapter
import com.audio.record.screen.test.data.VideoInfo
import com.audio.record.screen.test.databinding.AdapterVideoInfoBinding
import com.audio.record.screen.test.tool.Common

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

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


        itemHolder.vb.run {
            space.isVisible = position == data.size - 1 && isLast
            image.setImageBitmap(item.thumbnail)
            tvName.text = item.displayName
            tvTime.text = Common.formatDuration(item.duration)
            tvSize.text = Common.formatFileSize(item.size)
            root.setOnClickListener {
                mContext.startActivity(Intent(mContext, PlayActivity::class.java).apply {
                    putExtra(PlayActivity.KEY_URI, item.uri)
                    putExtra(PlayActivity.KEY_name, item.displayName)
                })
            }
        }

    }

}