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 e019ae0198..6b5d80897f 100644 --- a/app/src/main/java/com/gh/common/constant/Config.java +++ b/app/src/main/java/com/gh/common/constant/Config.java @@ -8,24 +8,26 @@ import android.text.TextUtils; import androidx.annotation.Nullable; -import com.gh.gamecenter.common.utils.DarkModeUtils; -import com.gh.gamecenter.common.utils.EnvHelper; -import com.gh.gamecenter.common.constant.Constants; -import com.gh.gamecenter.core.utils.GsonUtils; import com.gh.common.util.PackageHelper; import com.gh.common.util.PackageUtils; import com.gh.gamecenter.BuildConfig; import com.gh.gamecenter.SuggestionActivity; +import com.gh.gamecenter.common.constant.Constants; +import com.gh.gamecenter.common.eventbus.EBReuse; +import com.gh.gamecenter.common.retrofit.BiResponse; +import com.gh.gamecenter.common.retrofit.Response; +import com.gh.gamecenter.common.utils.DarkModeUtils; +import com.gh.gamecenter.common.utils.EnvHelper; +import com.gh.gamecenter.core.utils.GsonUtils; import com.gh.gamecenter.core.utils.SPUtils; import com.gh.gamecenter.entity.GameGuidePopupEntity; +import com.gh.gamecenter.entity.NewApiSettingsEntity; import com.gh.gamecenter.entity.NewSettingsEntity; import com.gh.gamecenter.entity.NewsEntity; import com.gh.gamecenter.entity.SettingsEntity; import com.gh.gamecenter.common.eventbus.EBReuse; import com.gh.gamecenter.entity.SimulatorEntity; import com.gh.gamecenter.entity.VSetting; -import com.gh.gamecenter.common.retrofit.BiResponse; -import com.gh.gamecenter.common.retrofit.Response; import com.gh.gamecenter.retrofit.RetrofitManager; import com.gh.vspace.VHelper; import com.halo.assistant.HaloApp; @@ -64,9 +66,9 @@ public class Config { private static SettingsEntity mSettingsEntity; private static NewSettingsEntity mNewSettingsEntity; + private static NewApiSettingsEntity mNewApiSettingsEntity; - private static NewSettingsEntity.NightMode mNightModeSetting; - private static SimulatorEntity mNewSimulatorEntity; + private static NewApiSettingsEntity.NightMode mNightModeSetting; private static VSetting mVSetting; private static GameGuidePopupEntity mGameGuidePopupEntity; private static SharedPreferences mDefaultSharedPreferences; @@ -235,11 +237,11 @@ public class Config { } @Nullable - public static NewSettingsEntity.NightMode getNightModeSetting() { + public static NewApiSettingsEntity.NightMode getNightModeSetting() { if (mNightModeSetting != null) { return mNightModeSetting; - } else if (mNewSettingsEntity != null && mNewSettingsEntity.getNightMode() != null) { - return mNewSettingsEntity.getNightMode(); + } else if (mNewApiSettingsEntity != null && mNewApiSettingsEntity.getNightMode() != null) { + return mNewApiSettingsEntity.getNightMode(); } else { return null; } @@ -364,9 +366,6 @@ public class Config { @Override public void onSuccess(NewSettingsEntity data) { mNewSettingsEntity = data; - if (mNightModeSetting != null) { - mNewSettingsEntity.setNightMode(mNightModeSetting); - } SPUtils.setString(Constants.SP_NEW_SETTINGS, GsonUtils.toJson(data)); } }); @@ -384,27 +383,22 @@ public class Config { }); } - if (mNightModeSetting == null && mNewSimulatorEntity == null) { + if (mNewApiSettingsEntity == null) { RetrofitManager.getInstance() .getNewApi().getNewSettings(PackageUtils.getGhVersionName(), channel) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new BiResponse() { + .subscribe(new BiResponse() { @Override - public void onSuccess(NewSettingsEntity data) { + public void onSuccess(NewApiSettingsEntity data) { + mNewApiSettingsEntity = data; mNightModeSetting = data.getNightMode(); mNewSimulatorEntity = data.getSimulator(); if (HaloApp.getInstance().isNewForThisVersion && mNightModeSetting != null && mNightModeSetting.getInstall()) { DarkModeUtils.INSTANCE.updateFollowSystemDarkModeToSp(true); - DarkModeUtils.INSTANCE.updateAppDarkModeStatusToSp(true); DarkModeUtils.INSTANCE.initDarkMode(); } - - if (mNewSettingsEntity != null) { - mNewSettingsEntity.setSimulator(mNewSimulatorEntity); - mNewSettingsEntity.setNightMode(mNightModeSetting); - SPUtils.setString(Constants.SP_NEW_SETTINGS, GsonUtils.toJson(data)); - } + SPUtils.setString(Constants.SP_NEW_API_SETTINGS, GsonUtils.toJson(data)); } }); } diff --git a/app/src/main/java/com/gh/download/DownloadManager.java b/app/src/main/java/com/gh/download/DownloadManager.java index 7ecc39609a..0e8e630d1e 100644 --- a/app/src/main/java/com/gh/download/DownloadManager.java +++ b/app/src/main/java/com/gh/download/DownloadManager.java @@ -36,6 +36,7 @@ import com.gh.common.util.PackageUtils; import com.gh.gamecenter.core.utils.PageSwitchDataHelper; import com.gh.gamecenter.core.utils.SPUtils; import com.gh.gamecenter.BuildConfig; +import com.gh.gamecenter.core.utils.SentryHelper; import com.gh.gamecenter.download.DownloadedGameIdAndPackageNameDao; import com.gh.gamecenter.entity.ApkEntity; import com.gh.gamecenter.entity.GameEntity; @@ -389,12 +390,16 @@ public class DownloadManager implements DownloadStatusListener { * 清理不存在本地 APK 文件的任务 */ public void clearTasksThatFileBeenDeleted() { - for (DownloadEntity entity : getAllDownloadEntity()) { - if (entity.getStatus() == DownloadStatus.done) { - if (FileUtils.isEmptyFile(entity.getPath())) { - cancel(entity.getUrl()); + try { + for (DownloadEntity entity : getAllDownloadEntity()) { + if (entity.getStatus() == DownloadStatus.done) { + if (FileUtils.isEmptyFile(entity.getPath())) { + cancel(entity.getUrl()); + } } } + } catch (Exception e) { + SentryHelper.INSTANCE.onEvent("CLEAR_DELETED_TASK_ERROR", "exception_digest", e.getLocalizedMessage()); } } diff --git a/app/src/main/java/com/gh/gamecenter/entity/NewApiSettingsEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/NewApiSettingsEntity.kt new file mode 100644 index 0000000000..d4ca9d7078 --- /dev/null +++ b/app/src/main/java/com/gh/gamecenter/entity/NewApiSettingsEntity.kt @@ -0,0 +1,20 @@ +package com.gh.gamecenter.entity + +import com.google.gson.annotations.SerializedName + +data class NewApiSettingsEntity( + @SerializedName("night_mode") + var nightMode: NightMode? = null, +) { + /** + * + * "icon": false, // 是否显示切换,true显示 + * "setting": false, // 设置页面是否显示,true显示 + * "install": false, // 安装时的默认值,true开启 + */ + data class NightMode( + val icon: Boolean, + val setting: Boolean, + val install: Boolean + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/entity/NewSettingsEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/NewSettingsEntity.kt index a9aa0e6899..6be2823b8b 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/NewSettingsEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/NewSettingsEntity.kt @@ -5,9 +5,6 @@ import com.google.gson.annotations.SerializedName data class NewSettingsEntity( @SerializedName("install_model") var installModel: InstallModel? = null, - @SerializedName("night_mode") - var nightMode: NightMode? = null, - var simulator: SimulatorEntity? = null ) { data class InstallModel( var status: String = "", @@ -15,16 +12,4 @@ data class NewSettingsEntity( @SerializedName("white_list") var whiteList: ArrayList? = arrayListOf() ) - - /** - * - * "icon": false, // 是否显示切换,true显示 - * "setting": false, // 设置页面是否显示,true显示 - * "install": false, // 安装时的默认值,true开启 - */ - data class NightMode( - val icon: Boolean, - val setting: Boolean, - val install: Boolean - ) } \ No newline at end of file diff --git a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java index c45e5026da..3927213fb9 100644 --- a/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java +++ b/app/src/main/java/com/gh/gamecenter/retrofit/service/ApiService.java @@ -756,7 +756,7 @@ public interface ApiService { * 新的设置接口 */ @GET("settings") - Single getNewSettings(@Query("version") String version, @Query("channel") String channel); + Single getNewSettings(@Query("version") String version, @Query("channel") String channel); /** * 获取新的配置信息,因为旧的已经太大了避免冲突 diff --git a/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java b/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java index 3aafe208cf..b70d2f0167 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java +++ b/module_common/src/main/java/com/gh/gamecenter/common/base/activity/BaseActivity.java @@ -80,6 +80,9 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; +import io.sentry.Breadcrumb; +import io.sentry.Sentry; +import io.sentry.SentryLevel; import kotlin.Pair; import pub.devrel.easypermissions.EasyPermissions; @@ -564,12 +567,19 @@ public abstract class BaseActivity extends BaseAppCompatActivity implements Easy // 这里根据调用栈是否存在 DarkModeUtils 来确定是否为系统回调 StackTraceElement[] trace = Thread.currentThread().getStackTrace(); for (StackTraceElement element : trace) { - if (element.getClassName().contains(DarkModeUtils.class.getSimpleName())) { + if (element.getClassName().equals(DarkModeUtils.class.getName())) { isCalledBySystem = false; break; } } + Breadcrumb breadcrumb = new Breadcrumb(); + breadcrumb.setCategory("onConfigurationChanged"); + breadcrumb.setMessage("IsCalledBySystem " + isCalledBySystem + "," + + this.getClass().getSimpleName() + " lifecycle is " + getLifecycle().getCurrentState()); + breadcrumb.setLevel(SentryLevel.INFO); + Sentry.addBreadcrumb(breadcrumb); + if (BuildConfig.IS_DARK_MODE_ON && mIsDarkModeOn != DarkModeUtils.INSTANCE.isDarkModeOn(this)) { // 当且仅当页面处于可见状态时响应新的 UiMode,并将它传递下去 // (在不可见的 activity 调用 onConfigurationChanged 方法有一定概率触发 ANR) diff --git a/module_common/src/main/java/com/gh/gamecenter/common/constant/Constants.java b/module_common/src/main/java/com/gh/gamecenter/common/constant/Constants.java index ef813e2964..6fcb33d29b 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/constant/Constants.java +++ b/module_common/src/main/java/com/gh/gamecenter/common/constant/Constants.java @@ -207,6 +207,9 @@ public class Constants { // 补充配置项 public static final String SP_NEW_SETTINGS = "new_settings"; + // 新接口配置项 + public static final String SP_NEW_API_SETTINGS = "new_api_settings"; + // 畅玩组件的配置 public static final String SP_V_SETTINGS = "v_settings"; diff --git a/module_common/src/main/java/com/gh/gamecenter/common/utils/Extensions.kt b/module_common/src/main/java/com/gh/gamecenter/common/utils/Extensions.kt index 2584bbabe7..7acea28deb 100644 --- a/module_common/src/main/java/com/gh/gamecenter/common/utils/Extensions.kt +++ b/module_common/src/main/java/com/gh/gamecenter/common/utils/Extensions.kt @@ -1,6 +1,7 @@ package com.gh.gamecenter.common.utils import android.animation.Animator +import android.annotation.SuppressLint import android.app.Activity import android.content.ClipData import android.content.ClipboardManager @@ -1271,8 +1272,15 @@ fun String.emojiCount(): Int { /** * WebView启用强制深色模式 */ +@SuppressLint("RequiresFeature") fun WebView.enableForceDark(isDarkModeOn: Boolean) { - if (BuildConfig.IS_DARK_MODE_ON && WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) { + val isFeatureSupported = try { + WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK) + } catch (throwable: Throwable) { + throwable.printStackTrace() + false + } + if (BuildConfig.IS_DARK_MODE_ON && isFeatureSupported) { WebSettingsCompat.setForceDark( settings, if (isDarkModeOn) WebSettingsCompat.FORCE_DARK_ON else WebSettingsCompat.FORCE_DARK_OFF