package com.gh.gamecenter.home

import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.gh.common.databind.BindingAdapters
import com.gh.common.util.*
import com.gh.common.util.LogUtils
import com.gh.common.util.NewFlatLogUtils
import com.gh.common.util.NewLogUtils
import com.gh.gamecenter.GameDetailActivity
import com.gh.gamecenter.R
import com.gh.gamecenter.adapter.viewholder.GameHeadViewHolder
import com.gh.gamecenter.adapter.viewholder.GameImageViewHolder
import com.gh.gamecenter.adapter.viewholder.GameViewHolder
import com.gh.gamecenter.common.constant.ItemViewType
import com.gh.gamecenter.common.entity.LinkEntity
import com.gh.gamecenter.common.exposure.ExposureSource
import com.gh.gamecenter.common.json.json
import com.gh.gamecenter.common.utils.*
import com.gh.gamecenter.core.iinterface.IOffsetable
import com.gh.gamecenter.core.runOnIoThread
import com.gh.gamecenter.core.utils.PageSwitchDataHelper
import com.gh.gamecenter.core.utils.StringUtils
import com.gh.gamecenter.databinding.ItemBlankDividerBinding
import com.gh.gamecenter.entity.CommonCollectionContentEntity
import com.gh.gamecenter.feature.entity.GameEntity
import com.gh.gamecenter.feature.exposure.ExposureEvent
import com.gh.gamecenter.feature.game.GameItemViewHolder
import com.gh.gamecenter.game.GameAndPosition
import com.gh.gamecenter.game.bigimagerecommend.BigImageRecommendViewHolder
import com.gh.gamecenter.game.columncollection.GameColumnCollectionViewHolder
import com.gh.gamecenter.game.commoncollection.CommonCollection12ViewHolder
import com.gh.gamecenter.game.commoncollection.CommonCollectionViewHolder
import com.gh.gamecenter.game.commoncollection.detail.CommonCollectionDetailActivity
import com.gh.gamecenter.game.doublecard.DoubleCardViewHolder
import com.gh.gamecenter.game.gallery.GameGallerySlideViewHolder
import com.gh.gamecenter.game.gallery.GameGalleryViewHolder
import com.gh.gamecenter.game.horizontal.GameHorizontalListViewHolder
import com.gh.gamecenter.game.horizontal.GameHorizontalSlideListViewHolder
import com.gh.gamecenter.game.imageslide.GameImageSlideViewHolder
import com.gh.gamecenter.game.rank.RankCollectionViewHolder
import com.gh.gamecenter.game.vertical.GameVerticalAdapter
import com.gh.gamecenter.game.vertical.GameVerticalSlideViewHolder
import com.gh.gamecenter.game.vertical.OnPagerSnapScrollListener
import com.gh.gamecenter.home.gamecollection.carousel.HomeGameCollectionCarouselViewHolder
import com.gh.gamecenter.home.gamecollection.refresh.HomeGameCollectionRefreshViewHolder
import com.gh.gamecenter.home.gamecollection.slide.HomeGameCollectionSlideViewHolder
import com.gh.gamecenter.home.horizontalslidevideo.HomeHorizontalSlideVideoListViewHolder
import com.gh.gamecenter.home.video.ScrollCalculatorHelper
import com.gh.gamecenter.servers.gametest2.GameServerTestV2Activity
import com.gh.gamecenter.subject.SubjectActivity
import com.halo.assistant.fragment.game.GamePluginAdapter
import com.halo.assistant.fragment.game.GamePluginViewHolder
import java.util.*

class LegacyHomeFragmentAdapterAssistant(
    private var mContext: Context,
    private var mAdapter: RecyclerView.Adapter<ViewHolder>,
    private var mBasicExposureSources: ArrayList<ExposureSource>,
    private var mMakeItemBackgroundTransparent: Boolean = false,
    private var mOuterType: OuterType = OuterType.NEW_HOME
) : IOffsetable {

    private var mPluginDisplayStatus = PluginDisplayStatus.DEFAULT

    private var mIsManualChangedDisplayStatus = false

    private var mHorizontalScrollOffsetMap: HashMap<Int, Int> = hashMapOf()

    fun getLegacyItemType(itemData: LegacyHomeItemData): Int {
        // 原游戏板块样式
        if (itemData.pluginList != null) return ItemViewType.GAME_PLUGIN
        if (itemData.columnHead != null) return ItemViewType.COLUMN_HEADER
        if (itemData.game != null) return ItemViewType.GAME_NORMAL
        if (itemData.image != null) return ItemViewType.GAME_IMAGE
        if (itemData.horizontalColumn != null) return ItemViewType.GAME_SUBJECT
        if (itemData.horizontalSlide != null) return ItemViewType.GAME_SUBJECT_SLIDE
        if (itemData.imageSlide != null) return ItemViewType.IMAGE_SLIDE_ITEM
        if (itemData.verticalSlide != null) return ItemViewType.VERTICAL_SLIDE_ITEM
        if (itemData.columnCollection != null) return ItemViewType.COLUMN_COLLECTION
        if (itemData.gallerySlide != null) return ItemViewType.GALLERY_SLIDE
        if (itemData.gallery != null) return ItemViewType.GALLERY
        if (itemData.blankDivider != null) return ItemViewType.BLANK_DIVIDER
        if (itemData.commonCollection != null) return ItemViewType.COMMON_LINK_COLLECTION
        if (itemData.commonCollection12 != null) return ItemViewType.COMMON_LINK_COLLECTION12
        if (itemData.rankCollection != null) return ItemViewType.RANK_COLLECTION
        if (itemData.doubleCardColumn != null) return ItemViewType.DOUBLE_CARD_COLUMN
        if (itemData.bigImageRecommend != null) return ItemViewType.BIG_IMAGE_RECOMMEND
        if (itemData.horizontalSlideVideo != null) return ItemViewType.HORIZONTAL_SLIDE_VIDEO
        if (itemData.gameCollection != null) {
            return when (itemData.gameCollection!!.style) {
                GAME_COLLECTION_CAROUSEL_STYLE -> ItemViewType.GAME_COLLECTION_CAROUSEL
                GAME_COLLECTION_BIG_SLIDE_STYLE -> ItemViewType.GAME_COLLECTION_BIG_SLIDE
                GAME_COLLECTION_SMALL_SLIDE_STYLE -> ItemViewType.GAME_COLLECTION_SMALL_SLIDE
                GAME_COLLECTION_HORIZONTAL_REFRESH_STYLE -> ItemViewType.GAME_COLLECTION_HORIZONTAL_REFRESH
                GAME_COLLECTION_VERTICAL_REFRESH_STYLE -> ItemViewType.GAME_COLLECTION_VERTICAL_REFRESH
                else -> ItemViewType.GAME_COLLECTION_CAROUSEL // style为空时默认展示轮播图
            }
        }

        return 0
    }

    fun createLegacyViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        return when (viewType) {
            // 游戏专题-横屏
            ItemViewType.GAME_SUBJECT -> GameHorizontalListViewHolder(parent.toBinding())
            // 游戏专题-横屏滑动
            ItemViewType.GAME_SUBJECT_SLIDE -> GameHorizontalSlideListViewHolder(parent.toBinding())
            // 正常游戏
            ItemViewType.GAME_NORMAL -> GameItemViewHolder(parent.toBinding())
            // 游戏专题-大图-显示/只显示
            ItemViewType.GAME_IMAGE -> GameImageViewHolder(parent.toBinding())
            // 专题头部
            ItemViewType.COLUMN_HEADER -> GameHeadViewHolder(parent.toBinding())
            // 游戏插件模块
            ItemViewType.GAME_PLUGIN -> GamePluginViewHolder(parent.toBinding())
            // 游戏专题-大图-只显示(滑动)
            ItemViewType.IMAGE_SLIDE_ITEM -> GameImageSlideViewHolder(parent.toBinding())
            // 游戏专题-竖屏滑动
            ItemViewType.VERTICAL_SLIDE_ITEM -> GameVerticalSlideViewHolder(parent.toBinding())
            // 专题合集
            ItemViewType.COLUMN_COLLECTION -> GameColumnCollectionViewHolder(parent.toBinding())
            // 游戏专题-图集滚动
            ItemViewType.GALLERY_SLIDE -> GameGallerySlideViewHolder(parent.toBinding())
            // 游戏专题-显示图集
            ItemViewType.GALLERY -> GameGalleryViewHolder(
                GameGalleryViewHolder.GameGalleryItemCell(mContext).apply { inflate() }
            )
            // 空白补充区域
            ItemViewType.BLANK_DIVIDER -> BlankDividerViewHolder(parent.toBinding())
            // 通用链接合集
            ItemViewType.COMMON_LINK_COLLECTION -> CommonCollectionViewHolder(parent.toBinding())
            // 通用链接合集(1-2样式)
            ItemViewType.COMMON_LINK_COLLECTION12 -> CommonCollection12ViewHolder(parent.toBinding())
            // 排行榜
            ItemViewType.RANK_COLLECTION -> RankCollectionViewHolder(parent.toBinding())
            // 游戏专题-双列卡片
            ItemViewType.DOUBLE_CARD_COLUMN -> DoubleCardViewHolder(parent.toBinding())
            // 提问、帖子、视频帖、文章
            ItemViewType.BIG_IMAGE_RECOMMEND -> BigImageRecommendViewHolder(parent.toBinding())
            // 游戏专题-视频横屏滑动
            ItemViewType.HORIZONTAL_SLIDE_VIDEO -> HomeHorizontalSlideVideoListViewHolder(parent.toBinding())
            // 游戏单合集-轮播图
            ItemViewType.GAME_COLLECTION_CAROUSEL -> HomeGameCollectionCarouselViewHolder(parent.toBinding())
            // 游戏单合集-横排滑动-大卡片/小卡片
            ItemViewType.GAME_COLLECTION_BIG_SLIDE,
            ItemViewType.GAME_COLLECTION_SMALL_SLIDE -> HomeGameCollectionSlideViewHolder(parent.toBinding())
            // 游戏单合集-刷新轮换-横排列表/竖排列表
            ItemViewType.GAME_COLLECTION_HORIZONTAL_REFRESH,
            ItemViewType.GAME_COLLECTION_VERTICAL_REFRESH -> HomeGameCollectionRefreshViewHolder(parent.toBinding())

            else -> throw NullPointerException()
        }
    }

    fun bindLegacyViewHolder(
        holder: ViewHolder,
        item: LegacyHomeItemData,
        position: Int,
        scrollCalculatorHelper: ScrollCalculatorHelper? = null,
    ) {
        when (holder) {
            is GameHeadViewHolder -> bindHeadView(holder, item, position)
            is GamePluginViewHolder -> bindPluginView(holder, item)
            is GameItemViewHolder -> bindGameItemView(holder, item, position)
            is GameImageViewHolder -> bindGameImageView(holder, item)
            is GameHorizontalListViewHolder -> bindGameHorizontalListView(holder, item)
            is GameHorizontalSlideListViewHolder -> bindGameHorizontalSlideListView(holder, item)
            is GameImageSlideViewHolder -> bindGameImageSlide(holder, item)
            is GameVerticalSlideViewHolder -> bindVerticalSlide(holder, item)
            is GameColumnCollectionViewHolder -> bindColumnCollection(holder, item)
            is GameGallerySlideViewHolder -> bindGallerySlide(holder, item)
            is GameGalleryViewHolder -> bindGallery(holder, item)
            is BlankDividerViewHolder -> holder.bindView(
                item.blankDivider!!,
                if (mOuterType == OuterType.NEW_HOME) {
                    com.gh.gamecenter.common.R.color.ui_surface.toColor(mContext)
                } else {
                    com.gh.gamecenter.common.R.color.ui_background.toColor(mContext)
                }
            )

            is CommonCollectionViewHolder -> bindCommonCollection(holder, item)
            is CommonCollection12ViewHolder -> bindCommonCollection(holder, item)
            is RankCollectionViewHolder -> bindRankCollection(holder, item)
            is DoubleCardViewHolder -> bindGameDoubleCard(holder, item)
            is BigImageRecommendViewHolder -> bindBigImageRecommend(holder, item)
            is HomeHorizontalSlideVideoListViewHolder -> bindHomeHorizontalSlideVideo(
                holder,
                item,
                scrollCalculatorHelper
            )

            is HomeGameCollectionCarouselViewHolder -> bindGameCollectionCarousel(holder, item)
            is HomeGameCollectionSlideViewHolder -> bindGameCollectionSlide(holder, item)
            is HomeGameCollectionRefreshViewHolder -> bindGameCollectionRefresh(holder, item)
        }
    }

    fun getLegacyGameEntityByPackage(
        positionList: ArrayList<GameAndPosition>,
        itemData: LegacyHomeItemData,
        packageName: String,
        position: Int
    ) {
        // 原游戏板块样式
        val plugins = itemData.pluginList
        if (plugins != null) {
            for (entity in plugins) {
                for (apkEntity in entity.getApk()) {
                    if (apkEntity.packageName == packageName) positionList.add(GameAndPosition(entity, position))
                }
            }
        }

        val game = itemData.game
        if (game != null) {
            positionList.add(GameAndPosition(game, position))
            return
        }

        val horizontalColumn = itemData.horizontalColumn
        if (horizontalColumn != null) {
            for (i in horizontalColumn.data!!.indices) {
                val entity = horizontalColumn.data!![i]
                if (!entity.image.isNullOrEmpty()) continue
                for (apkEntity in entity.getApk()) {
                    if (apkEntity.packageName == packageName) {
                        positionList.add(GameAndPosition(entity, position))
                    }
                }
            }
            return
        }

        val horizontalSlide = itemData.horizontalSlide
        if (horizontalSlide != null) {
            for (i in horizontalSlide.data!!.indices) {
                val entity = horizontalSlide.data!![i]
                if (!entity.image.isNullOrEmpty()) continue
                for (apkEntity in entity.getApk()) {
                    if (apkEntity.packageName == packageName) {
                        positionList.add(GameAndPosition(entity, position))
                    }
                }
            }
            return
        }

        val verticalSlide = itemData.verticalSlide
        if (verticalSlide != null) {
            for (i in verticalSlide.data!!.indices) {
                val entity = verticalSlide.data!![i]
                if (!entity.image.isNullOrEmpty()) continue
                for (apkEntity in entity.getApk()) {
                    if (apkEntity.packageName == packageName) {
                        positionList.add(GameAndPosition(entity, position))
                    }
                }
            }
            return
        }

        val rankCollection = itemData.rankCollection
        if (rankCollection != null) {
            rankCollection.columns.forEach { subjectEntity ->
                subjectEntity.data?.forEach {
                    for (apkEntity in it.getApk()) {
                        if (apkEntity.packageName == packageName) {
                            positionList.add(GameAndPosition(it, position))
                        }
                    }
                }
            }
            return
        }

        val horizontalSlideVideo = itemData.horizontalSlideVideo
        if (horizontalSlideVideo != null) {
            horizontalSlideVideo.data?.forEach {
                for (apkEntity in it.getApk()) {
                    if (apkEntity.packageName == packageName) {
                        positionList.add(GameAndPosition(it, position))
                    }
                }
            }
            return
        }

        val gameListCollection = itemData.gameCollection
        if (gameListCollection != null) {
            gameListCollection.gameCollectionItemDataList.forEach { gameCollectionItemData ->
                gameCollectionItemData.homeGameCollectionItem?.games?.forEach {
                    for (apkEntity in it.getApk()) {
                        if (apkEntity.packageName == packageName) {
                            positionList.add(GameAndPosition(it, position))
                        }
                    }
                }
            }
            return
        }

        val image = itemData.image
        if (image != null) {
            positionList.add(GameAndPosition(image, position))
        }
    }

    /**
     * bind 专题合集
     */
    private fun bindColumnCollection(holder: GameColumnCollectionViewHolder, item: LegacyHomeItemData) {
        if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(com.gh.gamecenter.common.R.color.transparent.toColor(mContext))

        val columnCollection = item.columnCollection!!
        // 重置曝光列表
        item.exposureEventList = arrayListOf()

        val clickClosure: (position: Int, gameEntity: GameEntity) -> Unit = { prefixedPosition, gameEntity ->
            // 类型为排行榜时点击处理不一样
            setPageSwitchData()
            if (columnCollection.style == "top") {
                DirectUtils.directToColumnCollection(
                    mContext,
                    columnCollection.id ?: "",
                    prefixedPosition,
                    "(首页游戏)",
                )
            } else {
                DirectUtils.directToLinkPage(
                    mContext,
                    LinkEntity(link = gameEntity.link, type = gameEntity.type),
                    "(首页游戏)",
                    "游戏-专题",
                    exposureEvent = gameEntity.exposureEvent
                )
            }
            NewLogUtils.logColumnCategoryHomeContentClick(
                gameEntity.name ?: "",
                gameEntity.link ?: "",
                columnCollection.name ?: "",
                columnCollection.id ?: "",
                "新首页",
                ""
            )

            SensorsBridge.trackColumnCollectionClick(
                location = "首页",
                blockName = "",
                blockId = "",
                columnCollectionName = columnCollection.name ?: "",
                columnCollectionId = columnCollection.id ?: "",
                position = prefixedPosition,
                gameColumnName = gameEntity.name ?: "",
                gameColumnId = gameEntity.link ?: "",
                text = "游戏专题",
                adGroupId = gameEntity.adGroupId
            )
        }

        holder.bindColumnCollection(columnCollection, mBasicExposureSources, clickClosure) {
            it.payload.outerSequence = item.blockPosition
            item.exposureEventList?.add(it)
        }

        val dataList = columnCollection.data!!
        if (dataList.size == 1) {
            val data = dataList[0]
            holder.binding.columnCollectionImage.setOnClickListener {
                setPageSwitchData()
                if (columnCollection.style == "top") {
                    DirectUtils.directToColumnCollection(
                        mContext,
                        columnCollection.id ?: "",
                        0,
                        "(首页游戏)"
                    )
                } else {
                    DirectUtils.directToLinkPage(
                        mContext,
                        LinkEntity(link = data.link, type = data.type),
                        "(首页游戏)",
                        "游戏-专题"
                    )
                }
                NewLogUtils.logColumnPictureClick(
                    "大图",
                    columnCollection.name ?: "",
                    columnCollection.id ?: "",
                    columnCollection.id ?: "",
                    "游戏专题",
                    columnCollection.name ?: "",
                    "新首页",
                    ""
                )
            }
        }
    }

    /**
     * 游戏专题-竖屏滑动
     */
    private fun bindVerticalSlide(holder: GameVerticalSlideViewHolder, item: LegacyHomeItemData) {
        if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(com.gh.gamecenter.common.R.color.transparent.toColor(mContext))

        val binding = holder.binding
        val verticalSlide = item.verticalSlide!!
        val exposureEventList = arrayListOf<ExposureEvent>()
        val listExposureEventList = arrayListOf<ExposureEvent>()

        val clickClosure: (Int, GameEntity) -> Unit = { _, gameEntity ->
            val subjectData = gameEntity.subjectData
            DataCollectionUtils.uploadClick(mContext, subjectData?.name + "-列表", "游戏-专题", gameEntity.name)
            GameDetailActivity.startGameDetailActivity(
                mContext,
                gameEntity.id,
                StringUtils.buildString(
                    "(游戏-专题:",
                    subjectData?.name,
                    "-列表[",
                    (subjectData?.position).toString(),
                    "])"
                ),
                traceEvent = gameEntity.exposureEvent
            )
        }

        val snapHelper = holder.bindVerticalSlide(verticalSlide, clickClosure, mMakeItemBackgroundTransparent)

        val exposureClosure: (Int) -> Unit = {
            val adapter = binding.recyclerView.adapter as GameVerticalAdapter
            val gameList = verticalSlide.data!!
            runOnIoThread(true) {
                listExposureEventList.clear()

                val startOffset = it * verticalSlide.list + adapter.getIndex()
                val endOffset = if (startOffset + verticalSlide.list >= gameList.size) {
                    gameList.size
                } else {
                    startOffset + verticalSlide.list
                }
                for (i in startOffset until endOffset) {
                    val event = ExposureEvent.createEventWithSourceConcat(
                        gameEntity = gameList[i].apply { isAdData = verticalSlide.adIconActive },
                        basicSource = mBasicExposureSources,
                        source = listOf(ExposureSource("专题", verticalSlide.name!!))
                    )
                    gameList[i].exposureEvent = event
                    listExposureEventList.add(event)
                }
                exposureEventList.addAll(listExposureEventList)
            }
        }
        exposureClosure(0)

        binding.recyclerView.addOnScrollListener(OnPagerSnapScrollListener(snapHelper) {
            exposureClosure(it)
        })

        if (mOuterType == OuterType.AMWAY) {
            binding.recyclerView.isNestedScrollingEnabled = false
        }

        item.exposureEventList = exposureEventList
    }

    /**
     * 游戏专题-大图-只显示(滑动)
     */
    private fun bindGameImageSlide(holder: GameImageSlideViewHolder, item: LegacyHomeItemData) {
        val binding = holder.binding
        val entity = item.imageSlide

        if (mOuterType == OuterType.AMWAY) {
            binding.columnList.isNestedScrollingEnabled = false
        }

        val exposureEventList = arrayListOf<ExposureEvent>()
        runOnIoThread(true) {
            for (gameEntity in entity?.games ?: arrayListOf()) {
                val exposureEvent = ExposureEvent.createEventWithSourceConcat(
                    gameEntity,
                    mBasicExposureSources,
                    listOf(ExposureSource("专题", entity?.name + "-大图"))
                )
                gameEntity.exposureEvent = exposureEvent
                exposureEventList.add(exposureEvent)
            }
        }
        item.exposureEventList = exposureEventList

        val imageClickListener = View.OnClickListener {
            DataCollectionUtils.uploadClick(mContext, entity?.name + "-大图", "游戏-专题")
            val linkEntity = LinkEntity()
            linkEntity.link = entity?.link
            linkEntity.type = entity?.type
            PageSwitchDataHelper.pushCurrentPageData(
                hashMapOf(
                    Pair(PageSwitchDataHelper.PAGE_BUSINESS_TYPE, "游戏专题-大图"),
                    Pair(PageSwitchDataHelper.PAGE_BUSINESS_NAME, entity?.subjectName ?: "")
                )
            )
            DirectUtils.directToLinkPage(
                mContext,
                linkEntity,
                "(游戏-专题:" + entity?.name + "-大图)",
                "首页游戏",
                exposureEventList.firstOrNull()
            )
        }

        holder.bindImageSlide(entity!!, imageClickListener, "游戏-专题", this)
    }

    /**
     * 游戏专题-横屏
     */
    private fun bindGameHorizontalListView(holder: GameHorizontalListViewHolder, item: LegacyHomeItemData) {
        if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(com.gh.gamecenter.common.R.color.transparent.toColor(mContext))

        val subjectEntity = item.horizontalColumn
        val subjectAdapter = holder.bindHorizontalList(subjectEntity!!)

        if (mOuterType == OuterType.AMWAY) {
            holder.binding.recyclerView.isNestedScrollingEnabled = false
        }

        val exposureEventList = arrayListOf<ExposureEvent>()
        subjectEntity.data?.let {
            runOnIoThread(true) {
                val positionOffset = subjectAdapter.getIndex()

                for (i in positionOffset until subjectAdapter.itemCount + positionOffset) {
                    if (i >= it.size) break

                    it[i].sequence = i
                    it[i].isAdData = subjectEntity.adIconActive
                    val event = ExposureEvent.createEventWithSourceConcat(
                        gameEntity = it[i],
                        basicSource = mBasicExposureSources,
                        source = listOf(ExposureSource("专题", subjectEntity.name!!))
                    )
                    exposureEventList.add(event)
                }
            }
            item.exposureEventList = exposureEventList
            subjectAdapter.exposureEventList = exposureEventList
        }
    }

    /**
     * 游戏专题-横屏滑动
     */
    private fun bindGameHorizontalSlideListView(holder: GameHorizontalSlideListViewHolder, item: LegacyHomeItemData) {
        if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(com.gh.gamecenter.common.R.color.transparent.toColor(mContext))

        val subjectEntity = item.horizontalSlide
        val subjectAdapter = holder.bindHorizontalSlideList(subjectEntity!!, this)

        if (mOuterType == OuterType.AMWAY) {
            holder.binding.recyclerView.isNestedScrollingEnabled = false
        }

        val exposureEventList = arrayListOf<ExposureEvent>()
        subjectEntity.data?.let {
            runOnIoThread(true) {
                val positionOffset = subjectAdapter.getIndex()
                for (i in positionOffset until subjectAdapter.itemCount + positionOffset) {
                    if (i >= it.size) break

                    it[i].sequence = i
                    it[i].isAdData = subjectEntity.adIconActive

                    val exposureKey = if (subjectEntity.remark != null) "开测表" else "专题"
                    val exposureValue =
                        if (!subjectEntity.remark.isNullOrBlank()) "${subjectEntity.name!!}-${subjectEntity.remark}" else subjectEntity.name!!

                    val event = ExposureEvent.createEventWithSourceConcat(
                        gameEntity = it[i],
                        basicSource = mBasicExposureSources,
                        source = listOf(ExposureSource(exposureKey, exposureValue))
                    )
                    exposureEventList.add(event)
                }
            }

            item.exposureEventList = exposureEventList
            subjectAdapter.exposureEventList = exposureEventList
        }
    }

    /**
     * 游戏专题-大图-显示/只显示
     */
    private fun bindGameImageView(holder: GameImageViewHolder, item: LegacyHomeItemData) {
        if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(com.gh.gamecenter.common.R.color.transparent.toColor(mContext))

        val entity = item.image
        holder.bindImage(entity!!, true)

        val name = entity.subjectData?.name
        val link = entity.link

        if (entity.type == "game") {
            item.exposureEvent = ExposureEvent.createEventWithSourceConcat(
                gameEntity = entity,
                basicSource = mBasicExposureSources,
                source = listOf(ExposureSource("专题", entity.subjectData?.name + "-大图"))
            )
            BindingAdapters.setDownloadButton(
                holder.binding.progressBar,
                entity,
                item.exposureEvent,
                null,
                "(游戏-专题:$name-大图)",
                ""
            )
        } else {
            BindingAdapters.setDownloadButton(
                holder.binding.progressBar,
                entity,
                null,
                null,
                "(游戏-专题:$name-大图)",
                ""
            )
        }
        holder.binding.gameImageIcon.setOnClickListener {
            DataCollectionUtils.uploadClick(mContext, "$name-大图", "游戏-专题")
            val linkEntity = LinkEntity()
            linkEntity.link = link
            linkEntity.type = entity.type
            linkEntity.text = entity.text
            setPageSwitchData()
            DirectUtils.directToLinkPage(mContext, linkEntity, "(游戏-专题:$name-大图)", "首页游戏")
            NewLogUtils.logColumnPictureClick(
                "大图", entity.name ?: "", entity.id, entity.id, "column",
                entity.name ?: "", "新首页", ""
            )
        }

        val padding = mContext.resources.getDimensionPixelSize(com.gh.gamecenter.common.R.dimen.home_item_padding)
        holder.binding.root.setPadding(padding, 0, padding, 0)
    }

    /**
     * 正常游戏
     */
    private fun bindGameItemView(holder: GameItemViewHolder, item: LegacyHomeItemData, position: Int) {
        if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(com.gh.gamecenter.common.R.color.transparent.toColor(mContext))

        val gameEntity = item.game
        val subjectData = gameEntity?.subjectData!!

        if (mAdapter.itemCount - 1 == position + 1) {
            holder.itemView.setPadding(16F.dip2px(), 8F.dip2px(), 16F.dip2px(), 16F.dip2px())
        } else {
            holder.itemView.setPadding(16F.dip2px(), 8F.dip2px(), 16F.dip2px(), 8F.dip2px())
        }

        holder.bindGameItem(gameEntity, subjectData.briefStyle)
        holder.initServerType(gameEntity)

        runOnIoThread(true) {
            item.exposureEvent = ExposureEvent.createEventWithSourceConcat(
                gameEntity = gameEntity,
                basicSource = mBasicExposureSources,
                source = listOf(ExposureSource("专题", gameEntity.subjectName ?: subjectData.name!!))
            )
        }

        DownloadItemUtils.setOnClickListener(
            mContext, holder.binding.downloadBtn, gameEntity, position,
            mAdapter,
            StringUtils.buildString("(游戏-专题:", subjectData.name, "-列表[", (position + 1).toString(), "])"),
            location = StringUtils.buildString("游戏-专题-", subjectData.name, ":", gameEntity.name),
            traceEvent = item.exposureEvent
        )
        DownloadItemUtils.updateItem(
            mContext,
            gameEntity,
            GameViewHolder(holder.binding),
            subjectData.briefStyle
        )

        holder.itemView.setOnClickListener {
            DataCollectionUtils.uploadClick(mContext, subjectData.name + "-列表", "游戏-专题", gameEntity.name)

            if (gameEntity.isPluggable) {
                GameDetailActivity.startGameDetailActivity(
                    mContext,
                    gameEntity.id,
                    StringUtils.buildString("(游戏-专题:插件化-列表[", (subjectData.position).toString(), "])"),
                    gameEntity.exposureEvent
                )
            } else {
                GameDetailActivity.startGameDetailActivity(
                    mContext,
                    gameEntity,
                    StringUtils.buildString(
                        "(游戏-专题:",
                        subjectData.name,
                        "-列表[",
                        (subjectData.position).toString(),
                        "])"
                    ),
                    traceEvent = gameEntity.exposureEvent
                )
            }
        }
        holder.binding.root.background = com.gh.gamecenter.common.R.drawable.reuse_listview_item_style.toDrawable(holder.binding.root.context)
        holder.binding.gameName.setTextColor(com.gh.gamecenter.common.R.color.text_primary.toColor(holder.binding.root.context))
    }

    /**
     * 专题头部
     */
    private fun bindHeadView(holder: GameHeadViewHolder, item: LegacyHomeItemData, position: Int) {
        if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(com.gh.gamecenter.common.R.color.transparent.toColor(mContext))

        val column = item.columnHead
        holder.bindHead(column!!)

        holder.binding.headMore.setOnClickListener {
            val buttonType = when (column.home) {
                "change" -> "换一批"
                "more" -> "更多"
                "game_list_square" -> "游戏单广场"
                else -> "全部"
            }
            val moreLink = column.moreLink
            NewLogUtils.logColumnListClickButton(
                buttonType, column.name ?: "", column.id ?: "", moreLink?.type ?: "",
                moreLink?.name ?: "", "新首页", ""
            )
            if ("change" == column.home) {
                holder.binding.headPb.visibility = View.VISIBLE
            } else if ("more" == column.home) {
                if (column.type == "game_list_collection") {
                    NewFlatLogUtils.logGameListCollectionClick(
                        "首页内容列表",
                        "",
                        "",
                        column.name ?: "",
                        column.id ?: "",
                        "更多",
                        column.moreLink?.type ?: "",
                        column.moreLink?.link ?: "",
                        column.moreLink?.text ?: ""
                    )
                    SensorsBridge.trackEvent("GameListCollectionClick", json {
                        "location" to "首页"
                        "game_list_collection_name" to column.name
                        "game_list_collection_id" to column.id
                        "text" to "更多"
                        "link_type" to column.moreLink?.type
                        "link_id" to column.moreLink?.link
                        "link_text" to column.moreLink?.text
                    })
                }
                column.moreLink?.let { link ->
                    DirectUtils.directToLinkPage(it.context, link, "(首页)", "(游戏-专题:" + column.name + "-全部)")
                }
            } else if ("game_list_square" == column.home) {
                NewFlatLogUtils.logGameListCollectionClick(
                    "首页内容列表",
                    "",
                    "",
                    column.name ?: "",
                    column.id ?: "",
                    "游戏单广场"
                )
                SensorsBridge.trackEvent("GameListCollectionClick", json {
                    "location" to "首页"
                    "game_list_collection_name" to column.name
                    "game_list_collection_id" to column.id
                    "text" to "游戏单广场"
                })
                DirectUtils.directToGameCollectionSquare(
                    mContext,
                    "首页内容列表",
                    column.name ?: "",
                    collectionId = column.id ?: "",
                    collectionName = column.name ?: ""
                )
            } else {
                setPageSwitchData()
                if (column.type == "column_collection") {
                    DirectUtils.directToColumnCollection(
                        mContext,
                        column.id!!,
                        -1,
                        "(游戏-专题:" + column.name + "-全部)"
                    )
                    NewLogUtils.logColumnCategoryHomeButtonClick(
                        buttonType, column.name ?: "", column.id ?: "", "首页", ""
                    )
                    SensorsBridge.trackColumnCollectionClick(
                        location = "首页",
                        blockName = "",
                        blockId = "",
                        columnCollectionName = column.name ?: "",
                        columnCollectionId = column.id ?: "",
                        position = -1,
                        gameColumnName = "",
                        gameColumnId = "",
                        text = "全部"
                    )
                } else if (column.type == "top_game_comment") {
                    DirectUtils.directToAmway(mContext, null, "(游戏-专题:" + column.name + "-全部)", "")
                    NewLogUtils.logHomeShareWallButtonClick("右上角")
                } else if (column.type == "common_collection") {
                    mContext.startActivity(
                        CommonCollectionDetailActivity.getIntent(
                            mContext,
                            column.id ?: "",
                            "",
                            "",
                            "首页内容列表"
                        )
                    )
                    NewLogUtils.logAccessToCommonCollectionDetail(column.id ?: "", column.name ?: "", "首页内容列表")
                    NewLogUtils.logCommonCategoryHomeButtonClick(
                        buttonType,
                        column.name ?: "",
                        column.id ?: "",
                        "新首页"
                    )
                    SensorsBridge.trackLinkContentCollectionClick(
                        location = "首页",
                        blockName = "",
                        blockId = "",
                        linkContentCollectionId = column.id ?: "",
                        linkContentCollectionName = column.name ?: "",
                        position = -1,
                        linkType = "",
                        linkId = "",
                        linkText = "",
                        text = "全部"
                    )
                } else if (column.type == "game_list_collection") {
                    DirectUtils.directToGameCollectionListDetail(
                        mContext,
                        column.id ?: "",
                        column.name ?: "",
                        column.explain,
                        "首页内容列表"
                    )
                } else if (column.type == "column_test_v2") {
                    //跳转到新游开测页面
                    val link = column.indexRightTopLink
                    val text = if (column.indexRightTop == "all") {
                        "全部"
                    } else {
                        "更多"
                    }
                    val location = "首页"
                    //埋点上报
                    if (text == "全部") {
                        NewFlatLogUtils.logGameTestV2MoreClick(text, location)
                        //点击进入[新游开测]详情页面
                        mContext.startActivity(GameServerTestV2Activity.getIntent(mContext, "none", "新游开测"))
                    } else {
                        //点击跳转通用链接
                        if (link != null) {
                            DirectUtils.directToLinkPage(mContext, link, "新游开测", "")
                            NewFlatLogUtils.logGameTestV2MoreClick(
                                text,
                                location,
                                linkType = link.type ?: "",
                                linkId = link.link ?: "",
                                linkText = link.text ?: ""
                            )
                        }
                    }

                } else {
                    if (column.indexRightTopLink != null) {
                        val link = column.indexRightTopLink!!

                        // ugly ugly ugly as hell
                        if (holder.binding.headMore.text.contains("更多")) {
                            LogUtils.logServerTestClickMoreEvent(link.text, column.remark, link.type, link.link)
                        } else {
                            LogUtils.logServerTestClickAllEvent(link.text, column.remark)
                        }

                        DirectUtils.directToLinkPage(mContext, link, "(游戏-专题:" + column.name + "-全部)", "")
                    } else {
                        SubjectActivity.startSubjectActivity(
                            mContext,
                            column.id,
                            column.getFilterName(),
                            column.isOrder,
                            mBasicExposureSources,
                            "(游戏-专题:" + column.name + "-全部)"
                        )
                    }
                }
            }
        }
    }

    /**
     * 游戏插件模块
     */
    private fun bindPluginView(holder: GamePluginViewHolder, item: LegacyHomeItemData) {
        if (mMakeItemBackgroundTransparent) holder.itemView.setBackgroundColor(com.gh.gamecenter.common.R.color.transparent.toColor(mContext))

        val pluginList = item.pluginList
        var adapter = holder.binding.recyclerView.adapter

        if (mPluginDisplayStatus == PluginDisplayStatus.DEFAULT) {
            mPluginDisplayStatus = HomePluggableHelper.getPluginDisplayedStyle(pluginList)
        }

        val exposureList = arrayListOf<ExposureEvent>()
        runOnIoThread(true) {
            for ((index, game) in pluginList!!.withIndex()) {
                game.sequence = index
                val event = ExposureEvent.createEventWithSourceConcat(
                    gameEntity = game,
                    basicSource = mBasicExposureSources,
                    source = listOf(ExposureSource("插件化", ""))
                )
                game.exposureEvent = event
                exposureList.add(event)
            }
        }
        item.exposureEventList = exposureList

        if (adapter == null) {
            adapter = GamePluginAdapter(mContext, pluginList) {
                if (!mIsManualChangedDisplayStatus) mPluginDisplayStatus = it
            }
            adapter.openList(mPluginDisplayStatus)
            (holder.binding.recyclerView.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false
            holder.binding.recyclerView.layoutManager = LinearLayoutManager(mContext)
            holder.binding.recyclerView.adapter = adapter
        } else {
            (adapter as GamePluginAdapter).openList(mPluginDisplayStatus)
            adapter.checkResetData(pluginList)
        }

        if ((mPluginDisplayStatus == PluginDisplayStatus.OPEN_AND_BUTTON || mPluginDisplayStatus == PluginDisplayStatus.OPEN_TWO_AND_BUTTON)) {
            holder.binding.pluginExtendContainer.visibility = View.VISIBLE
            holder.binding.pluginHeadOpen.visibility = View.GONE
            if (mPluginDisplayStatus == PluginDisplayStatus.OPEN_TWO_AND_BUTTON) {
                holder.binding.pluginExtend.text = "展开"
                holder.binding.pluginExtend.setDrawableEnd(R.drawable.home_plugin_bottom_open)
                holder.binding.pluginExtend.setTextColor(com.gh.gamecenter.common.R.color.primary_theme.toColor(mContext))
            } else {
                holder.binding.pluginExtend.text = "收起"
                holder.binding.pluginExtend.setDrawableEnd(R.drawable.home_plugin_bottom_close)
                holder.binding.pluginExtend.setTextColor(com.gh.gamecenter.common.R.color.text_tertiary.toColor(mContext))
            }
        } else {
            holder.binding.pluginExtendContainer.visibility = View.GONE
            holder.binding.pluginHeadOpen.visibility = View.VISIBLE
            if (mPluginDisplayStatus == PluginDisplayStatus.CLOSE) {
                holder.binding.pluginHeadOpen.setImageResource(R.drawable.home_plugin_open)
            } else {
                holder.binding.pluginHeadOpen.setImageResource(R.drawable.home_plugin_close)
            }
        }

        holder.binding.pluginHeadTitle.text =
            String.format(Locale.getDefault(), "你有%d个游戏可以升级插件版", pluginList?.size ?: 0)
        val expandClick: (View) -> Unit = {
            if (it.id != R.id.plugin_head || holder.binding.pluginExtendContainer.visibility == View.GONE) {
                if (mPluginDisplayStatus == PluginDisplayStatus.CLOSE || mPluginDisplayStatus == PluginDisplayStatus.OPEN_TWO_AND_BUTTON) {
                    if (mPluginDisplayStatus == PluginDisplayStatus.CLOSE) mPluginDisplayStatus =
                        PluginDisplayStatus.OPEN
                    if (mPluginDisplayStatus == PluginDisplayStatus.OPEN_TWO_AND_BUTTON) mPluginDisplayStatus =
                        PluginDisplayStatus.OPEN_AND_BUTTON
                } else {
                    mPluginDisplayStatus = PluginDisplayStatus.CLOSE
                }
                mIsManualChangedDisplayStatus = true
                mAdapter.notifyItemChanged(holder.adapterPosition)
            }
        }
        holder.binding.pluginExtendContainer.setOnClickListener(View.OnClickListener(function = expandClick))
        holder.binding.pluginHead.setOnClickListener(View.OnClickListener(function = expandClick))
    }

    /**
     * 游戏专题-图集滚动
     */
    private fun bindGallerySlide(holder: GameGallerySlideViewHolder, item: LegacyHomeItemData) {
        item.exposureEventList = arrayListOf()
        holder.bindView(item.gallerySlide!!, mBasicExposureSources, "(游戏-专题)") {
            item.exposureEventList?.add(it)
        }
    }

    /**
     * 游戏专题-显示图集
     */
    private fun bindGallery(holder: GameGalleryViewHolder, item: LegacyHomeItemData) {
        item.exposureEventList = arrayListOf()

        (holder.itemView as GameGalleryViewHolder.GameGalleryItemCell).bindWhenInflated {
            holder.bindView(item.gallery!!, holder.cell.binding!!, mBasicExposureSources) {
                item.exposureEventList?.add(it)
            }

            holder.cell.binding!!.root.setOnClickListener {
                DirectUtils.directToSubject(
                    it.context, item.gallery?.id ?: "", item.gallery?.name, "(游戏-专题)"
                )
                NewLogUtils.logColumnPictureClick(
                    "图集", item.gallery?.name ?: "", item.gallery?.id ?: "", item.gallery?.id ?: "", "column",
                    item.gallery?.name ?: "", "新首页", ""
                )
            }
        }
    }

    /**
     * bind 通用内容合集
     */
    private fun bindCommonCollection(holder: ViewHolder, item: LegacyHomeItemData) {
        val commonCollection = item.commonCollection ?: item.commonCollection12
        val clickClosure: (position: Int, contentEntity: CommonCollectionContentEntity) -> Unit =
            { sequence, contentEntity ->
                val linkEntity = contentEntity.linkEntity
                DirectUtils.directToLinkPage(
                    mContext,
                    linkEntity,
                    "(首页游戏)",
                    "通用链接合集",
                    linkEntity.exposureEvent
                )
                NewLogUtils.logCommonCollectionClick(
                    commonCollection?.id ?: "",
                    commonCollection?.name ?: "",
                    "",
                    "",
                    "首页内容列表",
                    "合集首页",
                    linkEntity.title ?: "",
                    contentEntity.addedContent1 ?: "",
                    contentEntity.addedContent2 ?: "",
                    linkEntity.type ?: "",
                    linkEntity.text ?: "",
                    sequence + 1
                )
                NewLogUtils.logCommonCategoryHomeContentClick(
                    contentEntity.title,
                    linkEntity.type ?: "",
                    linkEntity.link ?: "",
                    linkEntity.text ?: "",
                    commonCollection?.name ?: "",
                    commonCollection?.id ?: "",
                    "新首页"
                )
                SensorsBridge.trackLinkContentCollectionClick(
                    location = "首页",
                    blockName = "",
                    blockId = "",
                    linkContentCollectionId = commonCollection?.id ?: "",
                    linkContentCollectionName = commonCollection?.name ?: "",
                    position = sequence,
                    linkType = linkEntity.type ?: "",
                    linkId = linkEntity.link ?: "",
                    linkText = linkEntity.text ?: "",
                    text = "通用内容"
                )
            }

        if (holder is CommonCollectionViewHolder) {
            holder.bindCommonLinkCollection(
                commonCollection!!,
                "首页内容列表",
                "",
                "",
                clickClosure
            ) { position, linkEntity ->
                item.exposureEventList?.add(
                    ExposureEvent.createEventWithSourceConcat(
                        GameEntity(
                            id = linkEntity.link,
                            name = linkEntity.name
                        ).also {
                            it.sequence = position
                            it.outerSequence = item.blockPosition
                        },
                        mBasicExposureSources,
                        listOf(ExposureSource("内容合集", commonCollection.name ?: ""))
                    ).also { linkEntity.exposureEvent = it }
                )
            }
        } else if (holder is CommonCollection12ViewHolder) {
            holder.bindView(commonCollection!!, item.offset, clickClosure)

            for (i in item.offset until (item.offset + 1)) {
                if (commonCollection.commonCollectionList!!.size > i) {
                    item.exposureEventList?.add(
                        ExposureEvent.createEventWithSourceConcat(
                            GameEntity(
                                id = commonCollection.commonCollectionList?.get(i)?.linkEntity?.link,
                                name = commonCollection.commonCollectionList?.get(i)?.linkEntity?.name
                            ).also {
                                it.sequence = item.offset
                                it.outerSequence = commonCollection.outerSequence
                            },
                            mBasicExposureSources,
                            listOf(ExposureSource("内容合集", commonCollection.name ?: ""))
                        ).also { commonCollection.commonCollectionList?.get(i)?.linkEntity?.exposureEvent = it }
                    )
                }
            }
        }
    }

    /**
     * 排行榜
     */
    private fun bindRankCollection(holder: RankCollectionViewHolder, item: LegacyHomeItemData) {
        val rankCollection = item.rankCollection
        val rankCollectionAdapter = holder.bindRankCollection(rankCollection!!) { subject, sequence ->
            NewLogUtils.logColumnCategoryHomeContentClick(
                subject.name ?: "", subject.id ?: "", rankCollection.name ?: "",
                rankCollection.id ?: "", "新首页", ""
            )
            SensorsBridge.trackColumnCollectionClick(
                location = "首页",
                blockName = "",
                blockId = "",
                columnCollectionName = rankCollection.name ?: "",
                columnCollectionId = rankCollection.id ?: "",
                position = sequence,
                gameColumnName = subject.name ?: "",
                gameColumnId = subject.id ?: "",
                text = "游戏专题"
            )
        }

        val exposureEventList = arrayListOf<ExposureEvent>()
        rankCollection.columns.let {
            runOnIoThread(true) {
                rankCollection.columns.forEach {
                    it.data?.forEachIndexed { index, gameEntity ->
                        if (index > 4) return@forEach

                        val event = ExposureEvent.createEventWithSourceConcat(
                            gameEntity = gameEntity,
                            basicSource = mBasicExposureSources,
                            source = listOf(
                                ExposureSource("排行榜", ""),
                                ExposureSource("专题", it.name ?: "")
                            )
                        )
                        exposureEventList.add(event)
                    }
                }
            }
            item.exposureEventList = exposureEventList
            rankCollectionAdapter.exposureEventList = exposureEventList
        }
    }

    /**
     * 游戏专题-双列卡片
     */
    private fun bindGameDoubleCard(holder: DoubleCardViewHolder, item: LegacyHomeItemData) {
        item.doubleCardColumn?.data?.run {
            val subjectEntity = item.doubleCardColumn!!
            val startPosition = item.offset
            val endPosition = item.offset + 1

            holder.bindView(this, subjectEntity.name ?: "", startPosition)

            val exposureEventList = arrayListOf<ExposureEvent>()
            runOnIoThread(true) {
                for (i in startPosition until endPosition) {
                    if (i >= size) break

                    this[i].sequence = i
                    this[i].isAdData = subjectEntity.adIconActive
                    val event = ExposureEvent.createEventWithSourceConcat(
                        gameEntity = this[i],
                        basicSource = mBasicExposureSources,
                        source = listOf(ExposureSource("专题", subjectEntity.name ?: ""))
                    )
                    this[i].exposureEvent = event
                    exposureEventList.add(event)
                }
            }
            item.exposureEventList = exposureEventList
        }
    }

    /**
     * 提问、帖子、视频帖、文章
     */
    private fun bindBigImageRecommend(holder: BigImageRecommendViewHolder, item: LegacyHomeItemData) {
        item.bigImageRecommend?.run {
            holder.bindBigImageRecommend(this, "新首页") {
                NewFlatLogUtils.logHomeGameContentCardClick(it.type ?: "", it.link ?: "", it.linkText ?: "")
            }
        }
    }

    /**
     * 游戏专题-视频横屏滑动
     */
    private fun bindHomeHorizontalSlideVideo(
        holder: HomeHorizontalSlideVideoListViewHolder,
        item: LegacyHomeItemData,
        scrollCalculatorHelper: ScrollCalculatorHelper? = null
    ) {
        item.horizontalSlideVideo?.run {
            holder.bindView(this, "新首页", mBasicExposureSources, scrollCalculatorHelper) {
                item.exposureEventList?.add(it)
            }
        }
    }

    private fun getHomeGameCollectionExposureEventList(
        itemData: LegacyHomeItemData,
        refreshCurrentPosition: Int = -1
    ): ArrayList<ExposureEvent> {
        val exposureList = arrayListOf<ExposureEvent>()
        runOnIoThread(true) {
            itemData.gameCollection?.gameCollectionItemDataList?.run {
                val currentIndex = if (itemData.gameCollection?.style?.contains("refresh") == true) {
                    refreshCurrentPosition % size
                } else -1
                forEachIndexed { index, gameCollectionItemData ->
                    if (itemData.gameCollection?.style?.contains("refresh") == false || currentIndex == index) {
                        gameCollectionItemData.homeGameCollectionItem?.let {
                            val gameCollectionSource =
                                listOf(
                                    ExposureSource("游戏单合集", itemData.gameCollection?.id ?: ""),
                                    ExposureSource("游戏单", "${it.title} + ${it.id}")
                                )
                            val gameExposureList = arrayListOf<ExposureEvent>()
                            it.games?.forEach { game ->
                                game.isAdData = it.adIconActive
                                game.outerSequence = itemData.blockPosition
                                game.sequence = index

                                val exposureEvent = ExposureEvent.createEventWithSourceConcat(
                                    gameEntity = game,
                                    basicSource = mBasicExposureSources,
                                    source = gameCollectionSource
                                )
                                game.exposureEvent = exposureEvent
                                gameExposureList.add(exposureEvent)
                            }
                            exposureList.addAll(gameExposureList)
                            gameCollectionItemData.exposureEvent = ExposureEvent.createEventWithSourceConcat(
                                gameEntity = GameEntity().apply {
                                    adIconActive = it.adIconActive
                                    outerSequence = itemData.blockPosition
                                    sequence = index
                                },
                                basicSource = mBasicExposureSources,
                                source = gameCollectionSource
                            )
                        }
                    }
                }
            }
        }
        return exposureList
    }

    /**
     * 游戏单合集-轮播图
     */
    private fun bindGameCollectionCarousel(holder: HomeGameCollectionCarouselViewHolder, item: LegacyHomeItemData) {
        item.exposureEventList = getHomeGameCollectionExposureEventList(item)
        item.gameCollection?.let { holder.bindGameCollectionList(it, "首页内容列表") }
    }

    /**
     * 游戏单合集-横排滑动-大卡片/小卡片
     */
    private fun bindGameCollectionSlide(holder: HomeGameCollectionSlideViewHolder, item: LegacyHomeItemData) {
        item.exposureEventList = getHomeGameCollectionExposureEventList(item)
        item.gameCollection?.let { holder.bindGameCollectionSlide(it, "首页内容列表") }
    }

    /**
     * 游戏单合集-刷新轮换-横排列表/竖排列表
     */
    private fun bindGameCollectionRefresh(holder: HomeGameCollectionRefreshViewHolder, item: LegacyHomeItemData) {
        item.exposureEventList = getHomeGameCollectionExposureEventList(item, holder.currentPosition)
        item.gameCollection?.let {
            holder.bindGameCollectionRefresh(it, "首页内容列表") {
                false
            }
        }
    }

    private fun setPageSwitchData() {
        PageSwitchDataHelper.pushCurrentPageData(
            hashMapOf(
                Pair(
                    PageSwitchDataHelper.PAGE_BUSINESS_TYPE,
                    "首页-内容列表"
                )
            )
        )
    }

    override fun getOffset(position: Int) = mHorizontalScrollOffsetMap[position] ?: 0

    override fun updateOffset(position: Int, offset: Int) {
        mHorizontalScrollOffsetMap[position] = offset
    }

    override fun resetOffset() {
        mHorizontalScrollOffsetMap.clear()
    }

    enum class OuterType(val value: String) {
        NEW_HOME("首页_新"),

        AMWAY("安利墙")
    }

    companion object {
        const val GAME_COLLECTION_CAROUSEL_STYLE = "carousel"
        const val GAME_COLLECTION_BIG_SLIDE_STYLE = "x-slide-card"
        const val GAME_COLLECTION_SMALL_SLIDE_STYLE = "x-slide-card-small"
        const val GAME_COLLECTION_HORIZONTAL_REFRESH_STYLE = "refresh-x"
        const val GAME_COLLECTION_VERTICAL_REFRESH_STYLE = "refresh-y"
    }

}

/**
 * 空白补充区域
 */
class BlankDividerViewHolder(var binding: ItemBlankDividerBinding) : ViewHolder(binding.root) {
    fun bindView(height: Float, color: Int = com.gh.gamecenter.common.R.color.ui_surface.toColor(binding.root.context)) {
        binding.container.setBackgroundColor(color)
        binding.container.layoutParams = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height.dip2px())
    }

    companion object {
        const val DEFAULT_BLANK_HEIGHT = 8F
    }
}

enum class PluginDisplayStatus {
    // 收起
    CLOSE,

    // 展开
    OPEN,

    // 展开且底部显示收起按钮
    OPEN_AND_BUTTON,

    // 收起状态显示两个且底部显示展开按钮
    OPEN_TWO_AND_BUTTON,

    // 初始化状态
    DEFAULT
}