项目整理
This commit is contained in:
@ -20,6 +20,8 @@ import com.gh.common.constant.Constants;
|
||||
import com.gh.common.view.DownloadDialog;
|
||||
import com.gh.download.DownloadEntry;
|
||||
import com.gh.download.DownloadManager;
|
||||
import com.gh.gamecenter.GameDetailsActivity;
|
||||
import com.gh.gamecenter.MainActivity;
|
||||
import com.gh.gamecenter.R;
|
||||
import com.gh.gamecenter.entity.ApkEntity;
|
||||
import com.gh.gamecenter.entity.DismissEntity;
|
||||
@ -29,6 +31,8 @@ import com.gh.gamecenter.eventbus.EBRedDot;
|
||||
import com.gh.gamecenter.manager.DataCollectionManager;
|
||||
import com.gh.gamecenter.manager.PackageManager;
|
||||
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -123,11 +127,10 @@ public class DownloadItemUtils {
|
||||
} else {
|
||||
downloadBtn.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if (entity.getApk() != null
|
||||
&& entity.getApk().size() == 1
|
||||
&& PackageManager.isInstalled(entity.getApk().get(0)
|
||||
.getPackageName())) {
|
||||
&& PackageManager.isInstalled(entity.getApk().get(0).getPackageName())
|
||||
&& entity.getPluginPlatform() == null) {
|
||||
labelList.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
@ -141,8 +144,7 @@ public class DownloadItemUtils {
|
||||
|
||||
DownloadEntry downloadEntry;
|
||||
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(entity
|
||||
.getName());
|
||||
LinkedBlockingQueue<String> queue = platformMap.get(entity.getName());
|
||||
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntry = entryMap.get(queue.peek());
|
||||
@ -156,16 +158,14 @@ public class DownloadItemUtils {
|
||||
game_ll_info.setVisibility(View.VISIBLE);
|
||||
|
||||
String platform = PlatformUtils.getInstance(context)
|
||||
.getPlatformName(
|
||||
downloadEntry.getMeta().get("platform"));
|
||||
.getPlatformName(downloadEntry.getMeta().get("platform"));
|
||||
|
||||
switch (downloadEntry.getStatus()) {
|
||||
case downloading:
|
||||
if (!"pause".equals(statusMap.get(downloadEntry.getUrl()))) {
|
||||
if (isShowPlatform) {
|
||||
if (platform == null) {
|
||||
download_speed
|
||||
.setText(SpeedUtils
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry
|
||||
.getSpeed())
|
||||
+ "(剩"
|
||||
@ -178,8 +178,7 @@ public class DownloadItemUtils {
|
||||
.getSpeed() * 1024)
|
||||
+ ")");
|
||||
} else {
|
||||
download_speed
|
||||
.setText(platform
|
||||
download_speed.setText(platform
|
||||
+ " - "
|
||||
+ SpeedUtils
|
||||
.getSpeed(downloadEntry
|
||||
@ -195,8 +194,7 @@ public class DownloadItemUtils {
|
||||
+ ")");
|
||||
}
|
||||
} else {
|
||||
download_speed
|
||||
.setText(SpeedUtils
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry
|
||||
.getSpeed())
|
||||
+ "(剩"
|
||||
@ -254,23 +252,19 @@ public class DownloadItemUtils {
|
||||
download_speed.setText("下载完成");
|
||||
}
|
||||
download_percentage.setText("100%");
|
||||
if (entity.getApk() != null
|
||||
&& entity.getApk().size() == 1) {
|
||||
if (entity.getApk() != null && entity.getApk().size() == 1) {
|
||||
EventBus.getDefault().post(
|
||||
new EBPutUrl(entity.getApk().get(0)
|
||||
.getPackageName(), downloadEntry
|
||||
.getUrl()));
|
||||
.getPackageName(), downloadEntry.getUrl()));
|
||||
downloadBtn.setText("安装");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
} else {
|
||||
labelList.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
downloadBtn.setText("下载");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
}
|
||||
break;
|
||||
@ -302,7 +296,11 @@ public class DownloadItemUtils {
|
||||
labelList.setVisibility(View.VISIBLE);
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
downloadBtn.setText("下载");
|
||||
if (entity.getPluginPlatform() != null) {
|
||||
downloadBtn.setText("插件化");
|
||||
} else {
|
||||
downloadBtn.setText("下载");
|
||||
}
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
break;
|
||||
@ -317,9 +315,12 @@ public class DownloadItemUtils {
|
||||
game_progressbar.setVisibility(View.GONE);
|
||||
game_ll_info.setVisibility(View.GONE);
|
||||
if (entity.getApk() != null) {
|
||||
downloadBtn.setText("下载");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
if (entity.getPluginPlatform() != null) {
|
||||
downloadBtn.setText("插件化");
|
||||
} else {
|
||||
downloadBtn.setText("下载");
|
||||
}
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
@ -368,315 +369,40 @@ public class DownloadItemUtils {
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
if (entity.getApk().size() == 1) {
|
||||
String msg = FileUtils.isCanDownload(entity
|
||||
.getApk().get(0).getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk().get(0).getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(context, "游戏下载", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", entity.getApk().get(0)
|
||||
.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-开始");
|
||||
DataUtils.onEvent(context, "游戏下载位置", entity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<String, Object>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(context, "应用数据", entity.getName(), kv3);
|
||||
|
||||
if ("主页-最新插件".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "最新插件", kv4);
|
||||
} else if ("主页-热门卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "热门卡牌", kv4);
|
||||
} else if ("主页-新测卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "新测卡牌", kv4);
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
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("network", NetworkUtils.getConnectedType(context));
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(context, "download", map);
|
||||
|
||||
DownloadManager.getInstance(context).add(
|
||||
getDownloadEntry(context, entity, 0, entrance));
|
||||
Toast.makeText(context, entity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show();
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "downloading");
|
||||
} else {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog.getInstance(context)
|
||||
.showPopupWindow(viewBtn, entity, entrance, statusMap,
|
||||
download_speed, download_percentage, location);
|
||||
}
|
||||
}
|
||||
download(context, entity, downloadBtn, statusMap,
|
||||
dismissEntity, download_speed, download_percentage,
|
||||
viewBtn, entrance, location);
|
||||
} else {
|
||||
|
||||
final Dialog dialog = new Dialog(context);
|
||||
View view = View.inflate(context, R.layout.search_history_delete_dialog, null);
|
||||
TextView title = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_title);
|
||||
title.setText("警告");
|
||||
TextView content = (TextView) view.findViewById(R.id.delete_dialog_message);
|
||||
|
||||
content.setText("您当前的网络为2G/3G/4G,下载将会消耗移动流量,是否继续下载?");
|
||||
|
||||
TextView cancel = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_cancel);
|
||||
cancel.setText("取消");
|
||||
cancel.setOnClickListener(new OnClickListener() {
|
||||
DialogUtils.showWarningDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
public void onConfirem() {
|
||||
download(context, entity, downloadBtn, statusMap,
|
||||
dismissEntity, download_speed, download_percentage,
|
||||
viewBtn, entrance, location);
|
||||
}
|
||||
});
|
||||
TextView confirem = (TextView) view
|
||||
.findViewById(R.id.delete_dialog_confirm);
|
||||
confirem.setText("继续");
|
||||
confirem.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialog.dismiss();
|
||||
if (entity.getApk() == null
|
||||
|| entity.getApk().isEmpty()) {
|
||||
Toast.makeText(context,
|
||||
"稍等片刻~!游戏正在上传中...",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
if (entity.getApk().size() == 1) {
|
||||
String msg = FileUtils
|
||||
.isCanDownload(entity
|
||||
.getApk().get(0)
|
||||
.getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk()
|
||||
.get(0).getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(context, "游戏下载", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", entity.getApk().get(0).getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-开始");
|
||||
DataUtils.onEvent(context, "游戏下载位置", entity.getName(), kv2);
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
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("network", NetworkUtils.getConnectedType(context));
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(context, "download", map);
|
||||
|
||||
DownloadManager.getInstance(context).add(
|
||||
getDownloadEntry(context, entity, 0, entrance));
|
||||
Toast.makeText(context, entity.getName() + "已加入下载队列",
|
||||
Toast.LENGTH_SHORT).show();
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "downloading");
|
||||
} else {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog
|
||||
.getInstance(context)
|
||||
.showPopupWindow(
|
||||
viewBtn,
|
||||
entity,
|
||||
entrance,
|
||||
statusMap,
|
||||
download_speed,
|
||||
download_percentage,
|
||||
location);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
} else if ("插件化".equals(str)) {
|
||||
if (NetworkUtils.isWifiConnected(context)) {
|
||||
plugin(context, entity, downloadBtn, statusMap, entrance);
|
||||
} else {
|
||||
DialogUtils.showWarningDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
plugin(context, entity, downloadBtn, statusMap, entrance);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else if ("暂停".equals(str)) {
|
||||
ArrayMap<String, DownloadEntry> entryMap = entity
|
||||
.getEntryMap();
|
||||
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntry downloadEntry;
|
||||
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(entity.getName());
|
||||
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntry = entryMap.get(queue.peek());
|
||||
} else {
|
||||
downloadEntry = entryMap.get(entryMap.keyAt(0));
|
||||
}
|
||||
|
||||
if (downloadEntry != null) {
|
||||
|
||||
String platform = PlatformUtils
|
||||
.getInstance(context).getPlatformName(
|
||||
downloadEntry.getMeta().get(
|
||||
"platform"));
|
||||
if (isShowPlatform) {
|
||||
if (platform == null) {
|
||||
download_speed.setText("暂停");
|
||||
} else {
|
||||
download_speed.setText(platform + " - 暂停");
|
||||
}
|
||||
} else {
|
||||
download_speed.setText("暂停");
|
||||
}
|
||||
download_percentage.setText(downloadEntry
|
||||
.getPercent() + "%");
|
||||
}
|
||||
}
|
||||
downloadBtn.setText("继续");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "pause");
|
||||
Message msg = Message.obtain();
|
||||
msg.what = Constants.PAUSE_DOWNLOAD_TASK;
|
||||
msg.obj = entity.getApk().get(0).getUrl();
|
||||
DownloadManager.getInstance(context).put(entity.getApk().get(0).getUrl(),
|
||||
System.currentTimeMillis());
|
||||
DownloadManager.getInstance(context).sendMessageDelayed(msg, 1000);
|
||||
pause(context, entity, download_speed, download_percentage,
|
||||
downloadBtn, platformMap, statusMap, isShowPlatform);
|
||||
} else if ("继续".equals(str)) {
|
||||
ArrayMap<String, DownloadEntry> entryMap = entity
|
||||
.getEntryMap();
|
||||
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntry downloadEntry;
|
||||
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(entity.getName());
|
||||
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntry = entryMap.get(queue.peek());
|
||||
} else {
|
||||
downloadEntry = entryMap.get(entryMap.keyAt(0));
|
||||
}
|
||||
|
||||
if (downloadEntry != null) {
|
||||
|
||||
String platform = PlatformUtils
|
||||
.getInstance(context).getPlatformName(
|
||||
downloadEntry.getMeta().get(
|
||||
"platform"));
|
||||
if (isShowPlatform) {
|
||||
if (platform == null) {
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
} else {
|
||||
download_speed.setText(platform
|
||||
+ " - "
|
||||
+ SpeedUtils.getSpeed(downloadEntry
|
||||
.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
}
|
||||
} else {
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
}
|
||||
download_percentage.setText(downloadEntry
|
||||
.getPercent() + "%");
|
||||
}
|
||||
}
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
statusMap.put(entity.getApk().get(0).getUrl(),
|
||||
"downloading");
|
||||
EventBus.getDefault().post(new EBRedDot(0));
|
||||
Message msg = Message.obtain();
|
||||
msg.what = Constants.CONTINUE_DOWNLOAD_TASK;
|
||||
msg.obj = entity.getApk().get(0).getUrl();
|
||||
DownloadManager.getInstance(context).put(entity.getApk().get(0).getUrl(),
|
||||
System.currentTimeMillis());
|
||||
DownloadManager.getInstance(context).sendMessageDelayed(msg, 1000);
|
||||
goon(context, entity, download_speed, download_percentage,
|
||||
downloadBtn, platformMap, statusMap, isShowPlatform);
|
||||
} else if ("安装".equals(str)) {
|
||||
String path = entity.getEntryMap()
|
||||
.get(entity.getEntryMap().keyAt(0)).getPath();
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包错误", Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
DownloadManager.getInstance(context).cancel(
|
||||
entity.getEntryMap()
|
||||
.get(entity.getEntryMap().keyAt(0))
|
||||
.getUrl());
|
||||
entity.getEntryMap().remove(
|
||||
entity.getEntryMap().keyAt(0));
|
||||
adapter.notifyItemChanged(position);
|
||||
} else {
|
||||
PackageManager manager = new PackageManager(context);
|
||||
if (manager.launchSetup(path)) {
|
||||
context.startActivity(PackageUtils
|
||||
.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showDialog(context, path);
|
||||
}
|
||||
}
|
||||
install(context, entity, position, adapter);
|
||||
} else if ("启动".equals(str)) {
|
||||
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk().get(0).getPlatform());
|
||||
DataUtils.onEvent(context, "游戏启动", entity.getName(), kv);
|
||||
@ -688,6 +414,307 @@ public class DownloadItemUtils {
|
||||
});
|
||||
}
|
||||
|
||||
//下载
|
||||
private static void download(Context context, GameEntity entity, TextView downloadBtn,
|
||||
ArrayMap<String, String> statusMap, DismissEntity dismissEntity,
|
||||
TextView download_speed, TextView download_percentage, View viewBtn,
|
||||
String entrance, String location) {
|
||||
if (entity.getApk().size() == 1) {
|
||||
String msg = FileUtils.isCanDownload(entity.getApk().get(0).getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk().get(0).getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(context, "游戏下载", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", entity.getApk().get(0)
|
||||
.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-开始");
|
||||
DataUtils.onEvent(context, "游戏下载位置", entity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<String, Object>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(context, "应用数据", entity.getName(), kv3);
|
||||
|
||||
if ("主页-最新插件".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "最新插件", kv4);
|
||||
} else if ("主页-热门卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "热门卡牌", kv4);
|
||||
} else if ("主页-新测卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "新测卡牌", kv4);
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
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("network", NetworkUtils.getConnectedType(context));
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(context, "download", map);
|
||||
|
||||
DownloadManager.getInstance(context).add(
|
||||
getDownloadEntry(context, entity, 0, entrance));
|
||||
Toast.makeText(context, entity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show();
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "downloading");
|
||||
} else {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else {
|
||||
if (!dismissEntity.isShow()) {
|
||||
dismissEntity.setShow(true);
|
||||
DownloadDialog.getInstance(context)
|
||||
.showPopupWindow(viewBtn, entity, entrance, statusMap,
|
||||
download_speed, download_percentage, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//插件化
|
||||
private static void plugin(Context context, GameEntity entity, TextView downloadBtn,
|
||||
ArrayMap<String, String> statusMap, String entrance) {
|
||||
String msg = FileUtils.isCanDownload(entity.getApk().get(0).getSize());
|
||||
if (TextUtils.isEmpty(msg)) {
|
||||
Map<String, Object> kv = new HashMap<String, Object>();
|
||||
kv.put("版本", entity.getApk().get(0).getPlatform());
|
||||
kv.put("状态", "下载开始");
|
||||
DataUtils.onEvent(context, "游戏下载", entity.getName(), kv);
|
||||
|
||||
Map<String, Object> kv2 = new HashMap<String, Object>();
|
||||
kv2.put("版本", entity.getApk().get(0)
|
||||
.getPlatform());
|
||||
kv2.put("状态", "下载开始");
|
||||
kv2.put("位置", entrance + "-开始");
|
||||
DataUtils.onEvent(context, "游戏下载位置", entity.getName(), kv2);
|
||||
|
||||
Map<String, Object> kv3 = new HashMap<String, Object>();
|
||||
kv3.put(entrance, "下载数");
|
||||
kv3.put(entrance, "下载开始");
|
||||
DataUtils.onEvent(context, "应用数据", entity.getName(), kv3);
|
||||
|
||||
if ("主页-最新插件".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "最新插件", kv4);
|
||||
} else if ("主页-热门卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "热门卡牌", kv4);
|
||||
} else if ("主页-新测卡牌".equals(entrance)) {
|
||||
Map<String, Object> kv4 = new HashMap<String, Object>();
|
||||
kv4.put(entity.getName(), "下载数");
|
||||
DataUtils.onEvent(context, "主页数据", "新测卡牌", kv4);
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("game", entity.getName());
|
||||
map.put("method", "正常");
|
||||
map.put("platform", PlatformUtils.getInstance(context)
|
||||
.getPlatformName(entity.getApk().get(0).getPlatform()));
|
||||
map.put("status", "开始");
|
||||
map.put("isPlugin", "true");
|
||||
map.put("location", "游戏详情:" + entity.getName());
|
||||
map.put("from", entrance);
|
||||
map.put("network", NetworkUtils.getConnectedType(context));
|
||||
map.put("createdOn", System.currentTimeMillis() / 1000);
|
||||
DataCollectionManager.onEvent(context, "download", map);
|
||||
|
||||
DownloadManager.getInstance(context).add(
|
||||
getDownloadEntry(context, entity, 0, entrance));
|
||||
Toast.makeText(context, entity.getName() + "已加入下载队列", Toast.LENGTH_SHORT).show();
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
EventBus.getDefault().post(new EBRedDot(1));
|
||||
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "downloading");
|
||||
} else {
|
||||
Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
//暂停
|
||||
private static void pause(Context context, GameEntity entity, TextView download_speed,
|
||||
TextView download_percentage, TextView downloadBtn,
|
||||
ArrayMap<String, LinkedBlockingQueue<String>> platformMap,
|
||||
ArrayMap<String, String> statusMap,
|
||||
boolean isShowPlatform) {
|
||||
ArrayMap<String, DownloadEntry> entryMap = entity
|
||||
.getEntryMap();
|
||||
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntry downloadEntry;
|
||||
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(entity.getName());
|
||||
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntry = entryMap.get(queue.peek());
|
||||
} else {
|
||||
downloadEntry = entryMap.get(entryMap.keyAt(0));
|
||||
}
|
||||
|
||||
if (downloadEntry != null) {
|
||||
|
||||
String platform = PlatformUtils
|
||||
.getInstance(context).getPlatformName(
|
||||
downloadEntry.getMeta().get(
|
||||
"platform"));
|
||||
if (isShowPlatform) {
|
||||
if (platform == null) {
|
||||
download_speed.setText("暂停");
|
||||
} else {
|
||||
download_speed.setText(platform + " - 暂停");
|
||||
}
|
||||
} else {
|
||||
download_speed.setText("暂停");
|
||||
}
|
||||
download_percentage.setText(downloadEntry
|
||||
.getPercent() + "%");
|
||||
}
|
||||
}
|
||||
downloadBtn.setText("继续");
|
||||
downloadBtn.setBackgroundResource(R.drawable.textview_blue_style);
|
||||
downloadBtn.setTextColor(0xFFFFFFFF);
|
||||
statusMap.put(entity.getApk().get(0).getUrl(), "pause");
|
||||
Message msg = Message.obtain();
|
||||
msg.what = Constants.PAUSE_DOWNLOAD_TASK;
|
||||
msg.obj = entity.getApk().get(0).getUrl();
|
||||
DownloadManager.getInstance(context).put(entity.getApk().get(0).getUrl(),
|
||||
System.currentTimeMillis());
|
||||
DownloadManager.getInstance(context).sendMessageDelayed(msg, 1000);
|
||||
}
|
||||
|
||||
//继续
|
||||
private static void goon(Context context, GameEntity entity, TextView download_speed,
|
||||
TextView download_percentage, TextView downloadBtn,
|
||||
ArrayMap<String, LinkedBlockingQueue<String>> platformMap,
|
||||
ArrayMap<String, String> statusMap,
|
||||
boolean isShowPlatform) {
|
||||
ArrayMap<String, DownloadEntry> entryMap = entity
|
||||
.getEntryMap();
|
||||
|
||||
if (entryMap != null && !entryMap.isEmpty()) {
|
||||
|
||||
DownloadEntry downloadEntry;
|
||||
|
||||
LinkedBlockingQueue<String> queue = platformMap
|
||||
.get(entity.getName());
|
||||
|
||||
if (queue != null && !queue.isEmpty()) {
|
||||
downloadEntry = entryMap.get(queue.peek());
|
||||
} else {
|
||||
downloadEntry = entryMap.get(entryMap.keyAt(0));
|
||||
}
|
||||
|
||||
if (downloadEntry != null) {
|
||||
|
||||
String platform = PlatformUtils
|
||||
.getInstance(context).getPlatformName(
|
||||
downloadEntry.getMeta().get(
|
||||
"platform"));
|
||||
if (isShowPlatform) {
|
||||
if (platform == null) {
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
} else {
|
||||
download_speed.setText(platform
|
||||
+ " - "
|
||||
+ SpeedUtils.getSpeed(downloadEntry
|
||||
.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
}
|
||||
} else {
|
||||
download_speed.setText(SpeedUtils
|
||||
.getSpeed(downloadEntry.getSpeed())
|
||||
+ "(剩"
|
||||
+ SpeedUtils.getRemainTime(
|
||||
downloadEntry.getSize(),
|
||||
downloadEntry.getProgress(),
|
||||
downloadEntry.getSpeed() * 1024)
|
||||
+ ")");
|
||||
}
|
||||
download_percentage.setText(downloadEntry
|
||||
.getPercent() + "%");
|
||||
}
|
||||
}
|
||||
downloadBtn.setText("暂停");
|
||||
downloadBtn
|
||||
.setBackgroundResource(R.drawable.textview_gray_style);
|
||||
downloadBtn.setTextColor(0xFF999999);
|
||||
statusMap.put(entity.getApk().get(0).getUrl(),
|
||||
"downloading");
|
||||
EventBus.getDefault().post(new EBRedDot(0));
|
||||
Message msg = Message.obtain();
|
||||
msg.what = Constants.CONTINUE_DOWNLOAD_TASK;
|
||||
msg.obj = entity.getApk().get(0).getUrl();
|
||||
DownloadManager.getInstance(context).put(entity.getApk().get(0).getUrl(),
|
||||
System.currentTimeMillis());
|
||||
DownloadManager.getInstance(context).sendMessageDelayed(msg, 1000);
|
||||
}
|
||||
|
||||
//安装
|
||||
private static void install(final Context context, GameEntity entity, int position,
|
||||
RecyclerView.Adapter<RecyclerView.ViewHolder> adapter) {
|
||||
final String path = entity.getEntryMap()
|
||||
.get(entity.getEntryMap().keyAt(0)).getPath();
|
||||
if (FileUtils.isEmptyFile(path)) {
|
||||
Toast.makeText(context, "解析包错误", Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
DownloadManager.getInstance(context).cancel(
|
||||
entity.getEntryMap()
|
||||
.get(entity.getEntryMap().keyAt(0))
|
||||
.getUrl());
|
||||
entity.getEntryMap().remove(
|
||||
entity.getEntryMap().keyAt(0));
|
||||
adapter.notifyItemChanged(position);
|
||||
} else {
|
||||
PackageManager manager = new PackageManager(context);
|
||||
if (manager.launchSetup(path)) {
|
||||
context.startActivity(PackageUtils
|
||||
.getInstallIntent(path));
|
||||
} else {
|
||||
DialogUtils.showUninstallDialog(context, new DialogUtils.ConfiremListener() {
|
||||
@Override
|
||||
public void onConfirem() {
|
||||
MainActivity.uninstallMap.put(
|
||||
PackageUtils.getPackageNameByPath(context, path), path);
|
||||
context.startActivity(PackageUtils.getUninstallIntent(context, path));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static DownloadEntry getDownloadEntry(Context context,
|
||||
GameEntity game, int position, String entrance) {
|
||||
ApkEntity apkEntity = game.getApk().get(position);
|
||||
@ -695,8 +722,7 @@ public class DownloadItemUtils {
|
||||
|
||||
entry.setUrl(apkEntity.getUrl());
|
||||
entry.setName(game.getName());
|
||||
entry.setPath(FileUtils.getDownloadPath(
|
||||
context,
|
||||
entry.setPath(FileUtils.getDownloadPath(context,
|
||||
MD5Utils.getContentMD5(game.getName() + "_"
|
||||
+ System.currentTimeMillis())
|
||||
+ ".apk"));
|
||||
@ -707,6 +733,9 @@ public class DownloadItemUtils {
|
||||
meta.put("gameId", game.getId());
|
||||
meta.put("entrance", entrance);
|
||||
meta.put("location", "游戏详情:" + game.getName());
|
||||
if (game.getPluginPlatform() != null) {
|
||||
meta.put("PluginPlatform", PlatformUtils.getInstance(context).getPlatformName(game.getApk().get(0).getPlatform()));
|
||||
}
|
||||
entry.setMeta(meta);
|
||||
return entry;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user