Initial commit
This commit is contained in:
@@ -0,0 +1,162 @@
|
||||
package com.ubt.jimu.transport3.download;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import com.liulishuo.filedownloader.BaseDownloadTask;
|
||||
import com.liulishuo.filedownloader.FileDownloadListener;
|
||||
import com.liulishuo.filedownloader.FileDownloadQueueSet;
|
||||
import com.liulishuo.filedownloader.FileDownloader;
|
||||
import com.ubt.jimu.blockly.bean.SuperFilePath;
|
||||
import com.ubtrobot.log.ALog;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class AsyncTransportFileDownloader<T extends SuperFilePath> {
|
||||
public static final int MODEL = 0;
|
||||
private static final String TAG = "AsyncTransportFileDownloader";
|
||||
|
||||
private static class MyFileDownloadListener<T extends SuperFilePath> extends FileDownloadListener {
|
||||
private int count = 0;
|
||||
private List<T> downloadFiles = new ArrayList();
|
||||
private OnDownloadListener onDownloadListener;
|
||||
|
||||
public MyFileDownloadListener(List<T> list, OnDownloadListener onDownloadListener) {
|
||||
this.onDownloadListener = onDownloadListener;
|
||||
if (list == null || list.size() <= 0) {
|
||||
return;
|
||||
}
|
||||
this.downloadFiles.addAll(list);
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void blockComplete(BaseDownloadTask baseDownloadTask) {
|
||||
ALog.a(AsyncTransportFileDownloader.TAG).d("下载完成:" + baseDownloadTask.getUrl());
|
||||
for (T t : this.downloadFiles) {
|
||||
if (!TextUtils.isEmpty(t.getFileUrl()) && t.getFileUrl().equals(baseDownloadTask.getUrl())) {
|
||||
OnDownloadListener onDownloadListener = this.onDownloadListener;
|
||||
if (onDownloadListener != null) {
|
||||
onDownloadListener.onBlockComplete(t);
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void completed(BaseDownloadTask baseDownloadTask) {
|
||||
synchronized (this) {
|
||||
this.count++;
|
||||
ALog.a(AsyncTransportFileDownloader.TAG).d("completed:" + this.count);
|
||||
if (this.onDownloadListener == null) {
|
||||
return;
|
||||
}
|
||||
Iterator<T> it = this.downloadFiles.iterator();
|
||||
while (true) {
|
||||
if (!it.hasNext()) {
|
||||
break;
|
||||
}
|
||||
T next = it.next();
|
||||
if (!TextUtils.isEmpty(next.getFileUrl()) && next.getFileUrl().equals(baseDownloadTask.getUrl())) {
|
||||
this.onDownloadListener.onBlockCompleted(next);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this.count == this.downloadFiles.size()) {
|
||||
this.onDownloadListener.onCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void connected(BaseDownloadTask baseDownloadTask, String str, boolean z, int i, int i2) {
|
||||
ALog.a(AsyncTransportFileDownloader.TAG).d("connected");
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void error(BaseDownloadTask baseDownloadTask, Throwable th) {
|
||||
ALog.a(AsyncTransportFileDownloader.TAG).d("error: " + baseDownloadTask.getUrl());
|
||||
th.printStackTrace();
|
||||
synchronized (this) {
|
||||
this.count++;
|
||||
if (this.onDownloadListener == null) {
|
||||
return;
|
||||
}
|
||||
Iterator<T> it = this.downloadFiles.iterator();
|
||||
while (true) {
|
||||
if (!it.hasNext()) {
|
||||
break;
|
||||
}
|
||||
T next = it.next();
|
||||
if (!TextUtils.isEmpty(next.getFileUrl()) && next.getFileUrl().equals(baseDownloadTask.getUrl())) {
|
||||
this.onDownloadListener.onBlockError(next);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (this.count == this.downloadFiles.size()) {
|
||||
this.onDownloadListener.onCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void paused(BaseDownloadTask baseDownloadTask, int i, int i2) {
|
||||
ALog.a(AsyncTransportFileDownloader.TAG).d("paused: " + baseDownloadTask.getUrl());
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void pending(BaseDownloadTask baseDownloadTask, int i, int i2) {
|
||||
ALog.a(AsyncTransportFileDownloader.TAG).d("pending");
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void progress(BaseDownloadTask baseDownloadTask, int i, int i2) {
|
||||
ALog.a(AsyncTransportFileDownloader.TAG).d("progress:" + i + "/" + i2);
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void retry(BaseDownloadTask baseDownloadTask, Throwable th, int i, int i2) {
|
||||
ALog.a(AsyncTransportFileDownloader.TAG).d("retry: " + baseDownloadTask.getUrl());
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void warn(BaseDownloadTask baseDownloadTask) {
|
||||
ALog.a(AsyncTransportFileDownloader.TAG).d("warn: " + baseDownloadTask.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnDownloadListener<T> {
|
||||
void onBlockComplete(T t);
|
||||
|
||||
void onBlockCompleted(T t);
|
||||
|
||||
void onBlockError(T t);
|
||||
|
||||
void onCompleted();
|
||||
}
|
||||
|
||||
public FileDownloadListener downloadFile(List<T> list, OnDownloadListener onDownloadListener) {
|
||||
if (list == null || list.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
ArrayList arrayList = new ArrayList();
|
||||
for (T t : list) {
|
||||
String fileUrl = t.getFileUrl();
|
||||
String localFilePath = t.getLocalFilePath();
|
||||
if (!TextUtils.isEmpty(fileUrl) && !TextUtils.isEmpty(localFilePath)) {
|
||||
BaseDownloadTask a = FileDownloader.e().a(fileUrl);
|
||||
a.a("Accept-Encoding", "identity");
|
||||
a.a(localFilePath, false);
|
||||
a.a(true);
|
||||
arrayList.add(a);
|
||||
}
|
||||
}
|
||||
MyFileDownloadListener myFileDownloadListener = new MyFileDownloadListener(list, onDownloadListener);
|
||||
FileDownloadQueueSet fileDownloadQueueSet = new FileDownloadQueueSet(myFileDownloadListener);
|
||||
fileDownloadQueueSet.a(2);
|
||||
fileDownloadQueueSet.a(arrayList);
|
||||
fileDownloadQueueSet.a();
|
||||
return myFileDownloadListener;
|
||||
}
|
||||
}
|
@@ -0,0 +1,192 @@
|
||||
package com.ubt.jimu.transport3.download;
|
||||
|
||||
import com.liulishuo.filedownloader.BaseDownloadTask;
|
||||
import com.liulishuo.filedownloader.FileDownloadListener;
|
||||
import com.liulishuo.filedownloader.FileDownloadQueueSet;
|
||||
import com.liulishuo.filedownloader.FileDownloader;
|
||||
import com.ubt.jimu.base.download.DownloadInfo;
|
||||
import com.ubt.jimu.transport.model.TransportFile;
|
||||
import com.ubt.jimu.transport3.download.TransportFileDownloader;
|
||||
import com.ubt.jimu.utils.LogUtils;
|
||||
import com.ubtrobot.log.ALog;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.ObservableOnSubscribe;
|
||||
import io.reactivex.Observer;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.functions.Consumer;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
public class TransportFileDownloader {
|
||||
private static final String TAG = "TransportFileDownloader";
|
||||
|
||||
/* renamed from: com.ubt.jimu.transport3.download.TransportFileDownloader$1, reason: invalid class name */
|
||||
class AnonymousClass1 implements ObservableOnSubscribe<HashMap<String, TransportFile>> {
|
||||
final /* synthetic */ List val$files;
|
||||
|
||||
AnonymousClass1(List list) {
|
||||
this.val$files = list;
|
||||
}
|
||||
|
||||
static /* synthetic */ void a(ObservableEmitter observableEmitter, HashMap hashMap) {
|
||||
observableEmitter.onNext(hashMap);
|
||||
observableEmitter.onComplete();
|
||||
LogUtils.c("下~~~~~~" + Thread.currentThread().getName());
|
||||
}
|
||||
|
||||
@Override // io.reactivex.ObservableOnSubscribe
|
||||
public void subscribe(final ObservableEmitter<HashMap<String, TransportFile>> observableEmitter) {
|
||||
List<DownloadInfo> needDownloadInfo = DownloadInfo.getNeedDownloadInfo(this.val$files);
|
||||
if (needDownloadInfo == null || needDownloadInfo.size() == 0) {
|
||||
observableEmitter.onNext(new HashMap<>());
|
||||
observableEmitter.onComplete();
|
||||
return;
|
||||
}
|
||||
ArrayList arrayList = new ArrayList();
|
||||
for (DownloadInfo downloadInfo : needDownloadInfo) {
|
||||
LogUtils.c("下载基础文件:" + downloadInfo.getUrl());
|
||||
BaseDownloadTask a = FileDownloader.e().a(downloadInfo.getUrl());
|
||||
a.a("Accept-Encoding", "identity");
|
||||
a.a(downloadInfo.getSavePath(), false);
|
||||
a.a(true);
|
||||
a.a(Integer.valueOf(downloadInfo.getType()));
|
||||
arrayList.add(a);
|
||||
}
|
||||
LogUtils.c(" !!!!!!!!!!!! 开始下载文件");
|
||||
FileDownloadQueueSet fileDownloadQueueSet = new FileDownloadQueueSet(new MyFileDownloadListener(this.val$files, new OnDownloadListener() { // from class: com.ubt.jimu.transport3.download.a
|
||||
@Override // com.ubt.jimu.transport3.download.TransportFileDownloader.OnDownloadListener
|
||||
public final void onCompleted(HashMap hashMap) {
|
||||
TransportFileDownloader.AnonymousClass1.a(ObservableEmitter.this, hashMap);
|
||||
}
|
||||
}));
|
||||
fileDownloadQueueSet.a(2);
|
||||
fileDownloadQueueSet.a(arrayList);
|
||||
fileDownloadQueueSet.a();
|
||||
LogUtils.c("!!!!!!!!!!!!!!!!!!!!!!逻辑结束");
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyFileDownloadListener extends FileDownloadListener {
|
||||
private OnDownloadListener onDownloadListener;
|
||||
private Map<String, TransportFile> map = new HashMap();
|
||||
private HashMap<String, TransportFile> completed = new HashMap<>();
|
||||
private int count = 0;
|
||||
|
||||
public MyFileDownloadListener(List<TransportFile> list, OnDownloadListener onDownloadListener) {
|
||||
this.onDownloadListener = onDownloadListener;
|
||||
for (TransportFile transportFile : list) {
|
||||
this.map.put(transportFile.getFileUrl(), transportFile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void blockComplete(BaseDownloadTask baseDownloadTask) {
|
||||
int indexOf = baseDownloadTask.getUrl().indexOf("?");
|
||||
String url = baseDownloadTask.getUrl();
|
||||
if (indexOf > 0) {
|
||||
url = baseDownloadTask.getUrl().substring(0, indexOf);
|
||||
}
|
||||
TransportFile transportFile = this.map.get(url);
|
||||
if (transportFile != null) {
|
||||
this.completed.put(transportFile.getFileUrl(), transportFile);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void completed(BaseDownloadTask baseDownloadTask) {
|
||||
synchronized (this) {
|
||||
this.count++;
|
||||
ALog.a(TransportFileDownloader.TAG).d("completed:" + this.count);
|
||||
}
|
||||
if (this.onDownloadListener == null || this.count != this.map.size()) {
|
||||
return;
|
||||
}
|
||||
this.onDownloadListener.onCompleted(this.completed);
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void connected(BaseDownloadTask baseDownloadTask, String str, boolean z, int i, int i2) {
|
||||
ALog.a(TransportFileDownloader.TAG).d("connected");
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void error(BaseDownloadTask baseDownloadTask, Throwable th) {
|
||||
ALog.a(TransportFileDownloader.TAG).d("error: " + baseDownloadTask.getUrl());
|
||||
th.printStackTrace();
|
||||
synchronized (this) {
|
||||
this.count++;
|
||||
}
|
||||
if (this.onDownloadListener == null || this.count != this.map.size()) {
|
||||
return;
|
||||
}
|
||||
this.onDownloadListener.onCompleted(this.completed);
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void paused(BaseDownloadTask baseDownloadTask, int i, int i2) {
|
||||
ALog.a(TransportFileDownloader.TAG).d("paused: " + baseDownloadTask.getUrl());
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void pending(BaseDownloadTask baseDownloadTask, int i, int i2) {
|
||||
ALog.a(TransportFileDownloader.TAG).d("pending");
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void progress(BaseDownloadTask baseDownloadTask, int i, int i2) {
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void retry(BaseDownloadTask baseDownloadTask, Throwable th, int i, int i2) {
|
||||
ALog.a(TransportFileDownloader.TAG).d("retry: " + baseDownloadTask.getUrl());
|
||||
}
|
||||
|
||||
@Override // com.liulishuo.filedownloader.FileDownloadListener
|
||||
protected void warn(BaseDownloadTask baseDownloadTask) {
|
||||
ALog.a(TransportFileDownloader.TAG).d("warn: " + baseDownloadTask.getUrl());
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnDownloadListener {
|
||||
void onCompleted(HashMap<String, TransportFile> hashMap);
|
||||
}
|
||||
|
||||
public FileDownloadListener downloadFile(List<TransportFile> list, OnDownloadListener onDownloadListener) {
|
||||
List<DownloadInfo> needDownloadInfo = DownloadInfo.getNeedDownloadInfo(list);
|
||||
if (needDownloadInfo == null || needDownloadInfo.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
ArrayList arrayList = new ArrayList();
|
||||
for (DownloadInfo downloadInfo : needDownloadInfo) {
|
||||
BaseDownloadTask a = FileDownloader.e().a(downloadInfo.getUrl());
|
||||
a.a("Accept-Encoding", "identity");
|
||||
a.a(downloadInfo.getSavePath(), false);
|
||||
a.a(true);
|
||||
a.a(Integer.valueOf(downloadInfo.getType()));
|
||||
arrayList.add(a);
|
||||
}
|
||||
MyFileDownloadListener myFileDownloadListener = new MyFileDownloadListener(list, onDownloadListener);
|
||||
FileDownloadQueueSet fileDownloadQueueSet = new FileDownloadQueueSet(myFileDownloadListener);
|
||||
fileDownloadQueueSet.a(2);
|
||||
fileDownloadQueueSet.a(arrayList);
|
||||
fileDownloadQueueSet.a();
|
||||
return myFileDownloadListener;
|
||||
}
|
||||
|
||||
public Observable<HashMap<String, TransportFile>> downloadFile2(List<TransportFile> list) {
|
||||
return Observable.create(new AnonymousClass1(list));
|
||||
}
|
||||
|
||||
public void downloadFileSyn(List<TransportFile> list, Consumer<HashMap<String, TransportFile>> consumer) {
|
||||
downloadFile2(list).subscribe(consumer);
|
||||
}
|
||||
|
||||
public void downloadFile(List<TransportFile> list, Observer<HashMap<String, TransportFile>> observer) {
|
||||
downloadFile2(list).observeOn(AndroidSchedulers.a()).subscribeOn(Schedulers.b()).subscribe(observer);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user