diff --git a/app/src/main/java/com/gh/gamecenter/entity/DiscoveryCardEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/DiscoveryCardEntity.kt index ad975499ed..0e180596f4 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/DiscoveryCardEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/DiscoveryCardEntity.kt @@ -2,7 +2,7 @@ package com.gh.gamecenter.entity import com.gh.gamecenter.feature.entity.GameEntity -class DiscoveryCardEntity( +data class DiscoveryCardEntity( val games: ArrayList = arrayListOf(), val label: List = listOf() ) \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/game/columncollection/GameColumnCollectionAdapter.kt b/app/src/main/java/com/gh/gamecenter/game/columncollection/GameColumnCollectionAdapter.kt index 038ee643ca..8110e48607 100644 --- a/app/src/main/java/com/gh/gamecenter/game/columncollection/GameColumnCollectionAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/game/columncollection/GameColumnCollectionAdapter.kt @@ -2,13 +2,13 @@ package com.gh.gamecenter.game.columncollection import android.content.Context import android.view.ViewGroup -import com.gh.gamecenter.common.utils.ImageUtils -import com.gh.gamecenter.common.view.WrapContentDraweeView import com.gh.gamecenter.R import com.gh.gamecenter.adapter.viewholder.GameColumnCollectionItemViewHolder +import com.gh.gamecenter.common.utils.ImageUtils +import com.gh.gamecenter.common.view.WrapContentDraweeView import com.gh.gamecenter.databinding.GameColumnCollectionItemBinding -import com.gh.gamecenter.feature.entity.GameEntity import com.gh.gamecenter.entity.SubjectEntity +import com.gh.gamecenter.feature.entity.GameEntity import com.lightgame.adapter.BaseRecyclerAdapter class GameColumnCollectionAdapter( @@ -17,8 +17,17 @@ class GameColumnCollectionAdapter( private var mClickClosure: (position: Int, gameEntity: GameEntity) -> Unit ) : BaseRecyclerAdapter(context) { + private var mCountAndKey: Pair? = null var columnCollectionHeight = 0 + init { + var dataIds = "" + mSubjectEntity.data?.forEach { + dataIds += it.id + } + if (dataIds.isNotEmpty()) mCountAndKey = Pair(mSubjectEntity.data?.size ?: 0, dataIds) + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): GameColumnCollectionItemViewHolder { val view = mLayoutInflater.inflate(R.layout.game_column_collection_item, parent, false) return GameColumnCollectionItemViewHolder(GameColumnCollectionItemBinding.bind(view)) @@ -52,6 +61,19 @@ class GameColumnCollectionAdapter( } fun checkResetData(subjectEntity: SubjectEntity) { - if (subjectEntity != mSubjectEntity) mSubjectEntity = subjectEntity + var dataIds = "" + subjectEntity.data?.forEach { + dataIds += it.id + } + + mSubjectEntity = subjectEntity + if (mCountAndKey?.first == subjectEntity.data?.size && mCountAndKey?.second != dataIds) { // 数量不变,内容发生改变 + notifyItemRangeChanged(0, itemCount) + } else if (mCountAndKey?.first != subjectEntity.data?.size) { // 数量发生改变 + notifyDataSetChanged() + } + + // 重新刷新数据标识 + mCountAndKey = Pair(subjectEntity.data?.size ?: 0, dataIds) } } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/game/columncollection/GameColumnCollectionViewHolder.kt b/app/src/main/java/com/gh/gamecenter/game/columncollection/GameColumnCollectionViewHolder.kt index 0eb876bb81..1edbf1ef53 100644 --- a/app/src/main/java/com/gh/gamecenter/game/columncollection/GameColumnCollectionViewHolder.kt +++ b/app/src/main/java/com/gh/gamecenter/game/columncollection/GameColumnCollectionViewHolder.kt @@ -8,8 +8,8 @@ import com.gh.gamecenter.common.utils.ImageUtils import com.gh.gamecenter.common.utils.dip2px import com.gh.gamecenter.common.view.SpacingItemDecoration import com.gh.gamecenter.databinding.GameColumnCollectionListBinding -import com.gh.gamecenter.feature.entity.GameEntity import com.gh.gamecenter.entity.SubjectEntity +import com.gh.gamecenter.feature.entity.GameEntity class GameColumnCollectionViewHolder(val binding: GameColumnCollectionListBinding) : BaseRecyclerViewHolder(binding.root) { @@ -44,7 +44,6 @@ class GameColumnCollectionViewHolder(val binding: GameColumnCollectionListBindin binding.columnCollectionList.adapter = slideAdapter } else { (slideAdapter as GameColumnCollectionAdapter).checkResetData(columnCollection) - slideAdapter.notifyItemRangeChanged(0, slideAdapter.itemCount) } } } diff --git a/app/src/main/java/com/gh/gamecenter/game/commoncollection/CommonCollectionAdapter.kt b/app/src/main/java/com/gh/gamecenter/game/commoncollection/CommonCollectionAdapter.kt index 8265ccc316..5f5169d073 100644 --- a/app/src/main/java/com/gh/gamecenter/game/commoncollection/CommonCollectionAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/game/commoncollection/CommonCollectionAdapter.kt @@ -92,9 +92,11 @@ class CommonCollectionAdapter( fun checkResetData(updateDate: SubjectEntity) { val updateId = updateDate.id val id = mSubjectEntity.id + val originalSize = mSubjectEntity.commonCollectionList?.size + val updateSize = updateDate.commonCollectionList?.size mSubjectEntity = updateDate - if (updateId != id) { + if (updateId != id || originalSize != updateSize) { notifyDataSetChanged() } else { notifyItemRangeChanged(0, itemCount) diff --git a/app/src/main/java/com/gh/gamecenter/game/rank/RankCollectionAdapter.kt b/app/src/main/java/com/gh/gamecenter/game/rank/RankCollectionAdapter.kt index f9e76c7b84..da6be623ae 100644 --- a/app/src/main/java/com/gh/gamecenter/game/rank/RankCollectionAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/game/rank/RankCollectionAdapter.kt @@ -5,7 +5,6 @@ import android.util.SparseArray import android.view.View import android.view.ViewGroup import androidx.core.util.forEach -import com.gh.gamecenter.feature.exposure.ExposureEvent import com.gh.common.util.DirectUtils import com.gh.gamecenter.R import com.gh.gamecenter.common.base.BaseRecyclerViewHolder @@ -16,6 +15,7 @@ import com.gh.gamecenter.core.runOnUiThread import com.gh.gamecenter.databinding.RankCollectionItemBinding import com.gh.gamecenter.entity.SubjectEntity import com.gh.gamecenter.eventbus.EBDownloadStatus +import com.gh.gamecenter.feature.exposure.ExposureEvent import com.lightgame.adapter.BaseRecyclerAdapter import com.lightgame.download.DownloadEntity @@ -133,7 +133,7 @@ class RankCollectionAdapter( val id = mSubjectEntity.id mSubjectEntity = updateDate - if (updateId != id) { + if (updateId != id || mViewHolderList.size() != updateDate.columns.size) { notifyDataSetChanged() } else { mViewHolderList.forEach { position, viewHolder -> diff --git a/app/src/main/java/com/gh/gamecenter/game/vertical/GameVerticalAdapter.kt b/app/src/main/java/com/gh/gamecenter/game/vertical/GameVerticalAdapter.kt index fd44572d6c..c6bb3fa6b2 100644 --- a/app/src/main/java/com/gh/gamecenter/game/vertical/GameVerticalAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/game/vertical/GameVerticalAdapter.kt @@ -11,8 +11,8 @@ import com.gh.gamecenter.R import com.gh.gamecenter.adapter.viewholder.GameViewHolder import com.gh.gamecenter.common.utils.* import com.gh.gamecenter.common.view.AsyncUi -import com.gh.gamecenter.feature.entity.GameEntity import com.gh.gamecenter.entity.SubjectEntity +import com.gh.gamecenter.feature.entity.GameEntity import com.gh.gamecenter.feature.game.GameItemViewHolder import com.lightgame.adapter.BaseRecyclerAdapter import com.lightgame.download.DownloadEntity @@ -25,6 +25,15 @@ class GameVerticalAdapter( ) : BaseRecyclerAdapter(context) { private val mMaxWidth = mContext.resources.displayMetrics.widthPixels + private var countAndKey: Pair? = null + + init { + var dataIds = "" + mSubjectEntity.data?.forEach { + dataIds += it.id + } + if (dataIds.isNotEmpty()) countAndKey = Pair(mSubjectEntity.data?.size ?: 0, dataIds) + } fun getIndex(): Int { if (mSubjectEntity.data!!.isNotEmpty()) { @@ -156,16 +165,21 @@ class GameVerticalAdapter( } } - fun checkResetData(updateDate: SubjectEntity) { - val updateId = updateDate.id - val id = mSubjectEntity.id - mSubjectEntity = updateDate - - if (updateId != id) { - notifyDataSetChanged() - } else { - notifyItemRangeChanged(0, itemCount) + fun checkResetData(updateData: SubjectEntity) { + var dataIds = "" + mSubjectEntity.data?.forEach { + dataIds += it.id } + + mSubjectEntity = updateData + if (countAndKey?.first == updateData.data?.size && countAndKey?.second != dataIds) { // 数量不变,内容发生改变 + notifyItemRangeChanged(0, itemCount) + } else if (countAndKey?.first != updateData.data?.size) { // 数量发生改变 + notifyDataSetChanged() + } + + // 重新刷新数据标识 + countAndKey = Pair(updateData.data?.size ?: 0, dataIds) } fun notifyItemByDownload(downloadEntity: DownloadEntity?) { diff --git a/app/src/main/java/com/gh/gamecenter/home/HomeFragmentAdapter.kt b/app/src/main/java/com/gh/gamecenter/home/HomeFragmentAdapter.kt index 393beddca7..f08e1ab9fe 100644 --- a/app/src/main/java/com/gh/gamecenter/home/HomeFragmentAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/home/HomeFragmentAdapter.kt @@ -6,8 +6,6 @@ import android.view.ViewGroup import androidx.constraintlayout.widget.ConstraintLayout import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import com.gh.gamecenter.feature.exposure.ExposureEvent -import com.gh.gamecenter.feature.exposure.ExposureSource import com.gh.common.exposure.IExposable import com.gh.common.util.DirectUtils import com.gh.common.util.NewLogUtils @@ -25,6 +23,8 @@ import com.gh.gamecenter.core.runOnIoThread import com.gh.gamecenter.entity.AmwayCommentEntity import com.gh.gamecenter.entity.SubjectEntity import com.gh.gamecenter.eventbus.EBDownloadStatus +import com.gh.gamecenter.feature.exposure.ExposureEvent +import com.gh.gamecenter.feature.exposure.ExposureSource import com.gh.gamecenter.game.GameAndPosition import com.gh.gamecenter.game.horizontal.GameHorizontalAdapter import com.gh.gamecenter.game.horizontal.GameHorizontalSlideAdapter diff --git a/app/src/main/java/com/gh/gamecenter/home/HomeItemData.kt b/app/src/main/java/com/gh/gamecenter/home/HomeItemData.kt index 72c27b4476..0fa045ae28 100644 --- a/app/src/main/java/com/gh/gamecenter/home/HomeItemData.kt +++ b/app/src/main/java/com/gh/gamecenter/home/HomeItemData.kt @@ -4,7 +4,7 @@ import com.gh.gamecenter.entity.* import com.gh.gamecenter.gamecollection.square.GameCollectionListItemData import com.gh.vspace.VGameItemData -class HomeItemData( +data class HomeItemData( var slides: List? = null, var recommends: List? = null, var amway: List? = null, diff --git a/app/src/main/java/com/gh/gamecenter/home/HomeViewModel.kt b/app/src/main/java/com/gh/gamecenter/home/HomeViewModel.kt index 8d1e0dc005..d7915304b5 100644 --- a/app/src/main/java/com/gh/gamecenter/home/HomeViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/home/HomeViewModel.kt @@ -624,10 +624,15 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) { || linkType == "smart_subject" || linkType == "column_test" ) { + // 因为涉及到列表元素里面的字段的修改,所以要拷贝出来再进行修改,不然会影响DiffUtil的对比 + val tempLinkColumn = homeContent.linkColumn?.copy() + val tempData = mutableListOf() + tempData.addAll(homeContent.linkColumn?.data ?: mutableListOf()) + tempLinkColumn?.data = tempData - homeContent.linkColumn?.data = RegionSettingHelper.filterGame(homeContent.linkColumn?.data) + tempLinkColumn?.data = RegionSettingHelper.filterGame(tempLinkColumn?.data) - homeContent.linkColumn?.let { subjectEntity -> + tempLinkColumn?.let { subjectEntity -> subjectEntity.data?.let { data -> // 这个 for 循环主要功能是用来标识替换已安装的游戏 for (game in data) { @@ -649,12 +654,12 @@ class HomeViewModel(application: Application) : AndroidViewModel(application) { } // 仅普通纵向专题需要特别高的分割线 - useUltraHeightDivider = homeContent.linkColumn?.type == "game_vertical" + useUltraHeightDivider = tempLinkColumn?.type == "game_vertical" - homeContent.linkColumn?.adIconActive = homeContent.adIconActive + tempLinkColumn?.adIconActive = homeContent.adIconActive LegacyHomeSubjectTransformer.transform( mSnapshotItemList as ArrayList, - homeContent.linkColumn, + tempLinkColumn, i, { HomeItemData() }, { addGamePositionAndPackage(it) } diff --git a/app/src/main/java/com/gh/gamecenter/home/amway/HomeAmwayAdapter.kt b/app/src/main/java/com/gh/gamecenter/home/amway/HomeAmwayAdapter.kt index 83e670ffd7..835dc08df1 100644 --- a/app/src/main/java/com/gh/gamecenter/home/amway/HomeAmwayAdapter.kt +++ b/app/src/main/java/com/gh/gamecenter/home/amway/HomeAmwayAdapter.kt @@ -19,8 +19,17 @@ class HomeAmwayAdapter( private val mItemClick: (View, position: Int, AmwayCommentEntity) -> Unit ) : BaseRecyclerAdapter(context) { + private var mCountAndKey: Pair? = null var mMaxWidth = context.resources.displayMetrics.widthPixels + init { + var dataIds = "" + dataList.forEach { + dataIds += it.id + } + if (dataIds.isNotEmpty()) mCountAndKey = Pair(dataList.size, dataIds) + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = HomeAmwayItemViewHolder(parent.toBinding()) override fun getItemCount() = dataList.size @@ -65,11 +74,17 @@ class HomeAmwayAdapter( } fun checkResetData(update: List) { - if (dataList != update) { - dataList = update - notifyDataSetChanged() - } else { + var dataIds = "" + update.forEach { dataIds += it.id } + + dataList = update + if (mCountAndKey?.first == update.size && mCountAndKey?.second != dataIds) { // 数量不变,内容发生改变 notifyItemRangeChanged(0, itemCount) + } else if (mCountAndKey?.first != update.size) { // 数量发生改变 + notifyDataSetChanged() } + + // 重新刷新数据标识 + mCountAndKey = Pair(update.size, dataIds) } } \ No newline at end of file diff --git a/app/src/main/java/com/gh/vspace/VGameItemData.kt b/app/src/main/java/com/gh/vspace/VGameItemData.kt index 5f3aecd672..2b97be3b77 100644 --- a/app/src/main/java/com/gh/vspace/VGameItemData.kt +++ b/app/src/main/java/com/gh/vspace/VGameItemData.kt @@ -4,7 +4,7 @@ import com.gh.gamecenter.manager.PackagesManager import com.lightgame.download.DownloadEntity import com.lightgame.download.DownloadStatus -class VGameItemData( +data class VGameItemData( var downloadEntity: DownloadEntity, var shouldShowMask: Boolean = false, diff --git a/module_common/src/main/java/com/gh/gamecenter/common/entity/Display.kt b/module_common/src/main/java/com/gh/gamecenter/common/entity/Display.kt index b0736e6018..4c0d3afba9 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/entity/Display.kt +++ b/module_common/src/main/java/com/gh/gamecenter/common/entity/Display.kt @@ -4,7 +4,7 @@ import android.os.Parcelable import kotlinx.parcelize.Parcelize @Parcelize -class Display( +data class Display( var slide: Boolean = true, var recommend: Boolean = true, var navigation: Boolean = true,