From 2ceb7d793a180d64a2e7034e365ba1ee2e13a316 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Tue, 5 Sep 2017 20:42:43 +0800 Subject: [PATCH] fix bug https://github.com/AriaLyy/Aria/issues/112 --- .../core/command/normal/CancelAllCmd.java | 16 +++++++- .../com/arialyy/aria/util/CommonUtil.java | 37 +++++++++++++++++++ .../multi_download/MultiTaskActivity.java | 3 +- app/src/main/res/values/strings.xml | 24 ++++++------ 4 files changed, 66 insertions(+), 14 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java index fc10fb5a..938484a0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java @@ -16,6 +16,7 @@ package com.arialyy.aria.core.command.normal; +import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.upload.UploadTaskEntity; @@ -43,13 +44,26 @@ public class CancelAllCmd extends AbsNormalCmd { @Override public void executeCmd() { removeAll(); - if (mTaskEntity instanceof DownloadTaskEntity) { + if (mTaskEntity instanceof DownloadTaskEntity + || mTaskEntity instanceof DownloadGroupTaskEntity) { handleDownloadRemove(); + handleDownloadGroupRemove(); } else if (mTaskEntity instanceof UploadTaskEntity) { handleUploadRemove(); } } + /** + * 处理下载任务组的删除操作 + */ + private void handleDownloadGroupRemove() { + List allEntity = DbEntity.findAllData(DownloadGroupTaskEntity.class); + if (allEntity == null || allEntity.size() == 0) return; + for (DownloadGroupTaskEntity entity : allEntity) { + CommonUtil.delDownloadGroupTaskConfig(removeFile, entity); + } + } + /** * 处理上传的删除 */ diff --git a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java index abf7bf66..d8be3e6a 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -29,11 +29,14 @@ import com.arialyy.aria.core.command.group.GroupCmdFactory; import com.arialyy.aria.core.command.normal.AbsNormalCmd; import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.download.DownloadEntity; +import com.arialyy.aria.core.download.DownloadGroupEntity; +import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.BaseGroupTaskEntity; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadTaskEntity; +import com.arialyy.aria.orm.DbEntity; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; @@ -216,6 +219,39 @@ public class CommonUtil { return md5; } + /** + * 删除下载任务组的配置 + * + * @param removeFile {@code true} 不仅删除任务数据库记录,还会删除已经删除完成的文件 + * {@code false}如果任务已经完成,只删除任务数据库记录 + */ + public static void delDownloadGroupTaskConfig(boolean removeFile, + DownloadGroupTaskEntity tEntity) { + DownloadGroupEntity entity = tEntity.getEntity(); + List tasks = + DbEntity.findDatas(DownloadTaskEntity.class, "groupName=?", tEntity.key); + if (tasks != null && !tasks.isEmpty()) { + for (DownloadTaskEntity taskEntity : tasks) { + delDownloadTaskConfig(removeFile, taskEntity); + } + } + + File dir = new File(tEntity.getEntity().getDirPath()); + if (removeFile) { + if (dir.exists()) { + dir.delete(); + } + } else { + if (!tEntity.getEntity().isComplete()) { + dir.delete(); + } + } + if (entity != null) { + entity.deleteData(); + } + tEntity.deleteData(); + } + /** * 删除上传任务的配置 * @@ -246,6 +282,7 @@ public class CommonUtil { */ public static void delDownloadTaskConfig(boolean removeFile, DownloadTaskEntity tEntity) { DownloadEntity dEntity = tEntity.getEntity(); + if (dEntity == null) return; File file = new File(dEntity.getDownloadPath()); if (removeFile) { if (file.exists()) { diff --git a/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java index ab7efc65..cd8dba89 100644 --- a/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java @@ -66,7 +66,8 @@ public class MultiTaskActivity extends BaseActivity { dialog.show(getSupportFragmentManager(), "download_num"); break; case R.id.stop_all: - Aria.download(this).stopAllTask(); + //Aria.download(this).stopAllTask(); + Aria.download(this).removeAllTask(true); break; case R.id.turn: startActivity(new Intent(this, MultiDownloadActivity.class)); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 97bd4555..6ec4cea8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -55,18 +55,18 @@ - http://droidweb.smartgame-down.com/201708171123/C183E9C2010C7CABACFB398250A3DB75/new/game1/1/107001/qq_1502875308555.apk?f=web_1 - http://droidweb.smartgame-down.com/201708171124/6E5AF91791661236D0A2F60125D3B45F/new/game1/93/113093/00D42A6AA63A039485F510C2E4D69BAA_1498831237.apk?f=web_1 + http://hzdown.muzhiwan.com/2017/05/08/nl.noio.kingdom_59104935e56f0.apk + http://hzdown.muzhiwan.com/2017/09/05/com.mir.iphone.empire83jie.mzw_59ae6d5a3638d.apk - http://droidweb.smartgame-down.com/201708171125/005BCF0FFBB75510958D14074286B25F/new/game1/2/106202/qqkj_1502868291416.apk?f=web_1 - http://droidweb.smartgame-down.com/201708171126/05FAAA4FD294BC63AA8F792636961D19/new/game1/72/110472/com.taobao.taobao-6.9.0-157-0629_1498744826.apk?f=web_1 + http://down.muzhiwan.com/2017/04/05/org.sanguoqy01_58e4993914424.apk + http://apk500.bce.baidu-mgame.com/game/67000/67734/20170622040827_oem_5502845.apk?r=1 - http://droidweb.smartgame-down.com/201708171127/F55445FD8B7BBA8D72CA4B7D7BD91F90/new/game1/84/33184/txtim_1502854269836.apk?f=web_1 - http://droidweb.smartgame-down.com/201708171128/5C4D0289F0B83690BF252420F473FB9F/new/game1/46/108046/com.shuqi.controller-10.5.2.50-137-0703_1499083244.apk?f=web_1 + http://apk500.bce.baidu-mgame.com/game/883000/883227/20170828102306_oem_5502845.apk?r=1 + http://static.gaoshouyou.com/d/92/12/5592a647b8126755647abbe8074fde39.apk @@ -76,18 +76,18 @@ - QQ.apk - 百度贴吧.apk + 新大陆.apk + 罗马战争.apk - QQ空间.apk - 淘宝.apk + 三国群英传.apk + 海岛骑兵 - TIM.apk - 书旗小说.apk + 部落冲突.apk + 城堡争霸.apk