package com.gh.gamecenter.game.doublecard

import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import com.gh.gamecenter.R
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.view.GridSpacingItemColorDecoration
import com.gh.gamecenter.databinding.GameDoubleCardListBinding
import com.gh.gamecenter.entity.SubjectEntity

class DoubleCardListViewHolder(val binding: GameDoubleCardListBinding) : BaseRecyclerViewHolder<Any>(binding.root) {

    fun bindDoubleCardList(subject: SubjectEntity): DoubleCardListAdapter {
        return binding.doubleCardList.run {
            var subjectAdapter = adapter
            if (subjectAdapter is DoubleCardListAdapter) {
                subjectAdapter.checkResetData(subject)
            } else {
                (itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false
                isNestedScrollingEnabled = false
                layoutManager = GridLayoutManager(context, 2)
                subjectAdapter = DoubleCardListAdapter(context, subject)
                adapter = subjectAdapter
                addItemDecoration(GridSpacingItemColorDecoration(context, 8, 8, R.color.transparent))
            }
            subjectAdapter
        }
    }
}