package com.gh.gamecenter.qa.video.detail.comment

import android.content.Context
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.gh.gamecenter.R
import com.gh.gamecenter.qa.article.detail.CommentItemData
import com.gh.gamecenter.qa.comment.base.BaseCommentAdapter
import java.util.ArrayList

class VideoCommentAdapter(val context: Context, val mViewModel: VideoCommentViewModel, val entrance: String) :
    BaseCommentAdapter(context, mViewModel, AdapterType.COMMENT, entrance) {

    override fun setListData(updateData: MutableList<CommentItemData>?) {
        if (updateData != null && mEntityList != null && mEntityList.size >= updateData.size) {
            mEntityList = ArrayList(updateData)
            notifyDataSetChanged()
            return
        }
        super.setListData(updateData)
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is CommentErrorViewHolder) {
            val container = holder.itemView.findViewById<View>(R.id.container)
            (container.layoutParams as RecyclerView.LayoutParams).apply {
                height = RecyclerView.LayoutParams.MATCH_PARENT
                container.layoutParams = this
            }
        } else {
            super.onBindViewHolder(holder, position)
        }
    }
}