From 7ee1347ab43bd505680c3018cac19e63b5ddcdb2 Mon Sep 17 00:00:00 2001 From: laoyuyu <511455842@qq.com> Date: Mon, 9 Sep 2019 21:29:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AppFrame/build.gradle | 2 +- Aria/build.gradle | 7 +- .../aria/core/command/GroupCmdFactory.java | 4 +- .../aria/core/download/CheckDEntityUtil.java | 14 +-- .../aria/core/download/DTaskWrapper.java | 17 ++++ .../aria/core/download/DownloadReceiver.java | 60 +++++------- .../download/group/GroupTargetFactory.java | 65 ------------- .../AbsGroupConfigHandler.java | 6 +- .../DNormalConfigHandler.java | 11 +-- .../DTargetFactory.java} | 41 +++++--- .../{normal => target}/FtpBuilderTarget.java | 6 +- .../FtpDirBuilderTarget.java | 5 +- .../FtpDirConfigHandler.java | 3 +- .../{group => target}/FtpDirNormalTarget.java | 5 +- .../{normal => target}/FtpNormalTarget.java | 6 +- .../{group => target}/GroupBuilderTarget.java | 5 +- .../{group => target}/GroupNormalTarget.java | 5 +- .../{normal => target}/HttpBuilderTarget.java | 6 +- .../HttpGroupConfigHandler.java | 3 +- .../{normal => target}/HttpNormalTarget.java | 6 +- .../download/target/TcpBuilderTarget.java | 73 ++++++++++++++ .../aria/core/download/tcp/TcpDelegate.java | 97 +++++++++++++++++++ .../aria/core/download/tcp/TcpTaskConfig.java | 77 +++++++++++++++ .../com/arialyy/aria/core/inf/AbsTarget.java | 14 +-- .../arialyy/aria/core/inf/ITaskWrapper.java | 18 ++++ .../aria/core/manager/SubTaskManager.java | 14 +-- .../aria/core/upload/CheckUEntityUtil.java | 15 +-- .../aria/core/upload/UploadReceiver.java | 38 +++----- .../{normal => target}/FtpBuilderTarget.java | 6 +- .../{normal => target}/FtpNormalTarget.java | 6 +- .../{normal => target}/HttpBuilderTarget.java | 6 +- .../{normal => target}/HttpNormalTarget.java | 6 +- .../UNormalConfigHandler.java | 9 +- .../UTargetFactory.java} | 28 +++--- .../com/arialyy/aria/util/CommonUtil.java | 8 +- AriaFtpComponent/.gitignore | 1 + AriaFtpComponent/build.gradle | 32 ++++++ AriaFtpComponent/consumer-rules.pro | 0 AriaFtpComponent/proguard-rules.pro | 21 ++++ .../ExampleInstrumentedTest.java | 26 +++++ AriaFtpComponent/src/main/AndroidManifest.xml | 2 + .../com/arialyy/aria/ftpcomponent/bb.java | 4 + .../src/main/res/values/strings.xml | 3 + .../ariaftpcomponent/ExampleUnitTest.java | 17 ++++ .../assets/help_code/KotlinHttpDownload.kt | 2 +- build.gradle | 7 +- settings.gradle | 2 +- 47 files changed, 540 insertions(+), 269 deletions(-) delete mode 100644 Aria/src/main/java/com/arialyy/aria/core/download/group/GroupTargetFactory.java rename Aria/src/main/java/com/arialyy/aria/core/download/{group => target}/AbsGroupConfigHandler.java (95%) rename Aria/src/main/java/com/arialyy/aria/core/download/{normal => target}/DNormalConfigHandler.java (91%) rename Aria/src/main/java/com/arialyy/aria/core/download/{normal/DNormalTargetFactory.java => target/DTargetFactory.java} (56%) rename Aria/src/main/java/com/arialyy/aria/core/download/{normal => target}/FtpBuilderTarget.java (94%) rename Aria/src/main/java/com/arialyy/aria/core/download/{group => target}/FtpDirBuilderTarget.java (95%) rename Aria/src/main/java/com/arialyy/aria/core/download/{group => target}/FtpDirConfigHandler.java (92%) rename Aria/src/main/java/com/arialyy/aria/core/download/{group => target}/FtpDirNormalTarget.java (95%) rename Aria/src/main/java/com/arialyy/aria/core/download/{normal => target}/FtpNormalTarget.java (93%) rename Aria/src/main/java/com/arialyy/aria/core/download/{group => target}/GroupBuilderTarget.java (97%) rename Aria/src/main/java/com/arialyy/aria/core/download/{group => target}/GroupNormalTarget.java (96%) rename Aria/src/main/java/com/arialyy/aria/core/download/{normal => target}/HttpBuilderTarget.java (95%) rename Aria/src/main/java/com/arialyy/aria/core/download/{group => target}/HttpGroupConfigHandler.java (97%) rename Aria/src/main/java/com/arialyy/aria/core/download/{normal => target}/HttpNormalTarget.java (93%) create mode 100644 Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpDelegate.java create mode 100644 Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpTaskConfig.java rename Aria/src/main/java/com/arialyy/aria/core/upload/{normal => target}/FtpBuilderTarget.java (92%) rename Aria/src/main/java/com/arialyy/aria/core/upload/{normal => target}/FtpNormalTarget.java (91%) rename Aria/src/main/java/com/arialyy/aria/core/upload/{normal => target}/HttpBuilderTarget.java (90%) rename Aria/src/main/java/com/arialyy/aria/core/upload/{normal => target}/HttpNormalTarget.java (91%) rename Aria/src/main/java/com/arialyy/aria/core/upload/{normal => target}/UNormalConfigHandler.java (92%) rename Aria/src/main/java/com/arialyy/aria/core/upload/{normal/UNormalTargetFactory.java => target/UTargetFactory.java} (66%) create mode 100644 AriaFtpComponent/.gitignore create mode 100644 AriaFtpComponent/build.gradle create mode 100644 AriaFtpComponent/consumer-rules.pro create mode 100644 AriaFtpComponent/proguard-rules.pro create mode 100644 AriaFtpComponent/src/androidTest/java/com/example/ariaftpcomponent/ExampleInstrumentedTest.java create mode 100644 AriaFtpComponent/src/main/AndroidManifest.xml create mode 100644 AriaFtpComponent/src/main/java/com/arialyy/aria/ftpcomponent/bb.java create mode 100644 AriaFtpComponent/src/main/res/values/strings.xml create mode 100644 AriaFtpComponent/src/test/java/com/example/ariaftpcomponent/ExampleUnitTest.java diff --git a/AppFrame/build.gradle b/AppFrame/build.gradle index 7ff09de7..bf09497a 100644 --- a/AppFrame/build.gradle +++ b/AppFrame/build.gradle @@ -29,7 +29,7 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) testImplementation 'junit:junit:4.12' - api 'androidx.appcompat:appcompat:1.0.2' + api "androidx.appcompat:appcompat:${rootProject.ext.XAppcompatVersion}" api 'com.google.code.gson:gson:2.8.2' api 'io.reactivex:rxandroid:1.2.0' api 'io.reactivex:rxjava:1.1.5' diff --git a/Aria/build.gradle b/Aria/build.gradle index ca7841a2..39b76600 100644 --- a/Aria/build.gradle +++ b/Aria/build.gradle @@ -24,10 +24,11 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') testImplementation 'junit:junit:4.12' - implementation 'androidx.appcompat:appcompat:1.0.0' + implementation "androidx.appcompat:appcompat:${rootProject.ext.XAppcompatVersion}" api project(':AriaAnnotations') - api 'com.arialyy.aria:aria-ftp-plug:1.0.4' // 打包时用这个 + api 'com.arialyy.aria:aria-ftp-plug:1.0.4' // 打包时用这个 + + // compile project(':AriaFtpPlug') -// compile project(':AriaFtpPlug') } apply from: 'bintray-release.gradle' diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/GroupCmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/GroupCmdFactory.java index db7b1f31..0edbfec9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/GroupCmdFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/GroupCmdFactory.java @@ -46,13 +46,11 @@ public class GroupCmdFactory { } /** - * @param target 创建任务的对象 * @param wrapper 参数信息 * @param type 命令类型{@link #SUB_TASK_START}、{@link #SUB_TASK_STOP} * @param childUrl 需要控制的子任务url */ - public AbsGroupCmd createCmd(String target, AbsGroupTaskWrapper wrapper, int type, - String childUrl) { + public AbsGroupCmd createCmd(AbsGroupTaskWrapper wrapper, int type, String childUrl) { AbsGroupCmd cmd = null; switch (type) { case SUB_TASK_START: diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java index ea81c0e1..360cec28 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java @@ -51,7 +51,7 @@ public class CheckDEntityUtil implements ICheckEntityUtil { return false; } - boolean b = checkFtps() && checkUrl() && checkFilePath(); + boolean b = checkUrl() && checkFilePath(); if (b) { mEntity.save(); } @@ -188,16 +188,4 @@ public class CheckDEntityUtil implements ICheckEntityUtil { } return true; } - - private boolean checkFtps() { - //if (mWrapper.getRequestType() == ITaskWrapper.D_FTP && mWrapper.asFtp() - // .getUrlEntity().isFtps) { - // String ftpUrl = mEntity.getUrl(); - // if (!ftpUrl.startsWith("ftps") && !ftpUrl.startsWith("sftp")) { - // ALog.e(TAG, String.format("地址【%s】错误,ftps地址开头必须是:ftps或sftp", ftpUrl)); - // return false; - // } - //} - return true; - } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java index f86fcb91..8ee29ab7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java @@ -18,6 +18,7 @@ package com.arialyy.aria.core.download; import com.arialyy.aria.core.config.Configuration; import com.arialyy.aria.core.config.DownloadConfig; import com.arialyy.aria.core.download.m3u8.M3U8TaskConfig; +import com.arialyy.aria.core.download.tcp.TcpTaskConfig; import com.arialyy.aria.core.inf.AbsTaskWrapper; /** @@ -35,12 +36,21 @@ public class DTaskWrapper extends AbsTaskWrapper { */ private boolean isGroupTask = false; + /** + * M3u8任务配置信息 + */ private M3U8TaskConfig m3u8TaskConfig; + /** + * TCP任务配置信息 + */ + private TcpTaskConfig tcpTaskConfig; + /** * 文件下载url的临时保存变量 */ private String mTempUrl; + /** * 文件保存路径的临时变量 */ @@ -62,6 +72,13 @@ public class DTaskWrapper extends AbsTaskWrapper { return m3u8TaskConfig; } + public TcpTaskConfig asTcp() { + if (tcpTaskConfig == null) { + tcpTaskConfig = new TcpTaskConfig(); + } + return tcpTaskConfig; + } + /** * Task实体对应的key,下载url */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java index 3c28d429..71e5d906 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java @@ -15,7 +15,6 @@ */ package com.arialyy.aria.core.download; -import android.text.TextUtils; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; import com.arialyy.annotations.TaskEnum; @@ -24,16 +23,15 @@ import com.arialyy.aria.core.command.CancelAllCmd; import com.arialyy.aria.core.command.NormalCmdFactory; import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.ProxyHelper; -import com.arialyy.aria.core.download.group.FtpDirBuilderTarget; -import com.arialyy.aria.core.download.group.FtpDirNormalTarget; -import com.arialyy.aria.core.download.group.GroupBuilderTarget; -import com.arialyy.aria.core.download.group.GroupNormalTarget; -import com.arialyy.aria.core.download.group.GroupTargetFactory; -import com.arialyy.aria.core.download.normal.FtpBuilderTarget; -import com.arialyy.aria.core.download.normal.FtpNormalTarget; -import com.arialyy.aria.core.download.normal.HttpBuilderTarget; -import com.arialyy.aria.core.download.normal.HttpNormalTarget; -import com.arialyy.aria.core.download.normal.DNormalTargetFactory; +import com.arialyy.aria.core.download.target.DTargetFactory; +import com.arialyy.aria.core.download.target.FtpBuilderTarget; +import com.arialyy.aria.core.download.target.FtpDirBuilderTarget; +import com.arialyy.aria.core.download.target.FtpDirNormalTarget; +import com.arialyy.aria.core.download.target.FtpNormalTarget; +import com.arialyy.aria.core.download.target.GroupBuilderTarget; +import com.arialyy.aria.core.download.target.GroupNormalTarget; +import com.arialyy.aria.core.download.target.HttpBuilderTarget; +import com.arialyy.aria.core.download.target.HttpNormalTarget; import com.arialyy.aria.core.event.EventMsgUtil; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsReceiver; @@ -76,8 +74,8 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public HttpBuilderTarget load(@NonNull String url) { CheckUtil.checkUrlInvalidThrow(url); - return DNormalTargetFactory.getInstance() - .generateBuilderTarget(HttpBuilderTarget.class, url, targetName); + return DTargetFactory.getInstance() + .generateBuilderTarget(HttpBuilderTarget.class, url); } /** @@ -89,8 +87,8 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public HttpNormalTarget load(long taskId) { CheckUtil.checkTaskId(taskId); - return DNormalTargetFactory.getInstance() - .generateNormalTarget(HttpNormalTarget.class, taskId, targetName); + return DTargetFactory.getInstance() + .generateNormalTarget(HttpNormalTarget.class, taskId); } /** @@ -101,7 +99,7 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public GroupBuilderTarget loadGroup(List urls) { CheckUtil.checkDownloadUrls(urls); - return GroupTargetFactory.getInstance().generateGroupBuilderTarget(urls, targetName); + return DTargetFactory.getInstance().generateGroupBuilderTarget(urls); } /** @@ -113,8 +111,8 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public GroupNormalTarget loadGroup(long taskId) { CheckUtil.checkTaskId(taskId); - return GroupTargetFactory.getInstance() - .generateNormalTarget(GroupNormalTarget.class, taskId, targetName); + return DTargetFactory.getInstance() + .generateNormalTarget(GroupNormalTarget.class, taskId); } /** @@ -123,8 +121,8 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public FtpBuilderTarget loadFtp(@NonNull String url) { CheckUtil.checkUrlInvalidThrow(url); - return DNormalTargetFactory.getInstance() - .generateBuilderTarget(FtpBuilderTarget.class, url, targetName); + return DTargetFactory.getInstance() + .generateBuilderTarget(FtpBuilderTarget.class, url); } /** @@ -136,8 +134,8 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public FtpNormalTarget loadFtp(long taskId) { CheckUtil.checkTaskId(taskId); - return DNormalTargetFactory.getInstance() - .generateNormalTarget(FtpNormalTarget.class, taskId, targetName); + return DTargetFactory.getInstance() + .generateNormalTarget(FtpNormalTarget.class, taskId); } /** @@ -146,7 +144,7 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public FtpDirBuilderTarget loadFtpDir(@NonNull String dirUrl) { CheckUtil.checkUrlInvalidThrow(dirUrl); - return GroupTargetFactory.getInstance().generateDirBuilderTarget(dirUrl, targetName); + return DTargetFactory.getInstance().generateDirBuilderTarget(dirUrl); } /** @@ -158,21 +156,17 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public FtpDirNormalTarget loadFtpDir(long taskId) { CheckUtil.checkTaskId(taskId); - return GroupTargetFactory.getInstance() - .generateNormalTarget(FtpDirNormalTarget.class, taskId, targetName); + return DTargetFactory.getInstance() + .generateNormalTarget(FtpDirNormalTarget.class, taskId); } /** * 将当前类注册到Aria */ public void register() { - if (TextUtils.isEmpty(targetName)) { - ALog.e(TAG, "download register target null"); - return; - } Object obj = OBJ_MAP.get(getKey()); if (obj == null) { - ALog.e(TAG, String.format("【%s】观察者为空", targetName)); + ALog.e(TAG, String.format("【%s】观察者为空", getTargetName())); return; } Set set = ProxyHelper.getInstance().checkProxyType(obj.getClass()); @@ -216,13 +210,9 @@ public class DownloadReceiver extends AbsReceiver { } @Override protected void unRegisterListener() { - if (TextUtils.isEmpty(targetName)) { - ALog.e(TAG, "download unRegisterListener target null"); - return; - } Object obj = OBJ_MAP.get(getKey()); if (obj == null) { - ALog.e(TAG, String.format("【%s】观察者为空", targetName)); + ALog.e(TAG, String.format("【%s】观察者为空", getTargetName())); return; } Set set = ProxyHelper.getInstance().mProxyCache.get(obj.getClass().getName()); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupTargetFactory.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupTargetFactory.java deleted file mode 100644 index 73ab3772..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupTargetFactory.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.arialyy.aria.core.download.group; - -import com.arialyy.aria.core.common.AbsNormalTarget; -import java.util.List; - -/** - * @Author aria - * @Date 2019-09-05 - */ -public class GroupTargetFactory { - - public static volatile GroupTargetFactory INSTANCE; - - private GroupTargetFactory() { - - } - - public static GroupTargetFactory getInstance() { - - if (INSTANCE == null) { - synchronized (GroupTargetFactory.class) { - if (INSTANCE == null) { - INSTANCE = new GroupTargetFactory(); - } - } - } - - return INSTANCE; - } - - public T generateNormalTarget(Class clazz, long taskId, - String targetName) { - T target = null; - if (clazz == GroupNormalTarget.class) { - target = (T) new GroupNormalTarget(taskId, targetName); - } else if (clazz == FtpDirNormalTarget.class) { - target = (T) new FtpDirNormalTarget(taskId, targetName); - } - - return target; - } - - public FtpDirBuilderTarget generateDirBuilderTarget(String url, String targetName) { - return new FtpDirBuilderTarget(url, targetName); - } - - public GroupBuilderTarget generateGroupBuilderTarget(List urls, String targetName) { - return new GroupBuilderTarget(urls, targetName); - } -} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/AbsGroupConfigHandler.java similarity index 95% rename from Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupConfigHandler.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/AbsGroupConfigHandler.java index 30a26e2f..d3eae6e8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/AbsGroupConfigHandler.java @@ -13,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.group; +package com.arialyy.aria.core.download.target; -import androidx.annotation.CheckResult; import android.text.TextUtils; +import androidx.annotation.CheckResult; import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupTask; @@ -61,7 +61,7 @@ abstract class AbsGroupConfigHandler implements IConfi @CheckResult SubTaskManager getSubTaskManager() { if (mSubTaskManager == null) { - mSubTaskManager = new SubTaskManager(mTarget.getTargetName(), getTaskWrapper()); + mSubTaskManager = new SubTaskManager(getTaskWrapper()); } return mSubTaskManager; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/normal/DNormalConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/DNormalConfigHandler.java similarity index 91% rename from Aria/src/main/java/com/arialyy/aria/core/download/normal/DNormalConfigHandler.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/DNormalConfigHandler.java index 2c86fc08..5eeb8aea 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/normal/DNormalConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/DNormalConfigHandler.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.normal; +package com.arialyy.aria.core.download.target; import android.text.TextUtils; import com.arialyy.aria.core.download.DTaskWrapper; @@ -40,26 +40,25 @@ class DNormalConfigHandler implements IConfigHandler { /** * @param taskId 第一次下载,taskId为-1 */ - DNormalConfigHandler(TARGET target, long taskId, String targetName) { + DNormalConfigHandler(TARGET target, long taskId) { this.mTarget = target; - initTarget(taskId, targetName); + initTarget(taskId); } - private void initTarget(long taskId, String targetName) { + private void initTarget(long taskId) { mWrapper = TaskWrapperManager.getInstance().getNormalTaskWrapper(DTaskWrapper.class, taskId); if (taskId != -1 && mWrapper.getEntity().getId() == -1) { mWrapper.setErrorEvent(new ErrorEvent(taskId, String.format("没有id为%s的任务", taskId))); } mEntity = mWrapper.getEntity(); - mTarget.setTargetName(targetName); mTarget.setTaskWrapper(mWrapper); if (mEntity != null) { getWrapper().setTempFilePath(mEntity.getFilePath()); } } - public TARGET updateUrl(String newUrl) { + TARGET updateUrl(String newUrl) { if (TextUtils.isEmpty(newUrl)) { ALog.e(TAG, "url更新失败,newUrl为null"); return mTarget; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/normal/DNormalTargetFactory.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/DTargetFactory.java similarity index 56% rename from Aria/src/main/java/com/arialyy/aria/core/download/normal/DNormalTargetFactory.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/DTargetFactory.java index 31655cb3..693430e4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/normal/DNormalTargetFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/DTargetFactory.java @@ -13,29 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.normal; +package com.arialyy.aria.core.download.target; import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.AbsNormalTarget; +import java.util.List; /** * @Author aria * @Date 2019-09-05 */ -public class DNormalTargetFactory { +public class DTargetFactory { - public static volatile DNormalTargetFactory INSTANCE; + public static volatile DTargetFactory INSTANCE; - private DNormalTargetFactory() { + private DTargetFactory() { } - public static DNormalTargetFactory getInstance() { + public static DTargetFactory getInstance() { if (INSTANCE == null) { - synchronized (DNormalTargetFactory.class) { + synchronized (DTargetFactory.class) { if (INSTANCE == null) { - INSTANCE = new DNormalTargetFactory(); + INSTANCE = new DTargetFactory(); } } } @@ -43,27 +44,37 @@ public class DNormalTargetFactory { return INSTANCE; } - public T generateNormalTarget(Class clazz, long taskId, - String targetName) { + public T generateNormalTarget(Class clazz, long taskId) { T target = null; if (clazz == HttpNormalTarget.class) { - target = (T) new HttpNormalTarget(taskId, targetName); + target = (T) new HttpNormalTarget(taskId); } else if (clazz == FtpNormalTarget.class) { - target = (T) new FtpNormalTarget(taskId, targetName); + target = (T) new FtpNormalTarget(taskId); + } else if (clazz == GroupNormalTarget.class) { + target = (T) new GroupNormalTarget(taskId); + } else if (clazz == FtpDirNormalTarget.class) { + target = (T) new FtpDirNormalTarget(taskId); } return target; } - public T generateBuilderTarget(Class clazz, String url, - String targetName) { + public T generateBuilderTarget(Class clazz, String url) { T target = null; if (clazz == HttpBuilderTarget.class) { - target = (T) new HttpBuilderTarget(url, targetName); + target = (T) new HttpBuilderTarget(url); } else if (clazz == FtpBuilderTarget.class) { - target = (T) new FtpBuilderTarget(url, targetName); + target = (T) new FtpBuilderTarget(url); } return target; } + + public FtpDirBuilderTarget generateDirBuilderTarget(String url) { + return new FtpDirBuilderTarget(url); + } + + public GroupBuilderTarget generateGroupBuilderTarget(List urls) { + return new GroupBuilderTarget(urls); + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java similarity index 94% rename from Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java index 6f904f73..55c44716 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.normal; +package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; @@ -30,8 +30,8 @@ import com.arialyy.aria.util.CommonUtil; public class FtpBuilderTarget extends AbsBuilderTarget { private DNormalConfigHandler mConfigHandler; - FtpBuilderTarget(String url, String targetName) { - mConfigHandler = new DNormalConfigHandler<>(this, -1, targetName); + FtpBuilderTarget(String url) { + mConfigHandler = new DNormalConfigHandler<>(this, -1); mConfigHandler.setUrl(url); getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(url)); getTaskWrapper().setRequestType(ITaskWrapper.D_FTP); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java similarity index 95% rename from Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java index c581a363..a2e97691 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.group; +package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsBuilderTarget; @@ -30,8 +30,7 @@ import com.arialyy.aria.util.CommonUtil; public class FtpDirBuilderTarget extends AbsBuilderTarget { private FtpDirConfigHandler mConfigHandler; - FtpDirBuilderTarget(String url, String targetName) { - setTargetName(targetName); + FtpDirBuilderTarget(String url) { mConfigHandler = new FtpDirConfigHandler<>(this, -1); getEntity().setGroupHash(url); getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(url)); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirConfigHandler.java similarity index 92% rename from Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirConfigHandler.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirConfigHandler.java index ef75325d..35720be0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirConfigHandler.java @@ -13,9 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.group; +package com.arialyy.aria.core.download.target; import com.arialyy.aria.core.download.DTaskWrapper; +import com.arialyy.aria.core.download.target.AbsGroupConfigHandler; import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.ITaskWrapper; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java similarity index 95% rename from Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java index 45bd433b..742f455f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.group; +package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; @@ -30,8 +30,7 @@ import com.arialyy.aria.util.CommonUtil; public class FtpDirNormalTarget extends AbsNormalTarget { private FtpDirConfigHandler mConfigHandler; - FtpDirNormalTarget(long taskId, String targetName) { - setTargetName(targetName); + FtpDirNormalTarget(long taskId) { mConfigHandler = new FtpDirConfigHandler<>(this, taskId); getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getKey())); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java similarity index 93% rename from Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java index 10aa07c8..8c912f06 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.normal; +package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; @@ -31,8 +31,8 @@ import com.arialyy.aria.util.CommonUtil; public class FtpNormalTarget extends AbsNormalTarget { private DNormalConfigHandler mConfigHandler; - FtpNormalTarget(long taskId, String targetName) { - mConfigHandler = new DNormalConfigHandler<>(this, taskId, targetName); + FtpNormalTarget(long taskId) { + mConfigHandler = new DNormalConfigHandler<>(this, taskId); getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getUrl())); getTaskWrapper().setRequestType(ITaskWrapper.D_FTP); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java similarity index 97% rename from Aria/src/main/java/com/arialyy/aria/core/download/group/GroupBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java index c9dd1724..813561d8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.group; +package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsBuilderTarget; @@ -33,8 +33,7 @@ import java.util.List; public class GroupBuilderTarget extends AbsBuilderTarget { private HttpGroupConfigHandler mConfigHandler; - GroupBuilderTarget(List urls, String targetName) { - setTargetName(targetName); + GroupBuilderTarget(List urls) { mConfigHandler = new HttpGroupConfigHandler<>(this, -1); getTaskWrapper().setRequestType(ITaskWrapper.DG_HTTP); mConfigHandler.setGroupUrl(urls); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/download/group/GroupNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java index 4ba0cbed..2e7855b1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.group; +package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; @@ -30,8 +30,7 @@ import java.util.List; public class GroupNormalTarget extends AbsNormalTarget { private HttpGroupConfigHandler mConfigHandler; - GroupNormalTarget(long taskId, String targetName) { - setTargetName(targetName); + GroupNormalTarget(long taskId) { mConfigHandler = new HttpGroupConfigHandler<>(this, taskId); getTaskWrapper().setRequestType(ITaskWrapper.DG_HTTP); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/normal/HttpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java similarity index 95% rename from Aria/src/main/java/com/arialyy/aria/core/download/normal/HttpBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java index 7f68a5a7..e5eb6d5b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/normal/HttpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.normal; +package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; @@ -28,8 +28,8 @@ public class HttpBuilderTarget extends AbsBuilderTarget { private DNormalConfigHandler mConfigHandler; - HttpBuilderTarget(String url, String targetName) { - mConfigHandler = new DNormalConfigHandler<>(this, -1, targetName); + HttpBuilderTarget(String url) { + mConfigHandler = new DNormalConfigHandler<>(this, -1); getTaskWrapper().setRequestType(ITaskWrapper.D_HTTP); mConfigHandler.setUrl(url); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/HttpGroupConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpGroupConfigHandler.java similarity index 97% rename from Aria/src/main/java/com/arialyy/aria/core/download/group/HttpGroupConfigHandler.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/HttpGroupConfigHandler.java index b5a3c914..5ac49fb1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/HttpGroupConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpGroupConfigHandler.java @@ -13,11 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.group; +package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; +import com.arialyy.aria.core.download.target.AbsGroupConfigHandler; import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/normal/HttpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java similarity index 93% rename from Aria/src/main/java/com/arialyy/aria/core/download/normal/HttpNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java index 36cf7421..ada14aff 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/normal/HttpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download.normal; +package com.arialyy.aria.core.download.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; @@ -29,8 +29,8 @@ import com.arialyy.aria.core.download.m3u8.M3U8Delegate; public class HttpNormalTarget extends AbsNormalTarget { private DNormalConfigHandler mConfigHandler; - HttpNormalTarget(long taskId, String targetName) { - mConfigHandler = new DNormalConfigHandler<>(this, taskId, targetName); + HttpNormalTarget(long taskId) { + mConfigHandler = new DNormalConfigHandler<>(this, taskId); getTaskWrapper().setRequestType(getTaskWrapper().getEntity().getTaskType()); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java new file mode 100644 index 00000000..64b6041a --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.download.target; + +import androidx.annotation.CheckResult; +import androidx.annotation.NonNull; +import com.arialyy.aria.core.common.AbsBuilderTarget; +import com.arialyy.aria.core.common.Suggest; +import com.arialyy.aria.core.download.tcp.TcpDelegate; +import com.arialyy.aria.core.inf.ITaskWrapper; + +/** + * @Author aria + * @Date 2019-09-06 + */ +public class TcpBuilderTarget extends AbsBuilderTarget { + + private DNormalConfigHandler mConfigHandler; + + TcpBuilderTarget(String ip, int port) { + mConfigHandler = new DNormalConfigHandler<>(this, -1); + getTaskWrapper().setRequestType(ITaskWrapper.D_TCP); + } + + /** + * 设置tcp相应信息 + */ + @CheckResult(suggest = Suggest.TASK_CONTROLLER) + public TcpDelegate option() { + return new TcpDelegate<>(this, getTaskWrapper()); + } + + /** + * 设置文件存储路径,如果需要修改新的文件名,修改路径便可。 + * 如:原文件路径 /mnt/sdcard/test.zip + * 如果需要将test.zip改为game.zip,只需要重新设置文件路径为:/mnt/sdcard/game.zip + * + * @param filePath 路径必须为文件路径,不能为文件夹路径 + */ + @CheckResult(suggest = Suggest.TASK_CONTROLLER) + public TcpBuilderTarget setFilePath(@NonNull String filePath) { + mConfigHandler.setTempFilePath(filePath); + return this; + } + + /** + * 设置文件存储路径,如果需要修改新的文件名,修改路径便可。 + * 如:原文件路径 /mnt/sdcard/test.zip + * 如果需要将test.zip改为game.zip,只需要重新设置文件路径为:/mnt/sdcard/game.zip + * + * @param filePath 路径必须为文件路径,不能为文件夹路径 + * @param forceDownload {@code true}强制下载,不考虑文件路径是否被占用 + */ + @CheckResult(suggest = Suggest.TASK_CONTROLLER) + public TcpBuilderTarget setFilePath(@NonNull String filePath, boolean forceDownload) { + mConfigHandler.setTempFilePath(filePath); + mConfigHandler.setForceDownload(forceDownload); + return this; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpDelegate.java new file mode 100644 index 00000000..b8d395a5 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpDelegate.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.download.tcp; + +import android.text.TextUtils; +import androidx.annotation.CheckResult; +import com.arialyy.aria.core.common.BaseDelegate; +import com.arialyy.aria.core.common.Suggest; +import com.arialyy.aria.core.download.DTaskWrapper; +import com.arialyy.aria.core.inf.AbsTarget; +import com.arialyy.aria.core.inf.AbsTaskWrapper; +import com.arialyy.aria.util.ALog; +import java.nio.charset.Charset; + +/** + * @Author aria + * @Date 2019-09-06 + */ +public class TcpDelegate extends BaseDelegate { + + private TcpTaskConfig mTcpConfig; + + public TcpDelegate(TARGET target, AbsTaskWrapper wrapper) { + super(target, wrapper); + + mTcpConfig = ((DTaskWrapper) wrapper).asTcp(); + } + + /** + * 上传给tcp服务的初始数据,一般是文件名、文件路径等信息 + */ + @CheckResult(suggest = Suggest.TO_CONTROLLER) + public TcpDelegate setParam(String params) { + if (TextUtils.isEmpty(params)) { + ALog.w(TAG, "tcp传输的数据不能为空"); + return this; + } + mTcpConfig.setParams(params); + return this; + } + + /** + * 设置心跳包传输的数据 + * + * @param heartbeatInfo 心跳包数据 + */ + @CheckResult(suggest = Suggest.TO_CONTROLLER) + public TcpDelegate setHeartbeatInfo(String heartbeatInfo) { + if (TextUtils.isEmpty(heartbeatInfo)) { + ALog.w(TAG, "心跳包传输的数据不能为空"); + return this; + } + mTcpConfig.setHeartbeat(heartbeatInfo); + return this; + } + + /** + * 心跳间隔,默认1s + * + * @param interval 单位毫秒 + */ + @CheckResult(suggest = Suggest.TO_CONTROLLER) + public TcpDelegate setHeartbeatInterval(long interval) { + if (interval <= 0) { + ALog.w(TAG, "心跳间隔不能小于1毫秒"); + return this; + } + mTcpConfig.setHeartbeatInterval(interval); + return this; + } + + /** + * 数据传输编码,默认"utf-8" + */ + public TcpDelegate setCharset(String charset) { + if (!Charset.isSupported(charset)) { + ALog.w(TAG, "不支持的编码"); + return this; + } + + mTcpConfig.setCharset(charset); + return this; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpTaskConfig.java b/Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpTaskConfig.java new file mode 100644 index 00000000..58fee361 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpTaskConfig.java @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.download.tcp; + +/** + * tcp任务配置 + * + * @Author aria + * @Date 2019-09-06 + */ +public class TcpTaskConfig { + + /** + * 上传给tcp服务的初始数据,一般是文件名等信息 + */ + private String params; + + /** + * 心跳包传输的数据 + */ + private String heartbeat; + + /** + * 心跳间隔,单位毫秒,默认1s + */ + private long heartbeatInterval = 1000; + + /** + * 数据传输编码,默认"utf-8" + */ + private String charset = "utf-8"; + + public String getCharset() { + return charset; + } + + public void setCharset(String charset) { + this.charset = charset; + } + + public String getHeartbeat() { + return heartbeat; + } + + public void setHeartbeat(String heartbeat) { + this.heartbeat = heartbeat; + } + + public long getHeartbeatInterval() { + return heartbeatInterval; + } + + public void setHeartbeatInterval(long heartbeatInterval) { + this.heartbeatInterval = heartbeatInterval; + } + + public String getParams() { + return params; + } + + public void setParams(String params) { + this.params = params; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java index 806a39fe..3c190bf0 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java @@ -18,8 +18,8 @@ package com.arialyy.aria.core.inf; import android.text.TextUtils; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.Suggest; -import com.arialyy.aria.core.common.controller.NormalController; import com.arialyy.aria.core.common.controller.BuilderController; +import com.arialyy.aria.core.common.controller.NormalController; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CommonUtil; @@ -31,7 +31,6 @@ public abstract class AbsTarget { protected String TAG; private AbsEntity mEntity; private AbsTaskWrapper mTaskWrapper; - private String mTargetName; protected AbsTarget() { TAG = CommonUtil.getClassName(this); @@ -46,14 +45,6 @@ public abstract class AbsTarget { return mEntity; } - public String getTargetName() { - return mTargetName; - } - - public void setTargetName(String mTargetName) { - this.mTargetName = mTargetName; - } - /** * 获取任务实体 */ @@ -84,7 +75,8 @@ public abstract class AbsTarget { /** * 重置状态,将任务状态设置为未开始状态 * 注意:如果在后续方法调用链中没有调用 {@link NormalController#stop()}、{@link NormalController#cancel()}、 - * {@link NormalController#resume()}、{@link BuilderController#create()}、{@link BuilderController#add()} + * {@link NormalController#resume()}、{@link BuilderController#create()}、{@link + * BuilderController#add()} * 等操作任务的方法,那么你需要调用{@link NormalController#save()}才能将修改保存到数据库 */ @CheckResult(suggest = "after use #create()、#stop()、#cancel()、#resume()、#save()?") diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITaskWrapper.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITaskWrapper.java index 701247fa..192be8b5 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/ITaskWrapper.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITaskWrapper.java @@ -28,6 +28,7 @@ public interface ITaskWrapper { * HTTP单任务载 */ int D_HTTP = 1; + /** * HTTP任务组下载 */ @@ -37,6 +38,7 @@ public interface ITaskWrapper { * FTP单文件下载 */ int D_FTP = 3; + /** * FTP文件夹下载,为避免登录过多,子任务由单线程进行处理 */ @@ -46,6 +48,7 @@ public interface ITaskWrapper { * HTTP单文件上传 */ int U_HTTP = 5; + /** * FTP单文件上传 */ @@ -61,5 +64,20 @@ public interface ITaskWrapper { */ int M3U8_LIVE = 8; + /** + * TCP 文件下载 + */ + int D_TCP = 9; + + /** + * TCP 文件上传 + */ + int U_TCP = 10; + + /** + * TCP 分片上传 + */ + int U_TCP_PEER = 11; + ENTITY getEntity(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/manager/SubTaskManager.java b/Aria/src/main/java/com/arialyy/aria/core/manager/SubTaskManager.java index b2f8126c..fbbfd03e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/manager/SubTaskManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/manager/SubTaskManager.java @@ -30,10 +30,8 @@ import java.util.List; public class SubTaskManager { private String TAG = "SubTaskManager"; private DGTaskWrapper mEntity; - private String mTargetName; - public SubTaskManager(String targetName, DGTaskWrapper entity) { - mTargetName = targetName; + public SubTaskManager(DGTaskWrapper entity) { mEntity = entity; } @@ -44,9 +42,8 @@ public class SubTaskManager { */ public void startSubTask(String url) { if (checkUrl(url)) { - EventMsgUtil.getDefault() - .post( - CommonUtil.createGroupCmd(mTargetName, mEntity, GroupCmdFactory.SUB_TASK_START, url)); + EventMsgUtil.getDefault().post( + CommonUtil.createGroupCmd(mEntity, GroupCmdFactory.SUB_TASK_START, url)); } } @@ -57,9 +54,8 @@ public class SubTaskManager { */ public void stopSubTask(String url) { if (checkUrl(url)) { - EventMsgUtil.getDefault() - .post( - CommonUtil.createGroupCmd(mTargetName, mEntity, GroupCmdFactory.SUB_TASK_STOP, url)); + EventMsgUtil.getDefault().post( + CommonUtil.createGroupCmd(mEntity, GroupCmdFactory.SUB_TASK_STOP, url)); } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java b/Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java index b92446bb..923a1fe1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java @@ -17,7 +17,6 @@ package com.arialyy.aria.core.upload; import android.text.TextUtils; import com.arialyy.aria.core.inf.ICheckEntityUtil; -import com.arialyy.aria.core.inf.ITaskWrapper; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; import java.io.File; @@ -43,7 +42,7 @@ public class CheckUEntityUtil implements ICheckEntityUtil { return false; } - boolean b = checkFtps() && checkUrl() && checkFilePath(); + boolean b = checkUrl() && checkFilePath(); if (b) { mEntity.save(); } @@ -90,16 +89,4 @@ public class CheckUEntityUtil implements ICheckEntityUtil { mEntity.setUrl(url); return true; } - - private boolean checkFtps() { - //if (mWrapper.getRequestType() == ITaskWrapper.U_FTP && mWrapper.asFtp() - // .getUrlEntity().isFtps) { - // String ftpUrl = mEntity.getUrl(); - // if (!ftpUrl.startsWith("ftps") && !ftpUrl.startsWith("sftp")) { - // ALog.e(TAG, String.format("地址【%s】错误,ftps地址开头必须是:ftps或sftp", ftpUrl)); - // return false; - // } - //} - return true; - } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java index 99383582..0424fa47 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java @@ -30,11 +30,11 @@ import com.arialyy.aria.core.inf.AbsReceiver; import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.ReceiverType; import com.arialyy.aria.core.scheduler.TaskSchedulers; -import com.arialyy.aria.core.upload.normal.FtpBuilderTarget; -import com.arialyy.aria.core.upload.normal.FtpNormalTarget; -import com.arialyy.aria.core.upload.normal.HttpBuilderTarget; -import com.arialyy.aria.core.upload.normal.HttpNormalTarget; -import com.arialyy.aria.core.upload.normal.UNormalTargetFactory; +import com.arialyy.aria.core.upload.target.FtpBuilderTarget; +import com.arialyy.aria.core.upload.target.FtpNormalTarget; +import com.arialyy.aria.core.upload.target.HttpBuilderTarget; +import com.arialyy.aria.core.upload.target.HttpNormalTarget; +import com.arialyy.aria.core.upload.target.UTargetFactory; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; @@ -69,8 +69,8 @@ public class UploadReceiver extends AbsReceiver { @CheckResult public HttpBuilderTarget load(@NonNull String filePath) { CheckUtil.checkUploadPath(filePath); - return UNormalTargetFactory.getInstance() - .generateBuilderTarget(HttpBuilderTarget.class, filePath, targetName); + return UTargetFactory.getInstance() + .generateBuilderTarget(HttpBuilderTarget.class, filePath); } /** @@ -82,8 +82,8 @@ public class UploadReceiver extends AbsReceiver { @CheckResult public HttpNormalTarget load(long taskId) { CheckUtil.checkTaskId(taskId); - return UNormalTargetFactory.getInstance() - .generateNormalTarget(HttpNormalTarget.class, taskId, targetName); + return UTargetFactory.getInstance() + .generateNormalTarget(HttpNormalTarget.class, taskId); } /** @@ -94,8 +94,8 @@ public class UploadReceiver extends AbsReceiver { @CheckResult public FtpBuilderTarget loadFtp(@NonNull String filePath) { CheckUtil.checkUploadPath(filePath); - return UNormalTargetFactory.getInstance() - .generateBuilderTarget(FtpBuilderTarget.class, filePath, targetName); + return UTargetFactory.getInstance() + .generateBuilderTarget(FtpBuilderTarget.class, filePath); } /** @@ -107,8 +107,8 @@ public class UploadReceiver extends AbsReceiver { @CheckResult public FtpNormalTarget loadFtp(long taskId) { CheckUtil.checkTaskId(taskId); - return UNormalTargetFactory.getInstance() - .generateNormalTarget(FtpNormalTarget.class, taskId, targetName); + return UTargetFactory.getInstance() + .generateNormalTarget(FtpNormalTarget.class, taskId); } /** @@ -252,13 +252,9 @@ public class UploadReceiver extends AbsReceiver { * 将当前类注册到Aria */ public void register() { - if (TextUtils.isEmpty(targetName)) { - ALog.e(TAG, "upload register target null"); - return; - } Object obj = OBJ_MAP.get(getKey()); if (obj == null) { - ALog.e(TAG, String.format("【%s】观察者为空", targetName)); + ALog.e(TAG, String.format("【%s】观察者为空", getTargetName())); return; } Set set = ProxyHelper.getInstance().checkProxyType(obj.getClass()); @@ -289,13 +285,9 @@ public class UploadReceiver extends AbsReceiver { } @Override protected void unRegisterListener() { - if (TextUtils.isEmpty(targetName)) { - ALog.e(TAG, "upload unRegisterListener target null"); - return; - } Object obj = OBJ_MAP.get(getKey()); if (obj == null) { - ALog.e(TAG, String.format("【%s】观察者为空", targetName)); + ALog.e(TAG, String.format("【%s】观察者为空", getTargetName())); return; } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/FtpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java similarity index 92% rename from Aria/src/main/java/com/arialyy/aria/core/upload/normal/FtpBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java index a823b4da..a23b04a2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/FtpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.upload.normal; +package com.arialyy.aria.core.upload.target; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; @@ -30,8 +30,8 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper; public class FtpBuilderTarget extends AbsBuilderTarget { private UNormalConfigHandler mConfigHandler; - FtpBuilderTarget(String filePath, String targetName) { - mConfigHandler = new UNormalConfigHandler<>(this, -1, targetName); + FtpBuilderTarget(String filePath) { + mConfigHandler = new UNormalConfigHandler<>(this, -1); mConfigHandler.setFilePath(filePath); getTaskWrapper().setRequestType(AbsTaskWrapper.U_FTP); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/FtpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java similarity index 91% rename from Aria/src/main/java/com/arialyy/aria/core/upload/normal/FtpNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java index ba6e8128..e2db2cc4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/FtpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.upload.normal; +package com.arialyy.aria.core.upload.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; @@ -30,8 +30,8 @@ import com.arialyy.aria.util.CommonUtil; public class FtpNormalTarget extends AbsNormalTarget { private UNormalConfigHandler mConfigHandler; - FtpNormalTarget(long taskId, String targetName) { - mConfigHandler = new UNormalConfigHandler<>(this, taskId, targetName); + FtpNormalTarget(long taskId) { + mConfigHandler = new UNormalConfigHandler<>(this, taskId); getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getUrl())); getTaskWrapper().setRequestType(AbsTaskWrapper.U_FTP); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/HttpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java similarity index 90% rename from Aria/src/main/java/com/arialyy/aria/core/upload/normal/HttpBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java index 1badcbaa..53682c4e 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/HttpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.upload.normal; +package com.arialyy.aria.core.upload.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsBuilderTarget; @@ -28,9 +28,9 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper; public class HttpBuilderTarget extends AbsBuilderTarget { private UNormalConfigHandler mConfigHandler; - HttpBuilderTarget(String filePath, String targetName) { + HttpBuilderTarget(String filePath) { - mConfigHandler = new UNormalConfigHandler<>(this, -1, targetName); + mConfigHandler = new UNormalConfigHandler<>(this, -1); mConfigHandler.setFilePath(filePath); //http暂时不支持断点上传 getTaskWrapper().setSupportBP(false); diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/HttpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java similarity index 91% rename from Aria/src/main/java/com/arialyy/aria/core/upload/normal/HttpNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java index c83e8b46..95bc0c94 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/HttpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.upload.normal; +package com.arialyy.aria.core.upload.target; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; @@ -28,8 +28,8 @@ import com.arialyy.aria.core.inf.AbsTaskWrapper; public class HttpNormalTarget extends AbsNormalTarget { private UNormalConfigHandler mConfigHandler; - HttpNormalTarget(long taskId, String targetName) { - mConfigHandler = new UNormalConfigHandler<>(this, taskId, targetName); + HttpNormalTarget(long taskId) { + mConfigHandler = new UNormalConfigHandler<>(this, taskId); getTaskWrapper().setSupportBP(false); getTaskWrapper().setRequestType(AbsTaskWrapper.U_HTTP); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/UNormalConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/UNormalConfigHandler.java similarity index 92% rename from Aria/src/main/java/com/arialyy/aria/core/upload/normal/UNormalConfigHandler.java rename to Aria/src/main/java/com/arialyy/aria/core/upload/target/UNormalConfigHandler.java index 90144aa9..9ccf2faa 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/UNormalConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/UNormalConfigHandler.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.upload.normal; +package com.arialyy.aria.core.upload.target; import com.arialyy.aria.core.common.ftp.IFtpUploadInterceptor; import com.arialyy.aria.core.event.ErrorEvent; @@ -39,18 +39,17 @@ class UNormalConfigHandler implements IConfigHandler { private TARGET mTarget; private UTaskWrapper mWrapper; - UNormalConfigHandler(TARGET target, long taskId, String targetName) { + UNormalConfigHandler(TARGET target, long taskId) { mTarget = target; - initTarget(taskId, targetName); + initTarget(taskId); } - private void initTarget(long taskId, String targetName) { + private void initTarget(long taskId) { mWrapper = TaskWrapperManager.getInstance().getNormalTaskWrapper(UTaskWrapper.class, taskId); if (taskId != -1 && mWrapper.getEntity().getId() == -1) { mWrapper.setErrorEvent(new ErrorEvent(taskId, String.format("没有id为%s的任务", taskId))); } mEntity = mWrapper.getEntity(); - mTarget.setTargetName(targetName); mTarget.setTaskWrapper(mWrapper); getTaskWrapper().setTempUrl(mEntity.getUrl()); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/UNormalTargetFactory.java b/Aria/src/main/java/com/arialyy/aria/core/upload/target/UTargetFactory.java similarity index 66% rename from Aria/src/main/java/com/arialyy/aria/core/upload/normal/UNormalTargetFactory.java rename to Aria/src/main/java/com/arialyy/aria/core/upload/target/UTargetFactory.java index bdd87e7a..42d794c7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/normal/UNormalTargetFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/target/UTargetFactory.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.upload.normal; +package com.arialyy.aria.core.upload.target; import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.AbsNormalTarget; @@ -22,20 +22,20 @@ import com.arialyy.aria.core.common.AbsNormalTarget; * @Author aria * @Date 2019-09-05 */ -public class UNormalTargetFactory { +public class UTargetFactory { - public static volatile UNormalTargetFactory INSTANCE; + public static volatile UTargetFactory INSTANCE; - private UNormalTargetFactory() { + private UTargetFactory() { } - public static UNormalTargetFactory getInstance() { + public static UTargetFactory getInstance() { if (INSTANCE == null) { - synchronized (UNormalTargetFactory.class) { + synchronized (UTargetFactory.class) { if (INSTANCE == null) { - INSTANCE = new UNormalTargetFactory(); + INSTANCE = new UTargetFactory(); } } } @@ -43,25 +43,23 @@ public class UNormalTargetFactory { return INSTANCE; } - public T generateNormalTarget(Class clazz, long taskId, - String targetName) { + public T generateNormalTarget(Class clazz, long taskId) { T target = null; if (clazz == HttpNormalTarget.class) { - target = (T) new HttpNormalTarget(taskId, targetName); + target = (T) new HttpNormalTarget(taskId); } else if (clazz == FtpNormalTarget.class) { - target = (T) new FtpNormalTarget(taskId, targetName); + target = (T) new FtpNormalTarget(taskId); } return target; } - public T generateBuilderTarget(Class clazz, String url, - String targetName) { + public T generateBuilderTarget(Class clazz, String url) { T target = null; if (clazz == HttpBuilderTarget.class) { - target = (T) new HttpBuilderTarget(url, targetName); + target = (T) new HttpBuilderTarget(url); } else if (clazz == FtpBuilderTarget.class) { - target = (T) new FtpBuilderTarget(url, targetName); + target = (T) new FtpBuilderTarget(url); } return target; 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 2030159f..1d0871c3 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -24,11 +24,11 @@ import android.os.Environment; import android.text.TextUtils; import android.util.Base64; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.common.ftp.FtpUrlEntity; import com.arialyy.aria.core.command.AbsGroupCmd; import com.arialyy.aria.core.command.AbsNormalCmd; import com.arialyy.aria.core.command.GroupCmdFactory; import com.arialyy.aria.core.command.NormalCmdFactory; +import com.arialyy.aria.core.common.ftp.FtpUrlEntity; import com.arialyy.aria.core.inf.AbsGroupTaskWrapper; import com.arialyy.aria.core.inf.AbsTaskWrapper; import com.arialyy.aria.core.inf.ITask; @@ -558,9 +558,9 @@ public class CommonUtil { * * @param childUrl 子任务url */ - public static AbsGroupCmd createGroupCmd(String target, T entity, - int cmd, String childUrl) { - return GroupCmdFactory.getInstance().createCmd(target, entity, cmd, childUrl); + public static AbsGroupCmd createGroupCmd(T entity, int cmd, + String childUrl) { + return GroupCmdFactory.getInstance().createCmd(entity, cmd, childUrl); } /** diff --git a/AriaFtpComponent/.gitignore b/AriaFtpComponent/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/AriaFtpComponent/.gitignore @@ -0,0 +1 @@ +/build diff --git a/AriaFtpComponent/build.gradle b/AriaFtpComponent/build.gradle new file mode 100644 index 00000000..12924738 --- /dev/null +++ b/AriaFtpComponent/build.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion rootProject.ext.compileSdkVersion + buildToolsVersion rootProject.ext.buildToolsVersion + + defaultConfig { + minSdkVersion rootProject.ext.minSdkVersion + targetSdkVersion rootProject.ext.targetSdkVersion + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation "androidx.appcompat:appcompat:${rootProject.ext.XAppcompatVersion}" + + testImplementation 'junit:junit:4.12' + implementation project(path: ':AriaFtpPlug') +} diff --git a/AriaFtpComponent/consumer-rules.pro b/AriaFtpComponent/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/AriaFtpComponent/proguard-rules.pro b/AriaFtpComponent/proguard-rules.pro new file mode 100644 index 00000000..f1b42451 --- /dev/null +++ b/AriaFtpComponent/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/AriaFtpComponent/src/androidTest/java/com/example/ariaftpcomponent/ExampleInstrumentedTest.java b/AriaFtpComponent/src/androidTest/java/com/example/ariaftpcomponent/ExampleInstrumentedTest.java new file mode 100644 index 00000000..9e18a5cd --- /dev/null +++ b/AriaFtpComponent/src/androidTest/java/com/example/ariaftpcomponent/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.ariaftpcomponent; + +import android.content.Context; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.example.ariaftpcomponent.test", appContext.getPackageName()); + } +} diff --git a/AriaFtpComponent/src/main/AndroidManifest.xml b/AriaFtpComponent/src/main/AndroidManifest.xml new file mode 100644 index 00000000..25aac7fe --- /dev/null +++ b/AriaFtpComponent/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ + diff --git a/AriaFtpComponent/src/main/java/com/arialyy/aria/ftpcomponent/bb.java b/AriaFtpComponent/src/main/java/com/arialyy/aria/ftpcomponent/bb.java new file mode 100644 index 00000000..84ba97e3 --- /dev/null +++ b/AriaFtpComponent/src/main/java/com/arialyy/aria/ftpcomponent/bb.java @@ -0,0 +1,4 @@ +package com.arialyy.aria.ftpcomponent; + +public class bb { +} diff --git a/AriaFtpComponent/src/main/res/values/strings.xml b/AriaFtpComponent/src/main/res/values/strings.xml new file mode 100644 index 00000000..08862ffd --- /dev/null +++ b/AriaFtpComponent/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + AriaFtpComponent + diff --git a/AriaFtpComponent/src/test/java/com/example/ariaftpcomponent/ExampleUnitTest.java b/AriaFtpComponent/src/test/java/com/example/ariaftpcomponent/ExampleUnitTest.java new file mode 100644 index 00000000..79cfa215 --- /dev/null +++ b/AriaFtpComponent/src/test/java/com/example/ariaftpcomponent/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.example.ariaftpcomponent; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/app/src/main/assets/help_code/KotlinHttpDownload.kt b/app/src/main/assets/help_code/KotlinHttpDownload.kt index 9fc3bfcf..7f3033b9 100644 --- a/app/src/main/assets/help_code/KotlinHttpDownload.kt +++ b/app/src/main/assets/help_code/KotlinHttpDownload.kt @@ -21,7 +21,7 @@ import android.widget.Button import android.widget.Toast import com.arialyy.annotations.Download import com.arialyy.aria.core.Aria -import com.arialyy.aria.core.download.normal.HttpNormalTarget +import com.arialyy.aria.core.download.target.HttpNormalTarget import com.arialyy.aria.core.download.DownloadTask import com.arialyy.aria.core.inf.IEntity import com.arialyy.simple.R diff --git a/build.gradle b/build.gradle index 4bf2e476..40ad5c26 100644 --- a/build.gradle +++ b/build.gradle @@ -55,9 +55,8 @@ ext { buildToolsVersion = "28.0.3" targetSdkVersion = 28 lifecycleVersion = "1.1.1" -// compileSdkVersion = 28 -// supportLibVersion = "28.0.0" -// buildToolsVersion = "28.0.3" -// targetSdkVersion = 28 minSdkVersion = 15 + + // 以下是androidX + XAppcompatVersion = "1.1.0" } diff --git a/settings.gradle b/settings.gradle index 1ab002b2..b6d6bae2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include ':app', ':Aria', ':AriaAnnotations', ':AriaCompiler', ':AriaFtpPlug', ':AppFrame' +include ':app', ':Aria', ':AriaAnnotations', ':AriaCompiler', ':AriaFtpPlug', ':AppFrame', ':AriaFtpComponent'