Ensure gallery is paginating to get new items.
This commit is contained in:
parent
cb5988935f
commit
4c6f46e46c
4 changed files with 33 additions and 28 deletions
|
|
@ -198,6 +198,13 @@ private fun MediaGalleryPage(
|
|||
) {
|
||||
val groupedMediaItems = state.groupedMediaItems
|
||||
if (groupedMediaItems.isLoadingItems(mode)) {
|
||||
// Need to trigger a pagination now if there is only one LoadingIndicator.
|
||||
(groupedMediaItems.dataOrNull()
|
||||
?.getItems(mode)?.singleOrNull() as? MediaItem.LoadingIndicator)?.let { item ->
|
||||
LaunchedEffect(item.timestamp) {
|
||||
state.eventSink(MediaGalleryEvents.LoadMore(item.direction))
|
||||
}
|
||||
}
|
||||
LoadingContent(mode)
|
||||
} else {
|
||||
when (groupedMediaItems) {
|
||||
|
|
|
|||
|
|
@ -71,14 +71,26 @@ class MediaViewerDataSource(
|
|||
fun dataFlow(): Flow<PersistentList<MediaViewerPageData>> {
|
||||
return galleryDataSource.groupedMediaItemsFlow()
|
||||
.map { groupedItems ->
|
||||
if (groupedItems is AsyncData.Failure) {
|
||||
persistentListOf(
|
||||
MediaViewerPageData.Failure(groupedItems.error),
|
||||
)
|
||||
} else {
|
||||
val mediaItems = groupedItems.dataOrNull()?.getItems(galleryMode).orEmpty()
|
||||
withContext(dispatcher) {
|
||||
buildMediaViewerPageList(mediaItems)
|
||||
when (groupedItems) {
|
||||
AsyncData.Uninitialized,
|
||||
is AsyncData.Loading -> {
|
||||
persistentListOf(
|
||||
MediaViewerPageData.Loading(
|
||||
direction = Timeline.PaginationDirection.BACKWARDS,
|
||||
timestamp = systemClock.epochMillis(),
|
||||
)
|
||||
)
|
||||
}
|
||||
is AsyncData.Failure -> {
|
||||
persistentListOf(
|
||||
MediaViewerPageData.Failure(groupedItems.error),
|
||||
)
|
||||
}
|
||||
is AsyncData.Success -> {
|
||||
withContext(dispatcher) {
|
||||
val mediaItems = groupedItems.data.getItems(galleryMode)
|
||||
buildMediaViewerPageList(mediaItems)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -117,14 +129,6 @@ class MediaViewerDataSource(
|
|||
)
|
||||
}
|
||||
}
|
||||
if (isEmpty()) {
|
||||
add(
|
||||
MediaViewerPageData.Loading(
|
||||
direction = Timeline.PaginationDirection.BACKWARDS,
|
||||
timestamp = systemClock.epochMillis(),
|
||||
)
|
||||
)
|
||||
}
|
||||
}.toPersistentList()
|
||||
|
||||
fun clearLoadingError(data: MediaViewerPageData.MediaViewerData) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue