diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java index d7f5cd49..a3345e2c 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpInfoThread.java @@ -25,7 +25,6 @@ import aria.apache.commons.net.ftp.FTPFile; import aria.apache.commons.net.ftp.FTPReply; import aria.apache.commons.net.ftp.FTPSClient; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsTaskWrapper; diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpThreadTask.java index 27f3f716..0020ecde 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/AbsFtpThreadTask.java @@ -21,7 +21,6 @@ import aria.apache.commons.net.ftp.FTPClient; import aria.apache.commons.net.ftp.FTPClientConfig; import aria.apache.commons.net.ftp.FTPReply; import aria.apache.commons.net.ftp.FTPSClient; -import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.common.AbsThreadTask; import com.arialyy.aria.core.common.SubThreadConfig; import com.arialyy.aria.core.inf.AbsNormalEntity; diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FTPSDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FTPSDelegate.java index e8810be0..3a610e18 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FTPSDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FTPSDelegate.java @@ -17,7 +17,6 @@ package com.arialyy.aria.core.common.ftp; import android.text.TextUtils; import androidx.annotation.CheckResult; -import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.common.BaseDelegate; import com.arialyy.aria.core.common.ProtocolType; import com.arialyy.aria.core.common.Suggest; diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java index 31da7af3..2c019156 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpDelegate.java @@ -18,7 +18,6 @@ package com.arialyy.aria.core.common.ftp; import android.text.TextUtils; import androidx.annotation.CheckResult; import aria.apache.commons.net.ftp.FTPClientConfig; -import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.common.BaseDelegate; import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.inf.AbsTarget; diff --git a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskConfig.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskConfig.java index 301f97b6..c4b5a332 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskConfig.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpTaskConfig.java @@ -16,7 +16,6 @@ package com.arialyy.aria.core.common.ftp; import aria.apache.commons.net.ftp.FTPClientConfig; -import com.arialyy.aria.core.FtpUrlEntity; import com.arialyy.aria.core.inf.ITaskConfig; import java.lang.ref.SoftReference; import java.net.Proxy; diff --git a/Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpUrlEntity.java similarity index 98% rename from Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java rename to Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpUrlEntity.java index 39b43afa..ad5ac3ed 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/FtpUrlEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/common/ftp/FtpUrlEntity.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core; +package com.arialyy.aria.core.common.ftp; import com.arialyy.aria.core.common.ProtocolType; import java.net.InetAddress; 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 c89383dd..3c28d429 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 @@ -24,6 +24,16 @@ 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.event.EventMsgUtil; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsReceiver; @@ -66,7 +76,8 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public HttpBuilderTarget load(@NonNull String url) { CheckUtil.checkUrlInvalidThrow(url); - return new HttpBuilderTarget(url, targetName); + return DNormalTargetFactory.getInstance() + .generateBuilderTarget(HttpBuilderTarget.class, url, targetName); } /** @@ -78,7 +89,8 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public HttpNormalTarget load(long taskId) { CheckUtil.checkTaskId(taskId); - return new HttpNormalTarget(taskId, targetName); + return DNormalTargetFactory.getInstance() + .generateNormalTarget(HttpNormalTarget.class, taskId, targetName); } /** @@ -89,7 +101,7 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public GroupBuilderTarget loadGroup(List urls) { CheckUtil.checkDownloadUrls(urls); - return new GroupBuilderTarget(urls, targetName); + return GroupTargetFactory.getInstance().generateGroupBuilderTarget(urls, targetName); } /** @@ -101,7 +113,8 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public GroupNormalTarget loadGroup(long taskId) { CheckUtil.checkTaskId(taskId); - return new GroupNormalTarget(taskId, targetName); + return GroupTargetFactory.getInstance() + .generateNormalTarget(GroupNormalTarget.class, taskId, targetName); } /** @@ -110,7 +123,8 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public FtpBuilderTarget loadFtp(@NonNull String url) { CheckUtil.checkUrlInvalidThrow(url); - return new FtpBuilderTarget(url, targetName); + return DNormalTargetFactory.getInstance() + .generateBuilderTarget(FtpBuilderTarget.class, url, targetName); } /** @@ -122,7 +136,8 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public FtpNormalTarget loadFtp(long taskId) { CheckUtil.checkTaskId(taskId); - return new FtpNormalTarget(taskId, targetName); + return DNormalTargetFactory.getInstance() + .generateNormalTarget(FtpNormalTarget.class, taskId, targetName); } /** @@ -131,7 +146,7 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public FtpDirBuilderTarget loadFtpDir(@NonNull String dirUrl) { CheckUtil.checkUrlInvalidThrow(dirUrl); - return new FtpDirBuilderTarget(dirUrl, targetName); + return GroupTargetFactory.getInstance().generateDirBuilderTarget(dirUrl, targetName); } /** @@ -143,7 +158,8 @@ public class DownloadReceiver extends AbsReceiver { @CheckResult public FtpDirNormalTarget loadFtpDir(long taskId) { CheckUtil.checkTaskId(taskId); - return new FtpDirNormalTarget(taskId, targetName); + return GroupTargetFactory.getInstance() + .generateNormalTarget(FtpDirNormalTarget.class, taskId, targetName); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/AbsGroupConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupConfigHandler.java similarity index 93% rename from Aria/src/main/java/com/arialyy/aria/core/download/AbsGroupConfigHandler.java rename to Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupConfigHandler.java index 669d90fb..30a26e2f 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/AbsGroupConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/AbsGroupConfigHandler.java @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.group; import androidx.annotation.CheckResult; import android.text.TextUtils; +import com.arialyy.aria.core.download.DGTaskWrapper; +import com.arialyy.aria.core.download.DownloadGroupEntity; +import com.arialyy.aria.core.download.DownloadGroupTask; import com.arialyy.aria.core.event.ErrorEvent; import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.inf.IConfigHandler; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirBuilderTarget.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/download/FtpDirBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirBuilderTarget.java index 0b0f0b7a..c581a363 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirBuilderTarget.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.group; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.ftp.FtpDelegate; +import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.util.CommonUtil; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirConfigHandler.java similarity index 93% rename from Aria/src/main/java/com/arialyy/aria/core/download/FtpDirConfigHandler.java rename to Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirConfigHandler.java index 1e9c3548..ef75325d 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirConfigHandler.java @@ -13,8 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.group; +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.core.inf.ITaskWrapper; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java index 4716675b..85935c0b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirDownloadUtil.java @@ -17,7 +17,7 @@ package com.arialyy.aria.core.download.group; import android.net.Uri; import android.text.TextUtils; -import com.arialyy.aria.core.FtpUrlEntity; +import com.arialyy.aria.core.common.ftp.FtpUrlEntity; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.download.DGTaskWrapper; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirInfoThread.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirInfoThread.java index 3fa05f97..d9e54dac 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirInfoThread.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirInfoThread.java @@ -16,7 +16,7 @@ package com.arialyy.aria.core.download.group; import aria.apache.commons.net.ftp.FTPFile; -import com.arialyy.aria.core.FtpUrlEntity; +import com.arialyy.aria.core.common.ftp.FtpUrlEntity; import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.common.OnFileInfoCallback; import com.arialyy.aria.core.common.ftp.AbsFtpInfoThread; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirNormalTarget.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/download/FtpDirNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirNormalTarget.java index 37ff276a..45bd433b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpDirNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/FtpDirNormalTarget.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.group; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.ftp.FtpDelegate; +import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.manager.SubTaskManager; import com.arialyy.aria.util.CommonUtil; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/GroupBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupBuilderTarget.java similarity index 98% rename from Aria/src/main/java/com/arialyy/aria/core/download/GroupBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/group/GroupBuilderTarget.java index 89fcabe3..c9dd1724 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/GroupBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupBuilderTarget.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.group; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsBuilderTarget; import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.http.HttpDelegate; +import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.inf.IHttpFileLenAdapter; import com.arialyy.aria.core.inf.ITaskWrapper; import com.arialyy.aria.core.manager.SubTaskManager; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/GroupNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupNormalTarget.java similarity index 98% rename from Aria/src/main/java/com/arialyy/aria/core/download/GroupNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/group/GroupNormalTarget.java index a844f27b..4ba0cbed 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/GroupNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/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; +package com.arialyy.aria.core.download.group; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; 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 new file mode 100644 index 00000000..73ab3772 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/GroupTargetFactory.java @@ -0,0 +1,65 @@ +/* + * 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/HttpGroupConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/group/HttpGroupConfigHandler.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/download/HttpGroupConfigHandler.java rename to Aria/src/main/java/com/arialyy/aria/core/download/group/HttpGroupConfigHandler.java index a633e467..b5a3c914 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/HttpGroupConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/group/HttpGroupConfigHandler.java @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.group; import androidx.annotation.CheckResult; +import com.arialyy.aria.core.download.DTaskWrapper; +import com.arialyy.aria.core.download.DownloadEntity; 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/DNormalConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/download/normal/DNormalConfigHandler.java similarity index 94% rename from Aria/src/main/java/com/arialyy/aria/core/download/DNormalConfigHandler.java rename to Aria/src/main/java/com/arialyy/aria/core/download/normal/DNormalConfigHandler.java index 892b2796..2c86fc08 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DNormalConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/normal/DNormalConfigHandler.java @@ -13,9 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.normal; import android.text.TextUtils; +import com.arialyy.aria.core.download.DTaskWrapper; +import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.event.ErrorEvent; import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.inf.IConfigHandler; @@ -57,7 +59,7 @@ class DNormalConfigHandler implements IConfigHandler { } } - TARGET updateUrl(String newUrl) { + public 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/normal/DNormalTargetFactory.java new file mode 100644 index 00000000..31655cb3 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/normal/DNormalTargetFactory.java @@ -0,0 +1,69 @@ +/* + * 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.normal; + +import com.arialyy.aria.core.common.AbsBuilderTarget; +import com.arialyy.aria.core.common.AbsNormalTarget; + +/** + * @Author aria + * @Date 2019-09-05 + */ +public class DNormalTargetFactory { + + public static volatile DNormalTargetFactory INSTANCE; + + private DNormalTargetFactory() { + + } + + public static DNormalTargetFactory getInstance() { + + if (INSTANCE == null) { + synchronized (DNormalTargetFactory.class) { + if (INSTANCE == null) { + INSTANCE = new DNormalTargetFactory(); + } + } + } + + return INSTANCE; + } + + public T generateNormalTarget(Class clazz, long taskId, + String targetName) { + T target = null; + if (clazz == HttpNormalTarget.class) { + target = (T) new HttpNormalTarget(taskId, targetName); + } else if (clazz == FtpNormalTarget.class) { + target = (T) new FtpNormalTarget(taskId, targetName); + } + + return target; + } + + public T generateBuilderTarget(Class clazz, String url, + String targetName) { + T target = null; + if (clazz == HttpBuilderTarget.class) { + target = (T) new HttpBuilderTarget(url, targetName); + } else if (clazz == FtpBuilderTarget.class) { + target = (T) new FtpBuilderTarget(url, targetName); + } + + return target; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpBuilderTarget.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/download/FtpBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpBuilderTarget.java index ae29e75a..6f904f73 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpBuilderTarget.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.normal; 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.common.ftp.FtpDelegate; +import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.inf.ITaskWrapper; import com.arialyy.aria.util.CommonUtil; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/FtpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpNormalTarget.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/download/FtpNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpNormalTarget.java index 067c1f29..10aa07c8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/FtpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/normal/FtpNormalTarget.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.normal; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.ftp.FtpDelegate; +import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.inf.ITaskWrapper; import com.arialyy.aria.util.CommonUtil; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/HttpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/normal/HttpBuilderTarget.java similarity index 98% rename from Aria/src/main/java/com/arialyy/aria/core/download/HttpBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/normal/HttpBuilderTarget.java index 3bde5bd8..7f68a5a7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/HttpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/normal/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; +package com.arialyy.aria.core.download.normal; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/HttpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/normal/HttpNormalTarget.java similarity index 96% rename from Aria/src/main/java/com/arialyy/aria/core/download/HttpNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/download/normal/HttpNormalTarget.java index 41926549..36cf7421 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/HttpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/normal/HttpNormalTarget.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.download; +package com.arialyy.aria.core.download.normal; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.http.HttpDelegate; +import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.m3u8.M3U8Delegate; /** 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 94a2ad0d..99383582 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,6 +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.orm.DbEntity; import com.arialyy.aria.util.ALog; import com.arialyy.aria.util.CheckUtil; @@ -64,7 +69,8 @@ public class UploadReceiver extends AbsReceiver { @CheckResult public HttpBuilderTarget load(@NonNull String filePath) { CheckUtil.checkUploadPath(filePath); - return new HttpBuilderTarget(filePath, targetName); + return UNormalTargetFactory.getInstance() + .generateBuilderTarget(HttpBuilderTarget.class, filePath, targetName); } /** @@ -76,7 +82,8 @@ public class UploadReceiver extends AbsReceiver { @CheckResult public HttpNormalTarget load(long taskId) { CheckUtil.checkTaskId(taskId); - return new HttpNormalTarget(taskId, targetName); + return UNormalTargetFactory.getInstance() + .generateNormalTarget(HttpNormalTarget.class, taskId, targetName); } /** @@ -87,7 +94,8 @@ public class UploadReceiver extends AbsReceiver { @CheckResult public FtpBuilderTarget loadFtp(@NonNull String filePath) { CheckUtil.checkUploadPath(filePath); - return new FtpBuilderTarget(filePath, targetName); + return UNormalTargetFactory.getInstance() + .generateBuilderTarget(FtpBuilderTarget.class, filePath, targetName); } /** @@ -99,7 +107,8 @@ public class UploadReceiver extends AbsReceiver { @CheckResult public FtpNormalTarget loadFtp(long taskId) { CheckUtil.checkTaskId(taskId); - return new FtpNormalTarget(taskId, targetName); + return UNormalTargetFactory.getInstance() + .generateNormalTarget(FtpNormalTarget.class, taskId, targetName); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/normal/FtpBuilderTarget.java similarity index 98% rename from Aria/src/main/java/com/arialyy/aria/core/upload/FtpBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/upload/normal/FtpBuilderTarget.java index 3bc48816..a823b4da 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/normal/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; +package com.arialyy.aria.core.upload.normal; import androidx.annotation.CheckResult; import androidx.annotation.NonNull; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/normal/FtpNormalTarget.java similarity index 95% rename from Aria/src/main/java/com/arialyy/aria/core/upload/FtpNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/upload/normal/FtpNormalTarget.java index 8f0a8d6a..ba6e8128 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/FtpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/normal/FtpNormalTarget.java @@ -13,13 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.upload; +package com.arialyy.aria.core.upload.normal; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; import com.arialyy.aria.core.common.Suggest; import com.arialyy.aria.core.common.ftp.FtpDelegate; import com.arialyy.aria.core.inf.AbsTaskWrapper; +import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.util.CommonUtil; /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/HttpBuilderTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/normal/HttpBuilderTarget.java similarity index 97% rename from Aria/src/main/java/com/arialyy/aria/core/upload/HttpBuilderTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/upload/normal/HttpBuilderTarget.java index fe05c77f..1badcbaa 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/HttpBuilderTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/normal/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; +package com.arialyy.aria.core.upload.normal; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsBuilderTarget; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/HttpNormalTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/normal/HttpNormalTarget.java similarity index 97% rename from Aria/src/main/java/com/arialyy/aria/core/upload/HttpNormalTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/upload/normal/HttpNormalTarget.java index a5280ea2..c83e8b46 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/HttpNormalTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/normal/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; +package com.arialyy.aria.core.upload.normal; import androidx.annotation.CheckResult; import com.arialyy.aria.core.common.AbsNormalTarget; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UNormalConfigHandler.java b/Aria/src/main/java/com/arialyy/aria/core/upload/normal/UNormalConfigHandler.java similarity index 94% rename from Aria/src/main/java/com/arialyy/aria/core/upload/UNormalConfigHandler.java rename to Aria/src/main/java/com/arialyy/aria/core/upload/normal/UNormalConfigHandler.java index f9eae1de..90144aa9 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UNormalConfigHandler.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/normal/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; +package com.arialyy.aria.core.upload.normal; import com.arialyy.aria.core.common.ftp.IFtpUploadInterceptor; import com.arialyy.aria.core.event.ErrorEvent; @@ -22,6 +22,9 @@ import com.arialyy.aria.core.inf.AbsTarget; import com.arialyy.aria.core.inf.IConfigHandler; import com.arialyy.aria.core.manager.TaskWrapperManager; import com.arialyy.aria.core.queue.UploadTaskQueue; +import com.arialyy.aria.core.upload.UTaskWrapper; +import com.arialyy.aria.core.upload.UploadEntity; +import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.CommonUtil; import java.io.File; 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/normal/UNormalTargetFactory.java new file mode 100644 index 00000000..bdd87e7a --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/normal/UNormalTargetFactory.java @@ -0,0 +1,69 @@ +/* + * 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.upload.normal; + +import com.arialyy.aria.core.common.AbsBuilderTarget; +import com.arialyy.aria.core.common.AbsNormalTarget; + +/** + * @Author aria + * @Date 2019-09-05 + */ +public class UNormalTargetFactory { + + public static volatile UNormalTargetFactory INSTANCE; + + private UNormalTargetFactory() { + + } + + public static UNormalTargetFactory getInstance() { + + if (INSTANCE == null) { + synchronized (UNormalTargetFactory.class) { + if (INSTANCE == null) { + INSTANCE = new UNormalTargetFactory(); + } + } + } + + return INSTANCE; + } + + public T generateNormalTarget(Class clazz, long taskId, + String targetName) { + T target = null; + if (clazz == HttpNormalTarget.class) { + target = (T) new HttpNormalTarget(taskId, targetName); + } else if (clazz == FtpNormalTarget.class) { + target = (T) new FtpNormalTarget(taskId, targetName); + } + + return target; + } + + public T generateBuilderTarget(Class clazz, String url, + String targetName) { + T target = null; + if (clazz == HttpBuilderTarget.class) { + target = (T) new HttpBuilderTarget(url, targetName); + } else if (clazz == FtpBuilderTarget.class) { + target = (T) new FtpBuilderTarget(url, targetName); + } + + 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 4eeec4c7..2030159f 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -21,11 +21,10 @@ import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; import android.os.Environment; -import android.os.StatFs; import android.text.TextUtils; import android.util.Base64; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.FtpUrlEntity; +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; diff --git a/app/src/main/assets/help_code/KotlinHttpDownload.kt b/app/src/main/assets/help_code/KotlinHttpDownload.kt index 58da1b24..9fc3bfcf 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.HttpNormalTarget +import com.arialyy.aria.core.download.normal.HttpNormalTarget import com.arialyy.aria.core.download.DownloadTask import com.arialyy.aria.core.inf.IEntity import com.arialyy.simple.R