From 580b7fa3c01ab17bd85a18090d5d5921f4788c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Muller?= Date: Mon, 18 Dec 2023 11:48:52 +0100 Subject: [PATCH] Display a loading indicator when fetching the next page (#371) --- .../demo/tv/ui/integrationLayer/ListsHome.kt | 14 ++++++++++++++ .../demo/ui/integrationLayer/ContentListView.kt | 11 +++++++++++ .../demo/ui/integrationLayer/SearchView.kt | 10 ++++++++++ 3 files changed, 35 insertions(+) diff --git a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/integrationLayer/ListsHome.kt b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/integrationLayer/ListsHome.kt index 0a0a0aefc..c76aff678 100644 --- a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/integrationLayer/ListsHome.kt +++ b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/integrationLayer/ListsHome.kt @@ -63,6 +63,7 @@ import androidx.paging.compose.LazyPagingItems import androidx.paging.compose.collectAsLazyPagingItems import androidx.paging.compose.itemKey import androidx.tv.foundation.lazy.grid.TvGridCells +import androidx.tv.foundation.lazy.grid.TvGridItemSpan import androidx.tv.foundation.lazy.grid.TvLazyVerticalGrid import androidx.tv.foundation.lazy.grid.itemsIndexed import androidx.tv.foundation.lazy.grid.rememberTvLazyGridState @@ -505,6 +506,19 @@ private fun ListsSectionContent( } } } + + if (items.loadState.append is LoadState.Loading) { + item( + contentType = "LoadingView", + span = { TvGridItemSpan(columnCount) } + ) { + ListsSectionLoading( + modifier = modifier + .fillMaxSize() + .padding(MaterialTheme.paddings.baseline) + ) + } + } } } } diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/ContentListView.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/ContentListView.kt index 4b645c17b..b29605c41 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/ContentListView.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/ContentListView.kt @@ -7,6 +7,7 @@ package ch.srgssr.pillarbox.demo.ui.integrationLayer import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.shape.RoundedCornerShape @@ -116,6 +117,16 @@ fun ContentListView( } } } + + if (items.loadState.append is LoadState.Loading) { + item(contentType = "LoadingView") { + LoadingView( + modifier = modifier + .fillMaxSize() + .padding(top = MaterialTheme.paddings.baseline) + ) + } + } } } diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchView.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchView.kt index 695089a41..2e3efc610 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchView.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/integrationLayer/SearchView.kt @@ -168,6 +168,16 @@ private fun SearchResultList( } } } + + if (items.loadState.append is LoadState.Loading) { + item(contentType = "LoadingView") { + LoadingView( + modifier = modifier + .fillMaxSize() + .padding(MaterialTheme.paddings.baseline) + ) + } + } } } }