package com.gh.gamecenter.game.horizontal

import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.GridLayoutManager
import com.gh.gamecenter.common.base.BaseRecyclerViewHolder
import com.gh.gamecenter.common.utils.dip2px
import com.gh.gamecenter.databinding.GameHorizontalListBinding
import com.gh.gamecenter.entity.GameEntity
import com.gh.gamecenter.entity.SubjectEntity

class GameHorizontalListViewHolder(val binding: GameHorizontalListBinding) :
    BaseRecyclerViewHolder<GameEntity>(binding.root) {

    fun bindHorizontalList(subjectEntity: SubjectEntity): GameHorizontalAdapter {
        val context = binding.root.context
        var subjectAdapter = binding.recyclerView.adapter
        if (subjectAdapter == null) {
            binding.recyclerView.setPadding(5F.dip2px(), 8F.dip2px(), 5F.dip2px(), 8F.dip2px())
            binding.recyclerView.layoutManager = GridLayoutManager(context, 4)
            subjectAdapter = GameHorizontalAdapter(context, subjectEntity)
            (binding.recyclerView.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false
            binding.recyclerView.adapter = subjectAdapter
            binding.recyclerView.isNestedScrollingEnabled = false
        } else {
            (subjectAdapter as GameHorizontalAdapter).checkResetData(subjectEntity)
        }
        return subjectAdapter
    }

}