修复fragment bug
This commit is contained in:
@ -7,6 +7,7 @@ import android.app.Service;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.Fragment;
|
||||||
import com.arialyy.aria.core.command.CmdFactory;
|
import com.arialyy.aria.core.command.CmdFactory;
|
||||||
import com.arialyy.aria.util.CommonUtil;
|
import com.arialyy.aria.util.CommonUtil;
|
||||||
import com.arialyy.aria.core.command.IDownloadCmd;
|
import com.arialyy.aria.core.command.IDownloadCmd;
|
||||||
@ -21,11 +22,11 @@ import java.util.Set;
|
|||||||
* Aria管理器,任务操作在这里执行
|
* Aria管理器,任务操作在这里执行
|
||||||
*/
|
*/
|
||||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class AriaManager {
|
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public class AriaManager {
|
||||||
private static final Object LOCK = new Object();
|
private static final Object LOCK = new Object();
|
||||||
private static volatile AriaManager INSTANCE = null;
|
private static volatile AriaManager INSTANCE = null;
|
||||||
private Map<String, AMReceiver> mTargets = new HashMap<>();
|
private Map<String, AMReceiver> mTargets = new HashMap<>();
|
||||||
private DownloadManager mManager;
|
private DownloadManager mManager;
|
||||||
private LifeCallback mLifeCallback;
|
private LifeCallback mLifeCallback;
|
||||||
|
|
||||||
private AriaManager(Context context) {
|
private AriaManager(Context context) {
|
||||||
regAppLifeCallback(context);
|
regAppLifeCallback(context);
|
||||||
@ -48,8 +49,8 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* 设置同时下载的任务数
|
* 设置同时下载的任务数
|
||||||
*/
|
*/
|
||||||
public void setDownloadNum(int num){
|
public void setDownloadNum(int num) {
|
||||||
if (num <= 0){
|
if (num <= 0) {
|
||||||
throw new IllegalArgumentException("下载任务数不能小于1");
|
throw new IllegalArgumentException("下载任务数不能小于1");
|
||||||
}
|
}
|
||||||
mManager.getTaskQueue().setDownloadNum(num);
|
mManager.getTaskQueue().setDownloadNum(num);
|
||||||
@ -60,7 +61,7 @@ import java.util.Set;
|
|||||||
*/
|
*/
|
||||||
public void stopAllTask() {
|
public void stopAllTask() {
|
||||||
List<DownloadEntity> allEntity = mManager.getAllDownloadEntity();
|
List<DownloadEntity> allEntity = mManager.getAllDownloadEntity();
|
||||||
List<IDownloadCmd> stopCmds = new ArrayList<>();
|
List<IDownloadCmd> stopCmds = new ArrayList<>();
|
||||||
for (DownloadEntity entity : allEntity) {
|
for (DownloadEntity entity : allEntity) {
|
||||||
if (entity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
|
if (entity.getState() == DownloadEntity.STATE_DOWNLOAD_ING) {
|
||||||
stopCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_STOP));
|
stopCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_STOP));
|
||||||
@ -73,8 +74,8 @@ import java.util.Set;
|
|||||||
* 删除所有任务
|
* 删除所有任务
|
||||||
*/
|
*/
|
||||||
public void cancelAllTask() {
|
public void cancelAllTask() {
|
||||||
List<DownloadEntity> allEntity = mManager.getAllDownloadEntity();
|
List<DownloadEntity> allEntity = mManager.getAllDownloadEntity();
|
||||||
List<IDownloadCmd> cancelCmds = new ArrayList<>();
|
List<IDownloadCmd> cancelCmds = new ArrayList<>();
|
||||||
for (DownloadEntity entity : allEntity) {
|
for (DownloadEntity entity : allEntity) {
|
||||||
cancelCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_CANCEL));
|
cancelCmds.add(CommonUtil.createCmd(entity, CmdFactory.TASK_CANCEL));
|
||||||
}
|
}
|
||||||
@ -88,11 +89,16 @@ import java.util.Set;
|
|||||||
}
|
}
|
||||||
|
|
||||||
private AMReceiver putTarget(Object obj) {
|
private AMReceiver putTarget(Object obj) {
|
||||||
String clsName = obj.getClass().getName();
|
String clsName = obj.getClass().getName();
|
||||||
AMReceiver target = mTargets.get(clsName);
|
AMReceiver target = mTargets.get(clsName);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
target = new AMReceiver();
|
target = new AMReceiver();
|
||||||
target.obj = obj;
|
target.obj = obj;
|
||||||
|
if (obj instanceof android.support.v4.app.Fragment) {
|
||||||
|
clsName += "_" + ((Fragment) obj).getActivity().getClass().getName();
|
||||||
|
} else if (obj instanceof android.app.Fragment) {
|
||||||
|
clsName += "_" + ((android.app.Fragment) obj).getActivity().getClass().getName();
|
||||||
|
}
|
||||||
mTargets.put(clsName, target);
|
mTargets.put(clsName, target);
|
||||||
}
|
}
|
||||||
return target;
|
return target;
|
||||||
@ -149,7 +155,8 @@ import java.util.Set;
|
|||||||
@Override public void onActivityDestroyed(Activity activity) {
|
@Override public void onActivityDestroyed(Activity activity) {
|
||||||
Set<String> keys = mTargets.keySet();
|
Set<String> keys = mTargets.keySet();
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
if (key.equals(activity.getClass().getName())) {
|
String clsName = activity.getClass().getName();
|
||||||
|
if (key.equals(clsName) || key.contains(clsName)) {
|
||||||
AMReceiver target = mTargets.get(key);
|
AMReceiver target = mTargets.get(key);
|
||||||
if (target.obj != null) {
|
if (target.obj != null) {
|
||||||
if (target.obj instanceof Application || target.obj instanceof Service) break;
|
if (target.obj instanceof Application || target.obj instanceof Service) break;
|
||||||
|
@ -1,18 +1,19 @@
|
|||||||
# Project-wide Gradle settings.
|
## Project-wide Gradle settings.
|
||||||
|
#
|
||||||
# IDE (e.g. Android Studio) users:
|
|
||||||
# Gradle settings configured through the IDE *will override*
|
|
||||||
# any settings specified in this file.
|
|
||||||
|
|
||||||
# For more details on how to configure your build environment visit
|
# For more details on how to configure your build environment visit
|
||||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||||
|
#
|
||||||
# Specifies the JVM arguments used for the daemon process.
|
# Specifies the JVM arguments used for the daemon process.
|
||||||
# The setting is particularly useful for tweaking memory settings.
|
# The setting is particularly useful for tweaking memory settings.
|
||||||
# Default value: -Xmx10248m -XX:MaxPermSize=256m
|
# Default value: -Xmx1024m -XX:MaxPermSize=256m
|
||||||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||||
|
#
|
||||||
# When configured, Gradle will run in incubating parallel mode.
|
# When configured, Gradle will run in incubating parallel mode.
|
||||||
# This option should only be used with decoupled projects. More details, visit
|
# This option should only be used with decoupled projects. More details, visit
|
||||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||||
# org.gradle.parallel=true
|
# org.gradle.parallel=true
|
||||||
|
#Wed Dec 07 20:19:22 CST 2016
|
||||||
|
systemProp.http.proxyPassword=7RbgsDfOoBn
|
||||||
|
systemProp.http.proxyHost=hilton.h.xduotai.com
|
||||||
|
systemProp.http.proxyUser=duotai
|
||||||
|
systemProp.http.proxyPort=10969
|
||||||
|
Reference in New Issue
Block a user