package com.zxhy.fastfilemanagerpro.kokolistfile

import android.annotation.SuppressLint
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.zxhy.fastfilemanagerpro.R
import com.zxhy.fastfilemanagerpro.databinding.ActivityKoListFilekoBinding
import com.zxhy.fastfilemanagerpro.databinding.ItemKokoListFileBinding
import com.zxhy.fastfilemanagerpro.kokoadapter.CommonAdapter
import com.zxhy.fastfilemanagerpro.kokotools.XmlEx.inflate

class KoListFilekoAdapter(
    private val allSelect: (flag: Boolean) -> Unit
) : CommonAdapter<KoListFilekoAdapter.ItemKokoListFileViewHolder>() {


    inner class ItemKokoListFileViewHolder(view: View) : ViewHolder(view) {
        val binding = ItemKokoListFileBinding.bind(view)
    }

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

    override fun onBindViewHolder(holder: ItemKokoListFileViewHolder, position: Int) {

    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(
        holder: ItemKokoListFileViewHolder,
        position: Int,
        payloads: MutableList<Any>
    ) {
        val context = holder.binding.root.context
        val data = fileList[position]
        if (payloads.isEmpty()) {
            holder.binding.apply {
                tvName.text = data.name
                tvInfo.text = "${data.timeE}  ${data.sizeF}"
                ivSelector.isSelected = data.isSelect
                ivSelector.setOnClickListener {
                    data.isSelect = !data.isSelect
                    notifyItemChanged(position, "局部刷洗")
                    allSelect.invoke(fileList.all { it.isSelect })
                }
            }
        } else {
            holder.binding.apply {
                ivSelector.isSelected = data.isSelect
            }
            super.onBindViewHolder(holder, position, payloads)
        }
    }


}