diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java index 5bcad9cb..41bb1525 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java +++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java @@ -29,14 +29,13 @@ import android.text.TextUtils; import android.util.Log; import android.widget.PopupWindow; import com.arialyy.aria.core.download.DownloadReceiver; -import com.arialyy.aria.core.inf.ICmd; +import com.arialyy.aria.core.command.ICmd; import com.arialyy.aria.core.inf.IReceiver; import com.arialyy.aria.core.upload.UploadReceiver; import com.arialyy.aria.orm.DbUtil; import com.arialyy.aria.util.CommonUtil; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java index 8dc620c8..d337a453 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java @@ -16,50 +16,20 @@ package com.arialyy.aria.core.command; -import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; -import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.ITaskQueue; -import com.arialyy.aria.core.inf.ICmd; -import com.arialyy.aria.core.queue.UploadTaskQueue; -import com.arialyy.aria.core.upload.UploadTaskEntity; -import com.arialyy.aria.util.CheckUtil; -import com.arialyy.aria.util.CommonUtil; /** - * Created by lyy on 2016/8/22. - * 下载命令 + * Created by AriaL on 2017/6/29. */ -public abstract class AbsCmd implements ICmd { - ITaskQueue mQueue; - T mTaskEntity; - String TAG; - String mTargetName; - /** - * 能否执行命令 - */ - boolean canExeCmd = true; +public abstract class AbsCmd implements ICmd{ + protected ITaskQueue mQueue; + protected T mTaskEntity; + protected String TAG; + protected String mTargetName; /** * 是否是下载任务的命令 * {@code true} 下载任务的命令,{@code false} 上传任务的命令 */ - boolean isDownloadCmd = true; - - /** - * @param targetName 产生任务的对象名 - */ - AbsCmd(String targetName, T entity) { - canExeCmd = CheckUtil.checkCmdEntity(entity, - !(this instanceof CancelCmd) || !(this instanceof StopCmd)); - mTargetName = targetName; - mTaskEntity = entity; - TAG = CommonUtil.getClassName(this); - if (entity instanceof DownloadTaskEntity) { - mQueue = DownloadTaskQueue.getInstance(); - isDownloadCmd = true; - } else if (entity instanceof UploadTaskEntity) { - mQueue = UploadTaskQueue.getInstance(); - isDownloadCmd = false; - } - } -} \ No newline at end of file + protected boolean isDownloadCmd = true; +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java new file mode 100644 index 00000000..9f447b49 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java @@ -0,0 +1,30 @@ +/* + * 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.command; + +import com.arialyy.aria.core.inf.AbsTaskEntity; + +/** + * Created by AriaL on 2017/6/29. + */ +public abstract class AbsCmdFactory { + + /** + * @param target 创建任务的对象 + * @param entity 下载实体 + */ + public abstract CMD createCmd(String target, T entity, int type); +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ICmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/ICmd.java similarity index 90% rename from Aria/src/main/java/com/arialyy/aria/core/inf/ICmd.java rename to Aria/src/main/java/com/arialyy/aria/core/command/ICmd.java index 482cfb0c..dc938037 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/ICmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/ICmd.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.inf; +package com.arialyy.aria.core.command; /** * Created by lyy on 2017/2/9. @@ -23,5 +23,5 @@ public interface ICmd { /** * 执行命令 */ - public abstract void executeCmd(); + void executeCmd(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java new file mode 100644 index 00000000..f8b2e0ed --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java @@ -0,0 +1,47 @@ +/* + * 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.command.group; + +import com.arialyy.aria.core.command.AbsCmd; +import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.queue.DownloadTaskQueue; +import com.arialyy.aria.core.queue.UploadTaskQueue; +import com.arialyy.aria.core.upload.UploadTaskEntity; +import com.arialyy.aria.util.CommonUtil; + +/** + * Created by AriaL on 2017/6/29. + * 任务组命令 + */ +public abstract class AbsGroupCmd extends AbsCmd { + + /** + * @param targetName 创建任务的对象名 + */ + AbsGroupCmd(String targetName, T entity) { + mTargetName = targetName; + mTaskEntity = entity; + TAG = CommonUtil.getClassName(this); + if (entity instanceof DownloadTaskEntity) { + mQueue = DownloadTaskQueue.getInstance(); + isDownloadCmd = true; + } else if (entity instanceof UploadTaskEntity) { + mQueue = UploadTaskQueue.getInstance(); + isDownloadCmd = false; + } + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCancelCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCancelCmd.java new file mode 100644 index 00000000..5b6e5cf9 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCancelCmd.java @@ -0,0 +1,35 @@ +/* + * 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.command.group; + +import com.arialyy.aria.core.inf.AbsTaskEntity; + +/** + * Created by AriaL on 2017/6/29. + * 删除任务组 + */ +class GroupCancelCmd extends AbsGroupCmd { + /** + * @param targetName 创建任务的对象名 + */ + GroupCancelCmd(String targetName, T entity) { + super(targetName, entity); + } + + @Override public void executeCmd() { + + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java new file mode 100644 index 00000000..786dd6b8 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java @@ -0,0 +1,71 @@ +/* + * 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.command.group; + +import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.command.AbsCmdFactory; +import com.arialyy.aria.core.inf.AbsTaskEntity; + +/** + * Created by AriaL on 2017/6/29. + */ +public class GroupCmdFactory extends AbsCmdFactory { + /** + * 启动任务 + */ + public static final int TASK_START = 0xa1; + /** + * 停止任务 + */ + public static final int TASK_STOP = 0xa2; + /** + * 取消任务 + */ + public static final int TASK_CANCEL = 0xa3; + + private static volatile GroupCmdFactory INSTANCE = null; + + private GroupCmdFactory() { + + } + + public static GroupCmdFactory getInstance() { + if (INSTANCE == null) { + synchronized (AriaManager.LOCK) { + INSTANCE = new GroupCmdFactory(); + } + } + return INSTANCE; + } + + /** + * @param target 创建任务的对象 + * @param entity 下载实体 + * @param type 命令类型{@link #TASK_START}、{@link #TASK_CANCEL}、{@link #TASK_STOP} + */ + public AbsGroupCmd createCmd(String target, T entity, int type) { + switch (type) { + case TASK_START: + return new GroupStartCmd<>(target, entity); + case TASK_STOP: + return new GroupStopCmd<>(target, entity); + case TASK_CANCEL: + return new GroupCancelCmd<>(target, entity); + default: + return null; + } + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java new file mode 100644 index 00000000..7fdb8465 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java @@ -0,0 +1,35 @@ +/* + * 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.command.group; + +import com.arialyy.aria.core.inf.AbsTaskEntity; + +/** + * Created by AriaL on 2017/6/29. + * 任务组开始命令,该命令负责开始下载或恢复下载的操作 + */ +class GroupStartCmd extends AbsGroupCmd { + /** + * @param targetName 创建任务的对象名 + */ + GroupStartCmd(String targetName, T entity) { + super(targetName, entity); + } + + @Override public void executeCmd() { + + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStopCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStopCmd.java new file mode 100644 index 00000000..85c400bd --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStopCmd.java @@ -0,0 +1,35 @@ +/* + * 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.command.group; + +import com.arialyy.aria.core.inf.AbsTaskEntity; + +/** + * Created by AriaL on 2017/6/29. + * 停止任务组的命令 + */ +class GroupStopCmd extends AbsGroupCmd{ + /** + * @param targetName 创建任务的对象名 + */ + GroupStopCmd(String targetName, T entity) { + super(targetName, entity); + } + + @Override public void executeCmd() { + + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java new file mode 100644 index 00000000..e690524d --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java @@ -0,0 +1,56 @@ +/* + * 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.command.normal; + +import com.arialyy.aria.core.command.AbsCmd; +import com.arialyy.aria.core.download.DownloadTaskEntity; +import com.arialyy.aria.core.inf.AbsTaskEntity; +import com.arialyy.aria.core.queue.DownloadTaskQueue; +import com.arialyy.aria.core.queue.UploadTaskQueue; +import com.arialyy.aria.core.upload.UploadTaskEntity; +import com.arialyy.aria.util.CheckUtil; +import com.arialyy.aria.util.CommonUtil; + +/** + * Created by lyy on 2016/8/22. + * 下载命令 + */ +public abstract class AbsNormalCmd extends AbsCmd { + + /** + * 能否执行命令 + */ + boolean canExeCmd = true; + + /** + * @param targetName 产生任务的对象名 + */ + AbsNormalCmd(String targetName, T entity) { + canExeCmd = CheckUtil.checkCmdEntity(entity, + !(this instanceof CancelCmd) || !(this instanceof StopCmd)); + mTargetName = targetName; + mTaskEntity = entity; + TAG = CommonUtil.getClassName(this); + if (entity instanceof DownloadTaskEntity) { + mQueue = DownloadTaskQueue.getInstance(); + isDownloadCmd = true; + } else if (entity instanceof UploadTaskEntity) { + mQueue = UploadTaskQueue.getInstance(); + isDownloadCmd = false; + } + } +} \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java similarity index 90% rename from Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java rename to Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java index 44cf797f..e848813b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/AddCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java @@ -14,19 +14,18 @@ * limitations under the License. */ -package com.arialyy.aria.core.command; +package com.arialyy.aria.core.command.normal; import android.util.Log; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by lyy on 2016/8/22. * 添加任务的命令 */ -class AddCmd extends AbsCmd { +class AddCmd extends AbsNormalCmd { AddCmd(String targetName, T entity) { super(targetName, entity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/CancelAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java similarity index 91% rename from Aria/src/main/java/com/arialyy/aria/core/command/CancelAllCmd.java rename to Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java index 057c8a2b..f68b3bcc 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/CancelAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java @@ -14,23 +14,21 @@ * limitations under the License. */ -package com.arialyy.aria.core.command; +package com.arialyy.aria.core.command.normal; -import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.CommonUtil; -import java.io.File; import java.util.List; /** * Created by AriaL on 2017/6/27. * 删除所有任务,并且删除所有回掉 */ -final class CancelAllCmd extends AbsCmd { +final class CancelAllCmd extends AbsNormalCmd { /** * @param targetName 产生任务的对象名 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java similarity index 89% rename from Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java rename to Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java index 74079a93..d12f0cad 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/CancelCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java @@ -14,18 +14,17 @@ * limitations under the License. */ -package com.arialyy.aria.core.command; +package com.arialyy.aria.core.command.normal; import android.text.TextUtils; import com.arialyy.aria.core.inf.AbsTask; -import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by lyy on 2016/9/20. * 取消命令 */ -class CancelCmd extends AbsCmd { +class CancelCmd extends AbsNormalCmd { CancelCmd(String targetName, T entity) { super(targetName, entity); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java similarity index 95% rename from Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java rename to Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java index a846a41e..a52555a8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/HighestPriorityCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java @@ -13,11 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.arialyy.aria.core.command; +package com.arialyy.aria.core.command.normal; import android.text.TextUtils; import com.arialyy.aria.core.inf.AbsTask; -import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.AbsTaskEntity; /** @@ -30,7 +29,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity; * 5、如果下载队列中已经满了,则会停止队尾的任务,当高优先级任务完成后,该队尾任务将自动执行 * 6、把任务设置为最高优先级任务后,将自动执行任务,不需要重新调用start()启动任务 */ -final class HighestPriorityCmd extends AbsCmd { +final class HighestPriorityCmd extends AbsNormalCmd { /** * @param targetName 产生任务的对象名 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/NormalCmdFactory.java similarity index 85% rename from Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java rename to Aria/src/main/java/com/arialyy/aria/core/command/normal/NormalCmdFactory.java index e2fdf3e0..85aa33fc 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/CmdFactory.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/NormalCmdFactory.java @@ -14,16 +14,17 @@ * limitations under the License. */ -package com.arialyy.aria.core.command; +package com.arialyy.aria.core.command.normal; import com.arialyy.aria.core.AriaManager; +import com.arialyy.aria.core.command.AbsCmdFactory; import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by Lyy on 2016/9/23. * 命令工厂 */ -public class CmdFactory { +public class NormalCmdFactory extends AbsCmdFactory { /** * 创建任务 */ @@ -60,16 +61,16 @@ public class CmdFactory { * 删除所有任务, */ public static final int TASK_CANCEL_ALL = 0x131; - private static volatile CmdFactory INSTANCE = null; + private static volatile NormalCmdFactory INSTANCE = null; - private CmdFactory() { + private NormalCmdFactory() { } - public static CmdFactory getInstance() { + public static NormalCmdFactory getInstance() { if (INSTANCE == null) { synchronized (AriaManager.LOCK) { - INSTANCE = new CmdFactory(); + INSTANCE = new NormalCmdFactory(); } } return INSTANCE; @@ -81,7 +82,7 @@ public class CmdFactory { * @param type 命令类型{@link #TASK_CREATE}、{@link #TASK_START}、{@link #TASK_CANCEL}、{@link * #TASK_STOP}、{@link #TASK_HIGHEST_PRIORITY}、{@link #TASK_STOP_ALL}、{@link #TASK_RESUME_ALL} */ - public AbsCmd createCmd(String target, T entity, int type) { + public AbsNormalCmd createCmd(String target, T entity, int type) { switch (type) { case TASK_CREATE: return new AddCmd<>(target, entity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java similarity index 91% rename from Aria/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.java rename to Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java index 693b9c80..58b26bdc 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/ResumeAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java @@ -1,4 +1,4 @@ -package com.arialyy.aria.core.command; +package com.arialyy.aria.core.command.normal; import android.util.Log; import com.arialyy.aria.core.download.DownloadEntity; @@ -6,7 +6,6 @@ import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.orm.DbEntity; import java.util.List; @@ -16,7 +15,7 @@ import java.util.List; * 1.如果执行队列没有满,则开始下载任务,直到执行队列满 * 2.如果队列执行队列已经满了,则将所有任务添加到等待队列中 */ -final class ResumeAllCmd extends AbsCmd { +final class ResumeAllCmd extends AbsNormalCmd { /** * @param targetName 产生任务的对象名 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java similarity index 94% rename from Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java rename to Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java index 30906615..2b042a27 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/StartCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java @@ -14,14 +14,13 @@ * limitations under the License. */ -package com.arialyy.aria.core.command; +package com.arialyy.aria.core.command.normal; import android.text.TextUtils; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.QueueMod; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.AbsTaskEntity; /** @@ -29,7 +28,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity; * 开始命令 * 队列模型{@link QueueMod#NOW}、{@link QueueMod#WAIT} */ -class StartCmd extends AbsCmd { +class StartCmd extends AbsNormalCmd { StartCmd(String targetName, T entity) { super(targetName, entity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/StopAllCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java similarity index 75% rename from Aria/src/main/java/com/arialyy/aria/core/command/StopAllCmd.java rename to Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java index 2c16378e..431adfdd 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/StopAllCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java @@ -1,4 +1,4 @@ -package com.arialyy.aria.core.command; +package com.arialyy.aria.core.command.normal; import com.arialyy.aria.core.inf.AbsTaskEntity; @@ -6,7 +6,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity; * Created by AriaL on 2017/6/13. * 停止所有任务的命令,并清空所有等待队列 */ -final class StopAllCmd extends AbsCmd { +final class StopAllCmd extends AbsNormalCmd { /** * @param targetName 产生任务的对象名 */ diff --git a/Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java similarity index 91% rename from Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java rename to Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java index dc04609b..9d0b0811 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/command/StopCmd.java +++ b/Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java @@ -14,20 +14,19 @@ * limitations under the License. */ -package com.arialyy.aria.core.command; +package com.arialyy.aria.core.command.normal; import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.AbsTaskEntity; /** * Created by lyy on 2016/9/20. * 停止命令 */ -class StopCmd extends AbsCmd { +class StopCmd extends AbsNormalCmd { StopCmd(String targetName, T entity) { super(targetName, entity); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java index 5c0e18bf..e1102037 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java @@ -18,7 +18,7 @@ package com.arialyy.aria.core.download; import android.os.Parcel; import android.os.Parcelable; -import com.arialyy.aria.core.inf.AbsEntity; +import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.orm.Ignore; /** @@ -27,7 +27,7 @@ import com.arialyy.aria.orm.Ignore; * !!! 注意:CREATOR要进行@Ignore注解 * !!!并且需要Parcelable时需要手动填写rowID; */ -public class DownloadEntity extends AbsEntity implements Parcelable { +public class DownloadEntity extends AbsNormalEntity implements Parcelable { private String downloadUrl = ""; //下载路径 private String downloadPath = ""; //保存路径 private boolean isDownloadComplete = false; //是否下载完成 diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java new file mode 100644 index 00000000..e556c424 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java @@ -0,0 +1,38 @@ +/* + * 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; + +import com.arialyy.aria.core.inf.AbsGroupTarget; +import com.arialyy.aria.core.inf.ITarget; +import java.util.List; + +/** + * Created by AriaL on 2017/6/29. + */ +public class DownloadGroupTarget extends AbsGroupTarget { + + /** + * 设置保存路径组 + */ + public DownloadGroupTarget setDownloadPaths(List paths) { + + return this; + } + + @Override public int getPercent() { + return 0; + } +} 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 32a255d3..045902dd 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 @@ -20,15 +20,12 @@ import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.inf.AbsReceiver; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IReceiver; -import com.arialyy.aria.core.command.CmdFactory; -import com.arialyy.aria.core.command.AbsCmd; +import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulerListener; -import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CommonUtil; import java.io.File; -import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -142,8 +139,8 @@ public class DownloadReceiver extends AbsReceiver { */ @Override public void stopAllTask() { AriaManager.getInstance(AriaManager.APP) - .setCmd(CmdFactory.getInstance() - .createCmd(targetName, new DownloadTaskEntity(), CmdFactory.TASK_STOP_ALL)) + .setCmd(NormalCmdFactory.getInstance() + .createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_STOP_ALL)) .exe(); } @@ -154,8 +151,8 @@ public class DownloadReceiver extends AbsReceiver { */ public void resumeAllTask() { AriaManager.getInstance(AriaManager.APP) - .setCmd(CmdFactory.getInstance() - .createCmd(targetName, new DownloadTaskEntity(), CmdFactory.TASK_RESUME_ALL)) + .setCmd(NormalCmdFactory.getInstance() + .createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_RESUME_ALL)) .exe(); } @@ -169,7 +166,7 @@ public class DownloadReceiver extends AbsReceiver { final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP); AriaManager.getInstance(AriaManager.APP) .setCmd( - CommonUtil.createCmd(targetName, new DownloadTaskEntity(), CmdFactory.TASK_CANCEL_ALL)) + CommonUtil.createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_CANCEL_ALL)) .exe(); Set keys = ariaManager.getReceiver().keySet(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java index 05e6c2d9..914c1ff7 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java @@ -17,31 +17,21 @@ package com.arialyy.aria.core.download; import android.support.annotation.NonNull; import android.text.TextUtils; -import android.util.Log; -import com.arialyy.aria.core.RequestEnum; -import com.arialyy.aria.core.inf.AbsTarget; +import com.arialyy.aria.core.inf.AbsNormalTarget; import com.arialyy.aria.core.queue.DownloadTaskQueue; import java.io.File; -import java.util.Map; /** * Created by lyy on 2016/12/5. * https://github.com/AriaLyy/Aria */ -public class DownloadTarget extends AbsTarget { +public class DownloadTarget extends + AbsNormalTarget { DownloadTarget(DownloadEntity entity, String targetName) { - this.entity = entity; - this.targetName = targetName; - taskEntity = new DownloadTaskEntity(entity); - } - - @Override public void pause() { - super.pause(); - } - - @Override public void resume() { - super.resume(); + this.mEntity = entity; + this.mTargetName = targetName; + mTaskEntity = new DownloadTaskEntity(entity); } /** @@ -65,54 +55,14 @@ public class DownloadTarget extends AbsTarget headers) { - super._addHeaders(headers); - return this; - } /** * 下载任务是否存在 */ @Override public boolean taskExists() { - return DownloadTaskQueue.getInstance().getTask(entity.getDownloadUrl()) != null; + return DownloadTaskQueue.getInstance().getTask(mEntity.getDownloadUrl()) != null; } - /** - * 设置请求类型 - * - * @param requestEnum {@link RequestEnum} - */ - public DownloadTarget setRequestMode(RequestEnum requestEnum) { - super._setRequestMode(requestEnum); - return this; - } /** * 设置文件存储路径 @@ -122,8 +72,8 @@ public class DownloadTarget extends AbsTarget extends DbEntity implements IEntity, Parcelable { + /** + * 速度 + */ + @Ignore private long speed = 0; + /** + * 单位转换后的速度 + */ + @Ignore private String convertSpeed = "0b/s"; + + /** + * 扩展字段 + */ + private String str = ""; + /** + * 文件大小 + */ + private long fileSize = 1; + private int state = STATE_WAIT; + /** + * 当前下载进度 + */ + private long currentProgress = 0; + /** + * 完成时间 + */ + private long completeTime; + /** + * 文件名 + */ + private String grooupName = ""; + + public long getSpeed() { + return speed; + } + + public void setSpeed(long speed) { + this.speed = speed; + } + + public String getConvertSpeed() { + return convertSpeed; + } + + public void setConvertSpeed(String convertSpeed) { + this.convertSpeed = convertSpeed; + } + + public String getStr() { + return str; + } + + public void setStr(String str) { + this.str = str; + } + + public long getFileSize() { + return fileSize; + } + + public void setFileSize(long fileSize) { + this.fileSize = fileSize; + } + + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + } + + public long getCurrentProgress() { + return currentProgress; + } + + public void setCurrentProgress(long currentProgress) { + this.currentProgress = currentProgress; + } + + public long getCompleteTime() { + return completeTime; + } + + public void setCompleteTime(long completeTime) { + this.completeTime = completeTime; + } + + public AbsGroupEntity() { + } + + @Override public int describeContents() { + return 0; + } + + @Override public void writeToParcel(Parcel dest, int flags) { + dest.writeLong(this.speed); + dest.writeString(this.convertSpeed); + dest.writeString(this.str); + dest.writeLong(this.fileSize); + dest.writeInt(this.state); + dest.writeLong(this.currentProgress); + dest.writeLong(this.completeTime); + } + + protected AbsGroupEntity(Parcel in) { + this.speed = in.readLong(); + this.convertSpeed = in.readString(); + this.str = in.readString(); + this.fileSize = in.readLong(); + this.state = in.readInt(); + this.currentProgress = in.readLong(); + this.completeTime = in.readLong(); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTarget.java new file mode 100644 index 00000000..34834da5 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTarget.java @@ -0,0 +1,79 @@ +/* + * 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.inf; + +import android.support.annotation.NonNull; +import com.arialyy.aria.core.RequestEnum; +import java.util.Map; +import java.util.Set; + +/** + * Created by AriaL on 2017/6/29. + * 任务组超类 + */ +public abstract class AbsGroupTarget + implements ITarget { + + protected TASK_ENTITY mTaskEntity; + + @Override public void resume() { + + } + + @Override public void start() { + + } + + @Override public void stop() { + + } + + @Override public void cancel() { + + } + + @Override public long getSize() { + return 0; + } + + @Override public String getConvertSize() { + return null; + } + + @Override public long getCurrentProgress() { + return 0; + } + + @Override public TARGET addHeader(@NonNull String key, @NonNull String header) { + mTaskEntity.headers.put(key, header); + return (TARGET) this; + } + + @Override public TARGET addHeaders(Map headers) { + if (headers != null && headers.size() > 0) { + Set keys = headers.keySet(); + for (String key : keys) { + mTaskEntity.headers.put(key, headers.get(key)); + } + } + return (TARGET) this; + } + + @Override public TARGET setRequestMode(RequestEnum requestEnum) { + mTaskEntity.requestEnum = requestEnum; + return (TARGET) this; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java similarity index 95% rename from Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java rename to Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java index e6b4d2b9..8411c960 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java @@ -23,7 +23,7 @@ import com.arialyy.aria.orm.Ignore; /** * Created by AriaL on 2017/6/3. */ -public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable { +public abstract class AbsNormalEntity extends DbEntity implements IEntity, Parcelable { /** * 速度 */ @@ -130,7 +130,7 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable this.fileName = fileName; } - public AbsEntity() { + public AbsNormalEntity() { } @Override public int describeContents() { @@ -149,7 +149,7 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable dest.writeString(this.fileName); } - protected AbsEntity(Parcel in) { + protected AbsNormalEntity(Parcel in) { this.speed = in.readLong(); this.convertSpeed = in.readString(); this.failNum = in.readInt(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTarget.java similarity index 61% rename from Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java rename to Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTarget.java index c3dcbb48..c281b038 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTarget.java @@ -20,31 +20,29 @@ import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.RequestEnum; -import com.arialyy.aria.core.command.AbsCmd; -import com.arialyy.aria.core.command.CmdFactory; +import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.util.CommonUtil; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import java.util.Set; /** * Created by lyy on 2017/2/28. */ -public abstract class AbsTarget { - protected ENTITY entity; - protected TASK_ENTITY taskEntity; - protected String targetName; +public abstract class AbsNormalTarget + implements ITarget { + protected ENTITY mEntity; + protected TASK_ENTITY mTaskEntity; + protected String mTargetName; /** * 设置扩展字段,用来保存你的其它数据,如果你的数据比较多,你可以把你的数据转换为JSON字符串,然后再存到Aria中 * * @param str 扩展数据 */ - public AbsTarget setExtendField(String str) { - entity.setStr(str); + public AbsNormalTarget setExtendField(String str) { + mEntity.setStr(str); return this; } @@ -53,7 +51,7 @@ public abstract class AbsTarget headers) { + public TARGET addHeaders(Map headers) { if (headers != null && headers.size() > 0) { Set keys = headers.keySet(); for (String key : keys) { - taskEntity.headers.put(key, headers.get(key)); + mTaskEntity.headers.put(key, headers.get(key)); } } + return (TARGET) this; } /** @@ -189,56 +204,60 @@ public abstract class AbsTarget cmds = new ArrayList<>(); - //cmds.add(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_CREATE)); - //cmds.add(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_START)); - //cmds.clear(); + @Override public void start() { AriaManager.getInstance(AriaManager.APP) - .setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_START)) + .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START)) .exe(); } /** * 停止下载 + * + * @see #stop() */ - protected void pause() { + @Deprecated protected void pause() { + stop(); + } + + @Override public void stop() { AriaManager.getInstance(AriaManager.APP) - .setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_STOP)) + .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_STOP)) .exe(); } /** * 恢复下载 */ - protected void resume() { + @Override public void resume() { AriaManager.getInstance(AriaManager.APP) - .setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_START)) + .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START)) .exe(); } /** * 取消下载 */ - public void cancel() { + @Override public void cancel() { AriaManager.getInstance(AriaManager.APP) - .setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_CANCEL)) + .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL)) .exe(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsReceiver.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsReceiver.java index 4e67339e..e19d6945 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsReceiver.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsReceiver.java @@ -20,7 +20,7 @@ package com.arialyy.aria.core.inf; * Created by AriaL on 2017/6/27. */ -public abstract class AbsReceiver implements IReceiver{ +public abstract class AbsReceiver implements IReceiver{ public String targetName; public Object obj; diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java index 5521a882..3be9ea52 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java @@ -21,7 +21,7 @@ import com.arialyy.aria.util.CommonUtil; /** * Created by lyy on 2017/6/3. */ -public abstract class AbsTask +public abstract class AbsTask implements ITask { protected ENTITY mEntity; diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java index fe63cd37..8bbb8137 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java @@ -44,5 +44,5 @@ public abstract class AbsTaskEntity { */ public boolean removeFile = false; - public abstract AbsEntity getEntity(); + public abstract AbsNormalEntity getEntity(); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITarget.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITarget.java new file mode 100644 index 00000000..6a12071b --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITarget.java @@ -0,0 +1,86 @@ +/* + * 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.inf; + +import android.support.annotation.NonNull; +import com.arialyy.aria.core.RequestEnum; +import java.util.Map; + +/** + * Created by AriaL on 2017/6/29. + */ +public interface ITarget { + /** + * 任务文件大小 + */ + long getSize(); + + /** + * 转换后的大小 + */ + String getConvertSize(); + + /** + * 获取任务进度百分比 + */ + int getPercent(); + + /** + * 获取任务进度,如果任务存在,则返回当前进度 + */ + long getCurrentProgress(); + + /** + * 给url请求添加头部 + * + * @param key 头部key + * @param header 头部value + */ + TARGET addHeader(@NonNull String key, @NonNull String header) ; + + /** + * 给url请求添加头部 + */ + TARGET addHeaders(Map headers); + + /** + * 设置请求类型 + * + * @param requestEnum {@link RequestEnum} + */ + TARGET setRequestMode(RequestEnum requestEnum); + + /** + * 开始下载 + */ + void start(); + + /** + * 停止下载 + */ + void stop(); + + /** + * 恢复下载 + */ + void resume(); + + /** + * 取消下载 + */ + void cancel(); + +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java index 27b4af9b..5535ad92 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java @@ -19,7 +19,11 @@ package com.arialyy.aria.core.inf; * Created by lyy on 2017/2/13. */ -public interface ITask { +public interface ITask { + + /** + * 获取 + */ /** * 暂停任务,并让任务处于等待状态 diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java index 0bd83e6e..c2b1d239 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java @@ -17,11 +17,9 @@ package com.arialyy.aria.core.queue; import android.util.Log; -import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.inf.AbsEntity; +import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.core.inf.AbsTask; -import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.queue.pool.CachePool; import com.arialyy.aria.core.queue.pool.ExecutePool; @@ -31,7 +29,7 @@ import java.util.Set; * Created by lyy on 2017/2/23. * 任务队列 */ -abstract class AbsTaskQueue +abstract class AbsTaskQueue implements ITaskQueue { private final String TAG = "AbsTaskQueue"; CachePool mCachePool = new CachePool<>(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java new file mode 100644 index 00000000..4516ae3b --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java @@ -0,0 +1,24 @@ +/* + * 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.queue; + +/** + * Created by AriaL on 2017/6/29. + * 任务组下载队列 + */ +public class DownloadGroupTaskQueue { +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java index 1bafa3e7..4931e673 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java @@ -20,11 +20,10 @@ import android.os.Message; import android.util.Log; import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.download.DownloadTask; -import com.arialyy.aria.core.inf.AbsEntity; +import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.IEntity; -import com.arialyy.aria.core.inf.ITask; import com.arialyy.aria.core.queue.ITaskQueue; import com.arialyy.aria.core.upload.UploadTask; import java.util.Iterator; @@ -35,7 +34,7 @@ import java.util.concurrent.ConcurrentHashMap; /** * Created by lyy on 2017/6/4. */ -public abstract class AbsSchedulers, QUEUE extends ITaskQueue> +public abstract class AbsSchedulers, QUEUE extends ITaskQueue> implements ISchedulers { private static final String TAG = "AbsSchedulers"; diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java index dafc69d9..e9105255 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java @@ -17,14 +17,14 @@ package com.arialyy.aria.core.upload; import android.os.Parcel; import android.os.Parcelable; -import com.arialyy.aria.core.inf.AbsEntity; +import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.orm.Ignore; /** * Created by lyy on 2017/2/9. * 上传文件实体 */ -public class UploadEntity extends AbsEntity implements Parcelable { +public class UploadEntity extends AbsNormalEntity implements Parcelable { private String filePath; //文件路径 private boolean isComplete = false; 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 47ee5c6c..4430fb56 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 @@ -17,14 +17,12 @@ package com.arialyy.aria.core.upload; import android.support.annotation.NonNull; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.command.AbsCmd; -import com.arialyy.aria.core.command.CmdFactory; -import com.arialyy.aria.core.download.DownloadReceiver; +import com.arialyy.aria.core.command.normal.AbsNormalCmd; +import com.arialyy.aria.core.command.normal.NormalCmdFactory; import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.AbsReceiver; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IReceiver; -import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.ISchedulerListener; import com.arialyy.aria.core.scheduler.UploadSchedulers; import com.arialyy.aria.orm.DbEntity; @@ -84,11 +82,11 @@ public class UploadReceiver extends AbsReceiver { @Override public void stopAllTask() { List allEntity = DbEntity.findAllData(UploadEntity.class); - List stopCmds = new ArrayList<>(); + List stopCmds = new ArrayList<>(); for (UploadEntity entity : allEntity) { if (entity.getState() == IEntity.STATE_RUNNING) { stopCmds.add( - CommonUtil.createCmd(targetName, new UploadTaskEntity(entity), CmdFactory.TASK_STOP)); + CommonUtil.createCmd(targetName, new UploadTaskEntity(entity), NormalCmdFactory.TASK_STOP)); } } AriaManager.getInstance(AriaManager.APP).setCmds(stopCmds).exe(); @@ -105,7 +103,7 @@ public class UploadReceiver extends AbsReceiver { AriaManager.getInstance(AriaManager.APP) .setCmd( - CommonUtil.createCmd(targetName, new DownloadTaskEntity(), CmdFactory.TASK_CANCEL_ALL)) + CommonUtil.createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_CANCEL_ALL)) .exe(); Set keys = am.getReceiver().keySet(); diff --git a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java index 1868d51c..cdbde0e1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java +++ b/Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java @@ -16,28 +16,25 @@ package com.arialyy.aria.core.upload; import android.support.annotation.NonNull; -import com.arialyy.aria.core.RequestEnum; -import com.arialyy.aria.core.inf.AbsTarget; +import com.arialyy.aria.core.inf.AbsNormalTarget; import com.arialyy.aria.core.queue.UploadTaskQueue; -import com.arialyy.aria.orm.DbEntity; -import java.util.Map; /** * Created by lyy on 2017/2/28. */ -public class UploadTarget extends AbsTarget { +public class UploadTarget extends AbsNormalTarget { UploadTarget(UploadEntity entity, String targetName) { - this.entity = entity; - this.targetName = targetName; - taskEntity = new UploadTaskEntity(entity); + this.mEntity = entity; + this.mTargetName = targetName; + mTaskEntity = new UploadTaskEntity(entity); } /** * 设置userAgent */ public UploadTarget setUserAngent(@NonNull String userAgent) { - taskEntity.userAgent = userAgent; + mTaskEntity.userAgent = userAgent; return this; } @@ -47,7 +44,7 @@ public class UploadTarget extends AbsTarget { * @param uploadUrl 上传路径 */ public UploadTarget setUploadUrl(@NonNull String uploadUrl) { - taskEntity.uploadUrl = uploadUrl; + mTaskEntity.uploadUrl = uploadUrl; return this; } @@ -57,7 +54,7 @@ public class UploadTarget extends AbsTarget { * @param attachment 附件key */ public UploadTarget setAttachment(@NonNull String attachment) { - taskEntity.attachment = attachment; + mTaskEntity.attachment = attachment; return this; } @@ -65,7 +62,7 @@ public class UploadTarget extends AbsTarget { * 设置文件名 */ public UploadTarget setFileName(String fileName) { - entity.setFileName(fileName); + mEntity.setFileName(fileName); return this; } @@ -75,28 +72,7 @@ public class UploadTarget extends AbsTarget { * @param contentType tip:multipart/form-data */ public UploadTarget setContentType(String contentType) { - taskEntity.contentType = contentType; - return this; - } - - /** - * 给url请求添加头部 - * - * @param key 头部key - * @param header 头部value - */ - public UploadTarget addHeader(@NonNull String key, @NonNull String header) { - super._addHeader(key, header); - return this; - } - - /** - * 给url请求添加头部 - * - * @param headers key为http头部的key,Value为http头对应的配置 - */ - public UploadTarget addHeaders(Map headers) { - super._addHeaders(headers); + mTaskEntity.contentType = contentType; return this; } @@ -104,28 +80,16 @@ public class UploadTarget extends AbsTarget { * 下载任务是否存在 */ @Override public boolean taskExists() { - return UploadTaskQueue.getInstance().getTask(entity.getFilePath()) != null; - } - - /** - * 设置请求类型 - * - * @param requestEnum {@link RequestEnum} - */ - public UploadTarget setRequestMode(RequestEnum requestEnum) { - super._setRequestMode(requestEnum); - return this; + return UploadTaskQueue.getInstance().getTask(mEntity.getFilePath()) != null; } - private UploadEntity getDownloadEntity() { - return entity; - } /** * 是否在下载 */ public boolean isUploading() { - UploadTask task = UploadTaskQueue.getInstance().getTask(entity); + UploadTask task = UploadTaskQueue.getInstance().getTask(mEntity); return task != null && task.isRunning(); } + } 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 2b42354a..d9407c60 100644 --- a/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java @@ -23,8 +23,8 @@ import android.net.Uri; import android.text.TextUtils; import android.util.Log; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.command.CmdFactory; -import com.arialyy.aria.core.command.AbsCmd; +import com.arialyy.aria.core.command.normal.NormalCmdFactory; +import com.arialyy.aria.core.command.normal.AbsNormalCmd; import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.upload.UploadEntity; @@ -225,8 +225,8 @@ public class CommonUtil { } } - public static AbsCmd createCmd(String target, T entity, int cmd) { - return CmdFactory.getInstance().createCmd(target, entity, cmd); + public static AbsNormalCmd createCmd(String target, T entity, int cmd) { + return NormalCmdFactory.getInstance().createCmd(target, entity, cmd); } /**