代码优化

This commit is contained in:
AriaLyy
2017-03-21 21:43:55 +08:00
parent 76b9987f46
commit 80f3a38fc6
14 changed files with 160 additions and 110 deletions

View File

@ -43,7 +43,6 @@ import com.arialyy.aria.core.upload.UploadTask;
* .load(DOWNLOAD_URL) //下载地址,必填
* //文件保存路径,必填
* .setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
* .setDownloadName("test.apk") //文件名,必填
* .start();
* </code>
* <code>

View File

@ -21,6 +21,7 @@ import com.arialyy.aria.core.RequestEnum;
import com.arialyy.aria.core.inf.AbsTarget;
import com.arialyy.aria.core.queue.DownloadTaskQueue;
import com.arialyy.aria.util.CheckUtil;
import java.io.File;
import java.util.Map;
/**
@ -35,6 +36,14 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
taskEntity = new DownloadTaskEntity(entity);
}
@Override public void pause() {
super.pause();
}
@Override public void resume() {
super.resume();
}
/**
* 给url请求添加头部
*
@ -73,13 +82,16 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
if (TextUtils.isEmpty(downloadPath)) {
throw new IllegalArgumentException("文件保持路径不能为null");
}
File file = new File(downloadPath);
entity.setDownloadPath(downloadPath);
entity.setFileName(file.getName());
return this;
}
/**
* 设置文件名
*/
@Deprecated
public DownloadTarget setDownloadName(@NonNull String downloadName) {
if (TextUtils.isEmpty(downloadName)) {
throw new IllegalArgumentException("文件名不能为null");
@ -88,7 +100,6 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
return this;
}
private DownloadEntity getDownloadEntity(String downloadUrl) {
CheckUtil.checkDownloadUrl(downloadUrl);
return DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?", downloadUrl);

View File

@ -141,7 +141,7 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
/**
* 停止下载
*/
public void stop() {
protected void pause() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_STOP))
.exe();
@ -150,7 +150,7 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
/**
* 恢复下载
*/
public void resume() {
protected void resume() {
AriaManager.getInstance(AriaManager.APP)
.setCmd(CommonUtil.createCmd(targetName, taskEntity, CmdFactory.TASK_START))
.exe();
@ -168,7 +168,7 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
/**
* 重新下载
*/
public void reStart() {
void reStart() {
cancel();
start();
}