diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java index 06228179..d4a8f86a 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/DownloadTaskQueue.java @@ -89,21 +89,15 @@ public class DownloadTaskQueue implements ITaskQueue { @Override public void stopTask(Task task) { if (!task.isDownloading()) Log.w(TAG, "停止任务失败,【任务已经停止】"); - task.stop(); - //if (task.isDownloading()) { - // if (mExecutePool.removeTask(task)) { - // task.stop(); - // } - //} else { - // task.stop(); - // Log.w(TAG, "停止任务失败,【任务已经停止】"); - //} + if (mExecutePool.removeTask(task)) { + task.stop(); + } else { + task.stop(); + Log.w(TAG, "停止任务失败,【任务已经停止】"); + } } @Override public void cancelTask(Task task) { - //if (mExecutePool.removeTask(task) || mCachePool.removeTask(task)) { - // task.cancel(); - //} task.cancel(); } @@ -119,10 +113,6 @@ public class DownloadTaskQueue implements ITaskQueue { } } - //@Override public IDownloadSchedulers getDownloadSchedulers() { - // return mSchedulers; - //} - @Override public int size() { return mExecutePool.size(); } @@ -159,12 +149,10 @@ public class DownloadTaskQueue implements ITaskQueue { @Override public Task createTask(String target, DownloadEntity entity) { Task task; if (TextUtils.isEmpty(target)) { - //task = TaskFactory.getInstance().createTask(mContext, entity, mSchedulers); task = TaskFactory.getInstance().createTask(mContext, entity, DownloadSchedulers.getInstance()); } else { task = TaskFactory.getInstance() - //.createTask(target.getClass().getName(), mContext, entity, mSchedulers); .createTask(target, mContext, entity, DownloadSchedulers.getInstance()); } mCachePool.putTask(task); @@ -197,29 +185,15 @@ public class DownloadTaskQueue implements ITaskQueue { return mCachePool.pollTask(); } - //@Override public void setScheduler(IDownloadSchedulers schedulers) { - // mSchedulers = schedulers; - //} - public static class Builder { Context context; - IDownloadSchedulers schedulers; public Builder(Context context) { this.context = context.getApplicationContext(); } - //public Builder setDownloadSchedulers(IDownloadSchedulers schedulers) { - // this.schedulers = schedulers; - // return this; - //} - public DownloadTaskQueue build() { DownloadTaskQueue queue = new DownloadTaskQueue(context); - //if (schedulers == null) { - // schedulers = DownloadSchedulers.getInstance(); - //} - //queue.setScheduler(schedulers); return queue; } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java index 73163766..68576119 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/ITaskQueue.java @@ -73,11 +73,4 @@ public interface ITaskQueue extends IDownloader { * @return 下载任务 or null */ public Task getNextTask(); - - ///** - // * 设置下载调度器 - // * - // * @param schedulers 下载调度器{@link IDownloadSchedulers} - // */ - //public void setScheduler(IDownloadSchedulers schedulers); } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java index 5f5b8a4e..22a7d283 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadSchedulers.java @@ -16,6 +16,7 @@ package com.arialyy.aria.core.scheduler; +import android.os.CountDownTimer; import android.os.Message; import android.text.TextUtils; import android.util.Log; @@ -154,10 +155,8 @@ public class DownloadSchedulers implements IDownloadSchedulers { private void callback(int state, Task task, OnSchedulerListener listener) { if (listener != null) { - //Task task = mQueue.getTask(entity); if (task == null) { - //Log.e(TAG, "队列中没有下载链接【" + entity.getDownloadUrl() + "】的任务"); - Log.e(TAG, "传递的下载任务"); + Log.e(TAG, "TASK 为null,回调失败"); return; } switch (state) { @@ -195,9 +194,13 @@ public class DownloadSchedulers implements IDownloadSchedulers { * @param entity 失败实体 */ @Override public void handleFailTask(final DownloadEntity entity) { - new Thread(new Runnable() { - @Override public void run() { - final Configuration config = Configuration.getInstance(); + final Configuration config = Configuration.getInstance(); + CountDownTimer timer = new CountDownTimer(config.getReTryInterval(), 1000) { + @Override public void onTick(long millisUntilFinished) { + + } + + @Override public void onFinish() { if (entity.getFailNum() <= config.getReTryNum()) { Task task = mQueue.getTask(entity); mQueue.reTryStart(task); @@ -210,7 +213,8 @@ public class DownloadSchedulers implements IDownloadSchedulers { startNextTask(entity); } } - }).start(); + }; + timer.start(); } /** diff --git a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java b/Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java index c69ee94a..d5eb65e2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/task/DownloadUtil.java @@ -242,12 +242,16 @@ final class DownloadUtil implements IDownloadUtil, Runnable { handleBreakpoint(conn); } else if (code == HttpURLConnection.HTTP_OK || len < 0) { //在conn.setRequestProperty("Range", "bytes=" + 0 + "-");下,200为不支持断点状态 + if (len < 0){ + failDownload("任务【" + mDownloadEntity.getDownloadUrl() + "】下载失败,文件长度小于0"); + return; + } isSupportBreakpoint = false; mListener.supportBreakpoint(false); Log.w(TAG, "该下载链接不支持断点下载"); handleBreakpoint(conn); } else { - failDownload("下载失败,返回码:" + code); + failDownload("任务【" + mDownloadEntity.getDownloadUrl() + "】下载失败,返回码:" + code); } } catch (IOException e) { failDownload("下载失败【downloadUrl:" diff --git a/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java b/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java index 4f6fe2b1..10b64600 100644 --- a/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/orm/DbUtil.java @@ -113,7 +113,6 @@ public class DbUtil { params[i] = "'" + expression[i + 1] + "'"; } sql = String.format(sql, params); - Log.d(TAG, sql); print(DEL_DATA, sql); mDb.execSQL(sql); close(); @@ -185,7 +184,6 @@ public class DbUtil { params[i] = "'" + expression[i + 1] + "'"; } sql = String.format(sql, params); - Log.d(TAG, sql); print(FIND_DATA, sql); Cursor cursor = mDb.rawQuery(sql, null); return cursor.getCount() > 0 ? newInstanceEntity(clazz, cursor) : null;