整理app更新相关/礼包详情代码
This commit is contained in:
@ -2,7 +2,6 @@ package com.gh.gamecenter.manager;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@ -38,7 +37,6 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import retrofit2.HttpException;
|
||||
|
||||
@ -53,14 +51,15 @@ public class UpdateManager {
|
||||
private AppEntity appEntity;
|
||||
|
||||
private Dialog downloadDialog;
|
||||
private Dialog loadingDialog;
|
||||
|
||||
private ProgressBar app_pb_progress;
|
||||
private TextView app_tv_speed;
|
||||
private TextView app_tv_percent;
|
||||
|
||||
private Dialog loadingDialog;
|
||||
|
||||
private boolean isShowDownload;
|
||||
private boolean isChecking;
|
||||
|
||||
private DataWatcher dataWatcher = new DataWatcher() {
|
||||
@Override
|
||||
public void onDataChanged(DownloadEntity downloadEntity) {
|
||||
@ -104,56 +103,40 @@ public class UpdateManager {
|
||||
}
|
||||
|
||||
// 检查更新
|
||||
public void checkUpdate(final boolean isCheck, final Handler handler) {
|
||||
public void checkUpdate(final boolean isAutoCheck, final Handler handler) {
|
||||
if (isChecking) {
|
||||
return;
|
||||
}
|
||||
isChecking = true;
|
||||
if (!isCheck) {
|
||||
if (!isAutoCheck) {
|
||||
loadingDialog = DialogUtils.showWaitDialog(mContext, "检查更新中...");
|
||||
}
|
||||
String channel = HaloApp.getInstance().getChannel();
|
||||
RetrofitManager.getInstance(mContext).getApi().getUpdate(PackageUtils.getVersionName(), channel)
|
||||
.map(new Function<AppEntity, String>() {
|
||||
@Override
|
||||
public String apply(AppEntity appEntity) {
|
||||
String md5 = null;
|
||||
.map(appEntity -> {
|
||||
String md5 = null;
|
||||
|
||||
float version = Float.valueOf(appEntity.getVersion());
|
||||
float currentVersion = Float.valueOf(PackageUtils.getVersionName());
|
||||
if (version > currentVersion) {
|
||||
// 助手有更新
|
||||
UpdateManager.this.appEntity = appEntity;
|
||||
float version = Float.valueOf(appEntity.getVersion());
|
||||
float currentVersion = Float.valueOf(PackageUtils.getVersionName());
|
||||
if (version > currentVersion) {
|
||||
// 助手有更新
|
||||
UpdateManager.this.appEntity = appEntity;
|
||||
|
||||
if (isCheck) {
|
||||
if (appEntity.isForce()) {
|
||||
// 强制更新
|
||||
md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent());
|
||||
} else {
|
||||
// 非强制更新
|
||||
if ("EVERY_TIME_OPEN".equals(appEntity.getAlert())) {
|
||||
// 每次都提示
|
||||
md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent());
|
||||
} else if (!"NEVER".equals(appEntity.getAlert())) {
|
||||
// 一天提示一次
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
String showUpdateTime = sp.getString("show_update_tiem", 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_tiem", today).apply();
|
||||
md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 手动更新 强制更新 每次都提示
|
||||
if (!isAutoCheck || appEntity.isForce() || "EVERY_TIME_OPEN".equals(appEntity.getAlert())) {
|
||||
md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent());
|
||||
} else if (!"NEVER".equals(appEntity.getAlert())) { // 一天提示一次
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
String showUpdateTime = sp.getString("show_update_tiem", 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_tiem", today).apply();
|
||||
md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent());
|
||||
}
|
||||
}
|
||||
|
||||
return md5;
|
||||
}
|
||||
return md5;
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
@ -172,7 +155,7 @@ public class UpdateManager {
|
||||
message.obj = appEntity.getVersion();
|
||||
handler.sendMessage(message);
|
||||
}
|
||||
} else if (!isCheck) {
|
||||
} else if (!isAutoCheck) {
|
||||
Utils.toast(mContext, "已是最新版本");
|
||||
if (handler != null) {
|
||||
handler.sendEmptyMessage(1);
|
||||
@ -186,7 +169,7 @@ public class UpdateManager {
|
||||
if (loadingDialog != null) {
|
||||
loadingDialog.dismiss();
|
||||
}
|
||||
if (!isCheck) {
|
||||
if (!isAutoCheck) {
|
||||
if (handler != null) {
|
||||
handler.sendEmptyMessage(1);
|
||||
}
|
||||
@ -207,42 +190,36 @@ public class UpdateManager {
|
||||
|
||||
View view = View.inflate(mContext, R.layout.app_update_hint_dialog, null);
|
||||
|
||||
TextView content = (TextView) view.findViewById(R.id.updeta_content);
|
||||
TextView content = view.findViewById(R.id.updeta_content);
|
||||
content.setText(Html.fromHtml(appEntity.getContent()));
|
||||
|
||||
TextView version = (TextView) view.findViewById(R.id.update_app_version);
|
||||
TextView version = view.findViewById(R.id.update_app_version);
|
||||
version.setText(String.format("光环助手V%s更新内容:", appEntity.getVersion()));
|
||||
|
||||
TextView size = (TextView) view.findViewById(R.id.update_app_size);
|
||||
TextView size = view.findViewById(R.id.update_app_size);
|
||||
size.setText(String.format("大小:%s", appEntity.getSize()));
|
||||
|
||||
view.findViewById(R.id.update_cancel).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (appEntity.isForce()) {
|
||||
AppManager.getInstance().finishAllActivity();
|
||||
} else {
|
||||
updateDialog.dismiss();
|
||||
}
|
||||
v -> {
|
||||
if (appEntity.isForce()) {
|
||||
AppManager.getInstance().finishAllActivity();
|
||||
} else {
|
||||
updateDialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
view.findViewById(R.id.update_confirm).setOnClickListener(
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
updateDialog.dismiss();
|
||||
String path = FileUtils.getDownloadPath(mContext,
|
||||
"光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk");
|
||||
File file = new File(path);
|
||||
if (file.exists() && file.length() > 0) {
|
||||
DataLogUtils.uploadUpgradeLog(mContext, "install"); //上传更新安装数据
|
||||
mContext.startActivity(PackageUtils.getInstallIntent(mContext, path));
|
||||
} else {
|
||||
DataUtils.onEvent(mContext, "软件更新", "下载开始");
|
||||
showDownloadDialog(md5);
|
||||
}
|
||||
v -> {
|
||||
updateDialog.dismiss();
|
||||
String path = FileUtils.getDownloadPath(mContext,
|
||||
"光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk");
|
||||
File file = new File(path);
|
||||
if (file.exists() && file.length() > 0) {
|
||||
DataLogUtils.uploadUpgradeLog(mContext, "install"); //上传更新安装数据
|
||||
mContext.startActivity(PackageUtils.getInstallIntent(mContext, path));
|
||||
} else {
|
||||
DataUtils.onEvent(mContext, "软件更新", "下载开始");
|
||||
showDownloadDialog(md5);
|
||||
}
|
||||
});
|
||||
|
||||
@ -262,28 +239,22 @@ public class UpdateManager {
|
||||
|
||||
View view = View.inflate(mContext, R.layout.app_updating_dialog, null);
|
||||
|
||||
app_pb_progress = (ProgressBar) view.findViewById(R.id.app_pb_progress);
|
||||
app_tv_speed = (TextView) view.findViewById(R.id.app_tv_speed);
|
||||
app_tv_percent = (TextView) view.findViewById(R.id.app_tv_percent);
|
||||
app_pb_progress = view.findViewById(R.id.app_pb_progress);
|
||||
app_tv_speed = view.findViewById(R.id.app_tv_speed);
|
||||
app_tv_percent = view.findViewById(R.id.app_tv_percent);
|
||||
|
||||
view.findViewById(R.id.app_tv_cancel).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
DownloadManager.getInstance(mContext).cancel(appEntity.getUrl());
|
||||
if (appEntity.isForce()) {
|
||||
AppManager.getInstance().finishAllActivity();
|
||||
} else {
|
||||
downloadDialog.dismiss();
|
||||
}
|
||||
view.findViewById(R.id.app_tv_cancel).setOnClickListener(v -> {
|
||||
DownloadManager.getInstance(mContext).cancel(appEntity.getUrl());
|
||||
if (appEntity.isForce()) {
|
||||
AppManager.getInstance().finishAllActivity();
|
||||
} else {
|
||||
downloadDialog.dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
downloadDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
DownloadManager.getInstance(mContext).removeObserver(dataWatcher);
|
||||
isShowDownload = false;
|
||||
}
|
||||
downloadDialog.setOnDismissListener(dialog -> {
|
||||
DownloadManager.getInstance(mContext).removeObserver(dataWatcher);
|
||||
isShowDownload = false;
|
||||
});
|
||||
|
||||
downloadDialog.setCanceledOnTouchOutside(false);
|
||||
|
||||
Reference in New Issue
Block a user