diff options
Diffstat (limited to 'main/src/cgeo/geocaching/CgeoApplication.java')
| -rw-r--r-- | main/src/cgeo/geocaching/CgeoApplication.java | 97 |
1 files changed, 5 insertions, 92 deletions
diff --git a/main/src/cgeo/geocaching/CgeoApplication.java b/main/src/cgeo/geocaching/CgeoApplication.java index eea8154..1a25746 100644 --- a/main/src/cgeo/geocaching/CgeoApplication.java +++ b/main/src/cgeo/geocaching/CgeoApplication.java @@ -1,12 +1,6 @@ package cgeo.geocaching; -import cgeo.geocaching.playservices.LocationProvider; -import cgeo.geocaching.sensors.GeoData; -import cgeo.geocaching.sensors.GeoDataProvider; -import cgeo.geocaching.sensors.GpsStatusProvider; -import cgeo.geocaching.sensors.GpsStatusProvider.Status; -import cgeo.geocaching.sensors.OrientationProvider; -import cgeo.geocaching.sensors.RotationProvider; +import cgeo.geocaching.sensors.Sensors; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.Log; import cgeo.geocaching.utils.OOMDumpingUncaughtExceptionHandler; @@ -15,12 +9,6 @@ import cgeo.geocaching.utils.RxUtils; import com.google.android.gms.common.ConnectionResult; import com.google.android.gms.common.GooglePlayServicesUtil; -import org.eclipse.jdt.annotation.NonNull; - -import rx.Observable; -import rx.functions.Action1; -import rx.functions.Func1; - import android.app.Application; import android.view.ViewConfiguration; @@ -32,21 +20,7 @@ public class CgeoApplication extends Application { public boolean showLoginToast = true; //login toast shown just once. private boolean liveMapHintShownInThisSession = false; // livemap hint has been shown private static CgeoApplication instance; - private Observable<GeoData> geoDataObservable; - private Observable<GeoData> geoDataObservableLowPower; - private Observable<Float> directionObservable; - private Observable<Status> gpsStatusObservable; - @NonNull private volatile GeoData currentGeo = GeoData.DUMMY_LOCATION; - private volatile boolean hasValidLocation = false; - private volatile float currentDirection = 0.0f; private boolean isGooglePlayServicesAvailable = false; - private final Action1<GeoData> rememberGeodataAction = new Action1<GeoData>() { - @Override - public void call(final GeoData geoData) { - currentGeo = geoData; - hasValidLocation = true; - } - }; public static void dumpOnOutOfMemory(final boolean enable) { @@ -95,47 +69,14 @@ public class CgeoApplication extends Application { isGooglePlayServicesAvailable = true; } Log.i("Google Play services are " + (isGooglePlayServicesAvailable ? "" : "not ") + "available"); - setupGeoDataObservables(Settings.useGooglePlayServices(), Settings.useLowPowerMode()); - setupDirectionObservable(Settings.useLowPowerMode()); - gpsStatusObservable = GpsStatusProvider.create(this).replay(1).refCount(); + final Sensors sensors = Sensors.getInstance(); + sensors.setupGeoDataObservables(Settings.useGooglePlayServices(), Settings.useLowPowerMode()); + sensors.setupDirectionObservable(Settings.useLowPowerMode()); // Attempt to acquire an initial location before any real activity happens. - geoDataObservableLowPower.subscribeOn(RxUtils.looperCallbacksScheduler).first().subscribe(); + sensors.geoDataObservable(true).subscribeOn(RxUtils.looperCallbacksScheduler).first().subscribe(); } - public void setupGeoDataObservables(final boolean useGooglePlayServices, final boolean useLowPowerLocation) { - if (useGooglePlayServices) { - geoDataObservable = LocationProvider.getMostPrecise(this).doOnNext(rememberGeodataAction); - if (useLowPowerLocation) { - geoDataObservableLowPower = LocationProvider.getLowPower(this).doOnNext(rememberGeodataAction); - } else { - geoDataObservableLowPower = geoDataObservable; - } - } else { - geoDataObservable = RxUtils.rememberLast(GeoDataProvider.create(this).doOnNext(rememberGeodataAction)); - geoDataObservableLowPower = geoDataObservable; - } - } - - public void setupDirectionObservable(final boolean useLowPower) { - directionObservable = RxUtils.rememberLast(RotationProvider.create(this, useLowPower).onErrorResumeNext(new Func1<Throwable, Observable<? extends Float>>() { - @Override - public Observable<? extends Float> call(final Throwable throwable) { - return OrientationProvider.create(CgeoApplication.this); - } - }).onErrorResumeNext(new Func1<Throwable, Observable<? extends Float>>() { - @Override - public Observable<? extends Float> call(final Throwable throwable) { - Log.e("Device orientation will not be available as no suitable sensors were found"); - return Observable.<Float>never().startWith(0.0f); - } - }).doOnNext(new Action1<Float>() { - @Override - public void call(final Float direction) { - currentDirection = direction; - } - })); - } @Override public void onLowMemory() { @@ -143,34 +84,6 @@ public class CgeoApplication extends Application { DataStore.removeAllFromCache(); } - public Observable<GeoData> geoDataObservable(final boolean lowPower) { - return lowPower ? geoDataObservableLowPower : geoDataObservable; - } - - public Observable<Float> directionObservable() { - return directionObservable; - } - - public Observable<Status> gpsStatusObservable() { - if (gpsStatusObservable == null) { - gpsStatusObservable = GpsStatusProvider.create(this).share(); - } - return gpsStatusObservable; - } - - @NonNull - public GeoData currentGeo() { - return currentGeo; - } - - public boolean hasValidLocation() { - return hasValidLocation; - } - - public float currentDirection() { - return currentDirection; - } - public boolean isLiveMapHintShownInThisSession() { return liveMapHintShownInThisSession; } |
