From 14522e5d077c3fa6a5e1be595cc6edfe50326e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E7=A5=A5=E4=BF=8A?= Date: Thu, 20 Jun 2024 10:19:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DQQ=E5=B0=8F=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E9=A6=96=E9=A1=B5=E6=9C=80=E8=BF=91=E5=9C=A8=E7=8E=A9?= =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../minigame/MiniGameRecentlyPlayUseCase.kt | 2 ++ .../gamecenter/minigame/qq/QGameViewModel.kt | 29 +++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/gh/gamecenter/minigame/MiniGameRecentlyPlayUseCase.kt b/app/src/main/java/com/gh/gamecenter/minigame/MiniGameRecentlyPlayUseCase.kt index 00447230f8..422d628c76 100644 --- a/app/src/main/java/com/gh/gamecenter/minigame/MiniGameRecentlyPlayUseCase.kt +++ b/app/src/main/java/com/gh/gamecenter/minigame/MiniGameRecentlyPlayUseCase.kt @@ -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() { override fun onSuccess(data: ResponseBody) { loadRecentlyPlayedMiniGameList(Constants.QQ_MINI_GAME) + QGameViewModel.notifyQGameSubjectUpdate() // 通知QQ小游戏首页列表刷新 } }) } diff --git a/app/src/main/java/com/gh/gamecenter/minigame/qq/QGameViewModel.kt b/app/src/main/java/com/gh/gamecenter/minigame/qq/QGameViewModel.kt index d0af8c10fc..60e2cfed10 100644 --- a/app/src/main/java/com/gh/gamecenter/minigame/qq/QGameViewModel.kt +++ b/app/src/main/java/com/gh/gamecenter/minigame/qq/QGameViewModel.kt @@ -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> { - 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()) + } + } } \ No newline at end of file