fix: 修复QQ小游戏首页最近在玩刷新异常问题

This commit is contained in:
曾祥俊
2024-06-20 10:19:12 +08:00
parent 2fe8051280
commit 14522e5d07
2 changed files with 19 additions and 12 deletions

View File

@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
import com.gh.gamecenter.common.constant.Constants
import com.gh.gamecenter.common.retrofit.BiResponse
import com.gh.gamecenter.feature.entity.GameEntity
import com.gh.gamecenter.minigame.qq.QGameViewModel
import com.gh.gamecenter.retrofit.RetrofitManager
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
@ -66,6 +67,7 @@ object MiniGameRecentlyPlayUseCase {
.subscribe(object : BiResponse<ResponseBody>() {
override fun onSuccess(data: ResponseBody) {
loadRecentlyPlayedMiniGameList(Constants.QQ_MINI_GAME)
QGameViewModel.notifyQGameSubjectUpdate() // 通知QQ小游戏首页列表刷新
}
})
}

View File

@ -3,7 +3,6 @@ package com.gh.gamecenter.minigame.qq
import android.app.Application
import android.text.TextUtils
import androidx.collection.ArrayMap
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.gh.common.filter.RegionSettingHelper
@ -24,11 +23,13 @@ import com.gh.gamecenter.game.data.GameItemData
import com.gh.gamecenter.game.rank.RankCollectionAdapter
import com.gh.gamecenter.home.BlankDividerViewHolder
import com.gh.gamecenter.home.LegacyHomeFragmentAdapterAssistant
import com.gh.gamecenter.minigame.MiniGameRecentlyPlayUseCase
import com.gh.gamecenter.retrofit.RetrofitManager
import com.lightgame.utils.Utils
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import retrofit2.HttpException
import kotlin.math.roundToInt
@ -46,15 +47,9 @@ class QGameViewModel(application: Application, blockData: SubjectRecommendEntity
private var mIsLoading = false
private val mQGameRecentlyPlayObserver = Observer<List<GameEntity>> {
onInitData()
}
init {
initData()
MiniGameRecentlyPlayUseCase
.qqRecentGamesItemLiveData
.observeForever(mQGameRecentlyPlayObserver)
EventBus.getDefault().register(this)// 为了减少对原有逻辑的影响把EventBus注册在这里
}
override fun onInitData() {
@ -533,9 +528,12 @@ class QGameViewModel(application: Application, blockData: SubjectRecommendEntity
override fun onCleared() {
super.onCleared()
MiniGameRecentlyPlayUseCase
.qqRecentGamesItemLiveData
.removeObserver(mQGameRecentlyPlayObserver)
EventBus.getDefault().unregister(this)
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun onQGameSubjectUpdate(event: QGameSubjectUpdateEvent) {
onInitData()
}
override fun replaceRefreshData(itemData: GameItemData): Boolean = false
@ -550,4 +548,11 @@ class QGameViewModel(application: Application, blockData: SubjectRecommendEntity
return QGameViewModel(mApplication, blockData) as T
}
}
companion object {
fun notifyQGameSubjectUpdate() {
EventBus.getDefault().post(QGameSubjectUpdateEvent())
}
}
}