优化代码

pull/617/head
laoyuyu 5 years ago
parent d129e0a802
commit 7ee1347ab4
  1. 2
      AppFrame/build.gradle
  2. 7
      Aria/build.gradle
  3. 4
      Aria/src/main/java/com/arialyy/aria/core/command/GroupCmdFactory.java
  4. 14
      Aria/src/main/java/com/arialyy/aria/core/download/CheckDEntityUtil.java
  5. 17
      Aria/src/main/java/com/arialyy/aria/core/download/DTaskWrapper.java
  6. 60
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  7. 65
      Aria/src/main/java/com/arialyy/aria/core/download/group/GroupTargetFactory.java
  8. 6
      Aria/src/main/java/com/arialyy/aria/core/download/target/AbsGroupConfigHandler.java
  9. 11
      Aria/src/main/java/com/arialyy/aria/core/download/target/DNormalConfigHandler.java
  10. 41
      Aria/src/main/java/com/arialyy/aria/core/download/target/DTargetFactory.java
  11. 6
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpBuilderTarget.java
  12. 5
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirBuilderTarget.java
  13. 3
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirConfigHandler.java
  14. 5
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpDirNormalTarget.java
  15. 6
      Aria/src/main/java/com/arialyy/aria/core/download/target/FtpNormalTarget.java
  16. 5
      Aria/src/main/java/com/arialyy/aria/core/download/target/GroupBuilderTarget.java
  17. 5
      Aria/src/main/java/com/arialyy/aria/core/download/target/GroupNormalTarget.java
  18. 6
      Aria/src/main/java/com/arialyy/aria/core/download/target/HttpBuilderTarget.java
  19. 3
      Aria/src/main/java/com/arialyy/aria/core/download/target/HttpGroupConfigHandler.java
  20. 6
      Aria/src/main/java/com/arialyy/aria/core/download/target/HttpNormalTarget.java
  21. 73
      Aria/src/main/java/com/arialyy/aria/core/download/target/TcpBuilderTarget.java
  22. 97
      Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpDelegate.java
  23. 77
      Aria/src/main/java/com/arialyy/aria/core/download/tcp/TcpTaskConfig.java
  24. 14
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  25. 18
      Aria/src/main/java/com/arialyy/aria/core/inf/ITaskWrapper.java
  26. 14
      Aria/src/main/java/com/arialyy/aria/core/manager/SubTaskManager.java
  27. 15
      Aria/src/main/java/com/arialyy/aria/core/upload/CheckUEntityUtil.java
  28. 38
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  29. 6
      Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpBuilderTarget.java
  30. 6
      Aria/src/main/java/com/arialyy/aria/core/upload/target/FtpNormalTarget.java
  31. 6
      Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpBuilderTarget.java
  32. 6
      Aria/src/main/java/com/arialyy/aria/core/upload/target/HttpNormalTarget.java
  33. 9
      Aria/src/main/java/com/arialyy/aria/core/upload/target/UNormalConfigHandler.java
  34. 28
      Aria/src/main/java/com/arialyy/aria/core/upload/target/UTargetFactory.java
  35. 8
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java
  36. 1
      AriaFtpComponent/.gitignore
  37. 32
      AriaFtpComponent/build.gradle
  38. 0
      AriaFtpComponent/consumer-rules.pro
  39. 21
      AriaFtpComponent/proguard-rules.pro
  40. 26
      AriaFtpComponent/src/androidTest/java/com/example/ariaftpcomponent/ExampleInstrumentedTest.java
  41. 2
      AriaFtpComponent/src/main/AndroidManifest.xml
  42. 4
      AriaFtpComponent/src/main/java/com/arialyy/aria/ftpcomponent/bb.java
  43. 3
      AriaFtpComponent/src/main/res/values/strings.xml
  44. 17
      AriaFtpComponent/src/test/java/com/example/ariaftpcomponent/ExampleUnitTest.java
  45. 2
      app/src/main/assets/help_code/KotlinHttpDownload.kt
  46. 7
      build.gradle
  47. 2
      settings.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'

@ -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'

@ -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:

@ -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;
}
}

@ -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<DownloadEntity> {
*/
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<DownloadEntity> {
return m3u8TaskConfig;
}
public TcpTaskConfig asTcp() {
if (tcpTaskConfig == null) {
tcpTaskConfig = new TcpTaskConfig();
}
return tcpTaskConfig;
}
/**
* Task实体对应的key下载url
*/

@ -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<String> 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<Integer> 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<Integer> set = ProxyHelper.getInstance().mProxyCache.get(obj.getClass().getName());

@ -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 extends AbsNormalTarget> T generateNormalTarget(Class<T> 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<String> urls, String targetName) {
return new GroupBuilderTarget(urls, targetName);
}
}

@ -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<TARGET extends AbsTarget> implements IConfi
@CheckResult
SubTaskManager getSubTaskManager() {
if (mSubTaskManager == null) {
mSubTaskManager = new SubTaskManager(mTarget.getTargetName(), getTaskWrapper());
mSubTaskManager = new SubTaskManager(getTaskWrapper());
}
return mSubTaskManager;
}

@ -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<TARGET extends AbsTarget> 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;

@ -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 extends AbsNormalTarget> T generateNormalTarget(Class<T> clazz, long taskId,
String targetName) {
public <T extends AbsNormalTarget> T generateNormalTarget(Class<T> 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 extends AbsBuilderTarget> T generateBuilderTarget(Class<T> clazz, String url,
String targetName) {
public <T extends AbsBuilderTarget> T generateBuilderTarget(Class<T> 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<String> urls) {
return new GroupBuilderTarget(urls);
}
}

@ -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<FtpBuilderTarget> {
private DNormalConfigHandler<FtpBuilderTarget> 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);

@ -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<FtpDirBuilderTarget> {
private FtpDirConfigHandler<FtpDirBuilderTarget> 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));

@ -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;

@ -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<FtpDirNormalTarget> {
private FtpDirConfigHandler<FtpDirNormalTarget> mConfigHandler;
FtpDirNormalTarget(long taskId, String targetName) {
setTargetName(targetName);
FtpDirNormalTarget(long taskId) {
mConfigHandler = new FtpDirConfigHandler<>(this, taskId);
getTaskWrapper().asFtp().setUrlEntity(CommonUtil.getFtpUrlInfo(getEntity().getKey()));
}

@ -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<FtpNormalTarget> {
private DNormalConfigHandler<FtpNormalTarget> 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);
}

@ -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<GroupBuilderTarget> {
private HttpGroupConfigHandler<GroupBuilderTarget> mConfigHandler;
GroupBuilderTarget(List<String> urls, String targetName) {
setTargetName(targetName);
GroupBuilderTarget(List<String> urls) {
mConfigHandler = new HttpGroupConfigHandler<>(this, -1);
getTaskWrapper().setRequestType(ITaskWrapper.DG_HTTP);
mConfigHandler.setGroupUrl(urls);

@ -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<GroupNormalTarget> {
private HttpGroupConfigHandler<GroupNormalTarget> mConfigHandler;
GroupNormalTarget(long taskId, String targetName) {
setTargetName(targetName);
GroupNormalTarget(long taskId) {
mConfigHandler = new HttpGroupConfigHandler<>(this, taskId);
getTaskWrapper().setRequestType(ITaskWrapper.DG_HTTP);
}

@ -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<HttpBuilderTarget> {
private DNormalConfigHandler<HttpBuilderTarget> 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);
}

@ -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;

@ -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<HttpNormalTarget> {
private DNormalConfigHandler<HttpNormalTarget> 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());
}

@ -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<TcpBuilderTarget> {
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<TcpBuilderTarget> 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;
}
}

@ -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<TARGET extends AbsTarget> extends BaseDelegate<TARGET> {
private TcpTaskConfig mTcpConfig;
public TcpDelegate(TARGET target, AbsTaskWrapper wrapper) {
super(target, wrapper);
mTcpConfig = ((DTaskWrapper) wrapper).asTcp();
}
/**
* 上传给tcp服务的初始数据一般是文件名文件路径等信息
*/
@CheckResult(suggest = Suggest.TO_CONTROLLER)
public TcpDelegate<TARGET> 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<TARGET> 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<TARGET> setHeartbeatInterval(long interval) {
if (interval <= 0) {
ALog.w(TAG, "心跳间隔不能小于1毫秒");
return this;
}
mTcpConfig.setHeartbeatInterval(interval);
return this;
}
/**
* 数据传输编码默认"utf-8"
*/
public TcpDelegate<TARGET> setCharset(String charset) {
if (!Charset.isSupported(charset)) {
ALog.w(TAG, "不支持的编码");
return this;
}
mTcpConfig.setCharset(charset);
return this;
}
}

@ -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;
}
}

@ -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<TARGET extends 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<TARGET extends AbsTarget> {
return mEntity;
}
public String getTargetName() {
return mTargetName;
}
public void setTargetName(String mTargetName) {
this.mTargetName = mTargetName;
}
/**
* 获取任务实体
*/
@ -84,7 +75,8 @@ public abstract class AbsTarget<TARGET extends 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()?")

@ -28,6 +28,7 @@ public interface ITaskWrapper<ENTITY extends AbsEntity> {
* HTTP单任务载
*/
int D_HTTP = 1;
/**
* HTTP任务组下载
*/
@ -37,6 +38,7 @@ public interface ITaskWrapper<ENTITY extends AbsEntity> {
* FTP单文件下载
*/
int D_FTP = 3;
/**
* FTP文件夹下载为避免登录过多子任务由单线程进行处理
*/
@ -46,6 +48,7 @@ public interface ITaskWrapper<ENTITY extends AbsEntity> {
* HTTP单文件上传
*/
int U_HTTP = 5;
/**
* FTP单文件上传
*/
@ -61,5 +64,20 @@ public interface ITaskWrapper<ENTITY extends AbsEntity> {
*/
int M3U8_LIVE = 8;
/**
* TCP 文件下载
*/
int D_TCP = 9;
/**
* TCP 文件上传
*/
int U_TCP = 10;
/**
* TCP 分片上传
*/
int U_TCP_PEER = 11;
ENTITY getEntity();
}

@ -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));
}
}

@ -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;
}
}

@ -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<Integer> 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;
}

@ -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<FtpBuilderTarget> {
private UNormalConfigHandler<FtpBuilderTarget> 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);
}

@ -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<FtpNormalTarget> {
private UNormalConfigHandler<FtpNormalTarget> 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);
}

@ -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<HttpBuilderTarget> {
private UNormalConfigHandler<HttpBuilderTarget> 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);

@ -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<HttpNormalTarget> {
private UNormalConfigHandler<HttpNormalTarget> 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);
}

@ -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<TARGET extends AbsTarget> 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());
}

@ -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 extends AbsNormalTarget> T generateNormalTarget(Class<T> clazz, long taskId,
String targetName) {
public <T extends AbsNormalTarget> T generateNormalTarget(Class<T> 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 extends AbsBuilderTarget> T generateBuilderTarget(Class<T> clazz, String url,
String targetName) {
public <T extends AbsBuilderTarget> T generateBuilderTarget(Class<T> 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;

@ -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 <T extends AbsGroupTaskWrapper> AbsGroupCmd createGroupCmd(String target, T entity,
int cmd, String childUrl) {
return GroupCmdFactory.getInstance().createCmd(target, entity, cmd, childUrl);
public static <T extends AbsGroupTaskWrapper> AbsGroupCmd createGroupCmd(T entity, int cmd,
String childUrl) {
return GroupCmdFactory.getInstance().createCmd(entity, cmd, childUrl);
}
/**

@ -0,0 +1 @@
/build

@ -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')
}

@ -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

@ -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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@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());
}
}

@ -0,0 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.ariaftpcomponent" />

@ -0,0 +1,4 @@
package com.arialyy.aria.ftpcomponent;
public class bb {
}

@ -0,0 +1,3 @@
<resources>
<string name="app_name">AriaFtpComponent</string>
</resources>

@ -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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}

@ -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

@ -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"
}

@ -1 +1 @@
include ':app', ':Aria', ':AriaAnnotations', ':AriaCompiler', ':AriaFtpPlug', ':AppFrame'
include ':app', ':Aria', ':AriaAnnotations', ':AriaCompiler', ':AriaFtpPlug', ':AppFrame', ':AriaFtpComponent'

Loading…
Cancel
Save