Skip to content

Commit

Permalink
Update PagingWithNetworkSample README
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-sheil committed Aug 1, 2020
1 parent 1816dea commit 36c925d
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions PagingWithNetworkSample/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Paging With Network Sample

This sample demonstrates how to use the Paging library with a backend API (in this
case [Reddit API][8]).
case [Reddit API][7]).

There are 3 variations of the demo, which you can select in the `MainActivity` class.

Expand All @@ -13,9 +13,8 @@ This sample, implemented in the [DbRedditPostRepository][1] class, demonstrates
a Repository that will use the local database to page in data for the UI and also back-fill
the database from the network as the user reaches to the end of the data in the database.

It uses `Room` to create the `DataSource.Factory` ([dao][3]) and the Paging Boundary Callback
API to get notified when the Paging library consumes the available local data ([boundary callback
implementation][4])
It uses `Room` to create the `PagingSource` ([dao][3]). The `Pager` creates a stream of
data from the PagingSource to the UI, and more data is paged in as it is consumed.

This usually provides the best user experience as the cached content is always available
on the device and the user will still have a good experience even if the network is slow /
Expand All @@ -26,18 +25,18 @@ This sample, implemented in the [InMemoryByItemRepository][2] class, demonstrate
set up a Repository that will directly page in from the network and will use the `key` from
the previous item to find the request parameters for the next page.

[ItemKeyedSubredditPagingSource][5]: The data source that uses the `key` in items
[ItemKeyedSubredditPagingSource][4]: The data source that uses the `key` in items
(`name` in Reddit API) to find the next page. It extends from the `PagingSource` class
in the Paging Library.

## Paging Using Next Tokens From The Previous Query
This sample, implemented in the [InMemoryByPageKeyRepository][6] class, demonstrates how to
This sample, implemented in the [InMemoryByPageKeyRepository][5] class, demonstrates how to
utilize the `before` and `after` keys in the response to discover the next page. (This is
the intended use of the Reddit API but this sample still provides
[ItemKeyedSubredditPagingSource][5] to serve as an example if the backend does not provide
[ItemKeyedSubredditPagingSource][4] to serve as an example if the backend does not provide
before/after links)

[PageKeyedSubredditPagingSource][7]: The data source that uses the `after` and `before` fields
[PageKeyedSubredditPagingSource][6]: The data source that uses the `after` and `before` fields
in the API request response. It extends from the `PagingSource` class in the Paging Library.


Expand All @@ -53,11 +52,10 @@ in the API request response. It extends from the `PagingSource` class in the Pag
[1]: app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inDb/DbRedditPostRepository.kt
[2]: app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byItem/InMemoryByItemRepository.kt
[3]: app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/db/RedditPostDao.kt
[4]: app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inDb/SubredditBoundaryCallback.kt
[5]: app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byItem/ItemKeyedSubredditPagingSource.kt
[6]: app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byPage/InMemoryByPageKeyRepository.kt
[7]: app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byPage/PageKeyedSubredditPagingSource.kt
[8]: https://www.reddit.com/dev/api/#listings
[4]: app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byItem/ItemKeyedSubredditPagingSource.kt
[5]: app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byPage/InMemoryByPageKeyRepository.kt
[6]: app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byPage/PageKeyedSubredditPagingSource.kt
[7]: https://www.reddit.com/dev/api/#listings
[mockwebserver]: https://github.com/square/okhttp/tree/master/mockwebserver
[support-lib]: https://developer.android.com/topic/libraries/support-library/index.html
[arch]: https://developer.android.com/arch
Expand Down

0 comments on commit 36c925d

Please sign in to comment.