laoyuyu 7 years ago
parent d935e20822
commit 066bbbd006
  1. 2
      Aria/src/main/java/com/arialyy/aria/core/AriaManager.java
  2. 10
      Aria/src/main/java/com/arialyy/aria/core/scheduler/AbsSchedulers.java
  3. 8
      app/src/main/java/com/arialyy/simple/download/SingleTaskActivity.java

@ -347,7 +347,7 @@ import org.xml.sax.SAXException;
if (TextUtils.isEmpty(key)) { if (TextUtils.isEmpty(key)) {
throw new IllegalArgumentException("未知类型"); throw new IllegalArgumentException("未知类型");
} }
key += isDownload ? DOWNLOAD : UPLOAD; key += (isDownload ? DOWNLOAD : UPLOAD) + obj.hashCode();
return key; return key;
} }

@ -54,12 +54,12 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
@Override public void register(Object obj) { @Override public void register(Object obj) {
String targetName = obj.getClass().getName(); String targetName = obj.getClass().getName();
AbsSchedulerListener<TASK, AbsNormalEntity> listener = mObservers.get(targetName); AbsSchedulerListener<TASK, AbsNormalEntity> listener = mObservers.get(getKey(obj));
if (listener == null) { if (listener == null) {
listener = createListener(targetName); listener = createListener(targetName);
if (listener != null) { if (listener != null) {
listener.setListener(obj); listener.setListener(obj);
mObservers.put(targetName, listener); mObservers.put(getKey(obj), listener);
} else { } else {
ALog.e(TAG, "注册错误,没有【" + targetName + "】观察者"); ALog.e(TAG, "注册错误,没有【" + targetName + "】观察者");
} }
@ -73,12 +73,16 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
for (Iterator<Map.Entry<String, AbsSchedulerListener<TASK, AbsNormalEntity>>> iter = for (Iterator<Map.Entry<String, AbsSchedulerListener<TASK, AbsNormalEntity>>> iter =
mObservers.entrySet().iterator(); iter.hasNext(); ) { mObservers.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, AbsSchedulerListener<TASK, AbsNormalEntity>> entry = iter.next(); Map.Entry<String, AbsSchedulerListener<TASK, AbsNormalEntity>> entry = iter.next();
if (entry.getKey().equals(obj.getClass().getName())) { if (entry.getKey().equals(getKey(obj))) {
iter.remove(); iter.remove();
} }
} }
} }
private String getKey(Object obj) {
return obj.getClass().getName() + obj.hashCode();
}
/** /**
* 创建代理类 * 创建代理类
* *

@ -16,6 +16,7 @@
package com.arialyy.simple.download; package com.arialyy.simple.download;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.util.Log; import android.util.Log;
@ -67,7 +68,7 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Override protected void onCreate(Bundle savedInstanceState) { @Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Aria.upload(this).register(); Aria.download(this).register();
} }
/** /**
@ -207,7 +208,8 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
startD(); startD();
break; break;
case R.id.stop: case R.id.stop:
Aria.download(this).load(DOWNLOAD_URL).stop(); //Aria.download(this).load(DOWNLOAD_URL).stop();
startActivity(new Intent(this, SingleTaskActivity.class));
//Aria.download(this).load(DOWNLOAD_URL).removeRecord(); //Aria.download(this).load(DOWNLOAD_URL).removeRecord();
break; break;
case R.id.cancel: case R.id.cancel:
@ -243,6 +245,6 @@ public class SingleTaskActivity extends BaseActivity<ActivitySingleBinding> {
@Override protected void onStop() { @Override protected void onStop() {
super.onStop(); super.onStop();
Aria.download(this).unRegister(); //Aria.download(this).unRegister();
} }
} }
Loading…
Cancel
Save