任务组子任务控制bug修复,apt注解修复

pull/330/head
AriaLyy 7 years ago
parent a6434dc2f1
commit 9c39a95d85
  1. 20
      Aria/src/main/java/com/arialyy/aria/core/command/group/AbsGroupCmd.java
  2. 7
      Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java
  3. 8
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  4. 27
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/AbsGroupUtil.java
  5. 1
      Aria/src/main/java/com/arialyy/aria/core/download/downloader/HttpThreadTask.java
  6. 12
      AriaAnnotations/src/main/java/com/arialyy/annotations/DownloadGroup.java
  7. 2
      AriaCompiler/src/main/java/com/arialyy/compiler/AriaProcessor.java
  8. 4
      AriaCompiler/src/main/java/com/arialyy/compiler/CountFiler.java
  9. 5
      AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandler.java
  10. 13
      AriaCompiler/src/main/java/com/arialyy/compiler/EventProxyFiler.java
  11. 1
      AriaCompiler/src/main/java/com/arialyy/compiler/ProxyConstance.java
  12. 2
      AriaCompiler/src/main/java/com/arialyy/compiler/ValuesUtil.java
  13. 57
      app/src/main/java/com/arialyy/simple/download/group/ChildHandleDialog.java
  14. 41
      app/src/main/java/com/arialyy/simple/download/group/DownloadGroupActivity.java
  15. 4
      app/src/main/res/layout/activity_download_group.xml
  16. 16
      app/src/main/res/layout/dialog_sub_task_handler.xml

@ -19,6 +19,7 @@ import android.util.Log;
import com.arialyy.aria.core.command.AbsCmd; import com.arialyy.aria.core.command.AbsCmd;
import com.arialyy.aria.core.download.DownloadGroupTaskEntity; import com.arialyy.aria.core.download.DownloadGroupTaskEntity;
import com.arialyy.aria.core.inf.AbsGroupTask; import com.arialyy.aria.core.inf.AbsGroupTask;
import com.arialyy.aria.core.inf.AbsTask;
import com.arialyy.aria.core.inf.BaseGroupTaskEntity; import com.arialyy.aria.core.inf.BaseGroupTaskEntity;
import com.arialyy.aria.core.queue.DownloadGroupTaskQueue; import com.arialyy.aria.core.queue.DownloadGroupTaskQueue;
import com.arialyy.aria.util.CommonUtil; import com.arialyy.aria.util.CommonUtil;
@ -48,11 +49,24 @@ public abstract class AbsGroupCmd<T extends BaseGroupTaskEntity> extends AbsCmd<
} }
} }
/**
* 创建任务
*
* @return 创建的任务
*/
AbsTask createTask() {
tempTask = (AbsGroupTask) mQueue.createTask(mTargetName, mTaskEntity);
return tempTask;
}
boolean checkTask() { boolean checkTask() {
tempTask = (AbsGroupTask) mQueue.getTask(mTaskEntity.getEntity()); tempTask = (AbsGroupTask) mQueue.getTask(mTaskEntity.getEntity());
if (tempTask == null || !tempTask.isRunning()) { if (tempTask == null) {
Log.d(TAG, "任务组没有执行,先执行任务组任务才能够执行子任务"); createTask();
return false; if (tempTask.isComplete()) {
Log.w(TAG, "任务已完成");
return false;
}
} }
return true; return true;
} }

@ -27,7 +27,7 @@ import static java.util.Collections.unmodifiableSet;
* 代理参数获取 * 代理参数获取
*/ */
public class ProxyHelper { public class ProxyHelper {
public Set<String> downloadCounter, uploadCounter, downloadGroupCounter; public Set<String> downloadCounter, uploadCounter, downloadGroupCounter, downloadGroupSubCounter;
public static volatile ProxyHelper INSTANCE = null; public static volatile ProxyHelper INSTANCE = null;
@ -49,6 +49,7 @@ public class ProxyHelper {
Class clazz = Class.forName("com.arialyy.aria.ProxyClassCounter"); Class clazz = Class.forName("com.arialyy.aria.ProxyClassCounter");
Method download = clazz.getMethod("getDownloadCounter"); Method download = clazz.getMethod("getDownloadCounter");
Method downloadGroup = clazz.getMethod("getDownloadGroupCounter"); Method downloadGroup = clazz.getMethod("getDownloadGroupCounter");
Method downloadGroupSub = clazz.getMethod("getDownloadGroupSubCounter");
Method upload = clazz.getMethod("getUploadCounter"); Method upload = clazz.getMethod("getUploadCounter");
Object object = clazz.newInstance(); Object object = clazz.newInstance();
Object dc = download.invoke(object); Object dc = download.invoke(object);
@ -59,6 +60,10 @@ public class ProxyHelper {
if (dgc != null) { if (dgc != null) {
downloadGroupCounter = unmodifiableSet((Set<String>) dgc); downloadGroupCounter = unmodifiableSet((Set<String>) dgc);
} }
Object dgsc = downloadGroupSub.invoke(object);
if (dgsc != null){
downloadGroupSubCounter = unmodifiableSet((Set<? extends String>) dgsc);
}
Object uc = upload.invoke(object); Object uc = upload.invoke(object);
if (uc != null) { if (uc != null) {
uploadCounter = unmodifiableSet((Set<String>) uc); uploadCounter = unmodifiableSet((Set<String>) uc);

@ -139,10 +139,12 @@ public class DownloadReceiver extends AbsReceiver {
String className = obj.getClass().getName(); String className = obj.getClass().getName();
Set<String> dCounter = ProxyHelper.getInstance().downloadCounter; Set<String> dCounter = ProxyHelper.getInstance().downloadCounter;
Set<String> dgCounter = ProxyHelper.getInstance().downloadGroupCounter; Set<String> dgCounter = ProxyHelper.getInstance().downloadGroupCounter;
Set<String> dgsCounter = ProxyHelper.getInstance().downloadGroupSubCounter;
if (dCounter != null && dCounter.contains(className)) { if (dCounter != null && dCounter.contains(className)) {
DownloadSchedulers.getInstance().register(obj); DownloadSchedulers.getInstance().register(obj);
} }
if (dgCounter != null && dgCounter.contains(className)) { if ((dgCounter != null && dgCounter.contains(className)) || (dgsCounter != null
&& dgsCounter.contains(className))) {
DownloadGroupSchedulers.getInstance().register(obj); DownloadGroupSchedulers.getInstance().register(obj);
} }
return this; return this;
@ -155,10 +157,12 @@ public class DownloadReceiver extends AbsReceiver {
String className = obj.getClass().getName(); String className = obj.getClass().getName();
Set<String> dCounter = ProxyHelper.getInstance().downloadCounter; Set<String> dCounter = ProxyHelper.getInstance().downloadCounter;
Set<String> dgCounter = ProxyHelper.getInstance().downloadGroupCounter; Set<String> dgCounter = ProxyHelper.getInstance().downloadGroupCounter;
Set<String> dgsCounter = ProxyHelper.getInstance().downloadGroupSubCounter;
if (dCounter != null && dCounter.contains(className)) { if (dCounter != null && dCounter.contains(className)) {
DownloadSchedulers.getInstance().unRegister(obj); DownloadSchedulers.getInstance().unRegister(obj);
} }
if (dgCounter != null && dgCounter.contains(className)) { if (dgCounter != null && dgCounter.contains(className) || (dgsCounter != null
&& dgsCounter.contains(className))) {
DownloadGroupSchedulers.getInstance().unRegister(obj); DownloadGroupSchedulers.getInstance().unRegister(obj);
} }
if (needRmReceiver) { if (needRmReceiver) {

@ -15,7 +15,6 @@
*/ */
package com.arialyy.aria.core.download.downloader; package com.arialyy.aria.core.download.downloader;
import android.util.Log;
import com.arialyy.aria.core.AriaManager; import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.common.IUtil; import com.arialyy.aria.core.common.IUtil;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
@ -82,6 +81,8 @@ public abstract class AbsGroupUtil implements IUtil {
private int mCompleteNum = 0; private int mCompleteNum = 0;
//失败的任务数 //失败的任务数
private int mFailNum = 0; private int mFailNum = 0;
//停止的任务数
private int mStopNum = 0;
//实际的下载任务数 //实际的下载任务数
int mActualTaskNum = 0; int mActualTaskNum = 0;
/** /**
@ -98,6 +99,7 @@ public abstract class AbsGroupUtil implements IUtil {
if (tasks != null && !tasks.isEmpty()) { if (tasks != null && !tasks.isEmpty()) {
for (DownloadTaskEntity te : tasks) { for (DownloadTaskEntity te : tasks) {
te.removeFile = mTaskEntity.removeFile; te.removeFile = mTaskEntity.removeFile;
if (te.getEntity() == null) continue;
mTasksMap.put(te.getEntity().getUrl(), te); mTasksMap.put(te.getEntity().getUrl(), te);
} }
} }
@ -108,6 +110,7 @@ public abstract class AbsGroupUtil implements IUtil {
if (entity.getState() == IEntity.STATE_COMPLETE && file.exists()) { if (entity.getState() == IEntity.STATE_COMPLETE && file.exists()) {
mCompleteNum++; mCompleteNum++;
mInitNum++; mInitNum++;
mStopNum++;
mCurrentLocation += entity.getFileSize(); mCurrentLocation += entity.getFileSize();
} else { } else {
mExeMap.put(entity.getUrl(), createChildDownloadTask(entity)); mExeMap.put(entity.getUrl(), createChildDownloadTask(entity));
@ -134,6 +137,10 @@ public abstract class AbsGroupUtil implements IUtil {
* @param url 子任务下载地址 * @param url 子任务下载地址
*/ */
public void startSubTask(String url) { public void startSubTask(String url) {
isRunning = true;
if (mTimer == null) {
startTimer();
}
Downloader d = getDownloader(url); Downloader d = getDownloader(url);
if (d != null && !d.isRunning()) { if (d != null && !d.isRunning()) {
d.start(); d.start();
@ -172,8 +179,7 @@ public abstract class AbsGroupUtil implements IUtil {
private Downloader getDownloader(String url) { private Downloader getDownloader(String url) {
Downloader d = mDownloaderMap.get(url); Downloader d = mDownloaderMap.get(url);
if (d == null) { if (d == null) {
Log.e(TAG, "链接【" + url + "】对应的下载器不存在"); return startChildDownload(mExeMap.get(url));
return null;
} }
return d; return d;
} }
@ -283,6 +289,7 @@ public abstract class AbsGroupUtil implements IUtil {
if (mTimer != null) { if (mTimer != null) {
mTimer.purge(); mTimer.purge();
mTimer.cancel(); mTimer.cancel();
mTimer = null;
} }
} }
@ -293,6 +300,10 @@ public abstract class AbsGroupUtil implements IUtil {
closeTimer(true); closeTimer(true);
mListener.onPostPre(mTotalSize); mListener.onPostPre(mTotalSize);
mListener.onStart(mCurrentLocation); mListener.onStart(mCurrentLocation);
startTimer();
}
private void startTimer() {
mTimer = new Timer(true); mTimer = new Timer(true);
mTimer.schedule(new TimerTask() { mTimer.schedule(new TimerTask() {
@Override public void run() { @Override public void run() {
@ -308,12 +319,13 @@ public abstract class AbsGroupUtil implements IUtil {
/** /**
* 启动子任务下载器 * 启动子任务下载器
*/ */
void startChildDownload(DownloadTaskEntity taskEntity) { Downloader startChildDownload(DownloadTaskEntity taskEntity) {
ChildDownloadListener listener = new ChildDownloadListener(taskEntity); ChildDownloadListener listener = new ChildDownloadListener(taskEntity);
Downloader dt = new Downloader(listener, taskEntity); Downloader dt = new Downloader(listener, taskEntity);
mDownloaderMap.put(taskEntity.getEntity().getUrl(), dt); mDownloaderMap.put(taskEntity.getEntity().getUrl(), dt);
if (mExePool.isShutdown()) return; if (mExePool.isShutdown()) return dt;
mExePool.execute(dt); mExePool.execute(dt);
return dt;
} }
/** /**
@ -400,6 +412,11 @@ public abstract class AbsGroupUtil implements IUtil {
saveData(IEntity.STATE_STOP, stopLocation); saveData(IEntity.STATE_STOP, stopLocation);
handleSpeed(0); handleSpeed(0);
mListener.onSubStop(entity); mListener.onSubStop(entity);
mStopNum++;
if (mStopNum >= mInitNum) {
closeTimer(false);
mListener.onStop(mCurrentLocation);
}
} }
@Override public void onCancel() { @Override public void onCancel() {

@ -86,7 +86,6 @@ final class HttpThreadTask extends AbsThreadTask<DownloadEntity, DownloadTaskEnt
if (mSleepTime > 0) Thread.sleep(mSleepTime); if (mSleepTime > 0) Thread.sleep(mSleepTime);
file.write(buffer, 0, len); file.write(buffer, 0, len);
progress(len); progress(len);
Log.d(TAG, len + "");
} }
if (STATE.isCancel || STATE.isStop) return; if (STATE.isCancel || STATE.isStop) return;
//支持断点的处理 //支持断点的处理

@ -128,12 +128,12 @@ import java.lang.annotation.Target;
String[] value() default { AriaConstance.NO_URL }; String[] value() default { AriaConstance.NO_URL };
} }
/** ///**
* 任务组子任务删除的注解 // * 任务组子任务删除的注解
*/ // */
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onSubTaskCancel { //@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) @interface onSubTaskCancel {
String[] value() default { AriaConstance.NO_URL }; // String[] value() default { AriaConstance.NO_URL };
} //}
/** /**
* 任务组子任务失败的注解 * 任务组子任务失败的注解

@ -66,7 +66,7 @@ import javax.lang.model.element.TypeElement;
annotataions.add(DownloadGroup.onTaskStop.class.getCanonicalName()); annotataions.add(DownloadGroup.onTaskStop.class.getCanonicalName());
//任务组子任务的注解 //任务组子任务的注解
annotataions.add(DownloadGroup.onSubTaskPre.class.getCanonicalName()); annotataions.add(DownloadGroup.onSubTaskPre.class.getCanonicalName());
annotataions.add(DownloadGroup.onSubTaskCancel.class.getCanonicalName()); //annotataions.add(DownloadGroup.onSubTaskCancel.class.getCanonicalName());
annotataions.add(DownloadGroup.onSubTaskComplete.class.getCanonicalName()); annotataions.add(DownloadGroup.onSubTaskComplete.class.getCanonicalName());
annotataions.add(DownloadGroup.onSubTaskFail.class.getCanonicalName()); annotataions.add(DownloadGroup.onSubTaskFail.class.getCanonicalName());
annotataions.add(DownloadGroup.onSubTaskRunning.class.getCanonicalName()); annotataions.add(DownloadGroup.onSubTaskRunning.class.getCanonicalName());

@ -48,6 +48,7 @@ final class CountFiler {
*/ */
void createCountFile() throws IOException { void createCountFile() throws IOException {
Set<String> keys = mPbUtil.getListenerClass().keySet(); Set<String> keys = mPbUtil.getListenerClass().keySet();
if (keys.size() == 0) return;
TypeSpec.Builder builder = TypeSpec.classBuilder(ProxyConstance.PROXY_COUNTER_NAME) TypeSpec.Builder builder = TypeSpec.classBuilder(ProxyConstance.PROXY_COUNTER_NAME)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL); .addModifiers(Modifier.PUBLIC, Modifier.FINAL);
@ -76,6 +77,8 @@ final class CountFiler {
createMethod(ProxyConstance.COUNT_METHOD_UPLOAD, ProxyConstance.COUNT_UPLOAD)); createMethod(ProxyConstance.COUNT_METHOD_UPLOAD, ProxyConstance.COUNT_UPLOAD));
builder.addMethod(createMethod(ProxyConstance.COUNT_METHOD_DOWNLOAD_GROUP, builder.addMethod(createMethod(ProxyConstance.COUNT_METHOD_DOWNLOAD_GROUP,
ProxyConstance.COUNT_DOWNLOAD_GROUP)); ProxyConstance.COUNT_DOWNLOAD_GROUP));
builder.addMethod(createMethod(ProxyConstance.COUNT_METHOD_DOWNLOAD_GROUP_SUB,
ProxyConstance.COUNT_DOWNLOAD_GROUP_SUB));
JavaFile jf = JavaFile.builder(ProxyConstance.PROXY_COUNTER_PACKAGE, builder.build()).build(); JavaFile jf = JavaFile.builder(ProxyConstance.PROXY_COUNTER_PACKAGE, builder.build()).build();
createFile(jf); createFile(jf);
@ -113,6 +116,7 @@ final class CountFiler {
} }
private void createFile(JavaFile jf) throws IOException { private void createFile(JavaFile jf) throws IOException {
//jf.writeTo(System.out);
if (ProxyConstance.DEBUG) { if (ProxyConstance.DEBUG) {
// 如果需要在控制台打印生成的文件,则去掉下面的注释 // 如果需要在控制台打印生成的文件,则去掉下面的注释
jf.writeTo(System.out); jf.writeTo(System.out);

@ -95,8 +95,8 @@ class ElementHandler {
void handleDownloadGroupSub(RoundEnvironment roundEnv) { void handleDownloadGroupSub(RoundEnvironment roundEnv) {
mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP_SUB, roundEnv, DownloadGroup.onSubTaskPre.class, mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP_SUB, roundEnv, DownloadGroup.onSubTaskPre.class,
ProxyConstance.TASK_PRE); ProxyConstance.TASK_PRE);
mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP_SUB, roundEnv, DownloadGroup.onSubTaskCancel.class, //mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP_SUB, roundEnv, DownloadGroup.onSubTaskCancel.class,
ProxyConstance.TASK_CANCEL); // ProxyConstance.TASK_CANCEL);
mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP_SUB, roundEnv, DownloadGroup.onSubTaskComplete.class, mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP_SUB, roundEnv, DownloadGroup.onSubTaskComplete.class,
ProxyConstance.TASK_COMPLETE); ProxyConstance.TASK_COMPLETE);
mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP_SUB, roundEnv, DownloadGroup.onSubTaskFail.class, mPbUtil.saveMethod(TaskEnum.DOWNLOAD_GROUP_SUB, roundEnv, DownloadGroup.onSubTaskFail.class,
@ -146,5 +146,6 @@ class ElementHandler {
void clean() { void clean() {
mPbUtil.getMethodParams().clear(); mPbUtil.getMethodParams().clear();
mPbUtil.getListenerClass().clear();
} }
} }

@ -78,21 +78,11 @@ final class EventProxyFiler {
* 创建任务事件代理文件 * 创建任务事件代理文件
*/ */
void createEventProxyFile() throws IOException { void createEventProxyFile() throws IOException {
Map<String, ProxyClassParam> map = mPbUtil.getMethodParams();
Set<String> keys = mPbUtil.getMethodParams().keySet(); Set<String> keys = mPbUtil.getMethodParams().keySet();
for (String key : keys) { for (String key : keys) {
//if (key.equals(
// "com.arialyy.simple.download.SingleTaskActivity$$DownloadGroupListenerProxy")) {
//
// ProxyClassParam entity = mPbUtil.getMethodParams().get(key);
// JavaFile jf = JavaFile.builder(entity.packageName, createProxyClass(entity)).build();
// createFile(jf);
//}
ProxyClassParam entity = mPbUtil.getMethodParams().get(key); ProxyClassParam entity = mPbUtil.getMethodParams().get(key);
JavaFile jf = JavaFile.builder(entity.packageName, createProxyClass(entity)).build(); JavaFile jf = JavaFile.builder(entity.packageName, createProxyClass(entity)).build();
createFile(jf); createFile(jf);
} }
} }
@ -149,9 +139,6 @@ final class EventProxyFiler {
builder.addParameter(subTaskParam); builder.addParameter(subTaskParam);
} }
//PrintLog.getInstance().info(builder.build().toString());
return builder.build(); return builder.build();
} }

@ -47,6 +47,7 @@ interface ProxyConstance {
String COUNT_METHOD_DOWNLOAD = "getDownloadCounter"; String COUNT_METHOD_DOWNLOAD = "getDownloadCounter";
String COUNT_METHOD_DOWNLOAD_GROUP = "getDownloadGroupCounter"; String COUNT_METHOD_DOWNLOAD_GROUP = "getDownloadGroupCounter";
String COUNT_METHOD_DOWNLOAD_GROUP_SUB = "getDownloadGroupSubCounter";
String COUNT_METHOD_UPLOAD = "getUploadCounter"; String COUNT_METHOD_UPLOAD = "getUploadCounter";
int PRE = 0X11; int PRE = 0X11;

@ -47,7 +47,7 @@ final class ValuesUtil {
values = method.getAnnotation(DownloadGroup.onSubTaskComplete.class).value(); values = method.getAnnotation(DownloadGroup.onSubTaskComplete.class).value();
break; break;
case ProxyConstance.TASK_CANCEL: case ProxyConstance.TASK_CANCEL:
values = method.getAnnotation(DownloadGroup.onSubTaskCancel.class).value(); //values = method.getAnnotation(DownloadGroup.onSubTaskCancel.class).value();
break; break;
case ProxyConstance.TASK_FAIL: case ProxyConstance.TASK_FAIL:
values = method.getAnnotation(DownloadGroup.onSubTaskFail.class).value(); values = method.getAnnotation(DownloadGroup.onSubTaskFail.class).value();

@ -18,7 +18,6 @@ package com.arialyy.simple.download.group;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -31,6 +30,7 @@ import com.arialyy.annotations.DownloadGroup;
import com.arialyy.aria.core.Aria; import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity; import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadGroupTask; import com.arialyy.aria.core.download.DownloadGroupTask;
import com.arialyy.frame.util.show.L;
import com.arialyy.simple.R; import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseDialog; import com.arialyy.simple.base.BaseDialog;
import com.arialyy.simple.databinding.DialogSubTaskHandlerBinding; import com.arialyy.simple.databinding.DialogSubTaskHandlerBinding;
@ -47,13 +47,15 @@ import java.util.List;
@Bind(R.id.pb) HorizontalProgressBarWithNumber mPb; @Bind(R.id.pb) HorizontalProgressBarWithNumber mPb;
private String mGroupName; private String mGroupName;
private String mChildName; private String mChildName;
private List<String> mUrls;
private DownloadEntity mChildEntity; private DownloadEntity mChildEntity;
public ChildHandleDialog(Context context, String groupAliaName, DownloadEntity childEntity) { public ChildHandleDialog(Context context, List<String> urls, DownloadEntity childEntity) {
super(context); super(context);
setStyle(STYLE_NO_TITLE, R.style.Theme_Light_Dialog); setStyle(STYLE_NO_TITLE, R.style.Theme_Light_Dialog);
mChildEntity = childEntity; mChildEntity = childEntity;
mGroupName = groupAliaName; mGroupName = "任务组测试";
mUrls = urls;
mChildName = childEntity.getFileName(); mChildName = childEntity.getFileName();
} }
@ -81,39 +83,64 @@ import java.util.List;
window.setWindowAnimations(R.style.dialogStyle); window.setWindowAnimations(R.style.dialogStyle);
} }
@DownloadGroup.onTaskResume void onTaskResume(DownloadGroupTask task) { @DownloadGroup.onSubTaskRunning void onSubTaskRunning(DownloadGroupTask groupTask,
mSub.setText("子任务:" + mChildName + ",状态:下载中"); DownloadEntity subEntity) {
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
L.d(TAG, "p ==> " + subEntity.getPercent());
mPb.setProgress(subEntity.getPercent());
} }
@DownloadGroup.onTaskCancel void onTaskCancel(DownloadGroupTask task) { @DownloadGroup.onSubTaskPre void onSubTaskPre(DownloadGroupTask groupTask,
mSub.setText("子任务:" + mChildName + ",状态:取消下载"); DownloadEntity subEntity) {
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
L.d(TAG, subEntity.getPercent() + "");
} }
@DownloadGroup.onTaskRunning void onTaskRunning(DownloadGroupTask task) { @DownloadGroup.onSubTaskStop void onSubTaskStop(DownloadGroupTask groupTask,
mPb.setProgress((int) (mChildEntity.getCurrentProgress() * 100 / mChildEntity.getFileSize())); DownloadEntity subEntity) {
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
mSub.setText("子任务:" + mChildName + ",状态:任务停止");
} }
@DownloadGroup.onTaskStop void onTaskStop(DownloadGroupTask task) { @DownloadGroup.onSubTaskStart void onSubTaskStart(DownloadGroupTask groupTask,
mSub.setText("子任务:" + mChildName + ",状态:任务停止"); DownloadEntity subEntity) {
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
mSub.setText("子任务:" + mChildName + ",状态:下载中");
} }
@DownloadGroup.onTaskComplete void onTaskComplete(DownloadGroupTask task) { //@DownloadGroup.onSubTaskCancel void onSubTaskCancel(DownloadGroupTask groupTask,
// DownloadEntity subEntity) {
// mSub.setText("子任务:" + mChildName + ",状态:取消下载");
//}
@DownloadGroup.onSubTaskComplete void onSubTaskComplete(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
mSub.setText("子任务:" + mChildName + ",状态:任务完成"); mSub.setText("子任务:" + mChildName + ",状态:任务完成");
mPb.setProgress(100); mPb.setProgress(100);
} }
@DownloadGroup.onSubTaskFail void onSubTaskFail(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
if (!subEntity.getUrl().equals(mChildEntity.getUrl())) return;
L.d(TAG, subEntity.getPercent() + "");
}
@Override protected int setLayoutId() { @Override protected int setLayoutId() {
return R.layout.dialog_sub_task_handler; return R.layout.dialog_sub_task_handler;
} }
@OnClick({ R.id.start, R.id.stop, R.id.cancel }) void onClick(View view) { @OnClick({ R.id.start, R.id.stop }) void onClick(View view) {
switch (view.getId()) { switch (view.getId()) {
case R.id.start: case R.id.start:
Aria.download(this).load(mUrls).getSubTaskManager().startSubTask(mChildEntity.getUrl());
break; break;
case R.id.stop: case R.id.stop:
Aria.download(this).load(mUrls).getSubTaskManager().stopSubTask(mChildEntity.getUrl());
break; break;
case R.id.cancel: //case R.id.cancel:
break; // Aria.download(this).load(mUrls).getSubTaskManager().cancelSubTask(mChildEntity.getUrl());
// break;
} }
} }

@ -17,6 +17,7 @@ package com.arialyy.simple.download.group;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.support.design.widget.FloatingActionButton;
import android.view.View; import android.view.View;
import butterknife.Bind; import butterknife.Bind;
import com.arialyy.annotations.DownloadGroup; import com.arialyy.annotations.DownloadGroup;
@ -64,11 +65,12 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
showPopupWindow(position); showPopupWindow(position);
} }
}); });
} }
private void showPopupWindow(int position) { private void showPopupWindow(int position) {
ChildHandleDialog dialog = ChildHandleDialog dialog =
new ChildHandleDialog(this, "任务组测试", mChildList.getSubData().get(position)); new ChildHandleDialog(this, mUrls, mChildList.getSubData().get(position));
dialog.show(getSupportFragmentManager(), "sub_dialog"); dialog.show(getSupportFragmentManager(), "sub_dialog");
} }
@ -149,41 +151,4 @@ public class DownloadGroupActivity extends BaseActivity<ActivityDownloadGroupBin
L.d(TAG, "任务组下载完成"); L.d(TAG, "任务组下载完成");
} }
///////////////////////////////////任务组子任务///////////////////////////////////
@DownloadGroup.onSubTaskRunning void onSubTaskRunning(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
L.d(TAG, subEntity.getFileName() + "__________" + subEntity.getPercent() + "");
}
@DownloadGroup.onSubTaskPre void onSubTaskPre(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
L.d(TAG, subEntity.getPercent() + "");
}
@DownloadGroup.onSubTaskStop void onSubTaskStop(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
L.d(TAG, subEntity.getPercent() + "");
}
@DownloadGroup.onSubTaskStart void onSubTaskStart(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
L.d(TAG, subEntity.getPercent() + "");
}
@DownloadGroup.onSubTaskCancel void onSubTaskCancel(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
L.d(TAG, subEntity.getPercent() + "");
}
@DownloadGroup.onSubTaskComplete void onSubTaskComplete(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
L.d(TAG, subEntity.getPercent() + "");
}
@DownloadGroup.onSubTaskFail void onSubTaskFail(DownloadGroupTask groupTask,
DownloadEntity subEntity) {
L.d(TAG, subEntity.getPercent() + "");
}
} }

@ -40,11 +40,11 @@
android:id="@+id/child_list" android:id="@+id/child_list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_above="@+id/temp"
android:layout_below="@+id/content" android:layout_below="@+id/content"
android:paddingLeft="16dp" android:paddingLeft="16dp"
android:paddingRight="16dp" android:paddingRight="16dp"
/> />
</RelativeLayout> </RelativeLayout>
</layout> </layout>

@ -61,14 +61,14 @@
style="?buttonBarButtonStyle" style="?buttonBarButtonStyle"
/> />
<Button <!--<Button-->
android:id="@+id/cancel" <!--android:id="@+id/cancel"-->
android:layout_width="wrap_content" <!--android:layout_width="wrap_content"-->
android:layout_height="wrap_content" <!--android:layout_height="wrap_content"-->
android:layout_weight="1" <!--android:layout_weight="1"-->
android:text="删除" <!--android:text="删除"-->
style="?buttonBarButtonStyle" <!--style="?buttonBarButtonStyle"-->
/> <!--/>-->
</LinearLayout> </LinearLayout>
</RelativeLayout> </RelativeLayout>

Loading…
Cancel
Save