Created
February 17, 2019 22:10
-
-
Save gumil/2529836dbb93e88a7d90f7fef1c5fe5d to your computer and use it in GitHub Desktop.
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
fun <A : ListAction> Observable<ActionState<A, ListState>>.loadTrending( | |
mode: ListState.Mode, | |
offset: Int = 0, | |
limit: Int = 10, | |
listStateFunction: (ListState.Screen, List<GiphyItem>) -> ListState.Screen | |
): Observable<ListState> = this | |
.map { it.state as ListState.Screen } | |
.flatMap { state -> | |
repository.getTrending(offset, limit) | |
.map { giphies -> | |
val items = giphies.map { it.mapToItem() } | |
listStateFunction(state, items) | |
} | |
.startWith(state.copy(loadingMode = mode)) | |
} | |
.ofType(ListState::class.java) | |
.onErrorReturn { | |
Timber.e(it, "Error loading gifs") | |
ListState.Error(R.string.error_loading) | |
} | |
.applySchedulers() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment