diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/BaseListener.java similarity index 69% rename from Aria/src/main/java/com/arialyy/aria/core/download/DListener.java rename to Aria/src/main/java/com/arialyy/aria/core/download/BaseListener.java index 2d31b0d8..dbbed555 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/BaseListener.java @@ -17,10 +17,10 @@ package com.arialyy.aria.core.download; import android.os.Handler; import com.arialyy.aria.core.AriaManager; -import com.arialyy.aria.core.download.downloader.DownloadListener; import com.arialyy.aria.core.inf.AbsEntity; import com.arialyy.aria.core.inf.AbsTask; import com.arialyy.aria.core.inf.IEntity; +import com.arialyy.aria.core.inf.IEventListener; import com.arialyy.aria.core.scheduler.ISchedulers; import com.arialyy.aria.util.CommonUtil; import java.lang.ref.WeakReference; @@ -28,22 +28,23 @@ import java.lang.ref.WeakReference; /** * 下载监听类 */ -class DListener> - extends DownloadListener { +class BaseListener> + implements IEventListener { private WeakReference outHandler; - private long lastLen = 0; //上一次发送长度 + private long mLastLen = 0; //上一次发送长度 private boolean isFirst = true; - private ENTITY entity; - private TASK task; + protected ENTITY mEntity; + protected TASK mTask; private boolean isConvertSpeed = false; boolean isWait = false; - DListener(TASK task, Handler outHandler) { + BaseListener(TASK task, Handler outHandler) { this.outHandler = new WeakReference<>(outHandler); - this.task = new WeakReference<>(task).get(); - this.entity = this.task.getEntity(); + this.mTask = new WeakReference<>(task).get(); + this.mEntity = this.mTask.getEntity(); final AriaManager manager = AriaManager.getInstance(AriaManager.APP); isConvertSpeed = manager.getDownloadConfig().isConvertSpeed(); + mLastLen = mEntity.getCurrentProgress(); } @Override public void onPre() { @@ -52,8 +53,8 @@ class DListener> } @Override public void onPostPre(long fileSize) { - entity.setFileSize(fileSize); - entity.setConvertFileSize(CommonUtil.formatFileSize(fileSize)); + mEntity.setFileSize(fileSize); + mEntity.setConvertFileSize(CommonUtil.formatFileSize(fileSize)); saveData(IEntity.STATE_POST_PRE, -1); sendInState2Target(ISchedulers.POST_PRE); } @@ -69,15 +70,15 @@ class DListener> } @Override public void onProgress(long currentLocation) { - entity.setCurrentProgress(currentLocation); - long speed = currentLocation - lastLen; + mEntity.setCurrentProgress(currentLocation); + long speed = currentLocation - mLastLen; if (isFirst) { speed = 0; isFirst = false; } handleSpeed(speed); sendInState2Target(ISchedulers.RUNNING); - lastLen = currentLocation; + mLastLen = currentLocation; } @Override public void onStop(long stopLocation) { @@ -93,23 +94,23 @@ class DListener> } @Override public void onComplete() { - saveData(IEntity.STATE_COMPLETE, entity.getFileSize()); + saveData(IEntity.STATE_COMPLETE, mEntity.getFileSize()); handleSpeed(0); sendInState2Target(ISchedulers.COMPLETE); } @Override public void onFail() { - entity.setFailNum(entity.getFailNum() + 1); - saveData(IEntity.STATE_FAIL, -1); + mEntity.setFailNum(mEntity.getFailNum() + 1); + saveData(IEntity.STATE_FAIL, mEntity.getCurrentProgress()); handleSpeed(0); sendInState2Target(ISchedulers.FAIL); } private void handleSpeed(long speed) { if (isConvertSpeed) { - entity.setConvertSpeed(CommonUtil.formatFileSize(speed) + "/s"); + mEntity.setConvertSpeed(CommonUtil.formatFileSize(speed < 0 ? 0 : speed) + "/s"); } else { - entity.setSpeed(speed); + mEntity.setSpeed(speed < 0 ? 0 : speed); } } @@ -120,25 +121,25 @@ class DListener> */ private void sendInState2Target(int state) { if (outHandler.get() != null) { - outHandler.get().obtainMessage(state, task).sendToTarget(); + outHandler.get().obtainMessage(state, mTask).sendToTarget(); } } private void saveData(int state, long location) { + mEntity.setComplete(state == IEntity.STATE_COMPLETE); if (state == IEntity.STATE_CANCEL) { - entity.deleteData(); + mEntity.deleteData(); } else if (state == IEntity.STATE_COMPLETE) { - entity.setState(state); - entity.setComplete(true); - entity.setCompleteTime(System.currentTimeMillis()); - entity.setCurrentProgress(entity.getFileSize()); - entity.update(); + mEntity.setState(state); + mEntity.setCompleteTime(System.currentTimeMillis()); + mEntity.setCurrentProgress(mEntity.getFileSize()); + mEntity.update(); } else { - entity.setState(state); + mEntity.setState(state); if (location != -1) { - entity.setCurrentProgress(location); + mEntity.setCurrentProgress(location); } - entity.update(); + mEntity.update(); } } } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java new file mode 100644 index 00000000..e590bd1a --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.download; + +import android.os.Handler; +import android.util.Log; +import com.arialyy.aria.core.download.downloader.IDownloadGroupListener; + +/** + * Created by Aria.Lao on 2017/7/20. + * 任务组下载事件 + */ +class DownloadGroupListener extends BaseListener + implements IDownloadGroupListener { + private final String TAG = "DownloadGroupListener"; + + DownloadGroupListener(DownloadGroupTask task, Handler outHandler) { + super(task, outHandler); + } + + @Override public void supportBreakpoint(boolean support, DownloadEntity subEntity) { + + } + + @Override public void onSubStart(DownloadEntity subEntity) { + + } + + @Override public void onSubStop(DownloadEntity subEntity) { + saveCurrentLocation(); + } + + @Override public void onSubComplete(DownloadEntity subEntity) { + saveCurrentLocation(); + } + + @Override public void onSubFail(DownloadEntity subEntity) { + saveCurrentLocation(); + } + + @Override public void onSubCancel(DownloadEntity entity) { + saveCurrentLocation(); + } + + private void saveCurrentLocation() { + long location = 0; + for (DownloadEntity e : mEntity.getSubTask()) { + location += e.getCurrentProgress(); + } + mEntity.setCurrentProgress(location); + mEntity.update(); + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java index 1a375bba..6c668ad2 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTask.java @@ -29,7 +29,7 @@ import com.arialyy.aria.util.CheckUtil; */ public class DownloadGroupTask extends AbsGroupTask { private final String TAG = "DownloadGroupTask"; - private DListener mListener; + private DownloadGroupListener mListener; private IDownloadUtil mUtil; private DownloadGroupTask(DownloadGroupTaskEntity taskEntity, Handler outHandler) { @@ -37,7 +37,7 @@ public class DownloadGroupTask extends AbsGroupTask(this, mOutHandler); + mListener = new DownloadGroupListener(this, mOutHandler); mUtil = new DownloadGroupUtil(mListener, mTaskEntity); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadListener.java new file mode 100644 index 00000000..3d758029 --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadListener.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.download; + +import android.os.Handler; +import com.arialyy.aria.core.download.downloader.IDownloadListener; + +/** + * Created by Aria.Lao on 2017/7/20. + * 普通任务下载的事件监听器 + */ +class DownloadListener extends BaseListener + implements IDownloadListener { + DownloadListener(DownloadTask task, Handler outHandler) { + super(task, outHandler); + } + + @Override public void supportBreakpoint(boolean support) { + + } + +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java index 6e08b321..de0b2066 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadTask.java @@ -32,14 +32,14 @@ import java.io.File; public class DownloadTask extends AbsNormalTask { public static final String TAG = "DownloadTask"; - private DListener mListener; + private DownloadListener mListener; private SimpleDownloadUtil mUtil; private DownloadTask(DownloadTaskEntity taskEntity, Handler outHandler) { mEntity = taskEntity.getEntity(); mOutHandler = outHandler; mContext = AriaManager.APP; - mListener = new DListener<>(this, mOutHandler); + mListener = new DownloadListener(this, mOutHandler); mUtil = new SimpleDownloadUtil(taskEntity, mListener); } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java index d8a44363..fefe5a20 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadGroupUtil.java @@ -45,7 +45,7 @@ public class DownloadGroupUtil implements IDownloadUtil { private long mCurrentLocation = 0; private ExecutorService mInfoPool; private ExecutorService mExePool; - private IDownloadListener mListener; + private IDownloadGroupListener mListener; private DownloadGroupTaskEntity mTaskEntity; private boolean isRunning = true; private Timer mTimer; @@ -87,7 +87,7 @@ public class DownloadGroupUtil implements IDownloadUtil { //实际的下载任务数 private int mActualTaskNum = 0; - public DownloadGroupUtil(IDownloadListener listener, DownloadGroupTaskEntity taskEntity) { + public DownloadGroupUtil(IDownloadGroupListener listener, DownloadGroupTaskEntity taskEntity) { mListener = listener; mTaskEntity = taskEntity; mInfoPool = Executors.newCachedThreadPool(); @@ -102,8 +102,7 @@ public class DownloadGroupUtil implements IDownloadUtil { } for (DownloadEntity entity : mTaskEntity.entity.getSubTask()) { File file = new File(entity.getDownloadPath()); - if (entity.isComplete() && file.exists()) { - mTotalSize += entity.getFileSize(); + if (entity.getState() == IEntity.STATE_COMPLETE && file.exists()) { mCompleteNum++; mInitNum++; mCurrentLocation += entity.getFileSize(); @@ -111,6 +110,7 @@ public class DownloadGroupUtil implements IDownloadUtil { mExeMap.put(entity.getDownloadUrl(), createChildDownloadTask(entity)); mCurrentLocation += entity.getCurrentProgress(); } + mTotalSize += entity.getFileSize(); } } @@ -127,8 +127,7 @@ public class DownloadGroupUtil implements IDownloadUtil { } @Override public void cancelDownload() { - isRunning = false; - closeTimer(); + closeTimer(false); mListener.onCancel(); if (!mInfoPool.isShutdown()) { mInfoPool.shutdown(); @@ -161,8 +160,7 @@ public class DownloadGroupUtil implements IDownloadUtil { } @Override public void stopDownload() { - isRunning = false; - closeTimer(); + closeTimer(false); mListener.onStop(mCurrentLocation); if (!mInfoPool.isShutdown()) { mInfoPool.shutdown(); @@ -182,14 +180,23 @@ public class DownloadGroupUtil implements IDownloadUtil { @Override public void startDownload() { isRunning = true; + mFailNum = 0; Set keys = mExeMap.keySet(); mListener.onPre(); + int i = 0; for (String key : keys) { DownloadTaskEntity taskEntity = mExeMap.get(key); if (taskEntity != null) { - mInfoPool.execute(createFileInfoThread(taskEntity)); + if (taskEntity.getState() != IEntity.STATE_FAIL + && taskEntity.getState() != IEntity.STATE_WAIT) { + startChildDownload(taskEntity); + i++; + } else { + mInfoPool.execute(createFileInfoThread(taskEntity)); + } } } + if (i == mExeMap.size()) startRunningFlow(); } @Override public void resumeDownload() { @@ -214,7 +221,7 @@ public class DownloadGroupUtil implements IDownloadUtil { startChildDownload(te); } mInitNum++; - if (mInitNum + mInitFailNum == mTaskEntity.getEntity().getSubTask().size()) { + if (mInitNum + mInitFailNum >= mTaskEntity.getEntity().getSubTask().size()) { startRunningFlow(); } } @@ -235,7 +242,7 @@ public class DownloadGroupUtil implements IDownloadUtil { if (mActualTaskNum < 0) mActualTaskNum = 0; } failNum++; - if (mInitNum + mInitFailNum == mTaskEntity.getEntity().getSubTask().size()) { + if (mInitNum + mInitFailNum >= mTaskEntity.getEntity().getSubTask().size()) { startRunningFlow(); } } @@ -244,7 +251,8 @@ public class DownloadGroupUtil implements IDownloadUtil { return new FileInfoThread(taskEntity, callback); } - private void closeTimer() { + private void closeTimer(boolean isRunning) { + this.isRunning = isRunning; if (mTimer != null) { mTimer.purge(); mTimer.cancel(); @@ -255,13 +263,15 @@ public class DownloadGroupUtil implements IDownloadUtil { * 开始进度流程 */ private void startRunningFlow() { - closeTimer(); + closeTimer(true); mListener.onPostPre(mTotalSize); mListener.onStart(mCurrentLocation); mTimer = new Timer(true); mTimer.schedule(new TimerTask() { @Override public void run() { - if (mCurrentLocation >= 0) { + if (!isRunning) { + closeTimer(false); + } else if (mCurrentLocation >= 0) { mListener.onProgress(mCurrentLocation); } } @@ -304,7 +314,7 @@ public class DownloadGroupUtil implements IDownloadUtil { /** * 子任务事件监听 */ - private class ChildDownloadListener extends DownloadListener { + private class ChildDownloadListener implements IDownloadListener { DownloadTaskEntity taskEntity; DownloadEntity entity; @@ -314,6 +324,8 @@ public class DownloadGroupUtil implements IDownloadUtil { ChildDownloadListener(DownloadTaskEntity entity) { this.taskEntity = entity; this.entity = taskEntity.getEntity(); + lastLen = this.entity.getCurrentProgress(); + this.entity.setFailNum(0); } @Override public void onPre() { @@ -347,26 +359,35 @@ public class DownloadGroupUtil implements IDownloadUtil { @Override public void onStop(long stopLocation) { saveData(IEntity.STATE_STOP, stopLocation); handleSpeed(0); + mListener.onSubStop(entity); } @Override public void onCancel() { saveData(IEntity.STATE_CANCEL, -1); handleSpeed(0); + mListener.onSubCancel(entity); } @Override public void onComplete() { saveData(IEntity.STATE_COMPLETE, entity.getFileSize()); mCompleteNum++; + handleSpeed(0); + mListener.onSubComplete(entity); + //如果子任务完成的数量和总任务数一致,表示任务组任务已经完成 + if (mCompleteNum >= mTaskEntity.getEntity().getSubTask().size()){ + closeTimer(false); + mListener.onComplete(); + } + //如果子任务完成数量加上失败的数量和总任务数一致,则任务组停止下载 if (mCompleteNum + mFailNum >= mActualTaskNum) { - closeTimer(); + closeTimer(false); mListener.onComplete(); } - handleSpeed(0); } @Override public void onFail() { entity.setFailNum(entity.getFailNum() + 1); - saveData(IEntity.STATE_FAIL, -1); + saveData(IEntity.STATE_FAIL, lastLen); handleSpeed(0); reTry(); } @@ -376,13 +397,28 @@ public class DownloadGroupUtil implements IDownloadUtil { */ private void reTry() { if (entity.getFailNum() < 5) { - Downloader dt = mDownloaderMap.get(entity.getDownloadUrl()); - dt.startDownload(); + reStartTask(); } else { mFailNum++; + mListener.onSubFail(entity); + //如果失败的任务数大于实际的下载任务数,任务组停止下载 + if (mFailNum >= mActualTaskNum) { + closeTimer(false); + mListener.onStop(mCurrentLocation); + } } } + private void reStartTask() { + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + @Override public void run() { + Downloader dt = mDownloaderMap.get(entity.getDownloadUrl()); + dt.startDownload(); + } + }, 3000); + } + private void handleSpeed(long speed) { entity.setSpeed(speed); entity.setConvertSpeed(speed <= 0 ? "" : CommonUtil.formatFileSize(speed) + "/s"); @@ -394,10 +430,14 @@ public class DownloadGroupUtil implements IDownloadUtil { if (entity.isComplete()) { entity.setCompleteTime(System.currentTimeMillis()); entity.setCurrentProgress(entity.getFileSize()); - } else { + } else if (location > 0) { entity.setCurrentProgress(location); } entity.update(); } + + @Override public void supportBreakpoint(boolean support) { + + } } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadListener.java deleted file mode 100644 index f8d2349e..00000000 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/DownloadListener.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.arialyy.aria.core.download.downloader; - - -/** - * @author lyy - */ -public class DownloadListener implements IDownloadListener { - - @Override public void onResume(long resumeLocation) { - - } - - @Override public void supportBreakpoint(boolean support) { - - } - - @Override public void onCancel() { - - } - - @Override public void onFail() { - - } - - @Override public void onPre() { - - } - - @Override public void onPostPre(long fileSize) { - - } - - @Override public void onProgress(long currentLocation) { - - } - - @Override public void onChildComplete(long finishLocation) { - - } - - @Override public void onStart(long startLocation) { - - } - - @Override public void onChildResume(long resumeLocation) { - - } - - @Override public void onStop(long stopLocation) { - - } - - @Override public void onComplete() { - - } -} \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java index a7fa8721..172731e1 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/Downloader.java @@ -111,7 +111,7 @@ class Downloader implements Runnable, IDownloadUtil { mTimer = new Timer(true); mTimer.schedule(new TimerTask() { @Override public void run() { - if (mConstance.isComplete()) { + if (mConstance.isComplete() || !mConstance.isDownloading) { closeTimer(); } else if (mConstance.CURRENT_LOCATION >= 0) { mListener.onProgress(mConstance.CURRENT_LOCATION); @@ -343,7 +343,6 @@ class Downloader implements Runnable, IDownloadUtil { Long r = Long.parseLong(record + ""); mConstance.CURRENT_LOCATION += r - startL; Log.d(TAG, "任务【" + mEntity.getFileName() + "】线程__" + i + "__恢复下载"); - mListener.onChildResume(r); startL = r; recordL[rl] = i; rl++; diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadGroupListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadGroupListener.java new file mode 100644 index 00000000..2b0f130f --- /dev/null +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadGroupListener.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2016 AriaLyy(https://github.com/AriaLyy/Aria) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.arialyy.aria.core.download.downloader; + +import com.arialyy.aria.core.download.DownloadEntity; +import com.arialyy.aria.core.inf.IEventListener; + +/** + * Created by Aria.Lao on 2017/7/20. + * 下载任务组事件 + */ +public interface IDownloadGroupListener extends IEventListener { + + /** + * 子任务支持断点回调 + * + * @param support true,支持;false 不支持 + */ + void supportBreakpoint(boolean support, DownloadEntity subEntity); + + /** + * 子任务开始下载\恢复下载 + */ + void onSubStart(DownloadEntity subEntity); + + /** + * 子任务停止下载 + */ + void onSubStop(DownloadEntity subEntity); + + /** + * 子任务下载完成 + */ + void onSubComplete(DownloadEntity subEntity); + + /** + * 子任务下载失败 + */ + void onSubFail(DownloadEntity subEntity); + + /** + * 子任务取消下载 + */ + void onSubCancel(DownloadEntity subEntity); +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadListener.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadListener.java index aa6f3e2d..131c8779 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/IDownloadListener.java @@ -21,7 +21,7 @@ import com.arialyy.aria.core.inf.IEventListener; /** * 下载监听 */ -interface IDownloadListener extends IEventListener { +public interface IDownloadListener extends IEventListener { /** * 支持断点回调 @@ -29,14 +29,4 @@ interface IDownloadListener extends IEventListener { * @param support true,支持;false 不支持 */ void supportBreakpoint(boolean support); - - /** - * 单一线程的结束位置 - */ - void onChildComplete(long finishLocation); - - /** - * 子程恢复下载的位置 - */ - void onChildResume(long resumeLocation); } \ No newline at end of file diff --git a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/SingleThreadTask.java b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/SingleThreadTask.java index 8efe4eb3..65c51cc4 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/downloader/SingleThreadTask.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/downloader/SingleThreadTask.java @@ -134,7 +134,6 @@ final class SingleThreadTask implements Runnable { + mConfigEntity.THREAD_ID + "__下载完毕"); writeConfig(true, 1); - mListener.onChildComplete(mConfigEntity.END_LOCATION); CONSTANCE.COMPLETE_THREAD_NUM++; if (CONSTANCE.isComplete()) { File configFile = new File(mConfigFPath); diff --git a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java index ed651e99..84ec2588 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java +++ b/Aria/src/main/java/com/arialyy/aria/core/inf/AbsTaskEntity.java @@ -84,4 +84,13 @@ public abstract class AbsTaskEntity extends DbEntity { public int code; public abstract ENTITY getEntity(); + + /** + * 获取任务下载状态 + * + * @return {@link IEntity} + */ + public int getState() { + return getEntity().getState(); + } } diff --git a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java index 6123a62b..5c4d03e8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java +++ b/Aria/src/main/java/com/arialyy/aria/core/queue/pool/DownloadExecutePool.java @@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit; * Created by AriaL on 2017/6/29. * 单个下载任务的执行池 */ -public class DownloadExecutePool extends BaseExecutePool { +class DownloadExecutePool extends BaseExecutePool { private final String TAG = "DownloadExecutePool"; @Override protected int getMaxSize() { @@ -41,6 +41,7 @@ public class DownloadExecutePool extends BaseExecutePool - + - + - +