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.bean.RecycleBinBean
import com.base.filerecoveryrecyclebin.databinding.ItemRecycleBinBeanBinding
import com.base.filerecoveryrecyclebin.view.XmlEx.inflate

class RecycleBinAdapter : RecyclerView.Adapter<RecycleBinAdapter.RBAV>() {

    private val beanList = arrayListOf<RecycleBinBean>()


    inner class RBAV(view: View) : ViewHolder(view) {

    }

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

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

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: RBAV, position: Int) {
        val binding = ItemRecycleBinBeanBinding.bind(holder.itemView)
        val bean = beanList[position]
        binding.tvPath.text = bean.path
        binding.tvDeleted.text = "deleted=${bean.deleted}"
        binding.tvDeleteTime.text = "time=" + bean.deleteTime.toString()
        binding.tvSize.text = "size=${bean.size}"
        binding.tvMimetype.text = "mimetype=${bean.mimeType}"
    }

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