From 15e4194f26945bcb46f410041a055d470b049a76 Mon Sep 17 00:00:00 2001
From: AriaLyy <511455842@qq.com>
Date: Tue, 3 Jan 2017 10:11:19 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B2=A1=E5=81=9A=E5=95=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/misc.xml | 2 +-
Aria/build.gradle | 4 +-
.../com/arialyy/aria/core/AriaManager.java | 55 ++++++++++++-------
3 files changed, 39 insertions(+), 22 deletions(-)
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 5d199810..fbb68289 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -37,7 +37,7 @@
-
+
diff --git a/Aria/build.gradle b/Aria/build.gradle
index f9c8604e..b101e38d 100644
--- a/Aria/build.gradle
+++ b/Aria/build.gradle
@@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 23
- versionCode 81
- versionName "2.3.3"
+ versionCode 82
+ versionName "2.3.4"
}
buildTypes {
release {
diff --git a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
index a48e93c8..0377224e 100644
--- a/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
+++ b/Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
@@ -29,6 +29,7 @@ import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import com.arialyy.aria.core.command.CmdFactory;
+import com.arialyy.aria.core.scheduler.OnSchedulerListener;
import com.arialyy.aria.util.CheckUtil;
import com.arialyy.aria.util.CommonUtil;
import com.arialyy.aria.core.command.IDownloadCmd;
@@ -37,6 +38,7 @@ import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -47,12 +49,12 @@ import java.util.Set;
* Aria管理器,任务操作在这里执行
*/
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class AriaManager {
- private static final String TAG = "AriaManager";
- private static final Object LOCK = new Object();
- private static volatile AriaManager INSTANCE = null;
- private Map mTargets = new HashMap<>();
+ private static final String TAG = "AriaManager";
+ private static final Object LOCK = new Object();
+ private static volatile AriaManager INSTANCE = null;
+ private Map mTargets = new HashMap<>();
private DownloadManager mManager;
- private LifeCallback mLifeCallback;
+ private LifeCallback mLifeCallback;
private AriaManager(Context context) {
regAppLifeCallback(context);
@@ -99,7 +101,7 @@ import java.util.Set;
*/
public void stopAllTask() {
List allEntity = mManager.getAllDownloadEntity();
- List stopCmds = new ArrayList<>();
+ List stopCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) {
if (entity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
stopCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_STOP));
@@ -158,8 +160,8 @@ import java.util.Set;
* 删除所有任务
*/
public void cancelAllTask() {
- List allEntity = mManager.getAllDownloadEntity();
- List cancelCmds = new ArrayList<>();
+ List allEntity = mManager.getAllDownloadEntity();
+ List cancelCmds = new ArrayList<>();
for (DownloadEntity entity : allEntity) {
cancelCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_CANCEL));
}
@@ -173,9 +175,9 @@ import java.util.Set;
}
private AMReceiver putTarget(Object obj) {
- String clsName = obj.getClass().getName();
- AMReceiver target = null;
- String key = "";
+ String clsName = obj.getClass().getName();
+ AMReceiver target = null;
+ String key = "";
if (!(obj instanceof Activity)) {
if (obj instanceof android.support.v4.app.Fragment) {
key = clsName + "_" + ((Fragment) obj).getActivity().getClass().getName();
@@ -209,12 +211,12 @@ import java.util.Set;
*/
private void handleDialogDialogLift(Dialog dialog) {
try {
- Field dismissField = CommonUtil.getField(dialog.getClass(), "mDismissMessage");
- Message dismissMsg = (Message) dismissField.get(dialog);
+ Field dismissField = CommonUtil.getField(dialog.getClass(), "mDismissMessage");
+ Message dismissMsg = (Message) dismissField.get(dialog);
//如果Dialog已经设置Dismiss事件,则查找cancel事件
if (dismissMsg != null) {
- Field cancelField = CommonUtil.getField(dialog.getClass(), "mCancelMessage");
- Message cancelMsg = (Message) cancelField.get(dialog);
+ Field cancelField = CommonUtil.getField(dialog.getClass(), "mCancelMessage");
+ Message cancelMsg = (Message) cancelField.get(dialog);
if (cancelMsg != null) {
Log.e(TAG, "你已经对Dialog设置了Dismiss和cancel事件。为了防止内存泄露,"
+ "请在dismiss方法中调用Aria.whit(this).removeSchedulerListener();来注销事件");
@@ -282,20 +284,35 @@ import java.util.Set;
* onDestroy
*/
private void destroySchedulerListener(Object obj) {
- Set keys = mTargets.keySet();
- String clsName = obj.getClass().getName();
- for (String key : keys) {
+ Set keys = mTargets.keySet();
+ String clsName = obj.getClass().getName();
+ for (Iterator> iter = mTargets.entrySet().iterator();
+ iter.hasNext(); ) {
+ Map.Entry entry = iter.next();
+ String key = entry.getKey();
if (key.equals(clsName) || key.contains(clsName)) {
AMReceiver receiver = mTargets.get(key);
if (receiver.obj != null) {
if (receiver.obj instanceof Application || receiver.obj instanceof Service) break;
receiver.removeSchedulerListener();
receiver.destroy();
- mTargets.remove(key);
+ iter.remove();
}
break;
}
}
+ //for (String key : keys) {
+ // if (key.equals(clsName) || key.contains(clsName)) {
+ // AMReceiver receiver = mTargets.get(key);
+ // if (receiver.obj != null) {
+ // if (receiver.obj instanceof Application || receiver.obj instanceof Service) break;
+ // receiver.removeSchedulerListener();
+ // receiver.destroy();
+ // mTargets.remove(key);
+ // }
+ // break;
+ // }
+ //}
}
/**