From 063a0e95c25ea75cc2c08b9d87fd5bbd81c7e0f4 Mon Sep 17 00:00:00 2001 From: AriaLyy <511455842@qq.com> Date: Fri, 4 Aug 2017 14:35:55 +0800 Subject: [PATCH] bug fix --- .../core/command/normal/AbsNormalCmd.java | 1 - .../aria/core/command/normal/CancelCmd.java | 11 +- .../core/command/normal/ResumeAllCmd.java | 10 ++ .../aria/core/download/DownloadTarget.java | 8 +- .../download/downloader/AbsGroupUtil.java | 4 +- .../downloader/DownloadGroupUtil.java | 5 +- .../com/arialyy/aria/util/CommonUtil.java | 4 + .../download/HighestPriorityActivity.java | 114 ++++++++---------- 8 files changed, 88 insertions(+), 69 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java index 12bbfa0c..6e56f850 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java @@ -16,7 +16,6 @@ package com.arialyy.aria.core.command.normal; -import android.os.Handler; import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java index f13ae910..ff959b2d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java @@ -32,9 +32,14 @@ class CancelCmd extends AbsNormalCmd { @Override public void executeCmd() { if (!canExeCmd) return; AbsTask task = getTask(); - if (!TextUtils.isEmpty(mTargetName)) { - task.setTargetName(mTargetName); + if (task == null) { + task = createTask(); + } + if (task != null) { + if (!TextUtils.isEmpty(mTargetName)) { + task.setTargetName(mTargetName); + } + removeTask(); } - removeTask(); } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java index 1d06c79d..412a0ff3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java @@ -4,6 +4,9 @@ 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.IEntity; +import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; +import com.arialyy.aria.core.queue.DownloadTaskQueue; +import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.upload.UploadTaskEntity; import com.arialyy.aria.orm.DbEntity; import java.util.List; @@ -69,6 +72,13 @@ final class ResumeAllCmd extends AbsNormalCmd { * @param te 任务实体 */ private void resumeEntity(AbsTaskEntity te) { + if (te instanceof DownloadTaskEntity) { + mQueue = DownloadTaskQueue.getInstance(); + } else if (te instanceof UploadTaskEntity) { + mQueue = UploadTaskQueue.getInstance(); + } else if (te instanceof DownloadGroupTaskEntity) { + mQueue = DownloadGroupTaskQueue.getInstance(); + } int exeNum = mQueue.getCurrentExePoolNum(); if (exeNum == 0 || exeNum < mQueue.getMaxTaskNum()) { startTask(createTask(te)); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java index 16978e96..27aea5dc 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java @@ -33,13 +33,19 @@ public class DownloadTarget protected String url; DownloadTarget(DownloadEntity entity, String targetName) { - this(entity.getUrl(), targetName); + this.url = entity.getUrl(); + mTargetName = targetName; + initTask(entity); } DownloadTarget(String url, String targetName) { this.url = url; mTargetName = targetName; DownloadEntity entity = getEntity(url); + initTask(entity); + } + + private void initTask(DownloadEntity entity) { mTaskEntity = DbEntity.findFirst(DownloadTaskEntity.class, "key=? and isGroupTask='false'", entity.getDownloadPath()); if (mTaskEntity == null) { diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java index 21a10b8b..5c698a12 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java @@ -44,10 +44,10 @@ abstract class AbsGroupUtil implements IUtil { * 任务组所有任务总大小 */ long mTotalSize = 0; - private long mCurrentLocation = 0; + protected long mCurrentLocation = 0; private ExecutorService mExePool; protected IDownloadGroupListener mListener; - DownloadGroupTaskEntity mTaskEntity; + protected DownloadGroupTaskEntity mTaskEntity; private boolean isRunning = true; private Timer mTimer; /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java index 5b3abfbf..490b45cc 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java @@ -72,7 +72,10 @@ public class DownloadGroupUtil extends AbsGroupUtil implements IUtil { } } } - if (i == mExeMap.size()) startRunningFlow(); + if (i != 0 && i == mExeMap.size()) startRunningFlow(); + if (mCurrentLocation == mTotalSize) { + mListener.onComplete(); + } } /** 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 2f4fb2b4..21745edb 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -575,6 +575,10 @@ public class CommonUtil { * 如果文件存在,先删除原文件,然后重新创建一个新文件 */ public static void createFile(String path) { + if (TextUtils.isEmpty(path)) { + Log.e(TAG, "文件路径不能为null"); + return; + } File file = new File(path); if (!file.getParentFile().exists()) { Log.d(TAG, "目标文件所在路径不存在,准备创建……"); diff --git a/app/src/main/java/com/arialyy/simple/download/HighestPriorityActivity.java b/app/src/main/java/com/arialyy/simple/download/HighestPriorityActivity.java index 73cb28c4..6b699651 100644 --- a/app/src/main/java/com/arialyy/simple/download/HighestPriorityActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/HighestPriorityActivity.java @@ -25,6 +25,7 @@ import android.view.View; import android.widget.Button; import android.widget.TextView; import butterknife.Bind; +import com.arialyy.annotations.Download; import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTarget; @@ -71,6 +72,7 @@ public class HighestPriorityActivity extends BaseActivity