package com.base.filerecoveryrecyclebin.adapter

import android.annotation.SuppressLint
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.filerecoveryrecyclebin.R
import com.base.filerecoveryrecyclebin.databinding.ItemMediaGridBinding
import com.base.filerecoveryrecyclebin.utils.LogEx
import com.base.filerecoveryrecyclebin.view.XmlEx.inflate
import com.bumptech.glide.Glide

class FileGridAdapter : RecyclerView.Adapter<FileGridAdapter.FFF>() {

    private val beanList = arrayListOf<String>()
    private val TAG = "FileGridAdapter"

    inner class FFF(view: View) : ViewHolder(view)

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

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

    override fun onBindViewHolder(holder: FFF, position: Int) {
        val binding = ItemMediaGridBinding.bind(holder.itemView)
        val context = holder.itemView.context
        val data = beanList[position]
        LogEx.logDebug(TAG, data)
        Glide.with(context).load(data).centerCrop().into(binding.iv)
    }

    @SuppressLint("NotifyDataSetChanged")
    fun setData(list: List<String>) {
        beanList.clear()
        beanList.addAll(list)
        notifyDataSetChanged()
    }
}