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)) {
throw new IllegalArgumentException("未知类型");
}
key += isDownload ? DOWNLOAD : UPLOAD;
key += (isDownload ? DOWNLOAD : UPLOAD) + obj.hashCode();
return key;
}

@ -54,12 +54,12 @@ abstract class AbsSchedulers<TASK_ENTITY extends AbsTaskEntity, TASK extends Abs
@Override public void register(Object obj) {
String targetName = obj.getClass().getName();
AbsSchedulerListener<TASK, AbsNormalEntity> listener = mObservers.get(targetName);
AbsSchedulerListener<TASK, AbsNormalEntity> listener = mObservers.get(getKey(obj));
if (listener == null) {
listener = createListener(targetName);
if (listener != null) {
listener.setListener(obj);
mObservers.put(targetName, listener);
mObservers.put(getKey(obj), listener);
} else {
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 =
mObservers.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry<String, AbsSchedulerListener<TASK, AbsNormalEntity>> entry = iter.next();
if (entry.getKey().equals(obj.getClass().getName())) {
if (entry.getKey().equals(getKey(obj))) {
iter.remove();
}
}
}
private String getKey(Object obj) {
return obj.getClass().getName() + obj.hashCode();
}
/**
* 创建代理类
*

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