Apt 下载事件完成

pull/330/head
AriaLyy 8 years ago
parent 8049af34e0
commit 603a21fe43
  1. 3
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  2. 10
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadReceiver.java
  3. 5
      Aria/src/main/java/com/arialyy/aria/core/inf/IReceiver.java
  4. 8
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulerListener.java
  5. 21
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  6. 8
      Aria/src/main/java/com/arialyy/aria/core/scheduler/ISchedulers.java
  7. 15
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadReceiver.java
  8. 31
      AriaAnnotations/src/main/java/com/arialyy/annotations/Download.java
  9. 34
      AriaAnnotations/src/main/java/com/arialyy/annotations/Upload.java
  10. 9
      AriaCompiler/src/main/java/com/arialyy/compiler/ElementHandle.java
  11. 126
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java
  12. 36
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiDownloadActivity.java
  13. 45
      app/src/main/java/com/arialyy/simple/download/multi_download/MultiTaskActivity.java
  14. 43
      app/src/main/java/com/arialyy/simple/upload/UploadActivity.java

@ -176,11 +176,13 @@ import org.xml.sax.SAXException;
if (isDownload) {
DownloadReceiver dReceiver = new DownloadReceiver();
dReceiver.targetName = obj.getClass().getName();
dReceiver.obj = obj;
mReceivers.put(key, dReceiver);
receiver = dReceiver;
} else {
UploadReceiver uReceiver = new UploadReceiver();
uReceiver.targetName = obj.getClass().getName();
uReceiver.obj = obj;
mReceivers.put(key, uReceiver);
receiver = uReceiver;
}
@ -303,6 +305,7 @@ import org.xml.sax.SAXException;
if (key.contains(clsName)) {
IReceiver receiver = mReceivers.get(key);
receiver.removeSchedulerListener();
receiver.unRegister();
receiver.destroy();
iter.remove();
break;

@ -36,6 +36,7 @@ import java.util.Set;
public class DownloadReceiver implements IReceiver<DownloadEntity> {
private static final String TAG = "DownloadReceiver";
public String targetName;
public Object obj;
public ISchedulerListener<DownloadTask> listener;
/**
@ -72,16 +73,16 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
* 将当前类注册到Aria
*/
public DownloadReceiver register() {
DownloadSchedulers.getInstance().register(targetName);
DownloadSchedulers.getInstance().register(obj);
return this;
}
/**
* 取消注册
*/
public DownloadReceiver unRegister() {
DownloadSchedulers.getInstance().unRegister(targetName);
return this;
@Override
public void unRegister() {
DownloadSchedulers.getInstance().unRegister(obj);
}
/**
@ -149,6 +150,7 @@ public class DownloadReceiver implements IReceiver<DownloadEntity> {
for (String key : keys) {
IReceiver receiver = ariaManager.getReceiver().get(key);
receiver.removeSchedulerListener();
receiver.unRegister();
ariaManager.getReceiver().remove(key);
}
}

@ -31,6 +31,11 @@ public interface IReceiver<ENTITY extends IEntity> {
*/
public void removeSchedulerListener();
/**
* 移除观察者
*/
public void unRegister();
/**
* 停止所有任务
*/

@ -56,4 +56,12 @@ public class AbsSchedulerListener<TASK extends ITask> implements ISchedulerListe
@Override public void onTaskRunning(TASK task) {
}
public void onNoSupportBreakPoint(TASK task) {
}
public void setListener(Object obj) {
}
}

@ -49,7 +49,7 @@ public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY ex
/**
* @param targetName 观察者创建该监听器的对象类名
* @param schedulerListener {@link ISchedulerListener}
* @see #register(String)
* @see #register(Object)
*/
@Deprecated @Override public void addSchedulerListener(String targetName,
ISchedulerListener<TASK> schedulerListener) {
@ -58,7 +58,7 @@ public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY ex
/**
* @param targetName 观察者创建该监听器的对象类名
* @see #unRegister(String)
* @see #unRegister(Object)
*/
@Override public void removeSchedulerListener(String targetName,
ISchedulerListener<TASK> schedulerListener) {
@ -70,18 +70,21 @@ public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY ex
}
}
@Override public void register(String targetName) {
@Override public void register(Object obj) {
String targetName = obj.getClass().getName();
AbsSchedulerListener<TASK> listener = mObservers.get(targetName);
if (listener == null) {
mObservers.put(targetName, createListener(targetName));
listener = createListener(targetName);
listener.setListener(obj);
mObservers.put(targetName, listener);
}
}
@Override public void unRegister(String targetName) {
@Override public void unRegister(Object obj) {
for (Iterator<Map.Entry<String, AbsSchedulerListener<TASK>>> iter =
mObservers.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, AbsSchedulerListener<TASK>> entry = iter.next();
if (entry.getKey().equals(targetName)) iter.remove();
if (entry.getKey().equals(obj.getClass().getName())) iter.remove();
}
}
@ -151,15 +154,15 @@ public abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, ENTITY ex
if (mSchedulerListeners.size() > 0) {
Set<String> keys = mSchedulerListeners.keySet();
for (String key : keys) {
if (mSchedulerListeners.size() > 0) {
callback(state, task, mSchedulerListeners.get(key));
}
if (mObservers.size() > 0) {
} else if (mObservers.size() > 0) {
Set<String> keys = mObservers.keySet();
for (String key : keys) {
callback(state, task, mObservers.get(key));
}
}
}
}
private void callback(int state, TASK task, ISchedulerListener<TASK> listener) {
if (listener != null) {

@ -84,14 +84,14 @@ public interface ISchedulers<Task extends ITask> extends Handler.Callback {
/**
* 将当前类注册到Aria
*
* @param targetName 类完整路径
* @param obj 观察者类
*/
public void register(String targetName);
public void register(Object obj);
/**
* 移除注册
*
* @param targetName 类完整路径
* @param obj 观察者类
*/
public void unRegister(String targetName);
public void unRegister(Object obj);
}

@ -19,8 +19,10 @@ import android.support.annotation.NonNull;
import com.arialyy.aria.core.AriaManager;
import com.arialyy.aria.core.command.AbsCmd;
import com.arialyy.aria.core.command.CmdFactory;
import com.arialyy.aria.core.download.DownloadReceiver;
import com.arialyy.aria.core.inf.IEntity;
import com.arialyy.aria.core.inf.IReceiver;
import com.arialyy.aria.core.scheduler.DownloadSchedulers;
import com.arialyy.aria.core.scheduler.ISchedulerListener;
import com.arialyy.aria.core.scheduler.UploadSchedulers;
import com.arialyy.aria.orm.DbEntity;
@ -38,6 +40,7 @@ import java.util.regex.Pattern;
public class UploadReceiver implements IReceiver<UploadEntity> {
private static final String TAG = "DownloadReceiver";
public String targetName;
public Object obj;
public ISchedulerListener<UploadTask> listener;
/**
@ -127,4 +130,16 @@ public class UploadReceiver implements IReceiver<UploadEntity> {
UploadSchedulers.getInstance().removeSchedulerListener(targetName, listener);
}
}
/**
* 将当前类注册到Aria
*/
public UploadReceiver register() {
UploadSchedulers.getInstance().register(obj);
return this;
}
@Override public void unRegister() {
UploadSchedulers.getInstance().unRegister(obj);
}
}

@ -22,35 +22,66 @@ import java.lang.annotation.Target;
/**
* Created by Aria.Lao on 2017/6/6.
* 下载注解
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Download {
/**
* 如果你在方法中添加{@code @Download.onPre}注解在预处理完成时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onPre {
}
/**
* 如果你在方法中添加{@code @Download.onTaskPre}注解在任务预处理完成时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskPre {
}
/**
* 如果你在方法中添加{@code @Download.onTaskResume}注解在任务恢复下载时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskResume {
}
/**
* 如果你在方法中添加{@code @Download.onTaskStart}注解在任务开始下载时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStart {
}
/**
* 如果你在方法中添加{@code @Download.onTaskStop}注解在任务停止时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStop {
}
/**
* 如果你在方法中添加{@code @Download.onTaskCancel}l注解在任务取消时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskCancel {
}
/**
* 如果你在方法中添加{@code @Download.onTaskFail)注解在任务预失败时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskFail {
}
/**
* 如果你在方法中添加{@code @Download.onTaskComplete}注解在任务完成时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskComplete {
}
/**
* 如果你在方法中添加{@code @Download.onTaskRunning}注解在任务正在下载Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskRunning {
}
/**
* 如果你在方法中添加{@code @Download.onNoSupportBreakPoint}注解如果该任务不支持断点Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD)
public @interface onNoSupportBreakPoint {
}

@ -21,36 +21,68 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by Aria.Lao on 2017/6/6.
* Created by lyy on 2017/6/6.
* Aria下载事件注解
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface Upload {
/**
* 如果你在方法中添加{@code @Upload.onPre}注解在预处理完成时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onPre {
}
/**
* 如果你在方法中添加{@code @Upload.onTaskPre}注解在任务预处理完成时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskPre {
}
/**
* 如果你在方法中添加{@code @Upload.onTaskResume}注解在任务恢复下载时Aria会调用该方法
*/
//@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskResume {
//}
/**
* 如果你在方法中添加{@code @Upload.onTaskStart}注解在任务开始下载时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStart {
}
/**
* 如果你在方法中添加{@code @Upload.onTaskStop}注解在任务停止时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskStop {
}
/**
* 如果你在方法中添加{@code @Upload.onTaskCancel}l注解在任务取消时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskCancel {
}
/**
* 如果你在方法中添加{@code @Upload.onTaskFail)注解在任务预失败时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskFail {
}
/**
* 如果你在方法中添加{@code @Upload.onTaskComplete}注解在任务完成时Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskComplete {
}
/**
* 如果你在方法中添加{@code @Upload.onTaskRunning}注解在任务正在下载Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD) public @interface onTaskRunning {
}
/**
* 如果你在方法中添加{@code @Upload.onNoSupportBreakPoint}注解如果该任务不支持断点Aria会调用该方法
*/
@Retention(RetentionPolicy.CLASS) @Target(ElementType.METHOD)
public @interface onNoSupportBreakPoint {
}

@ -120,8 +120,8 @@ class ElementHandle {
* obj.onStart((DownloadTask)task);
* }
*
* public void setListener(final SingleTaskActivity obj) {
* this.obj = obj;
* public void setListener(final Object obj) {
* this.obj = (SingleTaskActivity)obj;
* }
* }
* </code>
@ -193,12 +193,13 @@ class ElementHandle {
//添加设置代理的类
ParameterSpec parameterSpec =
ParameterSpec.builder(obj, "obj").addModifiers(Modifier.FINAL).build();
ParameterSpec.builder(Object.class, "obj").addModifiers(Modifier.FINAL).build();
MethodSpec listener = MethodSpec.methodBuilder(ProxyConstance.SET_LISTENER)
.addModifiers(Modifier.PUBLIC)
.returns(void.class)
.addParameter(parameterSpec)
.addCode("this.obj = obj;\n")
.addAnnotation(Override.class)
.addCode("this.obj = (" + entity.className + ")obj;\n")
.build();
builder.addJavadoc("该文件为Aria自动生成的代理文件,请不要修改该文件的任何代码!\n");

@ -133,15 +133,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
}
};
@Download.onPre void onPre(DownloadTask task) {
}
@Download.onTaskStart
void onStart(DownloadTask task){
}
/**
* 设置start stop 按钮状态
*/
@ -152,7 +143,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Override protected void onResume() {
super.onResume();
Aria.download(this).addSchedulerListener(new MySchedulerListener());
Aria.download(this).register();
//Aria.download(this).addSchedulerListener(new MySchedulerListener());
//registerReceiver(mReceiver, getModule(DownloadModule.class).getDownloadFilter());
}
@ -172,63 +164,14 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
return true;
}
@Override protected int setLayoutId() {
return R.layout.activity_single;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setTitle("单任务下载");
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
mPb.setProgress(target.getPercent());
if (target.getTaskState() == IEntity.STATE_STOP) {
mStart.setText("恢复");
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
setBtState(true);
} else if (target.isDownloading()) {
setBtState(false);
}
mSize.setText(target.getConvertFileSize());
Aria.get(this).getDownloadConfig().setOpenBreadCast(true);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
String text = ((TextView) view).getText().toString();
if (text.equals("重新开始?") || text.equals("开始")) {
Aria.download(this)
.load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
.start();
} else if (text.equals("恢复")) {
Aria.download(this).load(DOWNLOAD_URL).resume();
}
break;
case R.id.stop:
Aria.download(this).load(DOWNLOAD_URL).pause();
break;
case R.id.cancel:
Aria.download(this).load(DOWNLOAD_URL).cancel();
break;
}
}
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
@Override public void onPre(DownloadTask task) {
@Download.onPre protected void onPre(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.obtainMessage(DOWNLOAD_PRE, task.getDownloadEntity().getFileSize())
.sendToTarget();
}
}
@Override public void onNoSupportBreakPoint(DownloadTask task) {
super.onNoSupportBreakPoint(task);
T.showShort(SingleTaskActivity.this, "该下载链接不支持断点");
}
@Override public void onTaskStart(DownloadTask task) {
@Download.onTaskStart void taskStart(DownloadTask task) {
//通过下载地址可以判断任务是否是你指定的任务
if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.obtainMessage(DOWNLOAD_START, task.getDownloadEntity().getFileSize())
@ -236,40 +179,87 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
}
}
@Override public void onTaskResume(DownloadTask task) {
@Download.onTaskRunning protected void running(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.obtainMessage(DOWNLOAD_RUNNING, task).sendToTarget();
}
}
@Download.onTaskResume void taskResume(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.obtainMessage(DOWNLOAD_START, task.getFileSize()).sendToTarget();
}
}
@Override public void onTaskStop(DownloadTask task) {
@Download.onTaskStop void taskStop(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_STOP);
}
}
@Override public void onTaskCancel(DownloadTask task) {
@Download.onTaskCancel void taskCancel(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_CANCEL);
}
}
@Override public void onTaskFail(DownloadTask task) {
@Download.onTaskFail void taskFail(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_FAILE);
}
}
@Override public void onTaskComplete(DownloadTask task) {
@Download.onTaskComplete void taskComplete(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.sendEmptyMessage(DOWNLOAD_COMPLETE);
}
}
@Override public void onTaskRunning(DownloadTask task) {
@Download.onNoSupportBreakPoint public void onNoSupportBreakPoint(DownloadTask task) {
if (task.getKey().equals(DOWNLOAD_URL)) {
mUpdateHandler.obtainMessage(DOWNLOAD_RUNNING, task).sendToTarget();
T.showShort(SingleTaskActivity.this, "该下载链接不支持断点");
}
}
@Override protected int setLayoutId() {
return R.layout.activity_single;
}
@Override protected void init(Bundle savedInstanceState) {
super.init(savedInstanceState);
setTitle("单任务下载");
DownloadTarget target = Aria.download(this).load(DOWNLOAD_URL);
mPb.setProgress(target.getPercent());
if (target.getTaskState() == IEntity.STATE_STOP) {
mStart.setText("恢复");
mStart.setTextColor(getResources().getColor(android.R.color.holo_blue_light));
setBtState(true);
} else if (target.isDownloading()) {
setBtState(false);
}
mSize.setText(target.getConvertFileSize());
Aria.get(this).getDownloadConfig().setOpenBreadCast(true);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.start:
String text = ((TextView) view).getText().toString();
if (text.equals("重新开始?") || text.equals("开始")) {
Aria.download(this)
.load(DOWNLOAD_URL)
.setDownloadPath(Environment.getExternalStorageDirectory().getPath() + "/test.apk")
.start();
} else if (text.equals("恢复")) {
Aria.download(this).load(DOWNLOAD_URL).resume();
}
break;
case R.id.stop:
Aria.download(this).load(DOWNLOAD_URL).pause();
break;
case R.id.cancel:
Aria.download(this).load(DOWNLOAD_URL).cancel();
break;
}
}
}

@ -21,6 +21,7 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import butterknife.Bind;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadEntity;
import com.arialyy.aria.core.download.DownloadTask;
@ -58,51 +59,42 @@ public class MultiDownloadActivity extends BaseActivity<ActivityMultiDownloadBin
@Override protected void onResume() {
super.onResume();
Aria.download(this).addSchedulerListener(new MySchedulerListener());
//Aria.download(this).addSchedulerListener(new MySchedulerListener());
Aria.download(this).register();
}
private class MySchedulerListener extends Aria.DownloadSchedulerListener {
@Override public void onTaskPre(DownloadTask task) {
super.onTaskPre(task);
@Download.onPre void onPre(DownloadTask task) {
L.d(TAG, "download onPre");
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskStart(DownloadTask task) {
super.onTaskStart(task);
@Download.onTaskStart void taskStart(DownloadTask task) {
L.d(TAG, "download start");
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskResume(DownloadTask task) {
super.onTaskResume(task);
@Download.onTaskResume void taskResume(DownloadTask task) {
L.d(TAG, "download resume");
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task);
mAdapter.setProgress(task.getDownloadEntity());
@Download.onTaskStop void taskStop(DownloadTask task) {
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskStop(DownloadTask task) {
super.onTaskStop(task);
@Download.onTaskCancel void taskCancel(DownloadTask task) {
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskCancel(DownloadTask task) {
super.onTaskCancel(task);
mAdapter.updateState(task.getDownloadEntity());
@Download.onTaskFail void taskFail(DownloadTask task) {
L.d(TAG, "download fail");
}
@Override public void onTaskComplete(DownloadTask task) {
super.onTaskComplete(task);
@Download.onTaskComplete void taskComplete(DownloadTask task) {
mAdapter.updateState(task.getDownloadEntity());
}
@Override public void onTaskFail(DownloadTask task) {
super.onTaskFail(task);
L.d(TAG, "download fail");
}
@Download.onTaskRunning void taskRunning(DownloadTask task) {
mAdapter.setProgress(task.getDownloadEntity());
}
}

@ -23,12 +23,15 @@ import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import butterknife.Bind;
import com.arialyy.annotations.Download;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.DownloadTask;
import com.arialyy.frame.util.show.T;
import com.arialyy.simple.R;
import com.arialyy.simple.base.BaseActivity;
import com.arialyy.simple.databinding.ActivityMultiBinding;
import com.arialyy.simple.download.DownloadModule;
import com.arialyy.simple.download.SingleTaskActivity;
import java.util.ArrayList;
import java.util.List;
@ -71,45 +74,37 @@ public class MultiTaskActivity extends BaseActivity<ActivityMultiBinding> {
@Override protected void onResume() {
super.onResume();
Aria.download(this).addSchedulerListener(new DownloadListener());
Aria.download(this).register();
}
@Override protected void onDestroy() {
super.onDestroy();
//unregisterReceiver(mReceiver);
@Download.onTaskStart void taskStart(DownloadTask task) {
mAdapter.updateBtState(task.getKey(), false);
}
@Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data);
if (result == DownloadNumDialog.RESULT_CODE) {
Aria.get(this).getDownloadConfig().setMaxTaskNum(Integer.parseInt(data + ""));
}
@Download.onTaskResume void taskResume(DownloadTask task) {
mAdapter.updateBtState(task.getKey(), false);
}
private class DownloadListener extends Aria.DownloadSchedulerListener {
@Override public void onTaskStart(DownloadTask task) {
super.onTaskStart(task);
mAdapter.updateBtState(task.getDownloadUrl(), false);
@Download.onTaskStop void taskStop(DownloadTask task) {
mAdapter.updateBtState(task.getKey(), true);
}
@Override public void onTaskRunning(DownloadTask task) {
super.onTaskRunning(task);
@Download.onTaskCancel void taskCancel(DownloadTask task) {
mAdapter.updateBtState(task.getKey(), true);
}
@Override public void onTaskResume(DownloadTask task) {
super.onTaskResume(task);
mAdapter.updateBtState(task.getDownloadUrl(), false);
@Download.onTaskFail void taskFail(DownloadTask task) {
mAdapter.updateBtState(task.getKey(), true);
}
@Override public void onTaskStop(DownloadTask task) {
super.onTaskStop(task);
mAdapter.updateBtState(task.getDownloadUrl(), true);
@Download.onTaskComplete void taskComplete(DownloadTask task) {
mAdapter.updateBtState(task.getKey(), true);
}
@Override public void onTaskComplete(DownloadTask task) {
super.onTaskComplete(task);
mAdapter.updateBtState(task.getDownloadUrl(), true);
@Override protected void dataCallback(int result, Object data) {
super.dataCallback(result, data);
if (result == DownloadNumDialog.RESULT_CODE) {
Aria.get(this).getDownloadConfig().setMaxTaskNum(Integer.parseInt(data + ""));
}
}
}

@ -21,6 +21,7 @@ import android.os.Handler;
import android.os.Message;
import butterknife.Bind;
import butterknife.OnClick;
import com.arialyy.annotations.Upload;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.upload.UploadTask;
import com.arialyy.frame.util.FileUtil;
@ -98,48 +99,34 @@ public class UploadActivity extends BaseActivity<ActivityUploadMeanBinding> {
@Override protected void onResume() {
super.onResume();
Aria.upload(this).addSchedulerListener(new UploadListener(mHandler));
//Aria.upload(this).addSchedulerListener(new UploadListener(mHandler));
Aria.upload(this).register();
}
static class UploadListener extends Aria.UploadSchedulerListener {
WeakReference<Handler> handler;
UploadListener(Handler handler) {
this.handler = new WeakReference<>(handler);
}
@Override public void onPre(UploadTask task) {
super.onPre(task);
@Upload.onPre public void onPre(UploadTask task) {
}
@Override public void onTaskPre(UploadTask task) {
super.onTaskPre(task);
@Upload.onTaskPre public void taskPre(UploadTask task) {
L.d(TAG, "fileSize = " + task.getConvertFileSize());
}
@Override public void onTaskStart(UploadTask task) {
super.onTaskStart(task);
handler.get().obtainMessage(START, task).sendToTarget();
@Upload.onTaskStart public void taskStart(UploadTask task) {
mHandler.obtainMessage(START, task).sendToTarget();
}
@Override public void onTaskStop(UploadTask task) {
super.onTaskStop(task);
handler.get().obtainMessage(STOP, task).sendToTarget();
@Upload.onTaskStop public void taskStop(UploadTask task) {
mHandler.obtainMessage(STOP, task).sendToTarget();
}
@Override public void onTaskCancel(UploadTask task) {
super.onTaskCancel(task);
handler.get().obtainMessage(CANCEL, task).sendToTarget();
@Upload.onTaskCancel public void taskCancel(UploadTask task) {
mHandler.obtainMessage(CANCEL, task).sendToTarget();
}
@Override public void onTaskRunning(UploadTask task) {
super.onTaskRunning(task);
handler.get().obtainMessage(RUNNING, task).sendToTarget();
@Upload.onTaskRunning public void taskRunning(UploadTask task) {
mHandler.obtainMessage(RUNNING, task).sendToTarget();
}
@Override public void onTaskComplete(UploadTask task) {
super.onTaskComplete(task);
handler.get().obtainMessage(COMPLETE, task).sendToTarget();
}
@Upload.onTaskComplete public void taskComplete(UploadTask task) {
mHandler.obtainMessage(COMPLETE, task).sendToTarget();
}
}

Loading…
Cancel
Save