package com.base.datarecovery.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.datarecovery.R
import com.base.datarecovery.databinding.ItemMediaGridBinding
import com.base.datarecovery.view.XmlEx.inflate
import com.bumptech.glide.Glide

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

    private val beanList = arrayListOf<String>()

    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
        Glide.with(context).load(beanList[position]).centerCrop().into(binding.iv)
    }

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