Created
February 8, 2020 08:10
-
-
Save roscrazy/8d2f12ddaba44fd71f01367fda20675f to your computer and use it in GitHub Desktop.
RxLocationManagerImpl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class RxLocationManagerImpl( | |
private val fusedLocationService: LocationService, | |
private val androidLocationService: LocationService, | |
private val locationAttributes: RxLocationAttributes | |
) : RxLocationManager { | |
private val sharedLocationObservable = createLocationObservable() | |
override fun singleLocation(): Single<Location> = observeLocationChange() | |
.firstOrError() | |
.timeout(locationAttributes.requestTimeOut, TimeUnit.MILLISECONDS) | |
override fun observeLocationChange(): Observable<Location> = sharedLocationObservable | |
private fun createLocationObservable(): Observable<Location> { | |
return fusedLocationService.requestLocationUpdates(locationAttributes) | |
.onErrorResumeNext { it: Throwable -> | |
androidLocationService.requestLocationUpdates(locationAttributes) | |
} | |
.replay(1) | |
.refCount() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment