diff --git a/app/src/main/java/com/gh/common/constant/Config.java b/app/src/main/java/com/gh/common/constant/Config.java index 3b38eb8b18..4bb1c72c89 100644 --- a/app/src/main/java/com/gh/common/constant/Config.java +++ b/app/src/main/java/com/gh/common/constant/Config.java @@ -218,7 +218,7 @@ public class Config { PackageHelper.initList(); // 初始化畅玩相关的东西 - VHelper.init(HaloApp.getInstance(), false); + VHelper.init(HaloApp.getInstance()); } @Nullable diff --git a/app/src/main/java/com/gh/vspace/VHelper.kt b/app/src/main/java/com/gh/vspace/VHelper.kt index 3e66b0ce02..1032724bcd 100644 --- a/app/src/main/java/com/gh/vspace/VHelper.kt +++ b/app/src/main/java/com/gh/vspace/VHelper.kt @@ -13,6 +13,7 @@ import androidx.annotation.WorkerThread import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.Observer import com.gh.common.constant.Config import com.gh.common.exposure.ExposureUtils import com.gh.common.history.HistoryHelper @@ -101,6 +102,12 @@ object VHelper { val vGameLiveData by lazy { mVGameDao.getAllLiveData() } + private val mVGameObserver by lazy { + Observer> { + mVGameSnapshotList = ArrayList(it) + } + } + private val mPackageObserver by lazy { PackageObserver.PackageChangeListener { val vaConfig = Config.getVSettingEntity()?.va ?: return@PackageChangeListener @@ -141,11 +148,10 @@ object VHelper { /** * 初始化 - * @param observeDatabaseChanges 是否启用数据库变动监听 */ @SuppressLint("CheckResult") @JvmStatic - fun init(context: Context, observeDatabaseChanges: Boolean) { + fun init(context: Context) { if (isVGameOn()) { if (!mIsInitialized) { mIsInitialized = true @@ -164,11 +170,7 @@ object VHelper { PackageObserver.registerPackageChangeChangeListener(mPackageObserver) } - if (observeDatabaseChanges) { - vGameLiveData.observeForever { - mVGameSnapshotList = ArrayList(it) - } - } + vGameLiveData.observeForever(mVGameObserver) } } diff --git a/app/src/main/java/com/halo/assistant/HaloApp.java b/app/src/main/java/com/halo/assistant/HaloApp.java index ec35cf3506..f854ef2d6d 100644 --- a/app/src/main/java/com/halo/assistant/HaloApp.java +++ b/app/src/main/java/com/halo/assistant/HaloApp.java @@ -273,9 +273,6 @@ public class HaloApp extends MultiDexApplication { // 获取 settings 配置 ExtensionsKt.doOnMainProcessOnly(this, com.gh.common.constant.Config::getGhzsSettings); - // 初始化畅玩相关数据 - ExtensionsKt.doOnMainProcessOnly(this, this::retrieveVGameInfoIfNeeded); - String localTemporaryDeviceId = SPUtils.getString(Constants.SP_TEMPORARY_DEVICE_ID); if (!TextUtils.isEmpty(localTemporaryDeviceId)) { HaloApp.getInstance().setLocalTemporaryDeviceId(localTemporaryDeviceId); @@ -311,6 +308,9 @@ public class HaloApp extends MultiDexApplication { // 注册回调以用于做各种统计 ProcessLifecycleOwner.get().getLifecycle().addObserver(new ProcessorLifeCycleOwner()); + // 初始化畅玩相关数据 + ExtensionsKt.doOnMainProcessOnly(this, this::retrieveVGameInfoIfNeeded); + // 开发环境不要强制捕获相关异常,这些异常通常是需要处理的 if (!BuildConfig.DEBUG) { RxJavaPlugins.setErrorHandler(throwable -> { @@ -470,7 +470,7 @@ public class HaloApp extends MultiDexApplication { } private void retrieveVGameInfoIfNeeded() { - VHelper.init(this, true); + VHelper.init(this); } public boolean isReinstallTheSameVersion() {