diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2014-04-24 12:28:36 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2014-04-24 12:28:36 +0200 |
| commit | 3f7542bca8404970f1d49c1f6be09298956eca6b (patch) | |
| tree | 1bbf58f6a333d5ef39131a706e0f203ab8af6b47 | |
| parent | 56984c893b40b8b692baf3c9ed6b65726c7b4027 (diff) | |
| download | cgeo-3f7542bca8404970f1d49c1f6be09298956eca6b.zip cgeo-3f7542bca8404970f1d49c1f6be09298956eca6b.tar.gz cgeo-3f7542bca8404970f1d49c1f6be09298956eca6b.tar.bz2 | |
Return an empty observable rather than null if local image is absent
This would not be a problem given the fact that we will always reference
existing local images, but returning an empty observable is more
consistent with the existing behaviour.
Part of implementation of #3438.
| -rw-r--r-- | main/src/cgeo/geocaching/network/HtmlImage.java | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java index ae9821b..36ce9c1 100644 --- a/main/src/cgeo/geocaching/network/HtmlImage.java +++ b/main/src/cgeo/geocaching/network/HtmlImage.java @@ -30,7 +30,6 @@ import rx.functions.Func1; import rx.schedulers.Schedulers; import rx.subjects.PublishSubject; import rx.subscriptions.CompositeSubscription; -import rx.util.async.Async; import android.content.res.Resources; import android.graphics.Bitmap; @@ -137,13 +136,13 @@ public class HtmlImage implements Html.ImageGetter { // Explicit local file URLs are loaded from the filesystem regardless of their age. The IO part is short // enough to make the whole operation on the computation scheduler. if (url.startsWith("file://")) { - return Async.fromCallable(new Func0<BitmapDrawable>() { + return Observable.defer(new Func0<Observable<? extends BitmapDrawable>>() { @Override - public BitmapDrawable call() { + public Observable<? extends BitmapDrawable> call() { final Bitmap bitmap = loadCachedImage(new File(url.substring(7)), true).getLeft(); - return bitmap != null ? ImageUtils.scaleBitmapToFitDisplay(bitmap) : null; + return bitmap != null ? Observable.from(ImageUtils.scaleBitmapToFitDisplay(bitmap)) : Observable.<BitmapDrawable>empty(); } - }, RxUtils.computationScheduler); + }).subscribeOn(RxUtils.computationScheduler); } final boolean shared = url.contains("/images/icons/icon_"); |
