Merge pull request #709 from chenfei0928/master

允许不使用apt直接通过实现监听器来回调下载进度更新
pull/716/head
lyy 4 years ago committed by GitHub
commit 41bae31d6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 50
      Aria/src/main/java/com/arialyy/aria/core/common/ProxyHelper.java
  2. 11
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadGroupTaskListener.java
  3. 11
      Aria/src/main/java/com/arialyy/aria/core/download/DownloadTaskListener.java
  4. 10
      Aria/src/main/java/com/arialyy/aria/core/scheduler/DownloadTaskInternalListenerInterface.java
  5. 8
      Aria/src/main/java/com/arialyy/aria/core/scheduler/M3U8PeerTaskListener.java
  6. 29
      Aria/src/main/java/com/arialyy/aria/core/scheduler/M3U8PeerTaskListenerInterface.java
  7. 24
      Aria/src/main/java/com/arialyy/aria/core/scheduler/NormalTaskListener.java
  8. 81
      Aria/src/main/java/com/arialyy/aria/core/scheduler/NormalTaskListenerInterface.java
  9. 18
      Aria/src/main/java/com/arialyy/aria/core/scheduler/SubTaskListener.java
  10. 42
      Aria/src/main/java/com/arialyy/aria/core/scheduler/SubTaskListenerInterface.java
  11. 54
      Aria/src/main/java/com/arialyy/aria/core/scheduler/TaskSchedulers.java
  12. 13
      Aria/src/main/java/com/arialyy/aria/core/upload/UploadTaskListener.java

@ -16,6 +16,13 @@
package com.arialyy.aria.core.common; package com.arialyy.aria.core.common;
import com.arialyy.annotations.TaskEnum; import com.arialyy.annotations.TaskEnum;
import com.arialyy.aria.core.download.DownloadGroupTaskListener;
import com.arialyy.aria.core.download.DownloadTaskListener;
import com.arialyy.aria.core.scheduler.DownloadTaskInternalListenerInterface;
import com.arialyy.aria.core.scheduler.M3U8PeerTaskListenerInterface;
import com.arialyy.aria.core.scheduler.SubTaskListenerInterface;
import com.arialyy.aria.core.upload.UploadTaskListener;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -69,12 +76,25 @@ public class ProxyHelper {
* @return {@link #PROXY_TYPE_DOWNLOAD}如果没有实体对象则返回空的list * @return {@link #PROXY_TYPE_DOWNLOAD}如果没有实体对象则返回空的list
*/ */
public Set<Integer> checkProxyType(Class clazz) { public Set<Integer> checkProxyType(Class clazz) {
final String className = clazz.getName();
Set<Integer> result = mProxyCache.get(clazz.getName()); Set<Integer> result = mProxyCache.get(clazz.getName());
if (result != null) { if (result != null) {
return result; return result;
} }
result = new HashSet<>(); result = checkProxyTypeByInterface(clazz);
if (result != null) {
return result;
}
result = checkProxyTypeByProxyClass(clazz);
if (!result.isEmpty()) {
mProxyCache.put(clazz.getName(), result);
}
return result;
}
private Set<Integer> checkProxyTypeByProxyClass(Class clazz) {
final String className = clazz.getName();
Set<Integer> result = new HashSet<>();
if (checkProxyExist(className, TaskEnum.DOWNLOAD_GROUP.proxySuffix)) { if (checkProxyExist(className, TaskEnum.DOWNLOAD_GROUP.proxySuffix)) {
result.add(PROXY_TYPE_DOWNLOAD_GROUP); result.add(PROXY_TYPE_DOWNLOAD_GROUP);
} }
@ -93,9 +113,31 @@ public class ProxyHelper {
if (checkProxyExist(className, TaskEnum.DOWNLOAD_GROUP_SUB.proxySuffix)) { if (checkProxyExist(className, TaskEnum.DOWNLOAD_GROUP_SUB.proxySuffix)) {
result.add(PROXY_TYPE_DOWNLOAD_GROUP_SUB); result.add(PROXY_TYPE_DOWNLOAD_GROUP_SUB);
} }
return result;
}
if (!result.isEmpty()) { private Set<Integer> checkProxyTypeByInterface(Class clazz) {
mProxyCache.put(clazz.getName(), result); if (!DownloadTaskInternalListenerInterface.class.isAssignableFrom(clazz)) {
return null;
}
Set<Integer> result = new HashSet<>();
if (DownloadGroupTaskListener.class.isAssignableFrom(clazz)) {
result.add(PROXY_TYPE_DOWNLOAD_GROUP);
}
if (DownloadTaskListener.class.isAssignableFrom(clazz)) {
result.add(PROXY_TYPE_DOWNLOAD);
}
if (UploadTaskListener.class.isAssignableFrom(clazz)) {
result.add(PROXY_TYPE_UPLOAD);
}
if (M3U8PeerTaskListenerInterface.class.isAssignableFrom(clazz)) {
result.add(PROXY_TYPE_M3U8_PEER);
}
if (SubTaskListenerInterface.class.isAssignableFrom(clazz)) {
result.add(PROXY_TYPE_DOWNLOAD_GROUP_SUB);
} }
return result; return result;
} }

@ -0,0 +1,11 @@
package com.arialyy.aria.core.download;
import com.arialyy.aria.core.scheduler.NormalTaskListenerInterface;
import com.arialyy.aria.core.task.DownloadGroupTask;
/**
* @author ChenFei(chenfei0928 @ gmail.com)
* @date 2020-07-07 14:12
*/
public interface DownloadGroupTaskListener extends NormalTaskListenerInterface<DownloadGroupTask> {
}

@ -0,0 +1,11 @@
package com.arialyy.aria.core.download;
import com.arialyy.aria.core.scheduler.NormalTaskListenerInterface;
import com.arialyy.aria.core.task.DownloadTask;
/**
* @author ChenFei(chenfei0928 @ gmail.com)
* @date 2020-07-07 14:12
*/
public interface DownloadTaskListener extends NormalTaskListenerInterface<DownloadTask> {
}

@ -0,0 +1,10 @@
package com.arialyy.aria.core.scheduler;
/**
* 直接实现监听器回调接口的基类不对外部直接开放仅作为内部监听器的父接口使用
*
* @author ChenFei(chenfei0928 @ gmail.com)
* @date 2020-07-07 15:18
*/
public interface DownloadTaskInternalListenerInterface {
}

@ -19,15 +19,15 @@ package com.arialyy.aria.core.scheduler;
* Created by Aria.Lao on 2019/6/26. * Created by Aria.Lao on 2019/6/26.
* m3u8切片事件回调类 * m3u8切片事件回调类
*/ */
public class M3U8PeerTaskListener implements ISchedulerListener { public class M3U8PeerTaskListener implements M3U8PeerTaskListenerInterface, ISchedulerListener{
public void onPeerStart(final String m3u8Url, final String peerPath, final int peerIndex) { @Override public void onPeerStart(final String m3u8Url, final String peerPath, final int peerIndex) {
} }
public void onPeerComplete(final String m3u8Url, final String peerPath, final int peerIndex) { @Override public void onPeerComplete(final String m3u8Url, final String peerPath, final int peerIndex) {
} }
public void onPeerFail(final String m3u8Url, final String peerPath, final int peerIndex) { @Override public void onPeerFail(final String m3u8Url, final String peerPath, final int peerIndex) {
} }
@Override public void setListener(Object obj) { @Override public void setListener(Object obj) {

@ -0,0 +1,29 @@
/*
* 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.scheduler;
/**
* Created by Aria.Lao on 2019/6/26.
* m3u8切片事件回调类
*/
public interface M3U8PeerTaskListenerInterface extends DownloadTaskInternalListenerInterface {
public void onPeerStart(final String m3u8Url, final String peerPath, final int peerIndex);
public void onPeerComplete(final String m3u8Url, final String peerPath, final int peerIndex);
public void onPeerFail(final String m3u8Url, final String peerPath, final int peerIndex);
}

@ -24,12 +24,12 @@ import com.arialyy.aria.core.task.UploadTask;
* Created by Aria.Lao on 2017/6/7. * Created by Aria.Lao on 2017/6/7.
* 普通任务事件{@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}回调类 * 普通任务事件{@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}回调类
*/ */
public class NormalTaskListener<TASK extends ITask> implements ISchedulerListener { public class NormalTaskListener<TASK extends ITask> implements NormalTaskListenerInterface<TASK>, ISchedulerListener {
/** /**
* 队列已经满了继续创建任务将会回调该方法 * 队列已经满了继续创建任务将会回调该方法
*/ */
public void onWait(TASK task) { @Override public void onWait(TASK task) {
} }
@ -37,42 +37,42 @@ public class NormalTaskListener<TASK extends ITask> implements ISchedulerListene
* 预处理有时有些地址链接比较慢这时可以先在这个地方出来一些界面上的UI如按钮的状态 * 预处理有时有些地址链接比较慢这时可以先在这个地方出来一些界面上的UI如按钮的状态
* 在这个回调中任务是获取不到文件大小下载速度等参数 * 在这个回调中任务是获取不到文件大小下载速度等参数
*/ */
public void onPre(TASK task) { @Override public void onPre(TASK task) {
} }
/** /**
* 任务预加载完成 * 任务预加载完成
*/ */
public void onTaskPre(TASK task) { @Override public void onTaskPre(TASK task) {
} }
/** /**
* 任务恢复下载 * 任务恢复下载
*/ */
public void onTaskResume(TASK task) { @Override public void onTaskResume(TASK task) {
} }
/** /**
* 任务开始 * 任务开始
*/ */
public void onTaskStart(TASK task) { @Override public void onTaskStart(TASK task) {
} }
/** /**
* 任务停止 * 任务停止
*/ */
public void onTaskStop(TASK task) { @Override public void onTaskStop(TASK task) {
} }
/** /**
* 任务取消 * 任务取消
*/ */
public void onTaskCancel(TASK task) { @Override public void onTaskCancel(TASK task) {
} }
@ -88,25 +88,25 @@ public class NormalTaskListener<TASK extends ITask> implements ISchedulerListene
/** /**
* 任务失败 * 任务失败
*/ */
public void onTaskFail(TASK task, Exception e) { @Override public void onTaskFail(TASK task, Exception e) {
} }
/** /**
* 任务完成 * 任务完成
*/ */
public void onTaskComplete(TASK task) { @Override public void onTaskComplete(TASK task) {
} }
/** /**
* 任务执行中 * 任务执行中
*/ */
public void onTaskRunning(TASK task) { @Override public void onTaskRunning(TASK task) {
} }
public void onNoSupportBreakPoint(TASK task) { @Override public void onNoSupportBreakPoint(TASK task) {
} }

@ -0,0 +1,81 @@
/*
* 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.scheduler;
import com.arialyy.aria.core.task.DownloadGroupTask;
import com.arialyy.aria.core.task.DownloadTask;
import com.arialyy.aria.core.task.ITask;
import com.arialyy.aria.core.task.UploadTask;
/**
* Created by Aria.Lao on 2017/6/7.
* 普通任务事件{@link DownloadTask}{@link UploadTask}{@link DownloadGroupTask}回调类
*/
public interface NormalTaskListenerInterface<TASK extends ITask> extends DownloadTaskInternalListenerInterface {
/**
* 队列已经满了继续创建任务将会回调该方法
*/
public void onWait(TASK task);
/**
* 预处理有时有些地址链接比较慢这时可以先在这个地方出来一些界面上的UI如按钮的状态
* 在这个回调中任务是获取不到文件大小下载速度等参数
*/
public void onPre(TASK task);
/**
* 任务预加载完成
*/
public void onTaskPre(TASK task);
/**
* 任务恢复下载
*/
public void onTaskResume(TASK task);
/**
* 任务开始
*/
public void onTaskStart(TASK task);
/**
* 任务停止
*/
public void onTaskStop(TASK task);
/**
* 任务取消
*/
public void onTaskCancel(TASK task);
/**
* 任务失败
*/
public void onTaskFail(TASK task, Exception e);
/**
* 任务完成
*/
public void onTaskComplete(TASK task);
/**
* 任务执行中
*/
public void onTaskRunning(TASK task);
public void onNoSupportBreakPoint(TASK task);
}

@ -23,29 +23,29 @@ import com.arialyy.aria.core.task.ITask;
* 子任务事件回调类 * 子任务事件回调类
*/ */
public class SubTaskListener<TASK extends ITask, SUB_ENTITY extends AbsNormalEntity> public class SubTaskListener<TASK extends ITask, SUB_ENTITY extends AbsNormalEntity>
implements ISchedulerListener { implements SubTaskListenerInterface<TASK, SUB_ENTITY>, ISchedulerListener {
public void onNoSupportBreakPoint(TASK task) { @Override public void onNoSupportBreakPoint(TASK task) {
} }
public void onSubTaskPre(TASK task, SUB_ENTITY subTask) { @Override public void onSubTaskPre(TASK task, SUB_ENTITY subTask) {
} }
public void onSubTaskStart(TASK task, SUB_ENTITY subTask) { @Override public void onSubTaskStart(TASK task, SUB_ENTITY subTask) {
} }
public void onSubTaskStop(TASK task, SUB_ENTITY subTask) { @Override public void onSubTaskStop(TASK task, SUB_ENTITY subTask) {
} }
public void onSubTaskCancel(TASK task, SUB_ENTITY subTask) { @Override public void onSubTaskCancel(TASK task, SUB_ENTITY subTask) {
} }
public void onSubTaskComplete(TASK task, SUB_ENTITY subTask) { @Override public void onSubTaskComplete(TASK task, SUB_ENTITY subTask) {
} }
@ -54,11 +54,11 @@ public class SubTaskListener<TASK extends ITask, SUB_ENTITY extends AbsNormalEnt
} }
public void onSubTaskFail(TASK task, SUB_ENTITY subTask, Exception e) { @Override public void onSubTaskFail(TASK task, SUB_ENTITY subTask, Exception e) {
} }
public void onSubTaskRunning(TASK task, SUB_ENTITY subTask) { @Override public void onSubTaskRunning(TASK task, SUB_ENTITY subTask) {
} }

@ -0,0 +1,42 @@
/*
* 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.scheduler;
import com.arialyy.aria.core.common.AbsNormalEntity;
import com.arialyy.aria.core.task.ITask;
/**
* Created by Aria.Lao on 2019/6/26.
* 子任务事件回调类
*/
public interface SubTaskListenerInterface<TASK extends ITask, SUB_ENTITY extends AbsNormalEntity> extends DownloadTaskInternalListenerInterface {
public void onNoSupportBreakPoint(TASK task);
public void onSubTaskPre(TASK task, SUB_ENTITY subTask);
public void onSubTaskStart(TASK task, SUB_ENTITY subTask);
public void onSubTaskStop(TASK task, SUB_ENTITY subTask);
public void onSubTaskCancel(TASK task, SUB_ENTITY subTask);
public void onSubTaskComplete(TASK task, SUB_ENTITY subTask);
public void onSubTaskFail(TASK task, SUB_ENTITY subTask, Exception e);
public void onSubTaskRunning(TASK task, SUB_ENTITY subTask);
}

@ -18,7 +18,6 @@ package com.arialyy.aria.core.scheduler;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Message; import android.os.Message;
import android.util.Log;
import com.arialyy.annotations.TaskEnum; import com.arialyy.annotations.TaskEnum;
import com.arialyy.aria.core.AriaConfig; import com.arialyy.aria.core.AriaConfig;
import com.arialyy.aria.core.common.AbsEntity; import com.arialyy.aria.core.common.AbsEntity;
@ -54,7 +53,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
private static volatile TaskSchedulers INSTANCE; private static volatile TaskSchedulers INSTANCE;
private static FailureTaskHandler mFailureTaskHandler; private static FailureTaskHandler mFailureTaskHandler;
private Map<String, Map<TaskEnum, ISchedulerListener>> mObservers = new ConcurrentHashMap<>(); private Map<String, Map<TaskEnum, Object>> mObservers = new ConcurrentHashMap<>();
private AriaConfig mAriaConfig; private AriaConfig mAriaConfig;
private TaskSchedulers() { private TaskSchedulers() {
@ -99,15 +98,19 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
*/ */
public void register(Object obj, TaskEnum taskEnum) { public void register(Object obj, TaskEnum taskEnum) {
String targetName = obj.getClass().getName(); String targetName = obj.getClass().getName();
Map<TaskEnum, ISchedulerListener> listeners = mObservers.get(getKey(obj)); Map<TaskEnum, Object> listeners = mObservers.get(getKey(obj));
if (listeners == null) { if (listeners == null) {
listeners = new ConcurrentHashMap<>(); listeners = new ConcurrentHashMap<>();
mObservers.put(getKey(obj), listeners); mObservers.put(getKey(obj), listeners);
} }
String proxyClassName = targetName + taskEnum.proxySuffix;
if (!hasProxyListener(listeners, taskEnum)) { if (!hasProxyListener(listeners, taskEnum)) {
if (obj instanceof DownloadTaskInternalListenerInterface) {
listeners.put(taskEnum, obj);
return;
}
String proxyClassName = targetName + taskEnum.proxySuffix;
ISchedulerListener listener = createListener(proxyClassName); ISchedulerListener listener = createListener(proxyClassName);
if (listener != null) { if (listener != null) {
listener.setListener(obj); listener.setListener(obj);
@ -124,7 +127,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
* @param taskEnum 代理类类型 * @param taskEnum 代理类类型
* @return true已注册代理类false没有注册代理类 * @return true已注册代理类false没有注册代理类
*/ */
private boolean hasProxyListener(Map<TaskEnum, ISchedulerListener> listeners, TaskEnum taskEnum) { private boolean hasProxyListener(Map<TaskEnum, Object> listeners, TaskEnum taskEnum) {
return !listeners.isEmpty() && listeners.get(taskEnum) != null; return !listeners.isEmpty() && listeners.get(taskEnum) != null;
} }
@ -137,9 +140,9 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
if (!mObservers.containsKey(getKey(obj))) { if (!mObservers.containsKey(getKey(obj))) {
return; return;
} }
for (Iterator<Map.Entry<String, Map<TaskEnum, ISchedulerListener>>> iter = for (Iterator<Map.Entry<String, Map<TaskEnum, Object>>> iter =
mObservers.entrySet().iterator(); iter.hasNext(); ) { mObservers.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, Map<TaskEnum, ISchedulerListener>> entry = iter.next(); Map.Entry<String, Map<TaskEnum, Object>> entry = iter.next();
if (entry.getKey().equals(getKey(obj))) { if (entry.getKey().equals(getKey(obj))) {
iter.remove(); iter.remove();
@ -202,12 +205,12 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
if (mObservers.size() > 0) { if (mObservers.size() > 0) {
Set<String> keys = mObservers.keySet(); Set<String> keys = mObservers.keySet();
for (String key : keys) { for (String key : keys) {
Map<TaskEnum, ISchedulerListener> listeners = mObservers.get(key); Map<TaskEnum, Object> listeners = mObservers.get(key);
if (listeners == null || listeners.isEmpty()) { if (listeners == null || listeners.isEmpty()) {
continue; continue;
} }
M3U8PeerTaskListener listener = M3U8PeerTaskListenerInterface listener =
(M3U8PeerTaskListener) listeners.get(TaskEnum.M3U8_PEER); (M3U8PeerTaskListenerInterface) listeners.get(TaskEnum.M3U8_PEER);
if (listener == null) { if (listener == null) {
continue; continue;
} }
@ -235,6 +238,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
boolean canSend = mAriaConfig.getAConfig().isUseBroadcast(); boolean canSend = mAriaConfig.getAConfig().isUseBroadcast();
if (canSend) { if (canSend) {
Intent intent = new Intent(ISchedulers.ARIA_TASK_INFO_ACTION); Intent intent = new Intent(ISchedulers.ARIA_TASK_INFO_ACTION);
intent.setPackage(mAriaConfig.getAPP().getPackageName());
intent.putExtras(data); intent.putExtras(data);
mAriaConfig.getAPP().sendBroadcast(intent); mAriaConfig.getAPP().sendBroadcast(intent);
} }
@ -250,12 +254,12 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
if (mObservers.size() > 0) { if (mObservers.size() > 0) {
Set<String> keys = mObservers.keySet(); Set<String> keys = mObservers.keySet();
for (String key : keys) { for (String key : keys) {
Map<TaskEnum, ISchedulerListener> listeners = mObservers.get(key); Map<TaskEnum, Object> listeners = mObservers.get(key);
if (listeners == null || listeners.isEmpty()) { if (listeners == null || listeners.isEmpty()) {
continue; continue;
} }
SubTaskListener<TASK, AbsNormalEntity> listener = SubTaskListenerInterface<TASK, AbsNormalEntity> listener =
(SubTaskListener<TASK, AbsNormalEntity>) listeners.get(TaskEnum.DOWNLOAD_GROUP_SUB); (SubTaskListenerInterface<TASK, AbsNormalEntity>) listeners.get(TaskEnum.DOWNLOAD_GROUP_SUB);
if (listener == null) { if (listener == null) {
continue; continue;
} }
@ -358,6 +362,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
boolean canSend = mAriaConfig.getAConfig().isUseBroadcast(); boolean canSend = mAriaConfig.getAConfig().isUseBroadcast();
if (canSend) { if (canSend) {
Intent intent = new Intent(ISchedulers.ARIA_TASK_INFO_ACTION); Intent intent = new Intent(ISchedulers.ARIA_TASK_INFO_ACTION);
intent.setPackage(mAriaConfig.getAPP().getPackageName());
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putInt(ISchedulers.TASK_TYPE, taskType); b.putInt(ISchedulers.TASK_TYPE, taskType);
b.putInt(ISchedulers.TASK_STATE, ISchedulers.FAIL); b.putInt(ISchedulers.TASK_STATE, ISchedulers.FAIL);
@ -368,18 +373,18 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
if (mObservers.size() > 0) { if (mObservers.size() > 0) {
Set<String> keys = mObservers.keySet(); Set<String> keys = mObservers.keySet();
for (String key : keys) { for (String key : keys) {
Map<TaskEnum, ISchedulerListener> listeners = mObservers.get(key); Map<TaskEnum, Object> listeners = mObservers.get(key);
if (listeners == null || listeners.isEmpty()) { if (listeners == null || listeners.isEmpty()) {
continue; continue;
} }
NormalTaskListener<TASK> listener = null; NormalTaskListenerInterface<TASK> listener = null;
if (mObservers.get(key) != null) { if (mObservers.get(key) != null) {
if (taskType == ITask.DOWNLOAD) { if (taskType == ITask.DOWNLOAD) {
listener = (NormalTaskListener<TASK>) listeners.get(TaskEnum.DOWNLOAD); listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD);
} else if (taskType == ITask.DOWNLOAD_GROUP) { } else if (taskType == ITask.DOWNLOAD_GROUP) {
listener = (NormalTaskListener<TASK>) listeners.get(TaskEnum.DOWNLOAD_GROUP); listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD_GROUP);
} else if (taskType == ITask.DOWNLOAD_GROUP) { } else if (taskType == ITask.DOWNLOAD_GROUP) {
listener = (NormalTaskListener<TASK>) listeners.get(TaskEnum.UPLOAD); listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.UPLOAD);
} }
} }
if (listener != null) { if (listener != null) {
@ -399,18 +404,18 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
if (mObservers.size() > 0) { if (mObservers.size() > 0) {
Set<String> keys = mObservers.keySet(); Set<String> keys = mObservers.keySet();
for (String key : keys) { for (String key : keys) {
Map<TaskEnum, ISchedulerListener> listeners = mObservers.get(key); Map<TaskEnum, Object> listeners = mObservers.get(key);
if (listeners == null || listeners.isEmpty()) { if (listeners == null || listeners.isEmpty()) {
continue; continue;
} }
NormalTaskListener<TASK> listener = null; NormalTaskListenerInterface<TASK> listener = null;
if (mObservers.get(key) != null) { if (mObservers.get(key) != null) {
if (task instanceof DownloadTask) { if (task instanceof DownloadTask) {
listener = (NormalTaskListener<TASK>) listeners.get(TaskEnum.DOWNLOAD); listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD);
} else if (task instanceof DownloadGroupTask) { } else if (task instanceof DownloadGroupTask) {
listener = (NormalTaskListener<TASK>) listeners.get(TaskEnum.DOWNLOAD_GROUP); listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.DOWNLOAD_GROUP);
} else if (task instanceof UploadTask) { } else if (task instanceof UploadTask) {
listener = (NormalTaskListener<TASK>) listeners.get(TaskEnum.UPLOAD); listener = (NormalTaskListenerInterface<TASK>) listeners.get(TaskEnum.UPLOAD);
} }
} }
if (listener != null) { if (listener != null) {
@ -420,7 +425,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
} }
} }
private void normalTaskCallback(int state, TASK task, NormalTaskListener<TASK> listener) { private void normalTaskCallback(int state, TASK task, NormalTaskListenerInterface<TASK> listener) {
if (listener != null) { if (listener != null) {
if (task == null && state != ISchedulers.CHECK_FAIL) { if (task == null && state != ISchedulers.CHECK_FAIL) {
ALog.e(TAG, "TASK 为null,回调失败"); ALog.e(TAG, "TASK 为null,回调失败");
@ -497,6 +502,7 @@ public class TaskSchedulers<TASK extends ITask> implements ISchedulers {
*/ */
private Intent createData(int taskState, int taskType, AbsEntity entity) { private Intent createData(int taskState, int taskType, AbsEntity entity) {
Intent intent = new Intent(ISchedulers.ARIA_TASK_INFO_ACTION); Intent intent = new Intent(ISchedulers.ARIA_TASK_INFO_ACTION);
intent.setPackage(mAriaConfig.getAPP().getPackageName());
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putInt(ISchedulers.TASK_TYPE, taskType); b.putInt(ISchedulers.TASK_TYPE, taskType);
b.putInt(ISchedulers.TASK_STATE, taskState); b.putInt(ISchedulers.TASK_STATE, taskState);

@ -0,0 +1,13 @@
package com.arialyy.aria.core.upload;
import com.arialyy.aria.core.scheduler.NormalTaskListenerInterface;
import com.arialyy.aria.core.task.UploadTask;
/**
* 上传任务接口
*
* @author ChenFei(chenfei0928 @ gmail.com)
* @date 2020-07-07 13:23
*/
public interface UploadTaskListener extends NormalTaskListenerInterface<UploadTask> {
}
Loading…
Cancel
Save