GeezerVison is showing github.com — fix: update README and concatMap · alanwgeorge/Android-RxJava@6fd11b4
File tree
Expand file treeCollapse file tree
Open diff view settings
app/src/main/java/com/morihacky/android/rxjava/pagination
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: README.md +9-5Lines changed: 9 additions & 5 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -162,16 +162,20 @@ Hit the start button and rotate the screen to your heart's content; you'll see t |
162 | 162 |
|
163 | 163 | *There are certain quirks about the "hotness" of the source observable used in this example. Check [my blog post](http://blog.kaush.co/2015/07/11/a-note-about-the-warmth-share-operator/) out where I explain the specifics.* |
164 | 164 |
|
165 | | -## Work in Progress: |
| 165 | +### Pagination |
166 | 166 |
|
167 | | -Examples that I would like to have here, but haven't found the time yet to flush out. |
| 167 | +I leverage the simple use of a Subject here. Honestly, if you don't have your items coming down via an `Observable` already (like through Retrofit or a network request), there's no good reason to use Rx and complicate things. |
168 | 168 |
|
| 169 | +This example basically sends the page number to a Subject, and the subject handles adding the items. Notice the use of `concatMap` and the return of an `Observable<List>` from `_itemsFromNetworkCall`. |
169 | 170 |
|
170 | | -### Pagination |
| 171 | +Here are some other fancy implementations (while i enjoyed reading them, i didn't land up using them for my real world app cause personally i don't think it's necessary): |
171 | 172 |
|
172 | | -a. Simple pagination |
173 | | -b. Optimized pagination |
| 173 | +* [Matthias example of an Rx based pager](https://gist.github.com/mttkay/24881a0ce986f6ec4b4d) |
| 174 | +* [Recursive Paging example](http://stackoverflow.com/questions/28047272/handle-paging-with-rxjava) |
174 | 175 |
|
| 176 | +## Work in Progress: |
| 177 | + |
| 178 | +Examples that I would like to have here, but haven't found the time yet to flush out. |
175 | 179 |
|
176 | 180 | ## Contributing: |
177 | 181 |
|
|
Collapse file
Copy file name to clipboardExpand all lines: app/src/main/java/com/morihacky/android/rxjava/pagination/PaginationFragment.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,7 +61,7 @@ public void onStart() { |
61 | 61 |
|
62 | 62 | Subscription s2 =// |
63 | 63 | _paginator// |
64 | | - .flatMap(nextPage -> _itemsFromNetworkCall(nextPage + 1, 10))// |
| 64 | + .concatMap(nextPage -> _itemsFromNetworkCall(nextPage + 1, 10))// |
65 | 65 | .observeOn(AndroidSchedulers.mainThread()) |
66 | 66 | .map(items -> { |
67 | 67 | int start = _adapter.getItemCount() - 1; |
|