光环助手V4.0.2-更新推送功能优化(2) https://gitlab.ghzs.com/pm/halo-app-issues/-/issues/882
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user