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 index c33dfeba..e127bec8 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupListener.java @@ -17,6 +17,7 @@ package com.arialyy.aria.core.download; import android.os.Handler; import com.arialyy.aria.core.download.downloader.IDownloadGroupListener; +import com.arialyy.aria.core.inf.GroupSendParams; import com.arialyy.aria.core.scheduler.ISchedulers; /** @@ -26,13 +27,16 @@ import com.arialyy.aria.core.scheduler.ISchedulers; class DownloadGroupListener extends BaseDListener implements IDownloadGroupListener { private final String TAG = "DownloadGroupListener"; + private GroupSendParams mSeedEntity; DownloadGroupListener(DownloadGroupTask task, Handler outHandler) { super(task, outHandler); + mSeedEntity = new GroupSendParams<>(); + mSeedEntity.groupTask = task; } @Override public void onSubPre(DownloadEntity subEntity) { - sendInState2Target(ISchedulers.SUB_PRE); + sendInState2Target(ISchedulers.SUB_PRE, subEntity); } @Override public void supportBreakpoint(boolean support, DownloadEntity subEntity) { @@ -40,31 +44,31 @@ class DownloadGroupListener extends BaseDListener { + + public GROUP_TASK groupTask; + public ENTITY entity; + + public GroupSendParams() { + } + + public GroupSendParams(GROUP_TASK groupTask, ENTITY entity) { + this.groupTask = groupTask; + this.entity = entity; + } +} diff --git a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java index da969577..863c595b 100644 --- a/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java +++ b/Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java @@ -15,13 +15,13 @@ */ package com.arialyy.aria.core.scheduler; -import com.arialyy.aria.core.inf.AbsNormalTask; +import com.arialyy.aria.core.inf.AbsNormalEntity; import com.arialyy.aria.core.inf.ITask; /** * Created by Aria.Lao on 2017/6/7. */ -public class AbsSchedulerListener implements ISchedulerListener { +public class AbsSchedulerListener implements ISchedulerListener { @Override public void onPre(TASK task) { @@ -67,31 +67,31 @@ public class AbsSchedulerListener> mObservers = new ConcurrentHashMap<>(); + private Map> mObservers = + new ConcurrentHashMap<>(); /** * 设置调度器类型 @@ -60,7 +62,7 @@ abstract class AbsSchedulers listener = mObservers.get(targetName); + AbsSchedulerListener listener = mObservers.get(targetName); if (listener == null) { listener = createListener(targetName); if (listener != null) { @@ -73,9 +75,9 @@ abstract class AbsSchedulers>> iter = + for (Iterator>> iter = mObservers.entrySet().iterator(); iter.hasNext(); ) { - Map.Entry> entry = iter.next(); + Map.Entry> entry = iter.next(); if (entry.getKey().equals(obj.getClass().getName())) iter.remove(); } } @@ -85,11 +87,11 @@ abstract class AbsSchedulers createListener(String targetName) { - AbsSchedulerListener listener = null; + private AbsSchedulerListener createListener(String targetName) { + AbsSchedulerListener listener = null; try { Class clazz = Class.forName(targetName + getProxySuffix()); - listener = (AbsSchedulerListener) clazz.newInstance(); + listener = (AbsSchedulerListener) clazz.newInstance(); } catch (ClassNotFoundException e) { Log.e(TAG, targetName + ",没有Aria的Download或Upload注解方法"); } catch (InstantiationException e) { @@ -101,49 +103,54 @@ abstract class AbsSchedulers 0) { Set keys = mObservers.keySet(); for (String key : keys) { - AbsSchedulerListener listener = mObservers.get(key); - switch (what) { + AbsSchedulerListener listener = mObservers.get(key); + switch (msg.what) { case SUB_PRE: - //listener.onSubTaskPre(task, ); + listener.onSubTaskPre((TASK) params.groupTask, params.entity); break; case SUB_START: + listener.onSubTaskStart((TASK) params.groupTask, params.entity); break; case SUB_STOP: + listener.onSubTaskStop((TASK) params.groupTask, params.entity); break; case SUB_FAIL: + listener.onSubTaskFail((TASK) params.groupTask, params.entity); break; case SUB_RUNNING: + listener.onSubTaskRunning((TASK) params.groupTask, params.entity); break; case SUB_CANCEL: + listener.onSubTaskCancel((TASK) params.groupTask, params.entity); break; case SUB_COMPLETE: + listener.onSubTaskComplete((TASK) params.groupTask, params.entity); break; } } } + return true; } /** @@ -189,7 +196,8 @@ abstract class AbsSchedulers listener) { + private void callback(int state, TASK task, + AbsSchedulerListener listener) { if (listener != null) { if (task == null) { Log.e(TAG, "TASK 为null,回调失败"); diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java b/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java index 78917280..50775981 100644 --- a/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java @@ -138,7 +138,7 @@ class ElementHandler { void createProxyFile() { try { new EventProxyFiler(mFiler, mPbUtil).createEventProxyFile(); - //new CountFiler(mFiler, mPbUtil).createCountFile(); + new CountFiler(mFiler, mPbUtil).createCountFile(); } catch (IOException e) { e.printStackTrace(); } diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/EventProxyFiler.java b/AriaCompiler/src/main/java/com/arialyy/compiler/EventProxyFiler.java index f5480410..1e382fd9 100644 --- a/AriaCompiler/src/main/java/com/arialyy/compiler/EventProxyFiler.java +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/EventProxyFiler.java @@ -112,7 +112,7 @@ final class EventProxyFiler { String callCode; if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) { - callCode = "task, subTask"; + callCode = "task, subEntity"; } else { callCode = "task"; } @@ -143,9 +143,9 @@ final class EventProxyFiler { //任务组接口 if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) { - ClassName subTask = ClassName.get(TaskEnum.DOWNLOAD.pkg, TaskEnum.DOWNLOAD.className); + ClassName subTask = ClassName.get(TaskEnum.DOWNLOAD_ENTITY.pkg, TaskEnum.DOWNLOAD_ENTITY.className); ParameterSpec subTaskParam = - ParameterSpec.builder(subTask, "subTask").addModifiers(Modifier.FINAL).build(); + ParameterSpec.builder(subTask, "subEntity").addModifiers(Modifier.FINAL).build(); builder.addParameter(subTaskParam); } diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/ParamObtainUtil.java b/AriaCompiler/src/main/java/com/arialyy/compiler/ParamObtainUtil.java index ef334390..128b361a 100644 --- a/AriaCompiler/src/main/java/com/arialyy/compiler/ParamObtainUtil.java +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/ParamObtainUtil.java @@ -84,7 +84,7 @@ class ParamObtainUtil { proxyEntity.proxyClassName = proxyEntity.className + taskEnum.proxySuffix; proxyEntity.mainTaskEnum = taskEnum; if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB || taskEnum == TaskEnum.DOWNLOAD_GROUP) { - proxyEntity.subTaskEnum = TaskEnum.DOWNLOAD; + proxyEntity.subTaskEnum = TaskEnum.DOWNLOAD_ENTITY; } mMethodParams.put(key, proxyEntity); } @@ -214,7 +214,7 @@ class ParamObtainUtil { */ private String getCheckSubParams(TaskEnum taskEnum) { if (taskEnum == TaskEnum.DOWNLOAD_GROUP_SUB) { - return TaskEnum.DOWNLOAD.pkg + "." + TaskEnum.DOWNLOAD.className; + return TaskEnum.DOWNLOAD_ENTITY.pkg + "." + TaskEnum.DOWNLOAD_ENTITY.className; } return ""; } diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyClassParam.java b/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyClassParam.java index 60aaa60a..ddfaaeaf 100644 --- a/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyClassParam.java +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/ProxyClassParam.java @@ -44,7 +44,7 @@ class ProxyClassParam { /** * 子任务泛型参数 */ - TaskEnum subTaskEnum = TaskEnum.NORMAL; + TaskEnum subTaskEnum = TaskEnum.NORMAL_ENTITY; Set taskEnums; Map> keyMappings = new HashMap<>(); diff --git a/AriaCompiler/src/main/java/com/arialyy/compiler/TaskEnum.java b/AriaCompiler/src/main/java/com/arialyy/compiler/TaskEnum.java index d7e2a9db..ee0fb4c8 100644 --- a/AriaCompiler/src/main/java/com/arialyy/compiler/TaskEnum.java +++ b/AriaCompiler/src/main/java/com/arialyy/compiler/TaskEnum.java @@ -23,10 +23,11 @@ enum TaskEnum { DOWNLOAD("com.arialyy.aria.core.download", "DownloadTask", "$$DownloadListenerProxy"), DOWNLOAD_GROUP("com.arialyy.aria.core.download", "DownloadGroupTask", "$$DownloadGroupListenerProxy"), DOWNLOAD_GROUP_SUB( - "com.arialyy.aria.core.download", "DownloadGroupTask", - "$$DownloadGroupListenerProxy"), UPLOAD("com.arialyy.aria.core.upload", "UploadTask", - "$$UploadListenerProxy"), UPLOAD_GROUP("com.arialyy.aria.core.upload", "UploadGroupTask", - "$$UploadGroupListenerProxy"), NORMAL("com.arialyy.aria.core.inf", "AbsNormalTask", ""); + "com.arialyy.aria.core.download", "DownloadGroupTask", "$$DownloadGroupListenerProxy"), UPLOAD( + "com.arialyy.aria.core.upload", "UploadTask", "$$UploadListenerProxy"), UPLOAD_GROUP( + "com.arialyy.aria.core.upload", "UploadGroupTask", + "$$UploadGroupListenerProxy"), NORMAL_ENTITY("com.arialyy.aria.core.inf", "AbsNormalEntity", + ""), DOWNLOAD_ENTITY("com.arialyy.aria.core.download", "DownloadEntity", ""); String pkg, className, proxySuffix; diff --git a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java index bef50a66..86f428a0 100644 --- a/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java @@ -18,7 +18,6 @@ package com.arialyy.simple.download; import android.os.Bundle; import android.os.Environment; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -29,10 +28,10 @@ import butterknife.Bind; import com.arialyy.annotations.Download; import com.arialyy.annotations.DownloadGroup; import com.arialyy.aria.core.Aria; +import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupTask; import com.arialyy.aria.core.download.DownloadTarget; import com.arialyy.aria.core.download.DownloadTask; -import com.arialyy.aria.core.download.DownloadTaskEntity; import com.arialyy.aria.core.inf.IEntity; import com.arialyy.aria.util.CommonUtil; import com.arialyy.frame.util.show.L; @@ -47,7 +46,8 @@ public class SingleTaskActivity extends BaseActivity { private static final String DOWNLOAD_URL = //"http://kotlinlang.org/docs/kotlin-docs.pdf"; //"https://atom-installer.github.com/v1.13.0/AtomSetup.exe?s=1484074138&ext=.exe"; - "http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; + //"http://static.gaoshouyou.com/d/22/94/822260b849944492caadd2983f9bb624.apk"; + "http://sitcac.daxincf.cn/wp-content/uploads/swift_vido/01/element.mp4"; //"http://120.25.196.56:8000/filereq?id=15692406294&ipncid=105635&client=android&filename=20170819185541.avi"; //"http://down2.xiaoshuofuwuqi.com/d/file/filetxt/20170608/14/%BA%DA%CE%D7%CA%A6%E1%C8%C6%F0.txt"; //"http://tinghuaapp.oss-cn-shanghai.aliyuncs.com/20170612201739607815"; @@ -116,14 +116,6 @@ public class SingleTaskActivity extends BaseActivity { return true; } - @DownloadGroup.onSubTaskFail void onSubTaskFail(DownloadGroupTask groupTask, DownloadTask subTask){ - - } - - @DownloadGroup.onPre void onGroupPre(DownloadGroupTask groupTask){ - - } - @Download.onPre(DOWNLOAD_URL) protected void onPre(DownloadTask task) { setBtState(false); } diff --git a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java index 7d97644c..7518d0d3 100644 --- a/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java +++ b/app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java @@ -17,15 +17,14 @@ package com.arialyy.simple.download.group; import android.os.Bundle; import android.os.Environment; -import android.view.Gravity; import android.view.View; import butterknife.Bind; import com.arialyy.annotations.DownloadGroup; import com.arialyy.aria.core.Aria; +import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadGroupEntity; import com.arialyy.aria.core.download.DownloadGroupTask; import com.arialyy.aria.core.download.DownloadGroupTaskEntity; -import com.arialyy.frame.util.AndroidUtils; import com.arialyy.frame.util.show.L; import com.arialyy.frame.util.show.T; import com.arialyy.simple.R; @@ -99,6 +98,11 @@ public class DownloadGroupActivity extends BaseActivity