You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-18Lines changed: 54 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,10 @@ A library that provides several functionalities to make it easy to write a list
9
9
# Usage
10
10
To start using this library, apps need to define pager data and provide it to the list
11
11
## Pager Data
12
-
Apps can define the pager data for list in the ViewModel by using [easyPager](https://github.com/KevinnZou/compose-pagingList/blob/main/core-paginglist/src/main/java/com/kevinnzou/compose/core/paginglist/EasyPager.kt)
12
+
Apps can define the pager data for list in the ViewModel in several ways
13
+
14
+
1. The simplest way is to use the [easyPager](https://github.com/KevinnZou/compose-pagingList/blob/main/core-paginglist/src/main/java/com/kevinnzou/compose/core/paginglist/EasyPager.kt).
15
+
It requires the apps wrap the data in [PagingListWrapper](https://github.com/KevinnZou/compose-pagingList/blob/main/core-paginglist/src/main/java/com/kevinnzou/compose/core/paginglist/pagerconfig/PaglingListWrapper.kt) which need the data list and the hasMore sign.
Also, this library provides a raw version of it so that apps have the freedom to decide how to process the data with the given PagingSource.LoadParams by themselves
33
+
2. However, the first method is only suitable for the simple data model. If you have a complex model, then you can use the [easyPager2](https://github.com/KevinnZou/compose-pagingList/blob/main/core-paginglist/src/main/java/com/kevinnzou/compose/core/paginglist/EasyPager2.kt)
It requires the data model to implement the interface [IHasMoreListVO](https://github.com/KevinnZou/compose-pagingList/blob/main/core-paginglist/src/main/java/com/kevinnzou/compose/core/paginglist/pagerconfig/IHasMoreListVO.kt) to provide the list data, hasMore sign, preKey and the nextKey.
data classPageListVO(varpage:Int, varitems:MutableList<String>, varhasMore:Boolean) : IHasMoreListVO<Int,String> {
51
+
overridefunhasMore(): Boolean {
52
+
return hasMore
39
53
}
40
-
41
-
if(reponse.code ==HttpCode.Error){
42
-
return@pager PagingSource.LoadResult.Error()
54
+
55
+
overridefungetList(): List<String> {
56
+
return items
57
+
}
58
+
59
+
overridefungetPreKey(): Int? {
60
+
returnif (page -1<0) nullelse page -1
43
61
}
44
62
45
-
return@pager PagingSource.LoadResult.Page(
46
-
response.list,
47
-
prevKey =if (page -1<0) nullelse page -1,
48
-
nextKey =if (!response.hasMore) nullelse page +1
49
-
)
63
+
overridefungetNextKey(): Int? {
64
+
return page +1
65
+
}
66
+
}
67
+
```
68
+
3. Lastly, the library provides the [pager](https://github.com/KevinnZou/compose-pagingList/blob/main/core-paginglist/src/main/java/com/kevinnzou/compose/core/paginglist/Pager.kt) which allows the apps to map their own defined Http Result to Kotlin Standard Result. Then it will map it to PagingSource.LoadResult automatically.
0 commit comments