任务组开始重构

pull/330/head
AriaLyy 8 years ago
parent ba7ad618be
commit 380b05de43
  1. 3
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  2. 42
      Aria/src/main/java/com/arialyy/aria/core/command/AbsCmd.java
  3. 30
      Aria/src/main/java/com/arialyy/aria/core/command/AbsCmdFactory.java
  4. 4
      Aria/src/main/java/com/arialyy/aria/core/command/ICmd.java
  5. 47
      Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java
  6. 35
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCancelCmd.java
  7. 71
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupCmdFactory.java
  8. 35
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStartCmd.java
  9. 35
      Aria/src/main/java/com/arialyy/aria/core/command/group/GroupStopCmd.java
  10. 56
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AbsNormalCmd.java
  11. 5
      Aria/src/main/java/com/arialyy/aria/core/command/normal/AddCmd.java
  12. 6
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelAllCmd.java
  13. 5
      Aria/src/main/java/com/arialyy/aria/core/command/normal/CancelCmd.java
  14. 5
      Aria/src/main/java/com/arialyy/aria/core/command/normal/HighestPriorityCmd.java
  15. 15
      Aria/src/main/java/com/arialyy/aria/core/command/normal/NormalCmdFactory.java
  16. 5
      Aria/src/main/java/com/arialyy/aria/core/command/normal/ResumeAllCmd.java
  17. 5
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StartCmd.java
  18. 4
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StopAllCmd.java
  19. 5
      Aria/src/main/java/com/arialyy/aria/core/command/normal/StopCmd.java
  20. 4
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadEntity.java
  21. 38
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTarget.java
  22. 15
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  23. 76
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  24. 140
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupEntity.java
  25. 79
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsGroupTarget.java
  26. 6
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalEntity.java
  27. 139
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsNormalTarget.java
  28. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsReceiver.java
  29. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTask.java
  30. 2
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java
  31. 86
      Aria/src/main/java/com/arialyy/aria/core/inf/ITarget.java
  32. 6
      Aria/src/main/java/com/arialyy/aria/core/inf/ITask.java
  33. 6
      Aria/src/main/java/com/arialyy/aria/core/queue/AbsTaskQueue.java
  34. 24
      Aria/src/main/java/com/arialyy/aria/core/queue/DownloadGroupTaskQueue.java
  35. 5
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  36. 4
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadEntity.java
  37. 12
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  38. 62
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTarget.java
  39. 8
      Aria/src/main/java/com/arialyy/aria/util/CommonUtil.java

@ -29,14 +29,13 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import com.arialyy.aria.core.download.DownloadReceiver; 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.inf.IReceiver;
import com.arialyy.aria.core.upload.UploadReceiver; import com.arialyy.aria.core.upload.UploadReceiver;
import com.arialyy.aria.orm.DbUtil; import com.arialyy.aria.orm.DbUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;

@ -16,50 +16,20 @@
package com.arialyy.aria.core.command; 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.inf.AbsTaskEntity;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.core.queue.ITaskQueue; 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<T extends AbsTaskEntity> implements ICmd{ public abstract class AbsCmd<T extends AbsTaskEntity> implements ICmd{
ITaskQueue mQueue; protected ITaskQueue mQueue;
T mTaskEntity; protected T mTaskEntity;
String TAG; protected String TAG;
String mTargetName; protected String mTargetName;
/**
* 能否执行命令
*/
boolean canExeCmd = true;
/** /**
* 是否是下载任务的命令 * 是否是下载任务的命令
* {@code true} 下载任务的命令{@code false} 上传任务的命令 * {@code true} 下载任务的命令{@code false} 上传任务的命令
*/ */
boolean isDownloadCmd = true; protected 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;
}
}
} }

@ -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<CMD extends AbsCmd> {
/**
* @param target 创建任务的对象
* @param entity 下载实体
*/
public abstract <T extends AbsTaskEntity> CMD createCmd(String target, T entity, int type);
}

@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.inf; package com.arialyy.aria.core.command;
/** /**
* Created by lyy on 2017/2/9. * Created by lyy on 2017/2/9.
@ -23,5 +23,5 @@ public interface ICmd {
/** /**
* 执行命令 * 执行命令
*/ */
public abstract void executeCmd(); void executeCmd();
} }

@ -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<T extends AbsTaskEntity> extends AbsCmd<T> {
/**
* @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;
}
}
}

@ -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<T extends AbsTaskEntity> extends AbsGroupCmd<T> {
/**
* @param targetName 创建任务的对象名
*/
GroupCancelCmd(String targetName, T entity) {
super(targetName, entity);
}
@Override public void executeCmd() {
}
}

@ -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<AbsGroupCmd> {
/**
* 启动任务
*/
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 <T extends AbsTaskEntity> AbsGroupCmd<T> 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;
}
}
}

@ -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<T extends AbsTaskEntity> extends AbsGroupCmd<T> {
/**
* @param targetName 创建任务的对象名
*/
GroupStartCmd(String targetName, T entity) {
super(targetName, entity);
}
@Override public void executeCmd() {
}
}

@ -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<T extends AbsTaskEntity> extends AbsGroupCmd<T>{
/**
* @param targetName 创建任务的对象名
*/
GroupStopCmd(String targetName, T entity) {
super(targetName, entity);
}
@Override public void executeCmd() {
}
}

@ -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<T extends AbsTaskEntity> extends AbsCmd<T> {
/**
* 能否执行命令
*/
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;
}
}
}

@ -14,19 +14,18 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.normal;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
/** /**
* Created by lyy on 2016/8/22. * Created by lyy on 2016/8/22.
* 添加任务的命令 * 添加任务的命令
*/ */
class AddCmd<T extends AbsTaskEntity> extends AbsCmd<T> { class AddCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
AddCmd(String targetName, T entity) { AddCmd(String targetName, T entity) {
super(targetName, entity); super(targetName, entity);

@ -14,23 +14,21 @@
* limitations under the License. * 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.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.io.File;
import java.util.List; import java.util.List;
/** /**
* Created by AriaL on 2017/6/27. * Created by AriaL on 2017/6/27.
* 删除所有任务并且删除所有回掉 * 删除所有任务并且删除所有回掉
*/ */
final class CancelAllCmd<T extends AbsTaskEntity> extends AbsCmd<T> { final class CancelAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
/** /**
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
*/ */

@ -14,18 +14,17 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.normal;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.inf.AbsTask; 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.inf.AbsTaskEntity;
/** /**
* Created by lyy on 2016/9/20. * Created by lyy on 2016/9/20.
* 取消命令 * 取消命令
*/ */
class CancelCmd<T extends AbsTaskEntity> extends AbsCmd<T> { class CancelCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
CancelCmd(String targetName, T entity) { CancelCmd(String targetName, T entity) {
super(targetName, entity); super(targetName, entity);
} }

@ -13,11 +13,10 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.normal;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.inf.AbsTask; 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.inf.AbsTaskEntity;
/** /**
@ -30,7 +29,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
* 5如果下载队列中已经满了则会停止队尾的任务当高优先级任务完成后该队尾任务将自动执行 * 5如果下载队列中已经满了则会停止队尾的任务当高优先级任务完成后该队尾任务将自动执行
* 6把任务设置为最高优先级任务后将自动执行任务不需要重新调用start()启动任务 * 6把任务设置为最高优先级任务后将自动执行任务不需要重新调用start()启动任务
*/ */
final class HighestPriorityCmd<T extends AbsTaskEntity> extends AbsCmd<T> { final class HighestPriorityCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
/** /**
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
*/ */

@ -14,16 +14,17 @@
* limitations under the License. * 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.AriaManager;
import com.arialyy.aria.core.command.AbsCmdFactory;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
/** /**
* Created by Lyy on 2016/9/23. * Created by Lyy on 2016/9/23.
* 命令工厂 * 命令工厂
*/ */
public class CmdFactory { public class NormalCmdFactory extends AbsCmdFactory<AbsNormalCmd> {
/** /**
* 创建任务 * 创建任务
*/ */
@ -60,16 +61,16 @@ public class CmdFactory {
* 删除所有任务 * 删除所有任务
*/ */
public static final int TASK_CANCEL_ALL = 0x131; 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) { if (INSTANCE == null) {
synchronized (AriaManager.LOCK) { synchronized (AriaManager.LOCK) {
INSTANCE = new CmdFactory(); INSTANCE = new NormalCmdFactory();
} }
} }
return INSTANCE; return INSTANCE;
@ -81,7 +82,7 @@ public class CmdFactory {
* @param type 命令类型{@link #TASK_CREATE}{@link #TASK_START}{@link #TASK_CANCEL}{@link * @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} * #TASK_STOP}{@link #TASK_HIGHEST_PRIORITY}{@link #TASK_STOP_ALL}{@link #TASK_RESUME_ALL}
*/ */
public <T extends AbsTaskEntity> AbsCmd<T> createCmd(String target, T entity, int type) { public <T extends AbsTaskEntity> AbsNormalCmd<T> createCmd(String target, T entity, int type) {
switch (type) { switch (type) {
case TASK_CREATE: case TASK_CREATE:
return new AddCmd<>(target, entity); return new AddCmd<>(target, entity);

@ -1,4 +1,4 @@
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.normal;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.download.DownloadEntity; 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.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
import java.util.List; import java.util.List;
@ -16,7 +15,7 @@ import java.util.List;
* 1.如果执行队列没有满则开始下载任务直到执行队列满 * 1.如果执行队列没有满则开始下载任务直到执行队列满
* 2.如果队列执行队列已经满了则将所有任务添加到等待队列中 * 2.如果队列执行队列已经满了则将所有任务添加到等待队列中
*/ */
final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsCmd<T> { final class ResumeAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
/** /**
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
*/ */

@ -14,14 +14,13 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.normal;
import android.text.TextUtils; import android.text.TextUtils;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.QueueMod; import com.arialyy.aria.core.QueueMod;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
/** /**
@ -29,7 +28,7 @@ import com.arialyy.aria.core.inf.AbsTaskEntity;
* 开始命令 * 开始命令
* 队列模型{@link QueueMod#NOW}{@link QueueMod#WAIT} * 队列模型{@link QueueMod#NOW}{@link QueueMod#WAIT}
*/ */
class StartCmd<T extends AbsTaskEntity> extends AbsCmd<T> { class StartCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
StartCmd(String targetName, T entity) { StartCmd(String targetName, T entity) {
super(targetName, entity); super(targetName, entity);

@ -1,4 +1,4 @@
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.normal;
import com.arialyy.aria.core.inf.AbsTaskEntity; 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. * Created by AriaL on 2017/6/13.
* 停止所有任务的命令并清空所有等待队列 * 停止所有任务的命令并清空所有等待队列
*/ */
final class StopAllCmd<T extends AbsTaskEntity> extends AbsCmd<T> { final class StopAllCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
/** /**
* @param targetName 产生任务的对象名 * @param targetName 产生任务的对象名
*/ */

@ -14,20 +14,19 @@
* limitations under the License. * limitations under the License.
*/ */
package com.arialyy.aria.core.command; package com.arialyy.aria.core.command.normal;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
/** /**
* Created by lyy on 2016/9/20. * Created by lyy on 2016/9/20.
* 停止命令 * 停止命令
*/ */
class StopCmd<T extends AbsTaskEntity> extends AbsCmd<T> { class StopCmd<T extends AbsTaskEntity> extends AbsNormalCmd<T> {
StopCmd(String targetName, T entity) { StopCmd(String targetName, T entity) {
super(targetName, entity); super(targetName, entity);

@ -18,7 +18,7 @@ package com.arialyy.aria.core.download;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.orm.Ignore; import com.arialyy.aria.orm.Ignore;
/** /**
@ -27,7 +27,7 @@ import com.arialyy.aria.orm.Ignore;
* 注意CREATOR要进行@Ignore注解 * 注意CREATOR要进行@Ignore注解
* 并且需要Parcelable时需要手动填写rowID; * 并且需要Parcelable时需要手动填写rowID;
*/ */
public class DownloadEntity extends AbsEntity implements Parcelable { public class DownloadEntity extends AbsNormalEntity implements Parcelable {
private String downloadUrl = ""; //下载路径 private String downloadUrl = ""; //下载路径
private String downloadPath = ""; //保存路径 private String downloadPath = ""; //保存路径
private boolean isDownloadComplete = false; //是否下载完成 private boolean isDownloadComplete = false; //是否下载完成

@ -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<DownloadGroupTarget, DownloadTaskEntity> {
/**
* 设置保存路径组
*/
public DownloadGroupTarget setDownloadPaths(List<String> paths) {
return this;
}
@Override public int getPercent() {
return 0;
}
}

@ -20,15 +20,12 @@ import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.inf.AbsReceiver; import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.IReceiver; import com.arialyy.aria.core.inf.IReceiver;
import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.command.AbsCmd;
import com.arialyy.aria.core.scheduler.DownloadSchedulers; import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.ISchedulerListener; import com.arialyy.aria.core.scheduler.ISchedulerListener;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.util.CheckUtil; import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -142,8 +139,8 @@ public class DownloadReceiver extends AbsReceiver<DownloadEntity> {
*/ */
@Override public void stopAllTask() { @Override public void stopAllTask() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CmdFactory.getInstance() .setCmd(NormalCmdFactory.getInstance()
.createCmd(targetName, new DownloadTaskEntity(), CmdFactory.TASK_STOP_ALL)) .createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_STOP_ALL))
.exe(); .exe();
} }
@ -154,8 +151,8 @@ public class DownloadReceiver extends AbsReceiver<DownloadEntity> {
*/ */
public void resumeAllTask() { public void resumeAllTask() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CmdFactory.getInstance() .setCmd(NormalCmdFactory.getInstance()
.createCmd(targetName, new DownloadTaskEntity(), CmdFactory.TASK_RESUME_ALL)) .createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_RESUME_ALL))
.exe(); .exe();
} }
@ -169,7 +166,7 @@ public class DownloadReceiver extends AbsReceiver<DownloadEntity> {
final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP); final AriaManager ariaManager = AriaManager.getInstance(AriaManager.APP);
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd( .setCmd(
CommonUtil.createCmd(targetName, new DownloadTaskEntity(), CmdFactory.TASK_CANCEL_ALL)) CommonUtil.createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_CANCEL_ALL))
.exe(); .exe();
Set<String> keys = ariaManager.getReceiver().keySet(); Set<String> keys = ariaManager.getReceiver().keySet();

@ -17,31 +17,21 @@ package com.arialyy.aria.core.download;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import com.arialyy.aria.core.inf.AbsNormalTarget;
import com.arialyy.aria.core.RequestEnum;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.queue.DownloadTaskQueue; import com.arialyy.aria.core.queue.DownloadTaskQueue;
import java.io.File; import java.io.File;
import java.util.Map;
/** /**
* Created by lyy on 2016/12/5. * Created by lyy on 2016/12/5.
* https://github.com/AriaLyy/Aria * https://github.com/AriaLyy/Aria
*/ */
public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity> { public class DownloadTarget extends
AbsNormalTarget<DownloadTarget, DownloadEntity, DownloadTaskEntity> {
DownloadTarget(DownloadEntity entity, String targetName) { DownloadTarget(DownloadEntity entity, String targetName) {
this.entity = entity; this.mEntity = entity;
this.targetName = targetName; this.mTargetName = targetName;
taskEntity = new DownloadTaskEntity(entity); mTaskEntity = new DownloadTaskEntity(entity);
}
@Override public void pause() {
super.pause();
}
@Override public void resume() {
super.resume();
} }
/** /**
@ -65,54 +55,14 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
return this; return this;
} }
@Override public int getPercent() {
if (entity == null) {
Log.e("DownloadTarget", "下载管理器中没有该任务");
return 0;
}
if (entity.getFileSize() != 0) {
return (int) (entity.getCurrentProgress() * 100 / entity.getFileSize());
}
return super.getPercent();
}
/**
* 给url请求添加头部
*
* @param key 头部key
* @param header 头部value
*/
public DownloadTarget addHeader(@NonNull String key, @NonNull String header) {
super._addHeader(key, header);
return this;
}
/**
* 给url请求添加头部
*
* @param headers key为http头部的keyValue为http头对应的配置
*/
public DownloadTarget addHeaders(Map<String, String> headers) {
super._addHeaders(headers);
return this;
}
/** /**
* 下载任务是否存在 * 下载任务是否存在
*/ */
@Override public boolean taskExists() { @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<DownloadEntity, DownloadTaskEntity
throw new IllegalArgumentException("文件保持路径不能为null"); throw new IllegalArgumentException("文件保持路径不能为null");
} }
File file = new File(downloadPath); File file = new File(downloadPath);
entity.setDownloadPath(downloadPath); mEntity.setDownloadPath(downloadPath);
entity.setFileName(file.getName()); mEntity.setFileName(file.getName());
return this; return this;
} }
@ -136,7 +86,7 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
if (TextUtils.isEmpty(downloadName)) { if (TextUtils.isEmpty(downloadName)) {
throw new IllegalArgumentException("文件名不能为null"); throw new IllegalArgumentException("文件名不能为null");
} }
entity.setFileName(downloadName); mEntity.setFileName(downloadName);
return this; return this;
} }
@ -147,19 +97,19 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
if (TextUtils.isEmpty(fileName)) { if (TextUtils.isEmpty(fileName)) {
throw new IllegalArgumentException("文件名不能为null"); throw new IllegalArgumentException("文件名不能为null");
} }
entity.setFileName(fileName); mEntity.setFileName(fileName);
return this; return this;
} }
private DownloadEntity getDownloadEntity() { private DownloadEntity getDownloadEntity() {
return entity; return mEntity;
} }
/** /**
* 是否在下载 * 是否在下载
*/ */
public boolean isDownloading() { public boolean isDownloading() {
DownloadTask task = DownloadTaskQueue.getInstance().getTask(entity); DownloadTask task = DownloadTaskQueue.getInstance().getTask(mEntity);
return task != null && task.isRunning(); return task != null && task.isRunning();
} }
} }

@ -0,0 +1,140 @@
/*
* 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.os.Parcel;
import android.os.Parcelable;
import com.arialyy.aria.orm.DbEntity;
import com.arialyy.aria.orm.Ignore;
/**
* Created by AriaL on 2017/6/3.
*/
public abstract class AbsGroupEntity<CHILD_ENTITY extends AbsNormalEntity> 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();
}
}

@ -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<TARGET extends AbsGroupTarget, TASK_ENTITY extends AbsTaskEntity>
implements ITarget<TARGET> {
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<String, String> headers) {
if (headers != null && headers.size() > 0) {
Set<String> 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;
}
}

@ -23,7 +23,7 @@ import com.arialyy.aria.orm.Ignore;
/** /**
* Created by AriaL on 2017/6/3. * 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; this.fileName = fileName;
} }
public AbsEntity() { public AbsNormalEntity() {
} }
@Override public int describeContents() { @Override public int describeContents() {
@ -149,7 +149,7 @@ public abstract class AbsEntity extends DbEntity implements IEntity, Parcelable
dest.writeString(this.fileName); dest.writeString(this.fileName);
} }
protected AbsEntity(Parcel in) { protected AbsNormalEntity(Parcel in) {
this.speed = in.readLong(); this.speed = in.readLong();
this.convertSpeed = in.readString(); this.convertSpeed = in.readString();
this.failNum = in.readInt(); this.failNum = in.readInt();

@ -20,31 +20,29 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.RequestEnum; import com.arialyy.aria.core.RequestEnum;
import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
/** /**
* Created by lyy on 2017/2/28. * Created by lyy on 2017/2/28.
*/ */
public abstract class AbsTarget<ENTITY extends AbsEntity, TASK_ENTITY extends AbsTaskEntity> { public abstract class AbsNormalTarget<TARGET extends AbsNormalTarget, ENTITY extends AbsNormalEntity, TASK_ENTITY extends AbsTaskEntity>
protected ENTITY entity; implements ITarget<TARGET> {
protected TASK_ENTITY taskEntity; protected ENTITY mEntity;
protected String targetName; protected TASK_ENTITY mTaskEntity;
protected String mTargetName;
/** /**
* 设置扩展字段用来保存你的其它数据如果你的数据比较多你可以把你的数据转换为JSON字符串然后再存到Aria中 * 设置扩展字段用来保存你的其它数据如果你的数据比较多你可以把你的数据转换为JSON字符串然后再存到Aria中
* *
* @param str 扩展数据 * @param str 扩展数据
*/ */
public AbsTarget setExtendField(String str) { public AbsNormalTarget setExtendField(String str) {
entity.setStr(str); mEntity.setStr(str);
return this; return this;
} }
@ -53,7 +51,7 @@ public abstract class AbsTarget<ENTITY extends AbsEntity, TASK_ENTITY extends Ab
* 设置扩展字段{@link #setExtendField(String)} * 设置扩展字段{@link #setExtendField(String)}
*/ */
public String getExtendField() { public String getExtendField() {
return entity.getStr(); return mEntity.getStr();
} }
/** /**
@ -62,7 +60,7 @@ public abstract class AbsTarget<ENTITY extends AbsEntity, TASK_ENTITY extends Ab
* @return {@link IEntity} * @return {@link IEntity}
*/ */
public int getTaskState() { public int getTaskState() {
return entity.getState(); return mEntity.getState();
} }
/** /**
@ -76,7 +74,7 @@ public abstract class AbsTarget<ENTITY extends AbsEntity, TASK_ENTITY extends Ab
*/ */
protected void setHighestPriority() { protected void setHighestPriority() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_HIGHEST_PRIORITY)) .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_HIGHEST_PRIORITY))
.exe(); .exe();
} }
@ -85,17 +83,33 @@ public abstract class AbsTarget<ENTITY extends AbsEntity, TASK_ENTITY extends Ab
*/ */
protected void _setRedirectUrlKey(String redirectUrlKey) { protected void _setRedirectUrlKey(String redirectUrlKey) {
if (TextUtils.isEmpty(redirectUrlKey)) { if (TextUtils.isEmpty(redirectUrlKey)) {
Log.w("AbsTarget", "重定向后,新url的key不能为null"); Log.w("AbsNormalTarget", "重定向后,新url的key不能为null");
return; return;
} }
taskEntity.redirectUrlKey = redirectUrlKey; mTaskEntity.redirectUrlKey = redirectUrlKey;
}
/**
* 获取任务进度百分比
*
* @return 返回任务进度
*/
@Override public int getPercent() {
if (mEntity == null) {
Log.e("AbsNormalTarget", "下载管理器中没有该任务");
return 0;
}
if (mEntity.getFileSize() != 0) {
return (int) (mEntity.getCurrentProgress() * 100 / mEntity.getFileSize());
}
return 0;
} }
/** /**
* 删除记录 * 删除记录
*/ */
public void removeRecord() { public void removeRecord() {
entity.deleteData(); mEntity.deleteData();
} }
/** /**
@ -104,30 +118,38 @@ public abstract class AbsTarget<ENTITY extends AbsEntity, TASK_ENTITY extends Ab
* @return 文件大小 * @return 文件大小
*/ */
public long getFileSize() { public long getFileSize() {
if (entity instanceof DownloadEntity) { return getSize();
DownloadEntity entity = (DownloadEntity) this.entity; }
@Override public long getSize() {
if (mEntity instanceof DownloadEntity) {
DownloadEntity entity = (DownloadEntity) this.mEntity;
return entity.getFileSize(); return entity.getFileSize();
} else if (entity instanceof UploadEntity) { } else if (mEntity instanceof UploadEntity) {
UploadEntity entity = (UploadEntity) this.entity; UploadEntity entity = (UploadEntity) this.mEntity;
return entity.getFileSize(); return entity.getFileSize();
} }
return 0; return 0;
} }
@Override public String getConvertSize() {
if (mEntity instanceof DownloadEntity) {
DownloadEntity entity = (DownloadEntity) this.mEntity;
return CommonUtil.formatFileSize(entity.getFileSize());
} else if (mEntity instanceof UploadEntity) {
UploadEntity entity = (UploadEntity) this.mEntity;
return CommonUtil.formatFileSize(entity.getFileSize());
}
return "0b";
}
/** /**
* 获取单位转换后的文件大小 * 获取单位转换后的文件大小
* *
* @return 文件大小{@code xxx mb} * @return 文件大小{@code xxx mb}
*/ */
public String getConvertFileSize() { public String getConvertFileSize() {
if (entity instanceof DownloadEntity) { return getConvertSize();
DownloadEntity entity = (DownloadEntity) this.entity;
return CommonUtil.formatFileSize(entity.getFileSize());
} else if (entity instanceof UploadEntity) {
UploadEntity entity = (UploadEntity) this.entity;
return CommonUtil.formatFileSize(entity.getFileSize());
}
return "0b";
} }
/** /**
@ -137,26 +159,17 @@ public abstract class AbsTarget<ENTITY extends AbsEntity, TASK_ENTITY extends Ab
return false; return false;
} }
/**
* 获取任务进度百分比
*
* @return 返回任务进度
*/
protected int getPercent() {
return 0;
}
/** /**
* 获取任务进度如果任务存在则返回当前进度 * 获取任务进度如果任务存在则返回当前进度
* *
* @return 该任务进度 * @return 该任务进度
*/ */
public long getCurrentProgress() { public long getCurrentProgress() {
if (entity instanceof DownloadEntity) { if (mEntity instanceof DownloadEntity) {
DownloadEntity entity = (DownloadEntity) this.entity; DownloadEntity entity = (DownloadEntity) this.mEntity;
return entity.getCurrentProgress(); return entity.getCurrentProgress();
} else if (entity instanceof UploadEntity) { } else if (mEntity instanceof UploadEntity) {
UploadEntity entity = (UploadEntity) this.entity; UploadEntity entity = (UploadEntity) this.mEntity;
return entity.getCurrentProgress(); return entity.getCurrentProgress();
} }
return -1; return -1;
@ -168,20 +181,22 @@ public abstract class AbsTarget<ENTITY extends AbsEntity, TASK_ENTITY extends Ab
* @param key 头部key * @param key 头部key
* @param header 头部value * @param header 头部value
*/ */
protected void _addHeader(@NonNull String key, @NonNull String header) { public TARGET addHeader(@NonNull String key, @NonNull String header) {
taskEntity.headers.put(key, header); mTaskEntity.headers.put(key, header);
return (TARGET) this;
} }
/** /**
* 给url请求添加头部 * 给url请求添加头部
*/ */
protected void _addHeaders(Map<String, String> headers) { public TARGET addHeaders(Map<String, String> headers) {
if (headers != null && headers.size() > 0) { if (headers != null && headers.size() > 0) {
Set<String> keys = headers.keySet(); Set<String> keys = headers.keySet();
for (String key : keys) { 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<ENTITY extends AbsEntity, TASK_ENTITY extends Ab
* *
* @param requestEnum {@link RequestEnum} * @param requestEnum {@link RequestEnum}
*/ */
protected void _setRequestMode(RequestEnum requestEnum) { public TARGET setRequestMode(RequestEnum requestEnum) {
taskEntity.requestEnum = requestEnum; mTaskEntity.requestEnum = requestEnum;
return (TARGET) this;
} }
/** /**
* 添加任务 * 添加任务
*/ */
public void add() { public void add() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_CREATE)) .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CREATE))
.exe(); .exe();
} }
/** /**
* 开始下载 * 开始下载
*/ */
public void start() { @Override public void start() {
//List<AbsCmd> cmds = new ArrayList<>();
//cmds.add(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_CREATE));
//cmds.add(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_START));
//cmds.clear();
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_START)) .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START))
.exe(); .exe();
} }
/** /**
* 停止下载 * 停止下载
*
* @see #stop()
*/ */
protected void pause() { @Deprecated protected void pause() {
stop();
}
@Override public void stop() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_STOP)) .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_STOP))
.exe(); .exe();
} }
/** /**
* 恢复下载 * 恢复下载
*/ */
protected void resume() { @Override public void resume() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_START)) .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_START))
.exe(); .exe();
} }
/** /**
* 取消下载 * 取消下载
*/ */
public void cancel() { @Override public void cancel() {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_CANCEL)) .setCmd(CommonUtil.createCmd(mTargetName, mTaskEntity, NormalCmdFactory.TASK_CANCEL))
.exe(); .exe();
} }

@ -20,7 +20,7 @@ package com.arialyy.aria.core.inf;
* Created by AriaL on 2017/6/27. * Created by AriaL on 2017/6/27.
*/ */
public abstract class AbsReceiver<ENTITY extends AbsEntity> implements IReceiver<ENTITY>{ public abstract class AbsReceiver<ENTITY extends AbsNormalEntity> implements IReceiver<ENTITY>{
public String targetName; public String targetName;
public Object obj; public Object obj;

@ -21,7 +21,7 @@ import com.arialyy.aria.util.CommonUtil;
/** /**
* Created by lyy on 2017/6/3. * Created by lyy on 2017/6/3.
*/ */
public abstract class AbsTask<TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsEntity> public abstract class AbsTask<TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsNormalEntity>
implements ITask<ENTITY> { implements ITask<ENTITY> {
protected ENTITY mEntity; protected ENTITY mEntity;

@ -44,5 +44,5 @@ public abstract class AbsTaskEntity {
*/ */
public boolean removeFile = false; public boolean removeFile = false;
public abstract AbsEntity getEntity(); public abstract AbsNormalEntity getEntity();
} }

@ -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<TARGET extends 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<String, String> headers);
/**
* 设置请求类型
*
* @param requestEnum {@link RequestEnum}
*/
TARGET setRequestMode(RequestEnum requestEnum);
/**
* 开始下载
*/
void start();
/**
* 停止下载
*/
void stop();
/**
* 恢复下载
*/
void resume();
/**
* 取消下载
*/
void cancel();
}

@ -19,7 +19,11 @@ package com.arialyy.aria.core.inf;
* Created by lyy on 2017/2/13. * Created by lyy on 2017/2/13.
*/ */
public interface ITask<ENTITY extends AbsEntity> { public interface ITask<ENTITY extends AbsNormalEntity> {
/**
* 获取
*/
/** /**
* 暂停任务并让任务处于等待状态 * 暂停任务并让任务处于等待状态

@ -17,11 +17,9 @@
package com.arialyy.aria.core.queue; package com.arialyy.aria.core.queue;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.AriaManager; 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.AbsTask;
import com.arialyy.aria.core.inf.ITask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.queue.pool.CachePool; import com.arialyy.aria.core.queue.pool.CachePool;
import com.arialyy.aria.core.queue.pool.ExecutePool; import com.arialyy.aria.core.queue.pool.ExecutePool;
@ -31,7 +29,7 @@ import java.util.Set;
* Created by lyy on 2017/2/23. * Created by lyy on 2017/2/23.
* 任务队列 * 任务队列
*/ */
abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsEntity> abstract class AbsTaskQueue<TASK extends AbsTask, TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsNormalEntity>
implements ITaskQueue<TASK, TASK_ENTITY, ENTITY> { implements ITaskQueue<TASK, TASK_ENTITY, ENTITY> {
private final String TAG = "AbsTaskQueue"; private final String TAG = "AbsTaskQueue";
CachePool<TASK> mCachePool = new CachePool<>(); CachePool<TASK> mCachePool = new CachePool<>();

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

@ -20,11 +20,10 @@ import android.os.Message;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.download.DownloadTask; 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.AbsTask;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.inf.IEntity; 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.queue.ITaskQueue;
import com.arialyy.aria.core.upload.UploadTask; import com.arialyy.aria.core.upload.UploadTask;
import java.util.Iterator; import java.util.Iterator;
@ -35,7 +34,7 @@ import java.util.concurrent.ConcurrentHashMap;
/** /**
* Created by lyy on 2017/6/4. * Created by lyy on 2017/6/4.
*/ */
public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsEntity, TASK extends AbsTask<TASK_ENTITY, ENTITY>, QUEUE extends ITaskQueue<TASK, TASK_ENTITY, ENTITY>> public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY extends AbsNormalEntity, TASK extends AbsTask<TASK_ENTITY, ENTITY>, QUEUE extends ITaskQueue<TASK, TASK_ENTITY, ENTITY>>
implements ISchedulers<TASK> { implements ISchedulers<TASK> {
private static final String TAG = "AbsSchedulers"; private static final String TAG = "AbsSchedulers";

@ -17,14 +17,14 @@ package com.arialyy.aria.core.upload;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsNormalEntity;
import com.arialyy.aria.orm.Ignore; import com.arialyy.aria.orm.Ignore;
/** /**
* Created by lyy on 2017/2/9. * 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 String filePath; //文件路径
private boolean isComplete = false; private boolean isComplete = false;

@ -17,14 +17,12 @@ package com.arialyy.aria.core.upload;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.command.normal.AbsNormalCmd;
import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.download.DownloadTaskEntity;
import com.arialyy.aria.core.inf.AbsReceiver; import com.arialyy.aria.core.inf.AbsReceiver;
import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.IReceiver; 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.ISchedulerListener;
import com.arialyy.aria.core.scheduler.UploadSchedulers; import com.arialyy.aria.core.scheduler.UploadSchedulers;
import com.arialyy.aria.orm.DbEntity; import com.arialyy.aria.orm.DbEntity;
@ -84,11 +82,11 @@ public class UploadReceiver extends AbsReceiver<UploadEntity> {
@Override public void stopAllTask() { @Override public void stopAllTask() {
List<UploadEntity> allEntity = DbEntity.findAllData(UploadEntity.class); List<UploadEntity> allEntity = DbEntity.findAllData(UploadEntity.class);
List<AbsCmd> stopCmds = new ArrayList<>(); List<AbsNormalCmd> stopCmds = new ArrayList<>();
for (UploadEntity entity : allEntity) { for (UploadEntity entity : allEntity) {
if (entity.getState() == IEntity.STATE_RUNNING) { if (entity.getState() == IEntity.STATE_RUNNING) {
stopCmds.add( 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(); AriaManager.getInstance(AriaManager.APP).setCmds(stopCmds).exe();
@ -105,7 +103,7 @@ public class UploadReceiver extends AbsReceiver<UploadEntity> {
AriaManager.getInstance(AriaManager.APP) AriaManager.getInstance(AriaManager.APP)
.setCmd( .setCmd(
CommonUtil.createCmd(targetName, new DownloadTaskEntity(), CmdFactory.TASK_CANCEL_ALL)) CommonUtil.createCmd(targetName, new DownloadTaskEntity(), NormalCmdFactory.TASK_CANCEL_ALL))
.exe(); .exe();
Set<String> keys = am.getReceiver().keySet(); Set<String> keys = am.getReceiver().keySet();

@ -16,28 +16,25 @@
package com.arialyy.aria.core.upload; package com.arialyy.aria.core.upload;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import com.arialyy.aria.core.RequestEnum; import com.arialyy.aria.core.inf.AbsNormalTarget;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.queue.UploadTaskQueue; import com.arialyy.aria.core.queue.UploadTaskQueue;
import com.arialyy.aria.orm.DbEntity;
import java.util.Map;
/** /**
* Created by lyy on 2017/2/28. * Created by lyy on 2017/2/28.
*/ */
public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> { public class UploadTarget extends AbsNormalTarget<UploadTarget, UploadEntity, UploadTaskEntity> {
UploadTarget(UploadEntity entity, String targetName) { UploadTarget(UploadEntity entity, String targetName) {
this.entity = entity; this.mEntity = entity;
this.targetName = targetName; this.mTargetName = targetName;
taskEntity = new UploadTaskEntity(entity); mTaskEntity = new UploadTaskEntity(entity);
} }
/** /**
* 设置userAgent * 设置userAgent
*/ */
public UploadTarget setUserAngent(@NonNull String userAgent) { public UploadTarget setUserAngent(@NonNull String userAgent) {
taskEntity.userAgent = userAgent; mTaskEntity.userAgent = userAgent;
return this; return this;
} }
@ -47,7 +44,7 @@ public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> {
* @param uploadUrl 上传路径 * @param uploadUrl 上传路径
*/ */
public UploadTarget setUploadUrl(@NonNull String uploadUrl) { public UploadTarget setUploadUrl(@NonNull String uploadUrl) {
taskEntity.uploadUrl = uploadUrl; mTaskEntity.uploadUrl = uploadUrl;
return this; return this;
} }
@ -57,7 +54,7 @@ public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> {
* @param attachment 附件key * @param attachment 附件key
*/ */
public UploadTarget setAttachment(@NonNull String attachment) { public UploadTarget setAttachment(@NonNull String attachment) {
taskEntity.attachment = attachment; mTaskEntity.attachment = attachment;
return this; return this;
} }
@ -65,7 +62,7 @@ public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> {
* 设置文件名 * 设置文件名
*/ */
public UploadTarget setFileName(String fileName) { public UploadTarget setFileName(String fileName) {
entity.setFileName(fileName); mEntity.setFileName(fileName);
return this; return this;
} }
@ -75,28 +72,7 @@ public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> {
* @param contentType tipmultipart/form-data * @param contentType tipmultipart/form-data
*/ */
public UploadTarget setContentType(String contentType) { public UploadTarget setContentType(String contentType) {
taskEntity.contentType = contentType; mTaskEntity.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头部的keyValue为http头对应的配置
*/
public UploadTarget addHeaders(Map<String, String> headers) {
super._addHeaders(headers);
return this; return this;
} }
@ -104,28 +80,16 @@ public class UploadTarget extends AbsTarget<UploadEntity, UploadTaskEntity> {
* 下载任务是否存在 * 下载任务是否存在
*/ */
@Override public boolean taskExists() { @Override public boolean taskExists() {
return UploadTaskQueue.getInstance().getTask(entity.getFilePath()) != null; return UploadTaskQueue.getInstance().getTask(mEntity.getFilePath()) != null;
}
/**
* 设置请求类型
*
* @param requestEnum {@link RequestEnum}
*/
public UploadTarget setRequestMode(RequestEnum requestEnum) {
super._setRequestMode(requestEnum);
return this;
} }
private UploadEntity getDownloadEntity() {
return entity;
}
/** /**
* 是否在下载 * 是否在下载
*/ */
public boolean isUploading() { public boolean isUploading() {
UploadTask task = UploadTaskQueue.getInstance().getTask(entity); UploadTask task = UploadTaskQueue.getInstance().getTask(mEntity);
return task != null && task.isRunning(); return task != null && task.isRunning();
} }
} }

@ -23,8 +23,8 @@ import android.net.Uri;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.CmdFactory; import com.arialyy.aria.core.command.normal.NormalCmdFactory;
import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.command.normal.AbsNormalCmd;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.inf.AbsTaskEntity; import com.arialyy.aria.core.inf.AbsTaskEntity;
import com.arialyy.aria.core.upload.UploadEntity; import com.arialyy.aria.core.upload.UploadEntity;
@ -225,8 +225,8 @@ public class CommonUtil {
} }
} }
public static <T extends AbsTaskEntity> AbsCmd createCmd(String target, T entity, int cmd) { public static <T extends AbsTaskEntity> AbsNormalCmd createCmd(String target, T entity, int cmd) {
return CmdFactory.getInstance().createCmd(target, entity, cmd); return NormalCmdFactory.getInstance().createCmd(target, entity, cmd);
} }
/** /**

Loading…
Cancel
Save