|
|
@ -29,10 +29,13 @@ import java.util.List; |
|
|
|
* https://github.com/AriaLyy/Aria
|
|
|
|
* https://github.com/AriaLyy/Aria
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class AMTarget { |
|
|
|
public class AMTarget { |
|
|
|
private AMReceiver mReceiver; |
|
|
|
//private AMReceiver mReceiver;
|
|
|
|
|
|
|
|
DownloadEntity entity; |
|
|
|
|
|
|
|
String targetName; |
|
|
|
|
|
|
|
|
|
|
|
AMTarget(AMReceiver receiver) { |
|
|
|
AMTarget(DownloadEntity entity, String targetName) { |
|
|
|
this.mReceiver = receiver; |
|
|
|
this.entity = entity; |
|
|
|
|
|
|
|
this.targetName = targetName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -42,7 +45,7 @@ public class AMTarget { |
|
|
|
if (TextUtils.isEmpty(downloadPath)) { |
|
|
|
if (TextUtils.isEmpty(downloadPath)) { |
|
|
|
throw new IllegalArgumentException("文件保持路径不能为null"); |
|
|
|
throw new IllegalArgumentException("文件保持路径不能为null"); |
|
|
|
} |
|
|
|
} |
|
|
|
mReceiver.entity.setDownloadPath(downloadPath); |
|
|
|
entity.setDownloadPath(downloadPath); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -53,7 +56,7 @@ public class AMTarget { |
|
|
|
if (TextUtils.isEmpty(downloadName)) { |
|
|
|
if (TextUtils.isEmpty(downloadName)) { |
|
|
|
throw new IllegalArgumentException("文件名不能为null"); |
|
|
|
throw new IllegalArgumentException("文件名不能为null"); |
|
|
|
} |
|
|
|
} |
|
|
|
mReceiver.entity.setFileName(downloadName); |
|
|
|
entity.setFileName(downloadName); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -61,7 +64,7 @@ public class AMTarget { |
|
|
|
* 获取下载文件大小 |
|
|
|
* 获取下载文件大小 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public long getFileSize() { |
|
|
|
public long getFileSize() { |
|
|
|
DownloadEntity entity = getDownloadEntity(mReceiver.entity.getDownloadUrl()); |
|
|
|
DownloadEntity entity = getDownloadEntity(this.entity.getDownloadUrl()); |
|
|
|
if (entity == null) { |
|
|
|
if (entity == null) { |
|
|
|
throw new NullPointerException("下载管理器中没有改任务"); |
|
|
|
throw new NullPointerException("下载管理器中没有改任务"); |
|
|
|
} |
|
|
|
} |
|
|
@ -72,7 +75,7 @@ public class AMTarget { |
|
|
|
* 获取当前下载进度,如果下載实体存在,则返回当前进度 |
|
|
|
* 获取当前下载进度,如果下載实体存在,则返回当前进度 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public long getCurrentProgress() { |
|
|
|
public long getCurrentProgress() { |
|
|
|
DownloadEntity entity = getDownloadEntity(mReceiver.entity.getDownloadUrl()); |
|
|
|
DownloadEntity entity = getDownloadEntity(this.entity.getDownloadUrl()); |
|
|
|
if (entity == null) { |
|
|
|
if (entity == null) { |
|
|
|
throw new NullPointerException("下载管理器中没有改任务"); |
|
|
|
throw new NullPointerException("下载管理器中没有改任务"); |
|
|
|
} |
|
|
|
} |
|
|
@ -89,8 +92,7 @@ public class AMTarget { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void add() { |
|
|
|
public void add() { |
|
|
|
DownloadManager.getInstance() |
|
|
|
DownloadManager.getInstance() |
|
|
|
.setCmd( |
|
|
|
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_CREATE)) |
|
|
|
CommonUtil.createCmd(mReceiver.targetName, mReceiver.entity, CmdFactory.TASK_CREATE)) |
|
|
|
|
|
|
|
.exe(); |
|
|
|
.exe(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -99,8 +101,8 @@ public class AMTarget { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void start() { |
|
|
|
public void start() { |
|
|
|
List<IDownloadCmd> cmds = new ArrayList<>(); |
|
|
|
List<IDownloadCmd> cmds = new ArrayList<>(); |
|
|
|
cmds.add(CommonUtil.createCmd(mReceiver.targetName, mReceiver.entity, CmdFactory.TASK_CREATE)); |
|
|
|
cmds.add(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_CREATE)); |
|
|
|
cmds.add(CommonUtil.createCmd(mReceiver.targetName, mReceiver.entity, CmdFactory.TASK_START)); |
|
|
|
cmds.add(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_START)); |
|
|
|
DownloadManager.getInstance().setCmds(cmds).exe(); |
|
|
|
DownloadManager.getInstance().setCmds(cmds).exe(); |
|
|
|
cmds.clear(); |
|
|
|
cmds.clear(); |
|
|
|
} |
|
|
|
} |
|
|
@ -110,7 +112,7 @@ public class AMTarget { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void stop() { |
|
|
|
public void stop() { |
|
|
|
DownloadManager.getInstance() |
|
|
|
DownloadManager.getInstance() |
|
|
|
.setCmd(CommonUtil.createCmd(mReceiver.targetName, mReceiver.entity, CmdFactory.TASK_STOP)) |
|
|
|
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_STOP)) |
|
|
|
.exe(); |
|
|
|
.exe(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -119,7 +121,7 @@ public class AMTarget { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void resume() { |
|
|
|
public void resume() { |
|
|
|
DownloadManager.getInstance() |
|
|
|
DownloadManager.getInstance() |
|
|
|
.setCmd(CommonUtil.createCmd(mReceiver.targetName, mReceiver.entity, CmdFactory.TASK_START)) |
|
|
|
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_START)) |
|
|
|
.exe(); |
|
|
|
.exe(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -128,8 +130,7 @@ public class AMTarget { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public void cancel() { |
|
|
|
public void cancel() { |
|
|
|
DownloadManager.getInstance() |
|
|
|
DownloadManager.getInstance() |
|
|
|
.setCmd( |
|
|
|
.setCmd(CommonUtil.createCmd(targetName, entity, CmdFactory.TASK_CANCEL)) |
|
|
|
CommonUtil.createCmd(mReceiver.targetName, mReceiver.entity, CmdFactory.TASK_CANCEL)) |
|
|
|
|
|
|
|
.exe(); |
|
|
|
.exe(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -137,7 +138,7 @@ public class AMTarget { |
|
|
|
* 是否在下载 |
|
|
|
* 是否在下载 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public boolean isDownloading() { |
|
|
|
public boolean isDownloading() { |
|
|
|
return DownloadManager.getInstance().getTaskQueue().getTask(mReceiver.entity).isDownloading(); |
|
|
|
return DownloadManager.getInstance().getTaskQueue().getTask(entity).isDownloading(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|