mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-18 03:17:03 +05:30
app: switch to PullToRefresh
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
a28d5085bb
commit
697e806dd8
4 changed files with 43 additions and 27 deletions
|
@ -55,6 +55,7 @@ dependencies {
|
||||||
implementation(Dependencies.ThirdParty.accompanist)
|
implementation(Dependencies.ThirdParty.accompanist)
|
||||||
implementation(Dependencies.ThirdParty.composeFlowLayout)
|
implementation(Dependencies.ThirdParty.composeFlowLayout)
|
||||||
implementation(Dependencies.ThirdParty.Moshi.lib)
|
implementation(Dependencies.ThirdParty.Moshi.lib)
|
||||||
|
implementation(Dependencies.ThirdParty.pullToRefresh)
|
||||||
implementation(Dependencies.ThirdParty.Retrofit.moshi)
|
implementation(Dependencies.ThirdParty.Retrofit.moshi)
|
||||||
implementation(Dependencies.ThirdParty.SQLDelight.androidDriver)
|
implementation(Dependencies.ThirdParty.SQLDelight.androidDriver)
|
||||||
testImplementation(Dependencies.Testing.junit)
|
testImplementation(Dependencies.Testing.junit)
|
||||||
|
|
|
@ -64,9 +64,10 @@ fun LobstersApp() {
|
||||||
HottestPosts(
|
HottestPosts(
|
||||||
posts = hottestPosts,
|
posts = hottestPosts,
|
||||||
listState = hottestPostsListState,
|
listState = hottestPostsListState,
|
||||||
|
modifier = Modifier.padding(bottom = innerPadding.calculateBottomPadding()),
|
||||||
isPostSaved = viewModel::isPostSaved,
|
isPostSaved = viewModel::isPostSaved,
|
||||||
saveAction = viewModel::toggleSave,
|
saveAction = viewModel::toggleSave,
|
||||||
modifier = Modifier.padding(bottom = innerPadding.calculateBottomPadding()),
|
refreshAction = viewModel::reloadPosts,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
composable(Destination.Saved.route) {
|
composable(Destination.Saved.route) {
|
||||||
|
|
|
@ -11,6 +11,7 @@ import androidx.compose.ui.Modifier
|
||||||
import androidx.paging.LoadState
|
import androidx.paging.LoadState
|
||||||
import androidx.paging.compose.LazyPagingItems
|
import androidx.paging.compose.LazyPagingItems
|
||||||
import androidx.paging.compose.items
|
import androidx.paging.compose.items
|
||||||
|
import com.puculek.pulltorefresh.PullToRefresh
|
||||||
import dev.msfjarvis.lobsters.data.local.SavedPost
|
import dev.msfjarvis.lobsters.data.local.SavedPost
|
||||||
import dev.msfjarvis.lobsters.model.LobstersPost
|
import dev.msfjarvis.lobsters.model.LobstersPost
|
||||||
import dev.msfjarvis.lobsters.ui.urllauncher.LocalUrlLauncher
|
import dev.msfjarvis.lobsters.ui.urllauncher.LocalUrlLauncher
|
||||||
|
@ -20,12 +21,23 @@ import dev.msfjarvis.lobsters.util.toDbModel
|
||||||
fun HottestPosts(
|
fun HottestPosts(
|
||||||
posts: LazyPagingItems<LobstersPost>,
|
posts: LazyPagingItems<LobstersPost>,
|
||||||
listState: LazyListState,
|
listState: LazyListState,
|
||||||
isPostSaved: (String) -> Boolean,
|
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
|
isPostSaved: (String) -> Boolean,
|
||||||
saveAction: (SavedPost) -> Unit,
|
saveAction: (SavedPost) -> Unit,
|
||||||
|
refreshAction: () -> Unit,
|
||||||
) {
|
) {
|
||||||
val urlLauncher = LocalUrlLauncher.current
|
val urlLauncher = LocalUrlLauncher.current
|
||||||
|
var isRefreshing by mutableStateOf(false)
|
||||||
|
|
||||||
|
PullToRefresh(
|
||||||
|
isRefreshing = isRefreshing,
|
||||||
|
onRefresh = {
|
||||||
|
if (posts.loadState.refresh != LoadState.Loading) {
|
||||||
|
isRefreshing = isRefreshing.not()
|
||||||
|
refreshAction()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
) {
|
||||||
if (posts.loadState.refresh == LoadState.Loading) {
|
if (posts.loadState.refresh == LoadState.Loading) {
|
||||||
LazyColumn {
|
LazyColumn {
|
||||||
items(15) {
|
items(15) {
|
||||||
|
@ -57,4 +69,5 @@ fun HottestPosts(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,7 @@ object Dependencies {
|
||||||
|
|
||||||
const val accompanist = "dev.chrisbanes.accompanist:accompanist-coil:0.6.2"
|
const val accompanist = "dev.chrisbanes.accompanist:accompanist-coil:0.6.2"
|
||||||
const val composeFlowLayout = "com.star-zero:compose-flowlayout:0.0.1"
|
const val composeFlowLayout = "com.star-zero:compose-flowlayout:0.0.1"
|
||||||
|
const val pullToRefresh = "com.puculek.pulltorefresh:pull-to-refresh-compose:1.0.0"
|
||||||
|
|
||||||
object Moshi {
|
object Moshi {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue