BrowseSourceToolbar.kt 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package eu.kanade.presentation.browse.components
  2. import androidx.compose.material.icons.Icons
  3. import androidx.compose.material.icons.automirrored.filled.ViewList
  4. import androidx.compose.material.icons.filled.ViewModule
  5. import androidx.compose.material3.Text
  6. import androidx.compose.material3.TopAppBarScrollBehavior
  7. import androidx.compose.runtime.Composable
  8. import androidx.compose.runtime.getValue
  9. import androidx.compose.runtime.mutableStateOf
  10. import androidx.compose.runtime.remember
  11. import androidx.compose.runtime.setValue
  12. import eu.kanade.presentation.components.AppBar
  13. import eu.kanade.presentation.components.AppBarActions
  14. import eu.kanade.presentation.components.AppBarTitle
  15. import eu.kanade.presentation.components.DropdownMenu
  16. import eu.kanade.presentation.components.RadioMenuItem
  17. import eu.kanade.presentation.components.SearchToolbar
  18. import eu.kanade.tachiyomi.source.ConfigurableSource
  19. import eu.kanade.tachiyomi.source.Source
  20. import kotlinx.collections.immutable.persistentListOf
  21. import tachiyomi.domain.library.model.LibraryDisplayMode
  22. import tachiyomi.i18n.MR
  23. import tachiyomi.presentation.core.i18n.stringResource
  24. import tachiyomi.source.local.LocalSource
  25. @Composable
  26. fun BrowseSourceToolbar(
  27. searchQuery: String?,
  28. onSearchQueryChange: (String?) -> Unit,
  29. source: Source?,
  30. displayMode: LibraryDisplayMode,
  31. onDisplayModeChange: (LibraryDisplayMode) -> Unit,
  32. navigateUp: () -> Unit,
  33. onWebViewClick: () -> Unit,
  34. onHelpClick: () -> Unit,
  35. onSettingsClick: () -> Unit,
  36. onSearch: (String) -> Unit,
  37. scrollBehavior: TopAppBarScrollBehavior? = null,
  38. ) {
  39. // Avoid capturing unstable source in actions lambda
  40. val title = source?.name
  41. val isLocalSource = source is LocalSource
  42. val isConfigurableSource = source is ConfigurableSource
  43. var selectingDisplayMode by remember { mutableStateOf(false) }
  44. SearchToolbar(
  45. navigateUp = navigateUp,
  46. titleContent = { AppBarTitle(title) },
  47. searchQuery = searchQuery,
  48. onChangeSearchQuery = onSearchQueryChange,
  49. onSearch = onSearch,
  50. onClickCloseSearch = navigateUp,
  51. actions = {
  52. AppBarActions(
  53. actions = persistentListOf<AppBar.AppBarAction>().builder()
  54. .apply {
  55. add(
  56. AppBar.Action(
  57. title = stringResource(MR.strings.action_display_mode),
  58. icon = if (displayMode == LibraryDisplayMode.List) {
  59. Icons.AutoMirrored.Filled.ViewList
  60. } else {
  61. Icons.Filled.ViewModule
  62. },
  63. onClick = { selectingDisplayMode = true },
  64. ),
  65. )
  66. if (isLocalSource) {
  67. add(
  68. AppBar.OverflowAction(
  69. title = stringResource(MR.strings.label_help),
  70. onClick = onHelpClick,
  71. ),
  72. )
  73. } else {
  74. add(
  75. AppBar.OverflowAction(
  76. title = stringResource(MR.strings.action_open_in_web_view),
  77. onClick = onWebViewClick,
  78. ),
  79. )
  80. }
  81. if (isConfigurableSource) {
  82. add(
  83. AppBar.OverflowAction(
  84. title = stringResource(MR.strings.action_settings),
  85. onClick = onSettingsClick,
  86. ),
  87. )
  88. }
  89. }
  90. .build(),
  91. )
  92. DropdownMenu(
  93. expanded = selectingDisplayMode,
  94. onDismissRequest = { selectingDisplayMode = false },
  95. ) {
  96. RadioMenuItem(
  97. text = { Text(text = stringResource(MR.strings.action_display_comfortable_grid)) },
  98. isChecked = displayMode == LibraryDisplayMode.ComfortableGrid,
  99. ) {
  100. selectingDisplayMode = false
  101. onDisplayModeChange(LibraryDisplayMode.ComfortableGrid)
  102. }
  103. RadioMenuItem(
  104. text = { Text(text = stringResource(MR.strings.action_display_grid)) },
  105. isChecked = displayMode == LibraryDisplayMode.CompactGrid,
  106. ) {
  107. selectingDisplayMode = false
  108. onDisplayModeChange(LibraryDisplayMode.CompactGrid)
  109. }
  110. RadioMenuItem(
  111. text = { Text(text = stringResource(MR.strings.action_display_list)) },
  112. isChecked = displayMode == LibraryDisplayMode.List,
  113. ) {
  114. selectingDisplayMode = false
  115. onDisplayModeChange(LibraryDisplayMode.List)
  116. }
  117. }
  118. },
  119. scrollBehavior = scrollBehavior,
  120. )
  121. }