DownloadTarget 添加获取任务进度百分比接口

pull/330/head
AriaLyy 8 years ago
parent 5ee2cba331
commit 52a4f1e7ea
  1. 13
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTarget.java
  2. 15
      Aria/src/main/java/com/arialyy/aria/core/inf/AbsTarget.java
  3. 4
      app/src/main/java/com/arialyy/simple/download/HighestPriorityActivity.java
  4. 4
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java

@ -66,6 +66,19 @@ public class DownloadTarget extends AbsTarget<DownloadEntity, DownloadTaskEntity
return this;
}
@Override public int getPercent() {
DownloadEntity entity = DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?",
this.entity.getDownloadUrl());
if (entity == null) {
Log.e("DownloadTarget", "下载管理器中没有该任务");
return 0;
}
if (entity.getFileSize() != 0) {
return (int) (entity.getCurrentProgress() * 100 / entity.getFileSize());
}
return super.getPercent();
}
/**
* 给url请求添加头部
*

@ -108,6 +108,15 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
return false;
}
/**
* 获取任务进度百分比
*
* @return 返回任务进度
*/
protected int getPercent() {
return 0;
}
/**
* 获取当前任务进度如果任务存在则返回当前进度
*
@ -118,14 +127,16 @@ public class AbsTarget<ENTITY extends IEntity, TASK_ENTITY extends ITaskEntity>
DownloadEntity entity = DownloadEntity.findData(DownloadEntity.class, "downloadUrl=?",
((DownloadEntity) this.entity).getDownloadUrl());
if (entity == null) {
throw new NullPointerException("下载管理器中没有该任务");
Log.e("DownloadTarget", "下载管理器中没有该任务");
return -1;
}
return entity.getCurrentProgress();
} else if (entity instanceof UploadEntity) {
UploadEntity entity = DbEntity.findData(UploadEntity.class, "filePath=?",
((UploadEntity) this.entity).getFilePath());
if (entity == null) {
throw new NullPointerException("没有找到该任务");
Log.e("DownloadTarget", "下载管理器中没有该任务");
return -1;
}
return entity.getCurrentProgress();
}

@ -52,9 +52,7 @@ public class HighestPriorityActivity extends BaseActivity<ActivityHighestPriorit
private void initWidget() {
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p);
mPb.setProgress(Aria.download(this).load(DOWNLOAD_URL).getPercent());
}
mAdapter = new DownloadAdapter(this, getModule(DownloadModule.class).getDownloadTaskList());
mList.setLayoutManager(new LinearLayoutManager(this));

@ -165,9 +165,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
private void init() {
if (Aria.download(this).taskExists(DOWNLOAD_URL)) {
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
int p = (int) (target.getCurrentProgress() * 100 / target.getFileSize());
mPb.setProgress(p);
mPb.setProgress(Aria.download(this).load(DOWNLOAD_URL).getPercent());
}
}

Loading…
Cancel
Save