private void getImageUrlPath(){
Observable.create(new ObservableOnSubscribe<File>() {
@Override
public void subscribe(@NonNull ObservableEmitter<File> emitter) throws Exception {
try {
FutureTarget<File> future = Glide.with(getContext())
.load(ImageUrl)
.downloadOnly(200, 200);
File cacheFile = future.get();
emitter.onNext(cacheFile);
} catch (Exception e) {
e.printStackTrace();
emitter.onComplete();
}
}
}).subscribeOn(Schedulers.io())
.doOnSubscribe(new Consumer<Disposable>() {
@Override
public void accept(@NonNull Disposable disposable) throws Exception {
showProgressBar();
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<File>() {
@Override
public void onSubscribe(@NonNull Disposable d) {
addDisposable(d);
}
@Override
public void onError(@NonNull Throwable e) {
e.printStackTrace();
hideProgressBar();
}
@Override
public void onComplete() {
hideProgressBar();
}
@Override
public void onNext(@NonNull File file) {
if (file != null) {
try {
filePath = file.getAbsolutePath();
LogUtil.d("wds",filePath);
} catch (Exception e) {
e.printStackTrace();
}
}
}
});
}
Glide获取 ImageURL本地路径
最新推荐文章于 2024-07-08 02:29:20 发布