1
1
# Paging With Network Sample
2
2
3
3
This sample demonstrates how to use the Paging library with a backend API (in this
4
- case [ Reddit API] [ 8 ] ).
4
+ case [ Reddit API] [ 7 ] ).
5
5
6
6
There are 3 variations of the demo, which you can select in the ` MainActivity ` class.
7
7
@@ -13,9 +13,8 @@ This sample, implemented in the [DbRedditPostRepository][1] class, demonstrates
13
13
a Repository that will use the local database to page in data for the UI and also back-fill
14
14
the database from the network as the user reaches to the end of the data in the database.
15
15
16
- It uses ` Room ` to create the ` DataSource.Factory ` ([ dao] [ 3 ] ) and the Paging Boundary Callback
17
- API to get notified when the Paging library consumes the available local data ([ boundary callback
18
- implementation] [ 4 ] )
16
+ It uses ` Room ` to create the ` PagingSource ` ([ dao] [ 3 ] ). The ` Pager ` creates a stream of
17
+ data from the PagingSource to the UI, and more data is paged in as it is consumed.
19
18
20
19
This usually provides the best user experience as the cached content is always available
21
20
on the device and the user will still have a good experience even if the network is slow /
@@ -26,18 +25,18 @@ This sample, implemented in the [InMemoryByItemRepository][2] class, demonstrate
26
25
set up a Repository that will directly page in from the network and will use the ` key ` from
27
26
the previous item to find the request parameters for the next page.
28
27
29
- [ ItemKeyedSubredditPagingSource] [ 5 ] : The data source that uses the ` key ` in items
28
+ [ ItemKeyedSubredditPagingSource] [ 4 ] : The data source that uses the ` key ` in items
30
29
(` name ` in Reddit API) to find the next page. It extends from the ` PagingSource ` class
31
30
in the Paging Library.
32
31
33
32
## Paging Using Next Tokens From The Previous Query
34
- This sample, implemented in the [ InMemoryByPageKeyRepository] [ 6 ] class, demonstrates how to
33
+ This sample, implemented in the [ InMemoryByPageKeyRepository] [ 5 ] class, demonstrates how to
35
34
utilize the ` before ` and ` after ` keys in the response to discover the next page. (This is
36
35
the intended use of the Reddit API but this sample still provides
37
- [ ItemKeyedSubredditPagingSource] [ 5 ] to serve as an example if the backend does not provide
36
+ [ ItemKeyedSubredditPagingSource] [ 4 ] to serve as an example if the backend does not provide
38
37
before/after links)
39
38
40
- [ PageKeyedSubredditPagingSource] [ 7 ] : The data source that uses the ` after ` and ` before ` fields
39
+ [ PageKeyedSubredditPagingSource] [ 6 ] : The data source that uses the ` after ` and ` before ` fields
41
40
in the API request response. It extends from the ` PagingSource ` class in the Paging Library.
42
41
43
42
@@ -53,11 +52,10 @@ in the API request response. It extends from the `PagingSource` class in the Pag
53
52
[ 1 ] : app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inDb/DbRedditPostRepository.kt
54
53
[ 2 ] : app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byItem/InMemoryByItemRepository.kt
55
54
[ 3 ] : app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/db/RedditPostDao.kt
56
- [ 4 ] : app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inDb/SubredditBoundaryCallback.kt
57
- [ 5 ] : app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byItem/ItemKeyedSubredditPagingSource.kt
58
- [ 6 ] : app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byPage/InMemoryByPageKeyRepository.kt
59
- [ 7 ] : app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byPage/PageKeyedSubredditPagingSource.kt
60
- [ 8 ] : https://www.reddit.com/dev/api/#listings
55
+ [ 4 ] : app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byItem/ItemKeyedSubredditPagingSource.kt
56
+ [ 5 ] : app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byPage/InMemoryByPageKeyRepository.kt
57
+ [ 6 ] : app/src/main/java/com/android/example/paging/pagingwithnetwork/reddit/repository/inMemory/byPage/PageKeyedSubredditPagingSource.kt
58
+ [ 7 ] : https://www.reddit.com/dev/api/#listings
61
59
[ mockwebserver ] : https://github.com/square/okhttp/tree/master/mockwebserver
62
60
[ support-lib ] : https://developer.android.com/topic/libraries/support-library/index.html
63
61
[ arch ] : https://developer.android.com/arch
0 commit comments