//package com.base.datarecovery.adapter
//
//import android.annotation.SuppressLint
//import android.view.View
//import android.view.ViewGroup
//import androidx.core.content.ContextCompat
//import androidx.recyclerview.widget.RecyclerView
//import com.base.datarecovery.R
//import com.base.datarecovery.bean.MediaBean
//import com.base.datarecovery.databinding.ItemMediaFileBinding
//import com.base.datarecovery.databinding.ItemMediaSelectBinding
//import com.base.datarecovery.help.KotlinExt.toFormatSize
//import com.base.datarecovery.view.XmlEx.inflate
//import com.bumptech.glide.Glide
//import java.io.File
//
//class WhatsAppMediaAdapter(
//    private val isList: Boolean = false,
//    private val click: (allSelect: Boolean) -> Unit
//) : RecyclerView.Adapter<WhatsAppMediaAdapter.WhatMedia>() {
//
//    private val beanList = arrayListOf<MediaBean>()
//
//    class WhatMedia(view: View) : RecyclerView.ViewHolder(view)
//
//
//    override fun getItemViewType(position: Int): Int {
//        return if (isList) 0 else 1
//    }
//
//    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WhatMedia {
//        val layout = if (viewType == 0) R.layout.item_media_file else R.layout.item_media_select
//        return WhatMedia(layout.inflate(parent))
//    }
//
//    override fun getItemCount(): Int {
//        return beanList.size
//    }
//
//    override fun onBindViewHolder(holder: WhatMedia, position: Int) {
//
//    }
//
//    override fun onBindViewHolder(holder: WhatMedia, position: Int, payloads: MutableList<Any>) {
//
//
//        val context = holder.itemView.context
//        val bean = beanList[position]
//
//        if (isList) {
//            val binding = ItemMediaFileBinding.bind(holder.itemView)
//
//            if (payloads.isEmpty()) {
//                binding.iv.setImageDrawable(ContextCompat.getDrawable(context, R.mipmap.audiomessages))
//                val file = File(bean.path)
//                binding.tvName.text = file.name
//                binding.tvSize.text = file.length().toFormatSize()
//                binding.ivSelector.isSelected = bean.isSelect
//                binding.root.setOnClickListener {
//                    binding.ivSelector.isSelected = !binding.ivSelector.isSelected
//                    bean.isSelect = binding.ivSelector.isSelected
//                    notifyItemChanged(position, "sdd")
//                    click.invoke(beanList.all { it.isSelect })
//                }
//            } else {
//                binding.ivSelector.isSelected = bean.isSelect
//                super.onBindViewHolder(holder, position, payloads)
//            }
//        } else {
//            val binding = ItemMediaSelectBinding.bind(holder.itemView)
//            if (payloads.isEmpty()) {
//                Glide.with(context).load(bean.path).centerCrop().into(binding.iv)
//                binding.ivSelector.isSelected = bean.isSelect
//                binding.root.setOnClickListener {
//                    binding.ivSelector.isSelected = !binding.ivSelector.isSelected
//                    bean.isSelect = binding.ivSelector.isSelected
//                    notifyItemChanged(position, "sdd")
//                    click.invoke(beanList.all { it.isSelect })
//                }
//            } else {
//                binding.ivSelector.isSelected = bean.isSelect
//                super.onBindViewHolder(holder, position, payloads)
//            }
//
//        }
//    }
//
//    @SuppressLint("NotifyDataSetChanged")
//    fun setData(pathList: List<MediaBean>) {
//        beanList.clear()
//        beanList.addAll(pathList)
//        notifyDataSetChanged()
//    }
//
//    @SuppressLint("NotifyDataSetChanged")
//    fun toggleSelect(select: Boolean) {
//        beanList.forEach { it.isSelect = select }
//        notifyDataSetChanged()
//    }
//
//    fun getSelectData(): List<String> {
//        return beanList.filter { it.isSelect }.map { it.path }
//    }
//
//    fun getSelectDataSize(): Long {
//        return getSelectData().map { File(it) }.sumOf { it.length() }
//    }
//}