Skip to content

Instantly share code, notes, and snippets.

@MarkyC
Created June 23, 2018 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkyC/654c4fd376fcd77ed8c8da3ee087030d to your computer and use it in GitHub Desktop.
Save MarkyC/654c4fd376fcd77ed8c8da3ee087030d to your computer and use it in GitHub Desktop.
view.getCurrentLocation()
.map(locationToPlaceTransformer::apply)
// TODO: need to show an error with the location name in it if the location isn't supported
.flatMap(place -> Observable.zip(
userLocationRepository.isLocationSupported(place), // returns Observable<Boolean>
Observable.just(place),
(isLocationSupported, p) -> {
if (isLocationSupported) {
return p;
}
throw new UnsupportedLocationException(p.getName());
}))
.map(place -> {
placesRepository.putRecentPlace(place);
userLocationRepository.putUserLocation(place);
return place;
})
.subscribe(
place -> view.onPlaceSelected(place),
error -> {
if (MyException.is(error, UNSUPPORTED_LOCATION) {
view.showUnsupportedLocationError(((UnsupportedLocationException) error).getName())
} else {
view.showError(error);
}
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment