DownloadTarget 添加获取任务进度百分比接口
This commit is contained in:
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user