处理下载网络异常导致的奔溃问题,和奔溃后进入助手下载状态显示错误问题

This commit is contained in:
huangzhuanghua
2016-09-23 18:14:20 +08:00
parent 39350b2cfb
commit 5e44460112
17 changed files with 327 additions and 201 deletions

View File

@ -376,30 +376,31 @@ public class DownloadItemUtils {
final GameEntity entity,
final int position,
final RecyclerView.Adapter<RecyclerView.ViewHolder> adapter,
final String entrance) {
final String entrance,
final String location) {
downloadBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str = downloadBtn.getText().toString();
if ("下载".equals(str)) {
if (NetworkUtils.isWifiConnected(context)) {
download(context, entity, downloadBtn, entrance);
download(context, entity, downloadBtn, entrance, location);
} else {
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
download(context, entity, downloadBtn, entrance);
download(context, entity, downloadBtn, entrance, location);
}
});
}
} else if ("插件化".equals(str)) {
if (NetworkUtils.isWifiConnected(context)) {
plugin(context, entity, downloadBtn, entrance);
plugin(context, entity, downloadBtn, entrance, location);
} else {
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
plugin(context, entity, downloadBtn, entrance);
plugin(context, entity, downloadBtn, entrance, location);
}
});
}
@ -415,12 +416,12 @@ public class DownloadItemUtils {
context.startActivity(new Intent(context, DownloadManagerActivity.class));
} else if ("更新".equals(str)) {
if (NetworkUtils.isWifiConnected(context)) {
update(context, entity);
update(context, entity, entrance, location);
} else {
DialogUtils.showDownloadDialog(context, new DialogUtils.ConfiremListener() {
@Override
public void onConfirem() {
update(context, entity);
update(context, entity, entrance, location);
}
});
}
@ -456,7 +457,7 @@ public class DownloadItemUtils {
String location) {
if (entity.getApk().size() == 1) {
setNormalOnClickListener(context, downloadBtn, entity, position, adapter, entrance);
setNormalOnClickListener(context, downloadBtn, entity, position, adapter, entrance, location);
} else {
setPluginOnClickListener(context, downloadBtn, download_speed, download_percentage, entity,
entrance, location);
@ -465,7 +466,7 @@ public class DownloadItemUtils {
}
//更新
private static void update(Context context, GameEntity gameEntity) {
private static void update(Context context, GameEntity gameEntity, String entrance, String location) {
ApkEntity apkEntity = gameEntity.getApk().get(0);
//下载可更新游戏
Map<String, Object> kv = new HashMap<>();
@ -473,6 +474,19 @@ public class DownloadItemUtils {
kv.put("状态", "下载开始");
DataUtils.onEvent(context, "游戏更新", gameEntity.getName(), kv);
Map<String, Object> map = new HashMap<>();
map.put("game", gameEntity.getName());
map.put("game_id", gameEntity.getId());
map.put("method", "更新");
map.put("platform", PlatformUtils.getInstance(context)
.getPlatformName(gameEntity.getApk().get(0).getPlatform()));
map.put("status", "开始");
map.put("location", location);
map.put("entrance", entrance);
map.put("btn_status", "更新");
map.put("network", NetworkUtils.getConnectedType(context));
DataCollectionManager.onEvent(context, "download", map);
DownloadEntity downloadEntity = new DownloadEntity();
downloadEntity.setUrl(apkEntity.getUrl());
downloadEntity.setName(gameEntity.getName());
@ -484,6 +498,8 @@ public class DownloadItemUtils {
downloadEntity.setIcon(gameEntity.getIcon());
downloadEntity.setUpdate(true);
downloadEntity.setETag(apkEntity.getEtag());
downloadEntity.setLocation(location);
downloadEntity.setEntrance(entrance);
DownloadManager.getInstance(context).add(downloadEntity);
}
@ -491,7 +507,8 @@ public class DownloadItemUtils {
private static void download(Context context,
GameEntity entity,
TextView downloadBtn,
String entrance) {
String entrance,
String location) {
String msg = FileUtils.isCanDownload(entity.getApk().get(0).getSize());
if (TextUtils.isEmpty(msg)) {
Map<String, Object> kv = new HashMap<>();
@ -510,20 +527,6 @@ public class DownloadItemUtils {
kv3.put(entrance, "下载开始");
DataUtils.onEvent(context, "应用数据", entity.getName(), kv3);
if ("主页-最新插件".equals(entrance)) {
Map<String, Object> kv4 = new HashMap<>();
kv4.put(entity.getName(), "下载数");
DataUtils.onEvent(context, "主页数据", "最新插件", kv4);
} else if ("主页-热门卡牌".equals(entrance)) {
Map<String, Object> kv4 = new HashMap<>();
kv4.put(entity.getName(), "下载数");
DataUtils.onEvent(context, "主页数据", "热门卡牌", kv4);
} else if ("主页-新测卡牌".equals(entrance)) {
Map<String, Object> kv4 = new HashMap<>();
kv4.put(entity.getName(), "下载数");
DataUtils.onEvent(context, "主页数据", "新测卡牌", kv4);
}
Map<String, Object> map = new HashMap<>();
map.put("game", entity.getName());
map.put("game_id", entity.getId());
@ -531,12 +534,13 @@ public class DownloadItemUtils {
map.put("platform", PlatformUtils.getInstance(context)
.getPlatformName(entity.getApk().get(0).getPlatform()));
map.put("status", "开始");
map.put("location", "游戏详情:" + entity.getName());
map.put("from", entrance);
map.put("location", location);
map.put("entrance", entrance);
map.put("btn_status", "下载");
map.put("network", NetworkUtils.getConnectedType(context));
DataCollectionManager.onEvent(context, "download", map);
addDownloadEntry(context, entity, 0, entrance);
addDownloadEntry(context, entity, 0, entrance, location);
Toast.makeText(context, entity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show();
downloadBtn.setText("下载中");
@ -553,7 +557,8 @@ public class DownloadItemUtils {
private static void plugin(Context context,
GameEntity entity,
TextView downloadBtn,
String entrance) {
String entrance,
String location) {
String msg = FileUtils.isCanDownload(entity.getApk().get(0).getSize());
if (TextUtils.isEmpty(msg)) {
Map<String, Object> kv = new HashMap<>();
@ -572,33 +577,20 @@ public class DownloadItemUtils {
kv3.put(entrance, "下载开始");
DataUtils.onEvent(context, "应用数据", entity.getName(), kv3);
if ("主页-最新插件".equals(entrance)) {
Map<String, Object> kv4 = new HashMap<>();
kv4.put(entity.getName(), "下载数");
DataUtils.onEvent(context, "主页数据", "最新插件", kv4);
} else if ("主页-热门卡牌".equals(entrance)) {
Map<String, Object> kv4 = new HashMap<>();
kv4.put(entity.getName(), "下载数");
DataUtils.onEvent(context, "主页数据", "热门卡牌", kv4);
} else if ("主页-新测卡牌".equals(entrance)) {
Map<String, Object> kv4 = new HashMap<>();
kv4.put(entity.getName(), "下载数");
DataUtils.onEvent(context, "主页数据", "新测卡牌", kv4);
}
Map<String, Object> map = new HashMap<>();
map.put("game", entity.getName());
map.put("game_id", entity.getId());
map.put("method", "正常");
map.put("method", "插件化");
map.put("platform", PlatformUtils.getInstance(context)
.getPlatformName(entity.getApk().get(0).getPlatform()));
map.put("status", "开始");
map.put("location", "游戏详情:" + entity.getName());
map.put("from", entrance);
map.put("location", location);
map.put("entrance", entrance);
map.put("btn_status", "插件化");
map.put("network", NetworkUtils.getConnectedType(context));
DataCollectionManager.onEvent(context, "download", map);
addDownloadEntry(context, entity, 0, entrance);
addDownloadEntry(context, entity, 0, entrance, location);
Toast.makeText(context, entity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show();
downloadBtn.setText("下载中");
@ -643,7 +635,8 @@ public class DownloadItemUtils {
private static void addDownloadEntry(Context context,
GameEntity gameEntity,
int position,
String entrance) {
String entrance,
String location) {
ApkEntity apkEntity = gameEntity.getApk().get(position);
@ -659,7 +652,7 @@ public class DownloadItemUtils {
downloadEntity.setGameId(gameEntity.getId());
downloadEntity.setPluggable(gameEntity.isPluggable());
downloadEntity.setEntrance(entrance);
downloadEntity.setLocation("游戏详情:" + gameEntity.getName());
downloadEntity.setLocation(location);
DownloadManager.getInstance(context).add(downloadEntity);
}