diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java index 50ffbe76..9261ad00 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGInfoTask.java @@ -20,7 +20,6 @@ import com.arialyy.aria.core.common.CompleteInfo; import com.arialyy.aria.core.download.DGTaskWrapper; import com.arialyy.aria.core.download.DTaskWrapper; import com.arialyy.aria.core.download.DownloadEntity; -import com.arialyy.aria.core.listener.DownloadGroupListener; import com.arialyy.aria.core.loader.IInfoTask; import com.arialyy.aria.core.loader.ILoaderVisitor; import com.arialyy.aria.exception.AriaException; @@ -44,9 +43,21 @@ public final class HttpDGInfoTask implements IInfoTask { private boolean getLenComplete = false; private AtomicInteger count = new AtomicInteger(); private AtomicInteger failCount = new AtomicInteger(); - private DownloadGroupListener listener; private boolean isStop = false, isCancel = false; + public interface DGInfoCallback extends Callback { + + /** + * 子任务失败 + */ + void onSubFail(DownloadEntity subEntity, AriaHTTPException e, boolean needRetry); + + /** + * 组合任务停止 + */ + void onStop(long len); + } + /** * 子任务回调 */ @@ -61,15 +72,14 @@ public final class HttpDGInfoTask implements IInfoTask { ALog.e(TAG, String.format("获取文件信息失败,url:%s", ((DownloadEntity) entity).getUrl())); count.getAndIncrement(); failCount.getAndIncrement(); - listener.onSubFail((DownloadEntity) entity, new AriaHTTPException( - String.format("子任务获取文件长度失败,url:%s", ((DownloadEntity) entity).getUrl()))); + ((DGInfoCallback) callback).onSubFail((DownloadEntity) entity, new AriaHTTPException( + String.format("子任务获取文件长度失败,url:%s", ((DownloadEntity) entity).getUrl())), needRetry); checkGetSizeComplete(count.get(), failCount.get()); } }; - HttpDGInfoTask(DGTaskWrapper wrapper, DownloadGroupListener listener) { + HttpDGInfoTask(DGTaskWrapper wrapper) { this.wrapper = wrapper; - this.listener = listener; } /** @@ -95,7 +105,7 @@ public final class HttpDGInfoTask implements IInfoTask { if (mPool != null && !getLenComplete) { ALog.d(TAG, "获取长度未完成的情况下,停止组合任务"); mPool.shutdown(); - listener.onStop(0); + ((DGInfoCallback)callback).onStop(0); return; } // 处理组合任务大小未知的情况 @@ -150,7 +160,7 @@ public final class HttpDGInfoTask implements IInfoTask { * 检查组合任务大小是否获取完成,获取完成后取消阻塞,并设置组合任务大小 */ private void checkGetSizeComplete(int count, int failCount) { - if (isStop || isCancel){ + if (isStop || isCancel) { ALog.w(TAG, "任务已停止或已取消,isStop = " + isStop + ", isCancel = " + isCancel); notifyLock(); return; diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoader.java b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoader.java index 9179f151..9f90fcb3 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoader.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoader.java @@ -26,6 +26,7 @@ import com.arialyy.aria.core.listener.DownloadGroupListener; import com.arialyy.aria.core.loader.IInfoTask; import com.arialyy.aria.core.wrapper.AbsTaskWrapper; import com.arialyy.aria.exception.AriaException; +import com.arialyy.aria.exception.AriaHTTPException; import java.io.File; /** @@ -64,7 +65,17 @@ final class HttpDGLoader extends AbsGroupLoader { @Override public void addComponent(IInfoTask infoTask) { mInfoTask = infoTask; - mInfoTask.setCallback(new IInfoTask.Callback() { + mInfoTask.setCallback(new HttpDGInfoTask.DGInfoCallback() { + + @Override + public void onSubFail(DownloadEntity subEntity, AriaHTTPException e, boolean needRetry) { + getState().countFailNum(subEntity.getKey()); + } + + @Override public void onStop(long len) { + getListener().onStop(len); + } + @Override public void onSucceed(String key, CompleteInfo info) { startSub(); } diff --git a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoaderUtil.java b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoaderUtil.java index cfeecd2a..e3dff075 100644 --- a/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoaderUtil.java +++ b/HttpComponent/src/main/java/com/arialyy/aria/http/download/HttpDGLoaderUtil.java @@ -38,8 +38,7 @@ public final class HttpDGLoaderUtil extends AbsGroupLoaderUtil { @Override protected LoaderStructure buildLoaderStructure() { LoaderStructure structure = new LoaderStructure(); - structure.addComponent(new HttpDGInfoTask((DGTaskWrapper) getTaskWrapper(), - (DownloadGroupListener) getListener())); + structure.addComponent(new HttpDGInfoTask((DGTaskWrapper) getTaskWrapper())); structure.accept(getLoader()); return structure; } diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/group/GroupRunState.java b/PublicComponent/src/main/java/com/arialyy/aria/core/group/GroupRunState.java index d1af88a3..94c487d8 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/group/GroupRunState.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/group/GroupRunState.java @@ -47,7 +47,6 @@ public final class GroupRunState { * 停止的任务数 */ private AtomicInteger mStopNum = new AtomicInteger(); - ; /** * 当前进度 diff --git a/PublicComponent/src/main/java/com/arialyy/aria/core/group/SimpleSchedulers.java b/PublicComponent/src/main/java/com/arialyy/aria/core/group/SimpleSchedulers.java index 2c232f06..f593e405 100644 --- a/PublicComponent/src/main/java/com/arialyy/aria/core/group/SimpleSchedulers.java +++ b/PublicComponent/src/main/java/com/arialyy/aria/core/group/SimpleSchedulers.java @@ -182,7 +182,7 @@ final class SimpleSchedulers implements Handler.Callback { Log.d(TAG, String.format("handleComplete, size = %s, completeNum = %s, failNum = %s, stopNum = %s", mGState.getSubSize(), mGState.getCompleteNum(), mGState.getFailNum(), - mGState.getSubSize())); + mGState.getStopNum())); TaskRecord record = loader.getRecord(); if (record != null && record.isBlock) { diff --git a/app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java b/app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java index cd9a1fb2..ec1ad778 100644 --- a/app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java +++ b/app/src/main/java/com/arialyy/simple/core/download/group/GroupModule.java @@ -32,9 +32,9 @@ public class GroupModule extends BaseModule { public List getUrls() { List urls = new ArrayList<>(); - urls.add("http://61.155.99.75:88/sdkdown.muzhiwan.com/openfile/2019/10/26/com.mrxz.mzw_5db3eeef782b1.apk"); - urls.add("http://cpsdown.muzhiwan.com/2020/05/07/com.kaihei.wufan.mars_5eb3947b4341b.apk"); - urls.add("http://113.143.35.118:88/sdkdown.muzhiwan.com/openfile/2019/11/27/com.droidhang.ad.mzw_5dde4ffe2b2e5.apk"); + urls.add("http://storage.jd.com/apk/newchannel/jingdongdaojia-lechuang30.apk"); + urls.add("https://appdownload.alicdn.com/publish/cainiao4android/latest/cainiao4android_1598322688221.apk"); + urls.add("http://dl-tc.coolapkmarket.com/down/apk_file/2020/0927/Coolapk-10.5.3-2009271_sign.apk"); return urls; } List getUrls1() { @@ -50,9 +50,9 @@ public class GroupModule extends BaseModule { List names = new ArrayList<>(); //String[] str = getContext().getResources().getStringArray(R.array.group_names); //Collections.addAll(names, str); - names.add("末日血战.apk"); - names.add("开黑三国.apk"); - names.add("放置奇兵.apk"); + names.add("京东到家.apk"); + names.add("菜鸟.apk"); + names.add("酷安.apk"); //names.add("4.png"); //names.add("5.png"); return names;