统一暂停,继续下载处理

This commit is contained in:
huangzhuanghua
2016-05-20 16:35:11 +08:00
parent a87a6fe256
commit 3d696fc991
25 changed files with 131 additions and 326 deletions

View File

@ -142,7 +142,6 @@ public class DownloadDialog {
private String gameType;
private String entrance;
private String mlocation;
private ArrayMap<String, Long> lastTimeMap;
private ArrayMap<String, String> statusMap;
private TextView download_speed;
private TextView download_percentage;
@ -152,41 +151,18 @@ public class DownloadDialog {
private int row;
private int column;
private Handler handler;
public void showPopupWindow(View view, GameEntity game, String entrance,
String location) {
ArrayMap<String, Long> mLastTimeMap = new ArrayMap<String, Long>();
ArrayMap<String, String> mStatusMap = new ArrayMap<String, String>();
Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
if (msg.what == Constants.CONTINUE_DOWNLOAD_TASK) {
String url = (String) msg.obj;
if (System.currentTimeMillis() - lastTimeMap.get(url) >= 1000) {
DownloadManager.getInstance(context).resume(url);
}
} else if (msg.what == Constants.PAUSE_DOWNLOAD_TASK) {
String url = (String) msg.obj;
if (System.currentTimeMillis() - lastTimeMap.get(url) >= 1000) {
DownloadManager.getInstance(context).pause(url);
}
}
}
};
showPopupWindow(view, game, entrance, mHandler, mLastTimeMap,
mStatusMap, location);
showPopupWindow(view, game, entrance, mStatusMap, location);
}
public void showPopupWindow(View view, GameEntity game, String entrance,
Handler hdler, ArrayMap<String, Long> ltMap,
ArrayMap<String, String> sMap, String location) {
showPopupWindow(view, game, entrance, hdler, ltMap, sMap, null, null,
location);
showPopupWindow(view, game, entrance, sMap, null, null, location);
}
public void showPopupWindow(View view, GameEntity game, String eStr,
Handler hdler, ArrayMap<String, Long> ltMap,
ArrayMap<String, String> sMap, TextView dSpeed,
TextView dPercentage, String lstr) {
@ -197,8 +173,6 @@ public class DownloadDialog {
mlocation = lstr;
entrance = eStr;
handler = hdler;
lastTimeMap = ltMap;
statusMap = sMap;
download_speed = dSpeed;
download_percentage = dPercentage;
@ -759,9 +733,9 @@ public class DownloadDialog {
Message msg = Message.obtain();
msg.what = Constants.CONTINUE_DOWNLOAD_TASK;
msg.obj = apkEntity.getUrl();
lastTimeMap.put(apkEntity.getUrl(),
DownloadManager.getInstance(context).put(apkEntity.getUrl(),
System.currentTimeMillis());
handler.sendMessageDelayed(msg, 1000);
DownloadManager.getInstance(context).sendMessageDelayed(msg, 1000);
EventBus.getDefault().post(new EBRedDot(0));
} else if ("启动".equals(status)) {
Map<String, Object> kv = new HashMap<String, Object>();
@ -942,9 +916,9 @@ public class DownloadDialog {
Message msg = Message.obtain();
msg.what = Constants.PAUSE_DOWNLOAD_TASK;
msg.obj = apkEntity.getUrl();
lastTimeMap.put(apkEntity.getUrl(),
DownloadManager.getInstance(context).put(apkEntity.getUrl(),
System.currentTimeMillis());
handler.sendMessageDelayed(msg, 1000);
DownloadManager.getInstance(context).sendMessageDelayed(msg, 1000);
}
}
}