SourceSearchScreen.kt 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package eu.kanade.presentation.browse
  2. import androidx.compose.material3.SnackbarHost
  3. import androidx.compose.material3.SnackbarHostState
  4. import androidx.compose.runtime.Composable
  5. import androidx.compose.runtime.getValue
  6. import androidx.compose.runtime.remember
  7. import androidx.compose.ui.platform.LocalUriHandler
  8. import androidx.compose.ui.res.stringResource
  9. import androidx.paging.compose.collectAsLazyPagingItems
  10. import eu.kanade.domain.manga.model.Manga
  11. import eu.kanade.presentation.browse.components.BrowseSourceSearchToolbar
  12. import eu.kanade.presentation.components.Scaffold
  13. import eu.kanade.tachiyomi.R
  14. import eu.kanade.tachiyomi.source.LocalSource
  15. import eu.kanade.tachiyomi.ui.browse.source.browse.BrowseSourcePresenter
  16. import eu.kanade.tachiyomi.ui.more.MoreController
  17. @Composable
  18. fun SourceSearchScreen(
  19. presenter: BrowseSourcePresenter,
  20. navigateUp: () -> Unit,
  21. onFabClick: () -> Unit,
  22. onMangaClick: (Manga) -> Unit,
  23. onWebViewClick: () -> Unit,
  24. ) {
  25. val columns by presenter.getColumnsPreferenceForCurrentOrientation()
  26. val mangaList = presenter.getMangaList().collectAsLazyPagingItems()
  27. val snackbarHostState = remember { SnackbarHostState() }
  28. val uriHandler = LocalUriHandler.current
  29. val onHelpClick = {
  30. uriHandler.openUri(LocalSource.HELP_URL)
  31. }
  32. Scaffold(
  33. topBar = { scrollBehavior ->
  34. BrowseSourceSearchToolbar(
  35. searchQuery = presenter.searchQuery ?: "",
  36. onSearchQueryChanged = { presenter.searchQuery = it },
  37. placeholderText = stringResource(R.string.action_search_hint),
  38. navigateUp = navigateUp,
  39. onResetClick = { presenter.searchQuery = "" },
  40. onSearchClick = { presenter.search() },
  41. scrollBehavior = scrollBehavior,
  42. )
  43. },
  44. floatingActionButton = {
  45. BrowseSourceFloatingActionButton(
  46. isVisible = presenter.filters.isNotEmpty(),
  47. onFabClick = onFabClick,
  48. )
  49. },
  50. snackbarHost = {
  51. SnackbarHost(hostState = snackbarHostState)
  52. },
  53. ) { paddingValues ->
  54. BrowseSourceContent(
  55. state = presenter,
  56. mangaList = mangaList,
  57. getMangaState = { presenter.getManga(it) },
  58. columns = columns,
  59. displayMode = presenter.displayMode,
  60. snackbarHostState = snackbarHostState,
  61. contentPadding = paddingValues,
  62. onWebViewClick = onWebViewClick,
  63. onHelpClick = { uriHandler.openUri(MoreController.URL_HELP) },
  64. onLocalSourceHelpClick = onHelpClick,
  65. onMangaClick = onMangaClick,
  66. onMangaLongClick = onMangaClick,
  67. )
  68. }
  69. }