markdown RxJava和Glide下载多个GIF图像

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown RxJava和Glide下载多个GIF图像相关的知识,希望对你有一定的参考价值。

# Using RxJava and Glide to download multiple GIFs

[SOURCE](https://stackoverflow.com/a/31893556/1602807)

This guide is for RxJava 1 and Glide v3 (3.8.0).

Have a list of URLs to GIFs, how to download them all in separated threads and proceed when all GIFs are downloaded?

```java
private void download(final List<String> urlList) {
        Observable observable = Observable.from(urlList)
                .flatMap(new Func1<String, Observable<File>>() {
                    @Override
                    public Observable<File> call(String url) {
                        return getDownloadObservable(url);
                    }
                });

        mSubscriptions.add(observable
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<File>() {
                    @Override
                    public void onCompleted() {
                        Timber.d("onCompleted(): DEBUG_GLIDE_DOWNLOAD");
                    }

                    @Override
                    public void onError(Throwable e) {
                        Timber.d("onError(): DEBUG_GLIDE_DOWNLOAD e: %s", e.getMessage());
                    }

                    @Override
                    public void onNext(File file) {
                        Timber.d("onNext(): DEBUG_GLIDE_DOWNLOAD file path: %s", file.getPath());
                    }
                }));
    }

    private Observable<File> getDownloadObservable(final String url){
        //need fromCallable as downloadOnly need to be put in a background thread
        //if not we can just use just as in the source
        return Observable.fromCallable(new Callable<File>() {
            @Override
            public File call() throws Exception {
                return Glide.with(mWeakContext.get())
                        .load(url)
                        .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL)
                        .get();
            }
        });
    }
```

以上是关于markdown RxJava和Glide下载多个GIF图像的主要内容,如果未能解决你的问题,请参考以下文章

高仿Android网易云音乐OkHttp+Retrofit+RxJava+Glide+MVC+MVVM

0.Android高仿网易云音乐OkHttp+Retrofit+RxJava+Glide+MVC+MVVM

0.Android高仿网易云音乐OkHttp+Retrofit+RxJava+Glide+MVC+MVVM

0.Android高仿网易云音乐OkHttp+Retrofit+RxJava+Glide+MVC+MVVM

Glide工具类/OkGo网络请求/MVP请求数据/Retrofit+RxJava/ARouter/补间动画/轮播图等等等等等 记录一下~~

Glide工具类/OkGo网络请求/MVP请求数据/Retrofit+RxJava/ARouter/补间动画/轮播图等等等等等 记录一下~~