|
@@ -31,6 +31,7 @@ import okhttp3.Response;
|
|
* @overview
|
|
* @overview
|
|
*/
|
|
*/
|
|
class DownloadManager {
|
|
class DownloadManager {
|
|
|
|
+
|
|
private static final AtomicReference<DownloadManager> INSTANCE = new AtomicReference<>();
|
|
private static final AtomicReference<DownloadManager> INSTANCE = new AtomicReference<>();
|
|
/**
|
|
/**
|
|
* 用来存放各个下载的请求
|
|
* 用来存放各个下载的请求
|
|
@@ -81,6 +82,16 @@ class DownloadManager {
|
|
return downCalls.containsKey(url);
|
|
return downCalls.containsKey(url);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 获取下载的downloadInfo
|
|
|
|
+ *
|
|
|
|
+ * @param url
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ DownloadInfo getDownloadInfo(String url) {
|
|
|
|
+ return downInfos.get(url);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 开始下载
|
|
* 开始下载
|
|
*
|
|
*
|
|
@@ -100,16 +111,18 @@ class DownloadManager {
|
|
* @param onDownLoadObserver 用来回调的接口
|
|
* @param onDownLoadObserver 用来回调的接口
|
|
*/
|
|
*/
|
|
void download(String url, String suffix, OnDownLoadObserver onDownLoadObserver) {
|
|
void download(String url, String suffix, OnDownLoadObserver onDownLoadObserver) {
|
|
|
|
+ this.suffix = suffix;
|
|
|
|
+ this.download(url, onDownLoadObserver);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 开始下载
|
|
* 开始下载
|
|
*
|
|
*
|
|
* @param url 下载请求的网址
|
|
* @param url 下载请求的网址
|
|
- * // * @param onDownLoadObserver 用来回调的接口
|
|
|
|
*/
|
|
*/
|
|
void download(String url) {
|
|
void download(String url) {
|
|
-// if (!downCalls.containsKey(url)) {
|
|
|
|
|
|
+ DownloadObserver observer = new DownloadObserver();
|
|
|
|
+ observer.setContext(mContext);
|
|
Observable.just(url)
|
|
Observable.just(url)
|
|
//call的map已经有了,就证明正在下载,则这次不下载
|
|
//call的map已经有了,就证明正在下载,则这次不下载
|
|
.filter(new Predicate<String>() {
|
|
.filter(new Predicate<String>() {
|
|
@@ -143,23 +156,7 @@ class DownloadManager {
|
|
//在子线程执行
|
|
//在子线程执行
|
|
.subscribeOn(Schedulers.io())
|
|
.subscribeOn(Schedulers.io())
|
|
//添加观察者
|
|
//添加观察者
|
|
- .subscribe(new DownloadObserver(mContext));
|
|
|
|
-// } else {
|
|
|
|
-//// Call call = downCalls.get(url);
|
|
|
|
-//// if (call != null) {
|
|
|
|
-//// call.cancel();
|
|
|
|
-//// }
|
|
|
|
-// Observable.just(url)
|
|
|
|
-// .flatMap(new Function<String, ObservableSource<DownloadInfo>>() {
|
|
|
|
-// @Override
|
|
|
|
-// public ObservableSource<DownloadInfo> apply(String s) throws Exception {
|
|
|
|
-// return Observable.create(new DownloadingSubscribe(s));
|
|
|
|
-// }
|
|
|
|
-// })
|
|
|
|
-// .subscribeOn(Schedulers.io())
|
|
|
|
-// .observeOn(AndroidSchedulers.mainThread())
|
|
|
|
-// .subscribe(onDownLoadObserver);
|
|
|
|
-// }
|
|
|
|
|
|
+ .subscribe(observer);
|
|
}
|
|
}
|
|
|
|
|
|
void download(String url, OnDownLoadObserver onDownLoadObserver) {
|
|
void download(String url, OnDownLoadObserver onDownLoadObserver) {
|