|
|
@ -89,21 +89,15 @@ public class DownloadTaskQueue implements ITaskQueue { |
|
|
|
|
|
|
|
|
|
|
|
@Override public void stopTask(Task task) { |
|
|
|
@Override public void stopTask(Task task) { |
|
|
|
if (!task.isDownloading()) Log.w(TAG, "停止任务失败,【任务已经停止】"); |
|
|
|
if (!task.isDownloading()) Log.w(TAG, "停止任务失败,【任务已经停止】"); |
|
|
|
|
|
|
|
if (mExecutePool.removeTask(task)) { |
|
|
|
task.stop(); |
|
|
|
task.stop(); |
|
|
|
//if (task.isDownloading()) {
|
|
|
|
} else { |
|
|
|
// if (mExecutePool.removeTask(task)) {
|
|
|
|
task.stop(); |
|
|
|
// task.stop();
|
|
|
|
Log.w(TAG, "停止任务失败,【任务已经停止】"); |
|
|
|
// }
|
|
|
|
} |
|
|
|
//} else {
|
|
|
|
|
|
|
|
// task.stop();
|
|
|
|
|
|
|
|
// Log.w(TAG, "停止任务失败,【任务已经停止】");
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override public void cancelTask(Task task) { |
|
|
|
@Override public void cancelTask(Task task) { |
|
|
|
//if (mExecutePool.removeTask(task) || mCachePool.removeTask(task)) {
|
|
|
|
|
|
|
|
// task.cancel();
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
task.cancel(); |
|
|
|
task.cancel(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -119,10 +113,6 @@ public class DownloadTaskQueue implements ITaskQueue { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//@Override public IDownloadSchedulers getDownloadSchedulers() {
|
|
|
|
|
|
|
|
// return mSchedulers;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override public int size() { |
|
|
|
@Override public int size() { |
|
|
|
return mExecutePool.size(); |
|
|
|
return mExecutePool.size(); |
|
|
|
} |
|
|
|
} |
|
|
@ -159,12 +149,10 @@ public class DownloadTaskQueue implements ITaskQueue { |
|
|
|
@Override public Task createTask(String target, DownloadEntity entity) { |
|
|
|
@Override public Task createTask(String target, DownloadEntity entity) { |
|
|
|
Task task; |
|
|
|
Task task; |
|
|
|
if (TextUtils.isEmpty(target)) { |
|
|
|
if (TextUtils.isEmpty(target)) { |
|
|
|
//task = TaskFactory.getInstance().createTask(mContext, entity, mSchedulers);
|
|
|
|
|
|
|
|
task = |
|
|
|
task = |
|
|
|
TaskFactory.getInstance().createTask(mContext, entity, DownloadSchedulers.getInstance()); |
|
|
|
TaskFactory.getInstance().createTask(mContext, entity, DownloadSchedulers.getInstance()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
task = TaskFactory.getInstance() |
|
|
|
task = TaskFactory.getInstance() |
|
|
|
//.createTask(target.getClass().getName(), mContext, entity, mSchedulers);
|
|
|
|
|
|
|
|
.createTask(target, mContext, entity, DownloadSchedulers.getInstance()); |
|
|
|
.createTask(target, mContext, entity, DownloadSchedulers.getInstance()); |
|
|
|
} |
|
|
|
} |
|
|
|
mCachePool.putTask(task); |
|
|
|
mCachePool.putTask(task); |
|
|
@ -197,29 +185,15 @@ public class DownloadTaskQueue implements ITaskQueue { |
|
|
|
return mCachePool.pollTask(); |
|
|
|
return mCachePool.pollTask(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//@Override public void setScheduler(IDownloadSchedulers schedulers) {
|
|
|
|
|
|
|
|
// mSchedulers = schedulers;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class Builder { |
|
|
|
public static class Builder { |
|
|
|
Context context; |
|
|
|
Context context; |
|
|
|
IDownloadSchedulers schedulers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Builder(Context context) { |
|
|
|
public Builder(Context context) { |
|
|
|
this.context = context.getApplicationContext(); |
|
|
|
this.context = context.getApplicationContext(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//public Builder setDownloadSchedulers(IDownloadSchedulers schedulers) {
|
|
|
|
|
|
|
|
// this.schedulers = schedulers;
|
|
|
|
|
|
|
|
// return this;
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DownloadTaskQueue build() { |
|
|
|
public DownloadTaskQueue build() { |
|
|
|
DownloadTaskQueue queue = new DownloadTaskQueue(context); |
|
|
|
DownloadTaskQueue queue = new DownloadTaskQueue(context); |
|
|
|
//if (schedulers == null) {
|
|
|
|
|
|
|
|
// schedulers = DownloadSchedulers.getInstance();
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//queue.setScheduler(schedulers);
|
|
|
|
|
|
|
|
return queue; |
|
|
|
return queue; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|