LibraryScreen.kt 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package eu.kanade.presentation.library
  2. import androidx.compose.animation.Crossfade
  3. import androidx.compose.runtime.Composable
  4. import androidx.compose.runtime.getValue
  5. import eu.kanade.domain.category.model.Category
  6. import eu.kanade.domain.library.model.display
  7. import eu.kanade.presentation.components.LibraryBottomActionMenu
  8. import eu.kanade.presentation.components.LoadingScreen
  9. import eu.kanade.presentation.components.Scaffold
  10. import eu.kanade.presentation.library.components.LibraryContent
  11. import eu.kanade.presentation.library.components.LibraryToolbar
  12. import eu.kanade.tachiyomi.source.LocalSource
  13. import eu.kanade.tachiyomi.ui.library.LibraryPresenter
  14. @Composable
  15. fun LibraryScreen(
  16. presenter: LibraryPresenter,
  17. onMangaClicked: (Long) -> Unit,
  18. onGlobalSearchClicked: () -> Unit,
  19. onChangeCategoryClicked: () -> Unit,
  20. onMarkAsReadClicked: () -> Unit,
  21. onMarkAsUnreadClicked: () -> Unit,
  22. onDownloadClicked: () -> Unit,
  23. onDeleteClicked: () -> Unit,
  24. onClickUnselectAll: () -> Unit,
  25. onClickSelectAll: () -> Unit,
  26. onClickInvertSelection: () -> Unit,
  27. onClickFilter: () -> Unit,
  28. onClickRefresh: (Category?) -> Boolean,
  29. ) {
  30. Crossfade(targetState = presenter.isLoading) { state ->
  31. when (state) {
  32. true -> LoadingScreen()
  33. false -> Scaffold(
  34. topBar = { scrollBehavior ->
  35. val title by presenter.getToolbarTitle()
  36. val tabVisible = presenter.tabVisibility && presenter.categories.size > 1
  37. LibraryToolbar(
  38. state = presenter,
  39. title = title,
  40. incognitoMode = !tabVisible && presenter.isIncognitoMode,
  41. downloadedOnlyMode = !tabVisible && presenter.isDownloadOnly,
  42. onClickUnselectAll = onClickUnselectAll,
  43. onClickSelectAll = onClickSelectAll,
  44. onClickInvertSelection = onClickInvertSelection,
  45. onClickFilter = onClickFilter,
  46. onClickRefresh = { onClickRefresh(null) },
  47. scrollBehavior = scrollBehavior.takeIf { !tabVisible }, // For scroll overlay when no tab
  48. )
  49. },
  50. bottomBar = {
  51. LibraryBottomActionMenu(
  52. visible = presenter.selectionMode,
  53. onChangeCategoryClicked = onChangeCategoryClicked,
  54. onMarkAsReadClicked = onMarkAsReadClicked,
  55. onMarkAsUnreadClicked = onMarkAsUnreadClicked,
  56. onDownloadClicked = onDownloadClicked.takeIf { presenter.selection.none { it.manga.source == LocalSource.ID } },
  57. onDeleteClicked = onDeleteClicked,
  58. )
  59. },
  60. ) { paddingValues ->
  61. LibraryContent(
  62. state = presenter,
  63. contentPadding = paddingValues,
  64. currentPage = { presenter.activeCategory },
  65. isLibraryEmpty = presenter.isLibraryEmpty,
  66. showPageTabs = presenter.tabVisibility,
  67. showMangaCount = presenter.mangaCountVisibility,
  68. onChangeCurrentPage = { presenter.activeCategory = it },
  69. onMangaClicked = onMangaClicked,
  70. onToggleSelection = { presenter.toggleSelection(it) },
  71. onRefresh = onClickRefresh,
  72. onGlobalSearchClicked = onGlobalSearchClicked,
  73. getNumberOfMangaForCategory = { presenter.getMangaCountForCategory(it) },
  74. getDisplayModeForPage = { presenter.categories[it].display },
  75. getColumnsForOrientation = { presenter.getColumnsPreferenceForCurrentOrientation(it) },
  76. getLibraryForPage = { presenter.getMangaForCategory(page = it) },
  77. isIncognitoMode = presenter.isIncognitoMode,
  78. isDownloadOnly = presenter.isDownloadOnly,
  79. )
  80. }
  81. }
  82. }
  83. }