1、更改部分下载类,未完成

2、@#&@*#
This commit is contained in:
CsHeng
2017-06-29 11:17:01 +08:00
parent 5cbf06f6a6
commit f97ccd5c5d
126 changed files with 454 additions and 6379 deletions

View File

@ -6,6 +6,7 @@ import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.text.Html;
import android.view.View;
import android.view.Window;
@ -14,25 +15,24 @@ import android.widget.TextView;
import android.widget.Toast;
import com.gh.base.AppController;
import com.gh.common.constant.Config;
import com.lightgame.utils.AppManager;
import com.gh.download.DownloadManager;
import com.gh.common.util.DataLogUtils;
import com.gh.common.util.DataUtils;
import com.gh.common.util.DialogUtils;
import com.gh.common.util.FileUtils;
import com.gh.common.util.MD5Utils;
import com.gh.common.util.PackageUtils;
import com.gh.common.util.SpeedUtils;
import com.gh.common.util.Utils;
import com.gh.download.DataWatcher;
import com.gh.download.DownloadEntity;
import com.gh.download.DownloadManager;
import com.gh.download.DownloadStatus;
import com.lightgame.utils.Utils;
import com.gh.gamecenter.R;
import com.gh.gamecenter.entity.AppEntity;
import com.gh.gamecenter.entity.GameUpdateEntity;
import com.gh.gamecenter.retrofit.Response;
import com.gh.gamecenter.retrofit.RetrofitManager;
import com.lightgame.download.DataWatcher;
import com.lightgame.download.DownloadEntity;
import com.lightgame.download.DownloadStatus;
import com.lightgame.download.FileUtils;
import com.lightgame.utils.AppManager;
import java.io.File;
import java.text.SimpleDateFormat;
@ -50,7 +50,7 @@ import rx.schedulers.Schedulers;
*/
public class UpdateManager {
private Context context;
private Context mContext;
private AppEntity appEntity;
@ -74,7 +74,7 @@ public class UpdateManager {
app_tv_percent.setText(String.format(
Locale.getDefault(), "%s%%", String.valueOf(downloadEntity.getPercent())));
if (DownloadStatus.done.equals(downloadEntity.getStatus())) {
DownloadManager.getInstance(context).cancel(downloadEntity.getUrl(), false);
DownloadManager.getInstance(mContext).cancel(downloadEntity.getUrl(), false);
if (downloadDialog != null) {
downloadDialog.dismiss();
}
@ -82,20 +82,20 @@ public class UpdateManager {
AppManager.getInstance().finishAllActivity();
}
} else if (DownloadStatus.neterror.equals(downloadEntity.getStatus())) {
Utils.toast(context, "网络错误,请稍后重试");
Utils.toast(mContext, "网络错误,请稍后重试");
} else if (DownloadStatus.timeout.equals(downloadEntity.getStatus())) {
Utils.toast(context, "请求超时,请稍后重试");
Utils.toast(mContext, "请求超时,请稍后重试");
} else if (DownloadStatus.notfound.equals(downloadEntity.getStatus())) {
Utils.toast(context, "下载链接异常,请稍后重试");
Utils.toast(mContext, "下载链接异常,请稍后重试");
} else if (DownloadStatus.hijack.equals(downloadEntity.getStatus())) {
Utils.toast(context, "网络劫持,请稍后重试");
Utils.toast(mContext, "网络劫持,请稍后重试");
}
}
}
};
private UpdateManager(Context context) {
this.context = context;
mContext = context;
this.isShowDownload = false;
this.isChecking = false;
this.loadingDialog = null;
@ -112,17 +112,17 @@ public class UpdateManager {
}
isChecking = true;
if (!isCheck) {
loadingDialog = DialogUtils.showWaitDialog(context, "检查更新中...");
loadingDialog = DialogUtils.showWaitDialog(mContext, "检查更新中...");
}
String channel = AppController.getInstance().getChannel();
RetrofitManager.getApi().getUpdate(PackageUtils.getVersionName(context), channel)
RetrofitManager.getApi().getUpdate(PackageUtils.getVersionName(mContext), channel)
.map(new Func1<AppEntity, String>() {
@Override
public String call(AppEntity appEntity) {
String md5 = null;
float version = Float.valueOf(appEntity.getVersion());
float currentVersion = Float.valueOf(PackageUtils.getVersionName(context));
float currentVersion = Float.valueOf(PackageUtils.getVersionName(mContext));
if (version > currentVersion) {
// 助手有更新
UpdateManager.this.appEntity = appEntity;
@ -130,7 +130,7 @@ public class UpdateManager {
// 添加到更新列表
GameUpdateEntity gameUpdateEntity = new GameUpdateEntity();
gameUpdateEntity.setName("光环助手V" + appEntity.getVersion());
gameUpdateEntity.setPackageName(context.getPackageName());
gameUpdateEntity.setPackageName(mContext.getPackageName());
gameUpdateEntity.setSize(appEntity.getSize());
gameUpdateEntity.setVersion(appEntity.getVersion());
gameUpdateEntity.setUrl(appEntity.getUrl());
@ -149,8 +149,7 @@ public class UpdateManager {
md5 = MD5Utils.getUpdateMD5(appEntity.getUrl(), appEntity.getContent());
} else if (!"NEVER".equals(appEntity.getAlert())) {
// 一天提示一次
SharedPreferences sp = context.getSharedPreferences(
Config.PREFERENCE, Context.MODE_PRIVATE);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(mContext);
String showUpdateTime = sp.getString("show_update_tiem", null);
SimpleDateFormat format = new SimpleDateFormat(
"yyyy-MM-dd", Locale.getDefault());
@ -187,7 +186,7 @@ public class UpdateManager {
handler.sendMessage(message);
}
} else if (!isCheck) {
Toast.makeText(context, "已是最新版本", Toast.LENGTH_SHORT).show();
Toast.makeText(mContext, "已是最新版本", Toast.LENGTH_SHORT).show();
if (handler != null) {
handler.sendEmptyMessage(1);
}
@ -205,11 +204,11 @@ public class UpdateManager {
handler.sendEmptyMessage(1);
}
if (e != null && e.code() == 304) {
Toast.makeText(context, "您的光环助手已是最新版本", Toast.LENGTH_SHORT).show();
Toast.makeText(mContext, "您的光环助手已是最新版本", Toast.LENGTH_SHORT).show();
return;
}
Toast.makeText(context, "检查更新失败", Toast.LENGTH_SHORT).show();
Toast.makeText(mContext, "检查更新失败", Toast.LENGTH_SHORT).show();
}
}
});
@ -217,9 +216,9 @@ public class UpdateManager {
// 显示助手有更新提示框
private void showUpdateDialog(final String md5) {
final Dialog updateDialog = new Dialog(context);
final Dialog updateDialog = new Dialog(mContext);
View view = View.inflate(context, R.layout.app_update_hint_dialog, null);
View view = View.inflate(mContext, R.layout.app_update_hint_dialog, null);
TextView content = (TextView) view.findViewById(R.id.updeta_content);
content.setText(Html.fromHtml(appEntity.getContent()));
@ -247,14 +246,14 @@ public class UpdateManager {
@Override
public void onClick(View v) {
updateDialog.dismiss();
String path = FileUtils.getDownloadPath(context,
String path = FileUtils.getDownloadPath(mContext,
"光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk");
File file = new File(path);
if (file.exists() && file.length() > 0) {
DataLogUtils.uploadUpgradeLog(context, "install"); //上传更新安装数据
context.startActivity(PackageUtils.getInstallIntent(context, path));
DataLogUtils.uploadUpgradeLog(mContext, "install"); //上传更新安装数据
mContext.startActivity(PackageUtils.getInstallIntent(mContext, path));
} else {
DataUtils.onEvent(context, "软件更新", "下载开始");
DataUtils.onEvent(mContext, "软件更新", "下载开始");
showDownloadDialog(md5);
}
}
@ -268,13 +267,13 @@ public class UpdateManager {
updateDialog.setContentView(view);
updateDialog.show();
DataLogUtils.uploadUpgradeLog(context, "notice"); //上传更新通知弹窗数据
DataLogUtils.uploadUpgradeLog(mContext, "notice"); //上传更新通知弹窗数据
}
private void showDownloadDialog(String md5) {
downloadDialog = new Dialog(context);
downloadDialog = new Dialog(mContext);
View view = View.inflate(context, R.layout.app_updating_dialog, null);
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);
@ -283,7 +282,7 @@ public class UpdateManager {
view.findViewById(R.id.app_tv_cancel).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DownloadManager.getInstance(context).cancel(appEntity.getUrl());
DownloadManager.getInstance(mContext).cancel(appEntity.getUrl());
if (appEntity.isForce()) {
AppManager.getInstance().finishAllActivity();
} else {
@ -295,7 +294,7 @@ public class UpdateManager {
downloadDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
DownloadManager.getInstance(context).removeObserver(dataWatcher);
DownloadManager.getInstance(mContext).removeObserver(dataWatcher);
isShowDownload = false;
}
});
@ -309,10 +308,10 @@ public class UpdateManager {
isShowDownload = true;
DownloadManager.getInstance(context).addObserver(dataWatcher);
DownloadManager.getInstance(mContext).addObserver(dataWatcher);
// 添加到下载列表
String path = FileUtils.getDownloadPath(context, "光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk");
String path = FileUtils.getDownloadPath(mContext, "光环助手V" + appEntity.getVersion() + "_" + md5 + ".apk");
File file = new File(path);
if (file.exists() && file.delete()) {
Utils.log(file.getName() + " file delete success.");
@ -323,10 +322,10 @@ public class UpdateManager {
downloadEntity.setName("光环助手V" + appEntity.getVersion());
downloadEntity.setPath(path);
downloadEntity.setPlatform("官方版");
downloadEntity.setPackageName(context.getPackageName());
DownloadManager.getInstance(context).cancel(downloadEntity.getUrl(), false);
DownloadManager.getInstance(context).pauseAll();
DownloadManager.getInstance(context).add(downloadEntity);
downloadEntity.setPackageName(mContext.getPackageName());
DownloadManager.getInstance(mContext).cancel(downloadEntity.getUrl(), false);
DownloadManager.getInstance(mContext).pauseAll();
DownloadManager.getInstance(mContext).add(downloadEntity);
}
}