feat: 完善首页列表的子项数据比对代码 https://jira.shanqu.cc/browse/GHZS-956

This commit is contained in:
刘贻荣
2023-01-13 15:51:36 +08:00
parent 392bdf9715
commit 479b243136
12 changed files with 91 additions and 34 deletions

View File

@ -2,7 +2,7 @@ package com.gh.gamecenter.entity
import com.gh.gamecenter.feature.entity.GameEntity
class DiscoveryCardEntity(
data class DiscoveryCardEntity(
val games: ArrayList<GameEntity> = arrayListOf(),
val label: List<DiscoveryGameCardLabel> = listOf()
)

View File

@ -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<GameColumnCollectionItemViewHolder>(context) {
private var mCountAndKey: Pair<Int, String>? = 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)
}
}

View File

@ -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<Any>(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)
}
}
}

View File

@ -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)

View File

@ -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 ->

View File

@ -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<GameVerticalAdapter.SimpleGameItemViewHolder>(context) {
private val mMaxWidth = mContext.resources.displayMetrics.widthPixels
private var countAndKey: Pair<Int, String>? = 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?) {

View File

@ -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

View File

@ -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<HomeSlide>? = null,
var recommends: List<HomeRecommend>? = null,
var amway: List<AmwayCommentEntity>? = null,

View File

@ -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<GameEntity>()
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<LegacyHomeItemData>,
homeContent.linkColumn,
tempLinkColumn,
i,
{ HomeItemData() },
{ addGamePositionAndPackage(it) }

View File

@ -19,8 +19,17 @@ class HomeAmwayAdapter(
private val mItemClick: (View, position: Int, AmwayCommentEntity) -> Unit
) : BaseRecyclerAdapter<HomeAmwayItemViewHolder>(context) {
private var mCountAndKey: Pair<Int, String>? = 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<AmwayCommentEntity>) {
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)
}
}

View File

@ -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,