aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--main/src/cgeo/geocaching/playservices/LocationProvider.java4
-rw-r--r--main/src/cgeo/geocaching/utils/RxUtils.java44
-rw-r--r--tests/src/cgeo/geocaching/utils/RxUtilsTest.java11
3 files changed, 2 insertions, 57 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>() {
diff --git a/tests/src/cgeo/geocaching/utils/RxUtilsTest.java b/tests/src/cgeo/geocaching/utils/RxUtilsTest.java
index 2487184..cc8589b 100644
--- a/tests/src/cgeo/geocaching/utils/RxUtilsTest.java
+++ b/tests/src/cgeo/geocaching/utils/RxUtilsTest.java
@@ -4,7 +4,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import rx.Observable;
import rx.Subscription;
-import rx.functions.Func1;
import rx.subjects.PublishSubject;
import rx.subjects.ReplaySubject;
@@ -21,16 +20,6 @@ public class RxUtilsTest extends AndroidTestCase {
range.onCompleted();
}
- public static void testTakeUntil() {
- final Observable<Integer> observable = range.lift(RxUtils.operatorTakeUntil(new Func1<Integer, Boolean>() {
- @Override
- public Boolean call(final Integer value) {
- return value > 6;
- }
- }));
- assertThat(observable.toList().toBlocking().single().toArray()).isEqualTo(new int[]{1, 2, 3, 4, 5, 6, 7});
- }
-
public static void testRememberLast() {
final PublishSubject<String> rawObservable = PublishSubject.create();
final Observable<String> observable = RxUtils.rememberLast(rawObservable, "initial");