diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2015-02-05 18:23:01 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2015-02-05 18:23:01 +0100 |
| commit | 0ece2fb2aa4b602c8e1a70f46c8610c0bfc08d1c (patch) | |
| tree | 6990e56a1758a51ff670fbea041ca56b7b34e9bc /main/src | |
| parent | 04633289c4088af8a9fe54064fcc18c4be2025a8 (diff) | |
| download | cgeo-0ece2fb2aa4b602c8e1a70f46c8610c0bfc08d1c.zip cgeo-0ece2fb2aa4b602c8e1a70f46c8610c0bfc08d1c.tar.gz cgeo-0ece2fb2aa4b602c8e1a70f46c8610c0bfc08d1c.tar.bz2 | |
Use operator TakeUntil from RxJava 1.0.5
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/playservices/LocationProvider.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/utils/RxUtils.java | 44 |
2 files changed, 2 insertions, 46 deletions
diff --git a/main/src/cgeo/geocaching/playservices/LocationProvider.java b/main/src/cgeo/geocaching/playservices/LocationProvider.java index 9d193b5..027ae29 100644 --- a/main/src/cgeo/geocaching/playservices/LocationProvider.java +++ b/main/src/cgeo/geocaching/playservices/LocationProvider.java @@ -102,12 +102,12 @@ public class LocationProvider implements GoogleApiClient.ConnectionCallbacks, Go // no less precise than 20 meters. final Observable<GeoData> untilPreciseEnoughObservable = lowPowerObservable.mergeWith(highPowerObservable.delaySubscription(6, TimeUnit.SECONDS)) - .lift(RxUtils.operatorTakeUntil(new Func1<GeoData, Boolean>() { + .takeUntil(new Func1<GeoData, Boolean>() { @Override public Boolean call(final GeoData geoData) { return geoData.getAccuracy() <= 20; } - })); + }); // After sending the last known location, try to get a precise location then use the low-power mode. If no // location information is given for 25 seconds (if the network location is turned off for example), get diff --git a/main/src/cgeo/geocaching/utils/RxUtils.java b/main/src/cgeo/geocaching/utils/RxUtils.java index 280575b..a028a56 100644 --- a/main/src/cgeo/geocaching/utils/RxUtils.java +++ b/main/src/cgeo/geocaching/utils/RxUtils.java @@ -2,7 +2,6 @@ package cgeo.geocaching.utils; import rx.Observable; import rx.Observable.OnSubscribe; -import rx.Observable.Operator; import rx.Scheduler; import rx.Scheduler.Worker; import rx.Subscriber; @@ -115,49 +114,6 @@ public class RxUtils { abstract protected void onStop(); } - public static <T> Operator<T, T> operatorTakeUntil(final Func1<? super T, Boolean> predicate) { - return new Operator<T, T>() { - @Override - public Subscriber<? super T> call(final Subscriber<? super T> subscriber) { - return new Subscriber<T>(subscriber) { - private boolean done = false; - - @Override - public void onCompleted() { - if (!done) { - subscriber.onCompleted(); - } - } - - @Override - public void onError(final Throwable throwable) { - if (!done) { - subscriber.onError(throwable); - } - } - - @Override - public void onNext(final T value) { - subscriber.onNext(value); - boolean shouldEnd = false; - try { - shouldEnd = predicate.call(value); - } catch (final Throwable e) { - done = true; - subscriber.onError(e); - unsubscribe(); - } - if (shouldEnd) { - done = true; - subscriber.onCompleted(); - unsubscribe(); - } - } - }; - } - }; - } - public static<T> Observable<T> rememberLast(final Observable<T> observable, final T initialValue) { final AtomicReference<T> lastValue = new AtomicReference<>(initialValue); return observable.doOnNext(new Action1<T>() { |
