Skip to content

Commit cadc165

Browse files
author
邹铭杰
committed
feat:Release Version 0.0.3
1 parent 0f86238 commit cadc165

File tree

6 files changed

+77
-8
lines changed

6 files changed

+77
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ fun CustomRefreshingContent() {
220220
```
221221

222222
# Download
223-
The Current Release Version is 0.0.2. For future release, please refer to the release session of the github repository.
223+
The Current Release Version is 0.0.3. For future release, please refer to the release session of the github repository.
224224
``` kotlin
225225
repositories {
226226
mavenCentral()

core-paginglist/src/main/java/com/kevinnzou/compose/core/paginglist/widget/ItemPaging.kt

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.kevinnzou.compose.core.paginglist.widget
22

3-
import androidx.compose.foundation.lazy.LazyColumn
4-
import androidx.compose.foundation.lazy.LazyListScope
5-
import androidx.compose.foundation.lazy.LazyRow
3+
import androidx.compose.foundation.lazy.*
4+
import androidx.compose.foundation.lazy.grid.GridItemSpan
5+
import androidx.compose.foundation.lazy.grid.LazyGridItemScope
6+
import androidx.compose.foundation.lazy.grid.LazyGridScope
67
import androidx.compose.runtime.Composable
78
import androidx.paging.LoadState
89
import androidx.paging.compose.LazyPagingItems
@@ -38,4 +39,35 @@ fun <T : Any> LazyListScope.itemPaging(
3839
}
3940

4041
}
42+
}
43+
44+
fun <T : Any> LazyGridScope.itemPaging(
45+
pagingData: LazyPagingItems<T>,
46+
span: Int,
47+
loadingContent: @Composable (() -> Unit)? = { DefaultLoadingContent() },
48+
noMoreContent: @Composable (() -> Unit)? = { DefaultNoMoreContent() },
49+
errorContent: @Composable ((retry: (() -> Unit)?) -> Unit)? = { retry ->
50+
DefaultErrorContent(
51+
retry
52+
)
53+
},
54+
) {
55+
when (pagingData.loadState.append) {
56+
is LoadState.Loading -> loadingContent?.let { item(span = { GridItemSpan(span) }) { loadingContent() } }
57+
is LoadState.Error -> errorContent?.let { item(span = { GridItemSpan(span) }) { errorContent { pagingData.retry() } } }
58+
is LoadState.NotLoading ->
59+
if (pagingData.loadState.append.endOfPaginationReached && noMoreContent != null) {
60+
item(span = { GridItemSpan(span) }) { noMoreContent() }
61+
}
62+
63+
}
64+
}
65+
66+
fun <T : Any> LazyGridScope.itemsIndexed(
67+
items: LazyPagingItems<T>,
68+
itemContent: @Composable LazyGridItemScope.(index: Int, value: T?) -> Unit
69+
) {
70+
items(items.itemCount) { index ->
71+
itemContent(index, items[index])
72+
}
4173
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ android.disableAutomaticComponentCreation=true
2525

2626
GROUP_ID=io.github.kevinnzou
2727
ARTIFACT_ID=compose-paginglist
28-
VERSION_NAME=0.0.2
28+
VERSION_NAME=0.0.3
2929

3030

3131
POM_DESCRIPTION=Pull To Refresh layout for Jetpack Compose

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ androidDesugarJdkLibs = "1.1.5"
77
androidGradlePlugin = "7.2.1"
88
androidxActivity = "1.4.0"
99
androidxAppCompat = "1.4.2"
10-
androidxCompose = "1.1.1"
10+
androidxCompose = "1.2.0"
1111
androidxComposeMaterial3 = "1.0.0-alpha13"
1212
androidxCore = "1.8.0"
1313
androidxCustomView = "1.0.0-beta02"
@@ -34,7 +34,7 @@ hiltCompose = "1.0.0"
3434
hiltLifecycleViewModel = "1.0.0-alpha01"
3535
jacoco = "0.8.7"
3636
junit4 = "4.13.2"
37-
kotlin = "1.6.10"
37+
kotlin = "1.7.0"
3838
kotlinxCoroutines = "1.6.2"
3939
kotlinxDatetime = "0.3.3"
4040
kotlinxSerializationJson = "1.3.3"

sample/src/main/java/com/example/compose_paginglist/MainActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class MainActivity : ComponentActivity() {
5151
composable("EmptyPagingList") {
5252
EmptyPagingListScreen()
5353
}
54+
composable("PagingGrid") {
55+
PagingGridScreen()
56+
}
5457
}
5558
}
5659
}

sample/src/main/java/com/example/compose_paginglist/MainScreen.kt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.example.compose_paginglist
22

3+
import androidx.compose.foundation.background
34
import androidx.compose.foundation.layout.*
45
import androidx.compose.foundation.lazy.LazyColumn
6+
import androidx.compose.foundation.lazy.grid.GridCells
7+
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
58
import androidx.compose.material.Button
69
import androidx.compose.material.ButtonDefaults
710
import androidx.compose.material.LinearProgressIndicator
@@ -24,6 +27,7 @@ import com.example.compose_paginglist.ui.theme.ComposepagingListTheme
2427
import com.kevinnzou.compose.core.paginglist.easylist.PagingLazyColumn
2528
import com.kevinnzou.compose.core.paginglist.widget.PagingListContainer
2629
import com.kevinnzou.compose.core.paginglist.widget.itemPaging
30+
import com.kevinnzou.compose.core.paginglist.widget.itemsIndexed
2731

2832
/**
2933
* Created By Kevin Zou On 2022/7/5
@@ -36,7 +40,8 @@ fun MainScreen(navController: NavController? = null) {
3640
"RawPagingList",
3741
"CustomLoadMore",
3842
"ErrorPagingList",
39-
"EmptyPagingList"
43+
"EmptyPagingList",
44+
"PagingGrid"
4045
)
4146
Column(
4247
Modifier.fillMaxSize(),
@@ -156,6 +161,35 @@ fun EmptyPagingListScreen(viewModel: MainViewModel = hiltViewModel()) {
156161
}
157162
}
158163

164+
@Composable
165+
fun PagingGridScreen(viewModel: MainViewModel = hiltViewModel()) {
166+
val pagerData = viewModel.pager.collectAsLazyPagingItems()
167+
PagingListContainer(pagingData = pagerData) {
168+
LazyVerticalGrid(
169+
columns = GridCells.Fixed(2),
170+
verticalArrangement = Arrangement.spacedBy(10.dp),
171+
horizontalArrangement = Arrangement.spacedBy(10.dp),
172+
contentPadding = PaddingValues(10.dp)
173+
) {
174+
itemsIndexed(pagerData) { index, value ->
175+
Box(
176+
Modifier
177+
.background(if (index.rem(2) == 0) Color.Yellow else Color.Magenta)
178+
.height(128.dp),
179+
contentAlignment = Alignment.Center
180+
) {
181+
Text(text = value.toString())
182+
}
183+
}
184+
if (pagerData.itemCount.rem(2) != 0) {
185+
item { Spacer(Modifier.background(Color.White)) }
186+
}
187+
itemPaging(pagerData, 2)
188+
}
189+
}
190+
}
191+
192+
159193
@Preview(showBackground = true)
160194
@Composable
161195
fun DefaultPreview() {

0 commit comments

Comments
 (0)