package com.remax.visualnovel.app

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by HJW on 2021/10/19
 */
abstract class BaseBindingQuickAdapter<T, out VB : ViewBinding>(
    private val inflate: (LayoutInflater, ViewGroup, Boolean) -> VB,
    layoutResId: Int = -1,
    data: MutableList<T>? = null
) :
    BaseQuickAdapter<T, BaseBindingQuickAdapter.BaseBindingHolder>(layoutResId, data) {

    override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int) =
        BaseBindingHolder(inflate(LayoutInflater.from(parent.context), parent, false))

    class BaseBindingHolder(private val binding: ViewBinding) : BaseViewHolder(binding.root) {
        constructor(itemView: View) : this(ViewBinding { itemView })

        @Suppress("UNCHECKED_CAST")
        fun <VB : ViewBinding> getViewBinding() = binding as VB

        var extraObj: Any? = null

    }

    /**
     * 带左右滑动的item收起
     */
//    fun resetDeleteView(position: Int) {
//        try {
//            (getViewByPosition(
//                position + headerLayoutCount,
//                R.id.easySwipeMenuLayout
//            ) as? EasySwipeMenuLayout)?.resetStatus()
//        } catch (e: Exception) {
//            Timber.d("resetDeleteView position:$position Exception:${e.localizedMessage}")
//        }
//    }

}