From 43915ad204535d291b5eeb170c6f7e27e7e009c9 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Tue, 30 Jul 2019 19:30:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=88=9B=E5=BB=BA=E5=94=AF?= =?UTF-8?q?=E4=B8=80id=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../aria/core/common/controller/ControllerType.java | 6 ++++++ .../aria/core/download/FtpDirNormalTarget.java | 11 +++++++++++ .../arialyy/aria/core/download/FtpDirStartTarget.java | 11 +++++++++++ .../main/java/com/arialyy/aria/util/IdGenerator.java | 3 ++- .../simple/core/download/SingleTaskActivity.java | 5 +++++ build.gradle | 2 +- 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/controller/ControllerType.java b/Aria/src/main/java/com/arialyy/aria/core/common/controller/ControllerType.java index e8859f91..6eaf39a9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/controller/ControllerType.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/controller/ControllerType.java @@ -19,6 +19,12 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @Retention(RetentionPolicy.SOURCE) public @interface ControllerType { + /** + * 仅用于第一次创建任务,后续可调用`#start()、#add()、#setHighestPriority()`方法。 + */ Class START_CONTROLLER = StartController.class; + /** + * 用于后续的任务控制,后续可调用`#stop()、#resume()、#cancel()、#cancel(boolean)、#retry()、#restart()`方法。 + */ Class NORMAL_CONTROLLER = NormalController.class; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirNormalTarget.java index 70ed972f..cabcea4b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirNormalTarget.java @@ -19,6 +19,7 @@ import android.support.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.ftp.FtpDelegate; +import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.util.CommonUtil; /** @@ -77,4 +78,14 @@ public class FtpDirNormalTarget extends AbsNormalTarget { @Override public DownloadGroupEntity getEntity() { return (DownloadGroupEntity) super.getEntity(); } + + /** + * 获取子任务管理器 + * + * @return 子任务管理器 + */ + @CheckResult(suggest = Suggest.TASK_CONTROLLER) + public SubTaskManager getSubTaskManager() { + return mConfigHandler.getSubTaskManager(); + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirStartTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirStartTarget.java index 73de3b42..268ccec3 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirStartTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirStartTarget.java @@ -19,6 +19,7 @@ import android.support.annotation.CheckResult; import com.arialyy.aria.core.common.AbsStartTarget; import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.ftp.FtpDelegate; +import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.util.CommonUtil; /** @@ -79,4 +80,14 @@ public class FtpDirStartTarget extends AbsStartTarget { @Override public DownloadGroupEntity getEntity() { return (DownloadGroupEntity) super.getEntity(); } + + /** + * 获取子任务管理器 + * + * @return 子任务管理器 + */ + @CheckResult(suggest = Suggest.TASK_CONTROLLER) + public SubTaskManager getSubTaskManager() { + return mConfigHandler.getSubTaskManager(); + } } diff --git a/Aria/src/main/java/com/arialyy/aria/util/IdGenerator.java b/Aria/src/main/java/com/arialyy/aria/util/IdGenerator.java index 1fca0ac8..f1bea63b 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/IdGenerator.java +++ b/Aria/src/main/java/com/arialyy/aria/util/IdGenerator.java @@ -51,7 +51,8 @@ public class IdGenerator { public synchronized long nextId() { long ts = timeGen(); if (ts < lastTs) {// 刚刚生成的时间戳比上次的时间戳还小,出错 - throw new RuntimeException("时间戳顺序错误"); + //throw new RuntimeException("时间戳顺序错误"); + ts = nextTs(lastTs); } if (ts == lastTs) {// 刚刚生成的时间戳跟上次的时间戳一样,则需要生成一个sequence序列号 // sequence循环自增 diff --git a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java index 03cb3488..ebb94c78 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/core/download/SingleTaskActivity.java @@ -31,6 +31,8 @@ import android.view.View; import android.widget.Toast; import com.arialyy.annotations.Download; import com.arialyy.aria.core.Aria; +import com.arialyy.aria.core.common.RequestEnum; +import com.arialyy.aria.core.common.controller.ControllerType; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTask; import com.arialyy.aria.core.inf.IEntity; @@ -302,6 +304,9 @@ public class SingleTaskActivity extends BaseActivity { return Long.parseLong(temp); } }) + .option() + .addHeader("1", "@") + .controller(ControllerType.START_CONTROLLER) .start(); } diff --git a/build.gradle b/build.gradle index 05b0c05b..813d3bac 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,7 @@ task clean(type: Delete) { ext { userOrg = 'arialyy' groupId = 'com.arialyy.aria' - publishVersion = '3.6.6_beta_1' + publishVersion = '3.6.6_beta_2' // publishVersion = '1.0.4' //FTP插件 repoName='maven' desc = 'android 下载框架'