package com.zxhy.simplefilesmanager.simplelist

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.zxhy.simplefilesmanager.R
import com.zxhy.simplefilesmanager.databinding.ItemJoListFileJoBinding
import com.zxhy.simplefilesmanager.simpleadpter.JoCommonJoAdapter
import com.zxhy.simplefilesmanager.simpledata.JoListFileJo
import com.zxhy.simplefilesmanager.simplejoke.DipPxEx
import com.zxhy.simplefilesmanager.simplejoke.JoXmljoEx.jojoinflate

class SimpleListAdapter(val context: Context) :
    JoCommonJoAdapter<SimpleListAdapter.CC, JoListFileJo>() {

    private val options =
        RequestOptions()
            .transform(CenterCrop(), RoundedCorners(DipPxEx.dp2px(context, R.dimen.dp_8)))

    class CC(view: View) : ViewHolder(view) {
        val binding = ItemJoListFileJoBinding.bind(view)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CC {
        return CC(R.layout.item_jo_list_file_jo.jojoinflate(parent))
    }

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

    }

    override fun onBindViewHolder(holder: CC, position: Int, payloads: MutableList<Any>) {

        val data = joFileList[position]

        if (payloads.isEmpty()) {
            Glide.with(context)
                .load(data.path)
                .apply(options)
                .into(holder.binding.iv)
        } else {
            super.onBindViewHolder(holder, position, payloads)
        }
    }
}