LibraryScreen.kt 3.8 KB

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