Initial commit
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package com.liulishuo.filedownloader.event;
|
||||
|
||||
import com.liulishuo.filedownloader.util.FileDownloadExecutors;
|
||||
import com.liulishuo.filedownloader.util.FileDownloadLog;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class DownloadEventPoolImpl implements IDownloadEventPool {
|
||||
private final Executor a = FileDownloadExecutors.a(10, "EventPool");
|
||||
private final HashMap<String, LinkedList<IDownloadListener>> b = new HashMap<>();
|
||||
|
||||
public boolean a(String str, IDownloadListener iDownloadListener) {
|
||||
boolean add;
|
||||
if (FileDownloadLog.a) {
|
||||
FileDownloadLog.d(this, "setListener %s", str);
|
||||
}
|
||||
if (iDownloadListener == null) {
|
||||
throw new IllegalArgumentException("listener must not be null!");
|
||||
}
|
||||
LinkedList<IDownloadListener> linkedList = this.b.get(str);
|
||||
if (linkedList == null) {
|
||||
synchronized (str.intern()) {
|
||||
linkedList = this.b.get(str);
|
||||
if (linkedList == null) {
|
||||
HashMap<String, LinkedList<IDownloadListener>> hashMap = this.b;
|
||||
LinkedList<IDownloadListener> linkedList2 = new LinkedList<>();
|
||||
hashMap.put(str, linkedList2);
|
||||
linkedList = linkedList2;
|
||||
}
|
||||
}
|
||||
}
|
||||
synchronized (str.intern()) {
|
||||
add = linkedList.add(iDownloadListener);
|
||||
}
|
||||
return add;
|
||||
}
|
||||
|
||||
public boolean b(IDownloadEvent iDownloadEvent) {
|
||||
if (FileDownloadLog.a) {
|
||||
FileDownloadLog.d(this, "publish %s", iDownloadEvent.a());
|
||||
}
|
||||
if (iDownloadEvent == null) {
|
||||
throw new IllegalArgumentException("event must not be null!");
|
||||
}
|
||||
String a = iDownloadEvent.a();
|
||||
LinkedList<IDownloadListener> linkedList = this.b.get(a);
|
||||
if (linkedList == null) {
|
||||
synchronized (a.intern()) {
|
||||
linkedList = this.b.get(a);
|
||||
if (linkedList == null) {
|
||||
if (FileDownloadLog.a) {
|
||||
FileDownloadLog.a(this, "No listener for this event %s", a);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
a(linkedList, iDownloadEvent);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void a(final IDownloadEvent iDownloadEvent) {
|
||||
if (FileDownloadLog.a) {
|
||||
FileDownloadLog.d(this, "asyncPublishInNewThread %s", iDownloadEvent.a());
|
||||
}
|
||||
if (iDownloadEvent != null) {
|
||||
this.a.execute(new Runnable() { // from class: com.liulishuo.filedownloader.event.DownloadEventPoolImpl.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
DownloadEventPoolImpl.this.b(iDownloadEvent);
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
throw new IllegalArgumentException("event must not be null!");
|
||||
}
|
||||
|
||||
private void a(LinkedList<IDownloadListener> linkedList, IDownloadEvent iDownloadEvent) {
|
||||
for (Object obj : linkedList.toArray()) {
|
||||
if (obj != null && ((IDownloadListener) obj).a(iDownloadEvent)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Runnable runnable = iDownloadEvent.a;
|
||||
if (runnable != null) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
package com.liulishuo.filedownloader.event;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public class DownloadServiceConnectChangedEvent extends IDownloadEvent {
|
||||
private final ConnectStatus c;
|
||||
|
||||
public enum ConnectStatus {
|
||||
connected,
|
||||
disconnected,
|
||||
lost
|
||||
}
|
||||
|
||||
public DownloadServiceConnectChangedEvent(ConnectStatus connectStatus, Class<?> cls) {
|
||||
super("event.service.connect.changed");
|
||||
this.c = connectStatus;
|
||||
}
|
||||
|
||||
public ConnectStatus b() {
|
||||
return this.c;
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.liulishuo.filedownloader.event;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class IDownloadEvent {
|
||||
public Runnable a = null;
|
||||
protected final String b;
|
||||
|
||||
public IDownloadEvent(String str) {
|
||||
this.b = str;
|
||||
}
|
||||
|
||||
public final String a() {
|
||||
return this.b;
|
||||
}
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package com.liulishuo.filedownloader.event;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
interface IDownloadEventPool {
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
package com.liulishuo.filedownloader.event;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class IDownloadListener {
|
||||
public abstract boolean a(IDownloadEvent iDownloadEvent);
|
||||
}
|
Reference in New Issue
Block a user