Wait for library to load before creating Pager (#7623)

This commit is contained in:
Andreas 2022-07-27 15:00:09 +02:00 committed by GitHub
parent 5bb1133f0f
commit f8d8cf9f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 52 deletions

View File

@ -1,11 +1,13 @@
package eu.kanade.presentation.library package eu.kanade.presentation.library
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.layout.safeDrawingPadding import androidx.compose.foundation.layout.safeDrawingPadding
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import eu.kanade.domain.category.model.Category import eu.kanade.domain.category.model.Category
import eu.kanade.presentation.components.LibraryBottomActionMenu import eu.kanade.presentation.components.LibraryBottomActionMenu
import eu.kanade.presentation.components.LoadingScreen
import eu.kanade.presentation.components.Scaffold import eu.kanade.presentation.components.Scaffold
import eu.kanade.presentation.library.components.LibraryContent import eu.kanade.presentation.library.components.LibraryContent
import eu.kanade.presentation.library.components.LibraryToolbar import eu.kanade.presentation.library.components.LibraryToolbar
@ -28,49 +30,54 @@ fun LibraryScreen(
onClickFilter: () -> Unit, onClickFilter: () -> Unit,
onClickRefresh: (Category?) -> Unit, onClickRefresh: (Category?) -> Unit,
) { ) {
Scaffold( Crossfade(targetState = presenter.isLoading) { state ->
modifier = Modifier.safeDrawingPadding(), when (state) {
topBar = { true -> LoadingScreen()
val title by presenter.getToolbarTitle() false -> Scaffold(
LibraryToolbar( modifier = Modifier.safeDrawingPadding(),
state = presenter, topBar = {
title = title, val title by presenter.getToolbarTitle()
onClickUnselectAll = onClickUnselectAll, LibraryToolbar(
onClickSelectAll = onClickSelectAll, state = presenter,
onClickInvertSelection = onClickInvertSelection, title = title,
onClickFilter = onClickFilter, onClickUnselectAll = onClickUnselectAll,
onClickRefresh = { onClickRefresh(null) }, onClickSelectAll = onClickSelectAll,
) onClickInvertSelection = onClickInvertSelection,
}, onClickFilter = onClickFilter,
bottomBar = { onClickRefresh = { onClickRefresh(null) },
LibraryBottomActionMenu( )
visible = presenter.selectionMode, },
onChangeCategoryClicked = onChangeCategoryClicked, bottomBar = {
onMarkAsReadClicked = onMarkAsReadClicked, LibraryBottomActionMenu(
onMarkAsUnreadClicked = onMarkAsUnreadClicked, visible = presenter.selectionMode,
onDownloadClicked = onDownloadClicked, onChangeCategoryClicked = onChangeCategoryClicked,
onDeleteClicked = onDeleteClicked.takeIf { presenter.selection.none { it.source == LocalSource.ID } }, onMarkAsReadClicked = onMarkAsReadClicked,
) onMarkAsUnreadClicked = onMarkAsUnreadClicked,
}, onDownloadClicked = onDownloadClicked,
) { paddingValues -> onDeleteClicked = onDeleteClicked.takeIf { presenter.selection.none { it.source == LocalSource.ID } },
LibraryContent( )
state = presenter, },
contentPadding = paddingValues, ) { paddingValues ->
currentPage = presenter.activeCategory, LibraryContent(
isLibraryEmpty = presenter.loadedManga.isEmpty(), state = presenter,
showPageTabs = presenter.tabVisibility, contentPadding = paddingValues,
showMangaCount = presenter.mangaCountVisibility, currentPage = presenter.activeCategory,
onChangeCurrentPage = { presenter.activeCategory = it }, isLibraryEmpty = presenter.loadedManga.isEmpty(),
onMangaClicked = onMangaClicked, showPageTabs = presenter.tabVisibility,
onToggleSelection = { presenter.toggleSelection(it) }, showMangaCount = presenter.mangaCountVisibility,
onRefresh = onClickRefresh, onChangeCurrentPage = { presenter.activeCategory = it },
onGlobalSearchClicked = onGlobalSearchClicked, onMangaClicked = onMangaClicked,
getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) }, onToggleSelection = { presenter.toggleSelection(it) },
getDisplayModeForPage = { presenter.getDisplayMode(index = it) }, onRefresh = onClickRefresh,
getColumnsForOrientation = { presenter.getColumnsPreferenceForCurrentOrientation(it) }, onGlobalSearchClicked = onGlobalSearchClicked,
getLibraryForPage = { presenter.getMangaForCategory(page = it) }, getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) },
isIncognitoMode = presenter.isIncognitoMode, getDisplayModeForPage = { presenter.getDisplayMode(index = it) },
isDownloadOnly = presenter.isDownloadOnly, getColumnsForOrientation = { presenter.getColumnsPreferenceForCurrentOrientation(it) },
) getLibraryForPage = { presenter.getMangaForCategory(page = it) },
isIncognitoMode = presenter.isIncognitoMode,
isDownloadOnly = presenter.isDownloadOnly,
)
}
}
} }
} }

View File

@ -14,7 +14,6 @@ import com.google.accompanist.swiperefresh.rememberSwipeRefreshState
import eu.kanade.core.prefs.PreferenceMutableState import eu.kanade.core.prefs.PreferenceMutableState
import eu.kanade.domain.category.model.Category import eu.kanade.domain.category.model.Category
import eu.kanade.presentation.components.EmptyScreen import eu.kanade.presentation.components.EmptyScreen
import eu.kanade.presentation.components.LoadingScreen
import eu.kanade.presentation.components.SwipeRefreshIndicator import eu.kanade.presentation.components.SwipeRefreshIndicator
import eu.kanade.presentation.library.LibraryState import eu.kanade.presentation.library.LibraryState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -44,21 +43,15 @@ fun LibraryContent(
getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>, getLibraryForPage: @Composable (Int) -> State<List<LibraryItem>>,
) { ) {
val categories = state.categories val categories = state.categories
val pagerState = rememberPagerState(currentPage.coerceAtMost(categories.lastIndex)) val pagerState = rememberPagerState(currentPage.coerceAtMost(categories.lastIndex))
if (categories.isEmpty()) {
LoadingScreen()
return
}
Column( Column(
modifier = Modifier.padding(contentPadding), modifier = Modifier.padding(contentPadding),
) { ) {
if (showPageTabs && categories.size > 1) { if (showPageTabs && categories.size > 1) {
LibraryTabs( LibraryTabs(
state = pagerState, state = pagerState,
categories = state.categories, categories = categories,
showMangaCount = showMangaCount, showMangaCount = showMangaCount,
getNumberOfMangaForCategory = getNumberOfMangaForCategory, getNumberOfMangaForCategory = getNumberOfMangaForCategory,
isDownloadOnly = isDownloadOnly, isDownloadOnly = isDownloadOnly,