Merge branch 'fix-GHZS-1587' into 'dev'

fix: 畅玩组件安装后自动下载游戏—0310测试(修复初始化时序问题) https://jira.shanqu.cc/browse/GHZS-1587

See merge request halo/android/assistant-android!809
This commit is contained in:
陈君陶
2023-03-16 17:56:55 +08:00
3 changed files with 14 additions and 12 deletions

View File

@ -218,7 +218,7 @@ public class Config {
PackageHelper.initList();
// 初始化畅玩相关的东西
VHelper.init(HaloApp.getInstance(), false);
VHelper.init(HaloApp.getInstance());
}
@Nullable

View File

@ -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<List<VGameEntity>> {
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)
}
}

View File

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