MigrateMangaScreen.kt 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package eu.kanade.presentation.browse
  2. import androidx.compose.foundation.layout.PaddingValues
  3. import androidx.compose.foundation.lazy.items
  4. import androidx.compose.runtime.Composable
  5. import androidx.compose.runtime.LaunchedEffect
  6. import androidx.compose.ui.Modifier
  7. import androidx.compose.ui.platform.LocalContext
  8. import eu.kanade.domain.manga.model.Manga
  9. import eu.kanade.presentation.components.AppBar
  10. import eu.kanade.presentation.components.EmptyScreen
  11. import eu.kanade.presentation.components.LoadingScreen
  12. import eu.kanade.presentation.components.Scaffold
  13. import eu.kanade.presentation.components.ScrollbarLazyColumn
  14. import eu.kanade.presentation.manga.components.BaseMangaListItem
  15. import eu.kanade.tachiyomi.R
  16. import eu.kanade.tachiyomi.ui.browse.migration.manga.MigrateMangaPresenter
  17. import eu.kanade.tachiyomi.ui.browse.migration.manga.MigrateMangaPresenter.Event
  18. import eu.kanade.tachiyomi.util.system.toast
  19. import kotlinx.coroutines.flow.collectLatest
  20. @Composable
  21. fun MigrateMangaScreen(
  22. navigateUp: () -> Unit,
  23. title: String?,
  24. presenter: MigrateMangaPresenter,
  25. onClickItem: (Manga) -> Unit,
  26. onClickCover: (Manga) -> Unit,
  27. ) {
  28. val context = LocalContext.current
  29. Scaffold(
  30. topBar = { scrollBehavior ->
  31. AppBar(
  32. title = title,
  33. navigateUp = navigateUp,
  34. scrollBehavior = scrollBehavior,
  35. )
  36. },
  37. ) { contentPadding ->
  38. when {
  39. presenter.isLoading -> LoadingScreen()
  40. presenter.isEmpty -> EmptyScreen(textResource = R.string.empty_screen)
  41. else -> {
  42. MigrateMangaContent(
  43. contentPadding = contentPadding,
  44. state = presenter,
  45. onClickItem = onClickItem,
  46. onClickCover = onClickCover,
  47. )
  48. }
  49. }
  50. }
  51. LaunchedEffect(Unit) {
  52. presenter.events.collectLatest { event ->
  53. when (event) {
  54. Event.FailedFetchingFavorites -> {
  55. context.toast(R.string.internal_error)
  56. }
  57. }
  58. }
  59. }
  60. }
  61. @Composable
  62. private fun MigrateMangaContent(
  63. contentPadding: PaddingValues,
  64. state: MigrateMangaState,
  65. onClickItem: (Manga) -> Unit,
  66. onClickCover: (Manga) -> Unit,
  67. ) {
  68. ScrollbarLazyColumn(
  69. contentPadding = contentPadding,
  70. ) {
  71. items(state.items) { manga ->
  72. MigrateMangaItem(
  73. manga = manga,
  74. onClickItem = onClickItem,
  75. onClickCover = onClickCover,
  76. )
  77. }
  78. }
  79. }
  80. @Composable
  81. private fun MigrateMangaItem(
  82. modifier: Modifier = Modifier,
  83. manga: Manga,
  84. onClickItem: (Manga) -> Unit,
  85. onClickCover: (Manga) -> Unit,
  86. ) {
  87. BaseMangaListItem(
  88. modifier = modifier,
  89. manga = manga,
  90. onClickItem = { onClickItem(manga) },
  91. onClickCover = { onClickCover(manga) },
  92. )
  93. }