完成首页游戏替换功能(第二期)https://gitlab.ghzhushou.com/pm/halo-app-issues/issues/498
This commit is contained in:
@ -66,11 +66,11 @@ object GameRepositoryHelper {
|
||||
* @param collectionId 补充游戏库相应专题 ID
|
||||
* @param gameIdList 该专题里已经包含的游戏 ID 列表
|
||||
*/
|
||||
fun getOneUniqueGame(collectionId: String?, gameIdList: List<String>): GameEntity? {
|
||||
fun getOneUniqueGame(collectionId: String?, gameIdList: HashSet<String>): GameEntity? {
|
||||
collectionId?.let {
|
||||
val collection = gameCollectionList.find { it.id == collectionId }
|
||||
collection?.let {
|
||||
val game = collection.data?.find { game -> findUniqueGame(game, gameIdList) }
|
||||
val game = collection.data?.find { game -> isThisGameUnique(game, gameIdList) }
|
||||
game?.let {
|
||||
collection.data?.remove(game)
|
||||
// 产品说要记录补充专题的曝光数,所以这个游戏附带了所在专题的名字
|
||||
@ -82,7 +82,12 @@ object GameRepositoryHelper {
|
||||
return null
|
||||
}
|
||||
|
||||
private fun findUniqueGame(game: GameEntity, gameIdList: List<String>): Boolean {
|
||||
private fun isThisGameUnique(game: GameEntity, gameIdList: HashSet<String>): Boolean {
|
||||
// 若该补充游戏已经存在关联关系,判定为非唯一
|
||||
for (relatedId in game.relatedGameIds!!) {
|
||||
gameIdList.contains(relatedId)
|
||||
return false
|
||||
}
|
||||
for (apk in game.getApk()) {
|
||||
// 检查本地是否已安装该游戏,已过滤那部分框架服务的包名
|
||||
if (PackageHelper.validLocalPackageNameSet.contains(apk.packageName)) {
|
||||
|
||||
@ -73,7 +73,10 @@ data class GameEntity(
|
||||
@SerializedName("download_notice")
|
||||
val downloadAd: LinkEntity? = null,
|
||||
// 社区名字,用于首页替换游戏曝光时使用
|
||||
var subjectName: String? = null) : Parcelable {
|
||||
var subjectName: String? = null,
|
||||
// 关联应用,供首页替换游戏确定该游戏是否应该被替换使用
|
||||
@SerializedName("relation_game_ids")
|
||||
var relatedGameIds: ArrayList<String>? = arrayListOf()) : Parcelable {
|
||||
|
||||
@IgnoredOnParcel
|
||||
private var entryMap: ArrayMap<String, DownloadEntity>? = ArrayMap()
|
||||
|
||||
@ -55,6 +55,9 @@ class GameViewModel(application: Application, var blockData: SubjectRecommendEnt
|
||||
|
||||
var positionAndPackageMap = HashMap<String, Int>() // key: packageName + position, value: position
|
||||
|
||||
// 首页所有专题里的所有游戏 ID 集合,供替换时排重用
|
||||
private var mSubjectGameIdList = hashSetOf<String>()
|
||||
|
||||
init {
|
||||
if (blockData == null) {
|
||||
itemDataList.addSource(PackageRepository.gameUpdateLiveData) {
|
||||
@ -370,6 +373,10 @@ class GameViewModel(application: Application, var blockData: SubjectRecommendEnt
|
||||
val data = subjectEntity.data
|
||||
if (data == null || data.isEmpty()) continue
|
||||
|
||||
for (game in data) {
|
||||
mSubjectGameIdList.add(game.id ?: "")
|
||||
}
|
||||
|
||||
subjectEntity.relatedColumnId?.let {
|
||||
replaceInstalledApp(data, it)
|
||||
}
|
||||
@ -418,12 +425,10 @@ class GameViewModel(application: Application, var blockData: SubjectRecommendEnt
|
||||
}
|
||||
|
||||
private fun replaceInstalledApp(gameList: MutableList<GameEntity>, relatedCollectionId: String) {
|
||||
val gameIdList = arrayListOf<String>() // 专题包含的游戏 ID 列表
|
||||
val positionOfTheGameToReplaceList = arrayListOf<Int>()
|
||||
|
||||
// 标记需要替换的已安装游戏
|
||||
for ((index, game) in gameList.withIndex()) {
|
||||
gameIdList.add(game.id ?: "")
|
||||
|
||||
// 是大图形式的游戏时不标记替换
|
||||
if ((index == 0 && !gameList[0].image.isNullOrEmpty())) {
|
||||
@ -466,7 +471,7 @@ class GameViewModel(application: Application, var blockData: SubjectRecommendEnt
|
||||
MtaHelper.onEvent("首页_加载", "启动光环", "替换游戏")
|
||||
}
|
||||
for (position in positionOfTheGameToReplaceList) {
|
||||
val replacingGame = GameRepositoryHelper.getOneUniqueGame(relatedCollectionId, gameIdList)
|
||||
val replacingGame = GameRepositoryHelper.getOneUniqueGame(relatedCollectionId, mSubjectGameIdList)
|
||||
replacingGame?.let {
|
||||
gameList[position] = replacingGame
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user