Created
March 14, 2018 19:11
-
-
Save AdamMc331/60e08efa73b2dc874d0d072ee62a9076 to your computer and use it in GitHub Desktop.
Notice how each function subscribes to an observable, sets the state based on the response, and otherwise logs an error? Is there a way to somehow combine these three methods into one?
This file contains 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
private fun fetchAllFacebookAlbums() { | |
val subscription = socialPhotosViewModel.getAllFacebookAlbums() | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe( | |
{ | |
state = it | |
}, | |
{ | |
Timber.e(it.message) | |
} | |
) | |
getCompositeSubscription().add(subscription) | |
} | |
private fun fetchFacebookAlbum(albumId: String) { | |
val subscription = socialPhotosViewModel.getFacebookAlbumFromId(albumId) | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe( | |
{ | |
state = it | |
}, | |
{ | |
Timber.e(it.message) | |
} | |
) | |
getCompositeSubscription().add(subscription) | |
} | |
private fun fetchInstagramPhotos(count: Int) { | |
val subscription = socialPhotosViewModel.getInstagramPhotos(count) | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribe( | |
{ | |
state = it | |
}, | |
{ | |
Timber.e(it.message) | |
} | |
) | |
getCompositeSubscription().add(subscription) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe I can do: