diff --git a/app/src/main/java/com/gh/gamecenter/entity/AppEntity.kt b/app/src/main/java/com/gh/gamecenter/entity/AppEntity.kt index 707c283e97..bbc8061cdc 100644 --- a/app/src/main/java/com/gh/gamecenter/entity/AppEntity.kt +++ b/app/src/main/java/com/gh/gamecenter/entity/AppEntity.kt @@ -18,5 +18,12 @@ class AppEntity { @SerializedName("force") var isForce: Boolean = false + /** + * NEVER(从不) + * ONCE_ONLY(仅一次) + * ONCE_ONLY_SECOND(仅一次(第二次打开)) + * ONCE_A_DAY(每天一次) + * EVERY_TIME_OPEN(每次打开) + */ var alert: String? = null } diff --git a/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java b/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java index bd087207c7..1d12ef561b 100644 --- a/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java +++ b/app/src/main/java/com/gh/gamecenter/manager/UpdateManager.java @@ -47,8 +47,15 @@ import retrofit2.HttpException; */ public class UpdateManager { + // 用于控制第二次打开更新弹窗 + private final static String ONCE_ONLY_SECOND_DEFAULT = "ONCE_ONLY_SECOND_DEFAULT"; + private final static String ONCE_ONLY_SECOND_CLOSE = "ONCE_ONLY_SECOND_CLOSE"; + private final static String ONCE_ONLY_SECOND_OPEN = "ONCE_ONLY_SECOND_OPEN"; + private Context mContext; + private SharedPreferences mSp; + private AppEntity appEntity; private Dialog downloadDialog; @@ -94,6 +101,8 @@ public class UpdateManager { private UpdateManager(Context context) { mContext = context; + mSp = PreferenceManager.getDefaultSharedPreferences(mContext); + this.isShowDownload = false; this.isChecking = false; this.loadingDialog = null; @@ -115,26 +124,40 @@ public class UpdateManager { String channel = HaloApp.getInstance().getChannel(); RetrofitManager.getInstance(mContext).getApi().getUpdate(PackageUtils.getVersionName(), PackageUtils.getVersionCode(), channel) .map(appEntity -> { - String md5 = null; + boolean isShowUpdateDialog = false; if (appEntity.getVersionCode() > PackageUtils.getVersionCode()) { // 助手有更新 UpdateManager.this.appEntity = appEntity; // 手动更新 强制更新 每次都提示 if (!isAutoCheck || "EVERY_TIME_OPEN".equals(appEntity.getAlert())) { - md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()); + isShowUpdateDialog = true; + } else if ("ONCE_ONLY".equals(appEntity.getAlert())) { + if (mSp.getBoolean(getUpdateOnceOnlySpKey(), true)) { + isShowUpdateDialog = true; + mSp.edit().putBoolean(getUpdateOnceOnlySpKey(), false).apply(); + } + } else if ("ONCE_ONLY_SECOND".equals(appEntity.getAlert())) { + String onceOnlySecond = mSp.getString(getUpdateOnceOnlySecondSpKey(), ONCE_ONLY_SECOND_DEFAULT); + if (ONCE_ONLY_SECOND_OPEN.equals(onceOnlySecond)) { + isShowUpdateDialog = true; + mSp.edit().putString(getUpdateOnceOnlySecondSpKey(), ONCE_ONLY_SECOND_CLOSE).apply(); + } + + if (ONCE_ONLY_SECOND_DEFAULT.equals(onceOnlySecond)) { + mSp.edit().putString(getUpdateOnceOnlySecondSpKey(), ONCE_ONLY_SECOND_OPEN).apply(); + } } else if (!"NEVER".equals(appEntity.getAlert())) { // 一天提示一次 - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext); - String showUpdateTime = sp.getString("show_update_time", null); + String showUpdateTime = mSp.getString("show_update_time", null); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); String today = format.format(new Date()); if (!today.equals(showUpdateTime)) { - sp.edit().putString("show_update_time", today).apply(); - md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()); + isShowUpdateDialog = true; + mSp.edit().putString("show_update_time", today).apply(); } } } - return md5; + return isShowUpdateDialog ? MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent()) : null; }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) @@ -288,4 +311,12 @@ public class UpdateManager { DownloadManager.getInstance(mContext).add(downloadEntity); } + private String getUpdateOnceOnlySpKey() { + return "UPDATE_ONCE_ONLY_KEY" + PackageUtils.getVersionCode(); + } + + private String getUpdateOnceOnlySecondSpKey() { + return "UPDATE_ONCE_ONLY_SECOND_KEY" + PackageUtils.getVersionCode(); + } + }