package com.xm.test.myfilemaster.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.util.SparseBooleanArray
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.CheckBox
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.xm.test.myfilemaster.R
import com.xm.test.myfilemaster.activity.MediaActivity
import com.xm.test.myfilemaster.databinding.ItemImageVideoBinding
import com.xm.test.myfilemaster.model.FileBean
import com.xm.test.myfilemaster.util.FileUtil

class MediaAdapter2 : RecyclerView.Adapter<MediaAdapter2.CCC>() {


    private var mListData: ArrayList<FileBean> = arrayListOf()

    fun Int.inflate(parent: ViewGroup, attachToRoot: Boolean = false): View {
        return LayoutInflater.from(parent.context).inflate(this, parent, attachToRoot)
    }

    class CCC(view: View) : RecyclerView.ViewHolder(view) {
        val binding = ItemImageVideoBinding.bind(view)
    }

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

    override fun getItemCount(): Int {
        return mListData.size
    }

    override fun onBindViewHolder(holder: CCC, position: Int) {
        val data = mListData[position]
        val context = holder.binding.root.context
        Glide.with(context).load(data.filePath).centerCrop().into(holder.binding.ivMedia)
    }

    @SuppressLint("NotifyDataSetChanged")
    fun setData(datas: List<FileBean>) {
        mListData.clear()
        mListData.addAll(datas)
        notifyDataSetChanged()
    }
}