158 lines
5.1 KiB
Java
158 lines
5.1 KiB
Java
package com.liulishuo.filedownloader;
|
|
|
|
import com.liulishuo.filedownloader.BaseDownloadTask;
|
|
import com.liulishuo.filedownloader.message.MessageSnapshot;
|
|
import com.liulishuo.filedownloader.message.MessageSnapshotTaker;
|
|
import com.liulishuo.filedownloader.util.FileDownloadLog;
|
|
import java.util.ArrayList;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class FileDownloadList {
|
|
private final ArrayList<BaseDownloadTask.IRunningTask> a;
|
|
|
|
private static final class HolderClass {
|
|
private static final FileDownloadList a = new FileDownloadList();
|
|
}
|
|
|
|
public static FileDownloadList b() {
|
|
return HolderClass.a;
|
|
}
|
|
|
|
int a() {
|
|
return this.a.size();
|
|
}
|
|
|
|
boolean c(BaseDownloadTask.IRunningTask iRunningTask) {
|
|
return this.a.isEmpty() || !this.a.contains(iRunningTask);
|
|
}
|
|
|
|
private FileDownloadList() {
|
|
this.a = new ArrayList<>();
|
|
}
|
|
|
|
int a(int i) {
|
|
int i2;
|
|
synchronized (this.a) {
|
|
Iterator<BaseDownloadTask.IRunningTask> it = this.a.iterator();
|
|
i2 = 0;
|
|
while (it.hasNext()) {
|
|
if (it.next().a(i)) {
|
|
i2++;
|
|
}
|
|
}
|
|
}
|
|
return i2;
|
|
}
|
|
|
|
List<BaseDownloadTask.IRunningTask> b(int i) {
|
|
byte status;
|
|
ArrayList arrayList = new ArrayList();
|
|
synchronized (this.a) {
|
|
Iterator<BaseDownloadTask.IRunningTask> it = this.a.iterator();
|
|
while (it.hasNext()) {
|
|
BaseDownloadTask.IRunningTask next = it.next();
|
|
if (next.a(i) && !next.D() && (status = next.F().getStatus()) != 0 && status != 10) {
|
|
arrayList.add(next);
|
|
}
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
List<BaseDownloadTask.IRunningTask> a(FileDownloadListener fileDownloadListener) {
|
|
ArrayList arrayList = new ArrayList();
|
|
synchronized (this.a) {
|
|
Iterator<BaseDownloadTask.IRunningTask> it = this.a.iterator();
|
|
while (it.hasNext()) {
|
|
BaseDownloadTask.IRunningTask next = it.next();
|
|
if (next.a(fileDownloadListener)) {
|
|
arrayList.add(next);
|
|
}
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
void b(BaseDownloadTask.IRunningTask iRunningTask) {
|
|
if (iRunningTask.x()) {
|
|
return;
|
|
}
|
|
synchronized (this.a) {
|
|
if (this.a.contains(iRunningTask)) {
|
|
FileDownloadLog.e(this, "already has %s", iRunningTask);
|
|
} else {
|
|
iRunningTask.H();
|
|
this.a.add(iRunningTask);
|
|
if (FileDownloadLog.a) {
|
|
FileDownloadLog.d(this, "add list in all %s %d %d", iRunningTask, Byte.valueOf(iRunningTask.F().getStatus()), Integer.valueOf(this.a.size()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
List<BaseDownloadTask.IRunningTask> a(int i, FileDownloadListener fileDownloadListener) {
|
|
ArrayList arrayList = new ArrayList();
|
|
synchronized (this.a) {
|
|
Iterator<BaseDownloadTask.IRunningTask> it = this.a.iterator();
|
|
while (it.hasNext()) {
|
|
BaseDownloadTask.IRunningTask next = it.next();
|
|
if (next.F().v() == fileDownloadListener && !next.F().m()) {
|
|
next.b(i);
|
|
arrayList.add(next);
|
|
}
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
void a(List<BaseDownloadTask.IRunningTask> list) {
|
|
synchronized (this.a) {
|
|
Iterator<BaseDownloadTask.IRunningTask> it = this.a.iterator();
|
|
while (it.hasNext()) {
|
|
BaseDownloadTask.IRunningTask next = it.next();
|
|
if (!list.contains(next)) {
|
|
list.add(next);
|
|
}
|
|
}
|
|
this.a.clear();
|
|
}
|
|
}
|
|
|
|
public boolean a(BaseDownloadTask.IRunningTask iRunningTask, MessageSnapshot messageSnapshot) {
|
|
boolean remove;
|
|
byte status = messageSnapshot.getStatus();
|
|
synchronized (this.a) {
|
|
remove = this.a.remove(iRunningTask);
|
|
}
|
|
if (FileDownloadLog.a && this.a.size() == 0) {
|
|
FileDownloadLog.d(this, "remove %s left %d %d", iRunningTask, Byte.valueOf(status), Integer.valueOf(this.a.size()));
|
|
}
|
|
if (remove) {
|
|
IFileDownloadMessenger h = iRunningTask.k().h();
|
|
if (status == -4) {
|
|
h.f(messageSnapshot);
|
|
} else if (status == -3) {
|
|
h.h(MessageSnapshotTaker.a(messageSnapshot));
|
|
} else if (status == -2) {
|
|
h.b(messageSnapshot);
|
|
} else if (status == -1) {
|
|
h.c(messageSnapshot);
|
|
}
|
|
} else {
|
|
FileDownloadLog.b(this, "remove error, not exist: %s %d", iRunningTask, Byte.valueOf(status));
|
|
}
|
|
return remove;
|
|
}
|
|
|
|
void a(BaseDownloadTask.IRunningTask iRunningTask) {
|
|
if (!iRunningTask.F().m()) {
|
|
iRunningTask.u();
|
|
}
|
|
if (iRunningTask.k().h().b()) {
|
|
b(iRunningTask);
|
|
}
|
|
}
|
|
}
|