From f8d8cf9f6a27c536ad3126de8d2d5de373248e04 Mon Sep 17 00:00:00 2001 From: Andreas Date: Wed, 27 Jul 2022 15:00:09 +0200 Subject: [PATCH] Wait for library to load before creating Pager (#7623) --- .../presentation/library/LibraryScreen.kt | 95 ++++++++++--------- .../library/components/LibraryContent.kt | 9 +- 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt b/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt index e7655a35cf..fec2432eab 100644 --- a/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/library/LibraryScreen.kt @@ -1,11 +1,13 @@ package eu.kanade.presentation.library +import androidx.compose.animation.Crossfade import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import eu.kanade.domain.category.model.Category import eu.kanade.presentation.components.LibraryBottomActionMenu +import eu.kanade.presentation.components.LoadingScreen import eu.kanade.presentation.components.Scaffold import eu.kanade.presentation.library.components.LibraryContent import eu.kanade.presentation.library.components.LibraryToolbar @@ -28,49 +30,54 @@ fun LibraryScreen( onClickFilter: () -> Unit, onClickRefresh: (Category?) -> Unit, ) { - Scaffold( - modifier = Modifier.safeDrawingPadding(), - topBar = { - val title by presenter.getToolbarTitle() - LibraryToolbar( - state = presenter, - title = title, - onClickUnselectAll = onClickUnselectAll, - onClickSelectAll = onClickSelectAll, - onClickInvertSelection = onClickInvertSelection, - onClickFilter = onClickFilter, - onClickRefresh = { onClickRefresh(null) }, - ) - }, - bottomBar = { - LibraryBottomActionMenu( - visible = presenter.selectionMode, - onChangeCategoryClicked = onChangeCategoryClicked, - onMarkAsReadClicked = onMarkAsReadClicked, - onMarkAsUnreadClicked = onMarkAsUnreadClicked, - onDownloadClicked = onDownloadClicked, - onDeleteClicked = onDeleteClicked.takeIf { presenter.selection.none { it.source == LocalSource.ID } }, - ) - }, - ) { paddingValues -> - LibraryContent( - state = presenter, - contentPadding = paddingValues, - currentPage = presenter.activeCategory, - isLibraryEmpty = presenter.loadedManga.isEmpty(), - showPageTabs = presenter.tabVisibility, - showMangaCount = presenter.mangaCountVisibility, - onChangeCurrentPage = { presenter.activeCategory = it }, - onMangaClicked = onMangaClicked, - onToggleSelection = { presenter.toggleSelection(it) }, - onRefresh = onClickRefresh, - onGlobalSearchClicked = onGlobalSearchClicked, - getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) }, - getDisplayModeForPage = { presenter.getDisplayMode(index = it) }, - getColumnsForOrientation = { presenter.getColumnsPreferenceForCurrentOrientation(it) }, - getLibraryForPage = { presenter.getMangaForCategory(page = it) }, - isIncognitoMode = presenter.isIncognitoMode, - isDownloadOnly = presenter.isDownloadOnly, - ) + Crossfade(targetState = presenter.isLoading) { state -> + when (state) { + true -> LoadingScreen() + false -> Scaffold( + modifier = Modifier.safeDrawingPadding(), + topBar = { + val title by presenter.getToolbarTitle() + LibraryToolbar( + state = presenter, + title = title, + onClickUnselectAll = onClickUnselectAll, + onClickSelectAll = onClickSelectAll, + onClickInvertSelection = onClickInvertSelection, + onClickFilter = onClickFilter, + onClickRefresh = { onClickRefresh(null) }, + ) + }, + bottomBar = { + LibraryBottomActionMenu( + visible = presenter.selectionMode, + onChangeCategoryClicked = onChangeCategoryClicked, + onMarkAsReadClicked = onMarkAsReadClicked, + onMarkAsUnreadClicked = onMarkAsUnreadClicked, + onDownloadClicked = onDownloadClicked, + onDeleteClicked = onDeleteClicked.takeIf { presenter.selection.none { it.source == LocalSource.ID } }, + ) + }, + ) { paddingValues -> + LibraryContent( + state = presenter, + contentPadding = paddingValues, + currentPage = presenter.activeCategory, + isLibraryEmpty = presenter.loadedManga.isEmpty(), + showPageTabs = presenter.tabVisibility, + showMangaCount = presenter.mangaCountVisibility, + onChangeCurrentPage = { presenter.activeCategory = it }, + onMangaClicked = onMangaClicked, + onToggleSelection = { presenter.toggleSelection(it) }, + onRefresh = onClickRefresh, + onGlobalSearchClicked = onGlobalSearchClicked, + getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) }, + getDisplayModeForPage = { presenter.getDisplayMode(index = it) }, + getColumnsForOrientation = { presenter.getColumnsPreferenceForCurrentOrientation(it) }, + getLibraryForPage = { presenter.getMangaForCategory(page = it) }, + isIncognitoMode = presenter.isIncognitoMode, + isDownloadOnly = presenter.isDownloadOnly, + ) + } + } } } diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt index 1b20b8df6b..a42f65d111 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryContent.kt @@ -14,7 +14,6 @@ import com.google.accompanist.swiperefresh.rememberSwipeRefreshState import eu.kanade.core.prefs.PreferenceMutableState import eu.kanade.domain.category.model.Category import eu.kanade.presentation.components.EmptyScreen -import eu.kanade.presentation.components.LoadingScreen import eu.kanade.presentation.components.SwipeRefreshIndicator import eu.kanade.presentation.library.LibraryState import eu.kanade.tachiyomi.R @@ -44,21 +43,15 @@ fun LibraryContent( getLibraryForPage: @Composable (Int) -> State>, ) { val categories = state.categories - val pagerState = rememberPagerState(currentPage.coerceAtMost(categories.lastIndex)) - if (categories.isEmpty()) { - LoadingScreen() - return - } - Column( modifier = Modifier.padding(contentPadding), ) { if (showPageTabs && categories.size > 1) { LibraryTabs( state = pagerState, - categories = state.categories, + categories = categories, showMangaCount = showMangaCount, getNumberOfMangaForCategory = getNumberOfMangaForCategory, isDownloadOnly = isDownloadOnly,