123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- package eu.kanade.presentation.browse.components
- import androidx.compose.material.icons.Icons
- import androidx.compose.material.icons.automirrored.filled.ViewList
- import androidx.compose.material.icons.filled.ViewModule
- import androidx.compose.material3.Text
- import androidx.compose.material3.TopAppBarScrollBehavior
- import androidx.compose.runtime.Composable
- import androidx.compose.runtime.getValue
- import androidx.compose.runtime.mutableStateOf
- import androidx.compose.runtime.remember
- import androidx.compose.runtime.setValue
- import eu.kanade.presentation.components.AppBar
- import eu.kanade.presentation.components.AppBarActions
- import eu.kanade.presentation.components.AppBarTitle
- import eu.kanade.presentation.components.DropdownMenu
- import eu.kanade.presentation.components.RadioMenuItem
- import eu.kanade.presentation.components.SearchToolbar
- import eu.kanade.tachiyomi.source.ConfigurableSource
- import eu.kanade.tachiyomi.source.Source
- import kotlinx.collections.immutable.persistentListOf
- import tachiyomi.domain.library.model.LibraryDisplayMode
- import tachiyomi.i18n.MR
- import tachiyomi.presentation.core.i18n.stringResource
- import tachiyomi.source.local.LocalSource
- @Composable
- fun BrowseSourceToolbar(
- searchQuery: String?,
- onSearchQueryChange: (String?) -> Unit,
- source: Source?,
- displayMode: LibraryDisplayMode,
- onDisplayModeChange: (LibraryDisplayMode) -> Unit,
- navigateUp: () -> Unit,
- onWebViewClick: () -> Unit,
- onHelpClick: () -> Unit,
- onSettingsClick: () -> Unit,
- onSearch: (String) -> Unit,
- scrollBehavior: TopAppBarScrollBehavior? = null,
- ) {
- // Avoid capturing unstable source in actions lambda
- val title = source?.name
- val isLocalSource = source is LocalSource
- val isConfigurableSource = source is ConfigurableSource
- var selectingDisplayMode by remember { mutableStateOf(false) }
- SearchToolbar(
- navigateUp = navigateUp,
- titleContent = { AppBarTitle(title) },
- searchQuery = searchQuery,
- onChangeSearchQuery = onSearchQueryChange,
- onSearch = onSearch,
- onClickCloseSearch = navigateUp,
- actions = {
- AppBarActions(
- actions = persistentListOf<AppBar.AppBarAction>().builder()
- .apply {
- add(
- AppBar.Action(
- title = stringResource(MR.strings.action_display_mode),
- icon = if (displayMode == LibraryDisplayMode.List) {
- Icons.AutoMirrored.Filled.ViewList
- } else {
- Icons.Filled.ViewModule
- },
- onClick = { selectingDisplayMode = true },
- ),
- )
- if (isLocalSource) {
- add(
- AppBar.OverflowAction(
- title = stringResource(MR.strings.label_help),
- onClick = onHelpClick,
- ),
- )
- } else {
- add(
- AppBar.OverflowAction(
- title = stringResource(MR.strings.action_open_in_web_view),
- onClick = onWebViewClick,
- ),
- )
- }
- if (isConfigurableSource) {
- add(
- AppBar.OverflowAction(
- title = stringResource(MR.strings.action_settings),
- onClick = onSettingsClick,
- ),
- )
- }
- }
- .build(),
- )
- DropdownMenu(
- expanded = selectingDisplayMode,
- onDismissRequest = { selectingDisplayMode = false },
- ) {
- RadioMenuItem(
- text = { Text(text = stringResource(MR.strings.action_display_comfortable_grid)) },
- isChecked = displayMode == LibraryDisplayMode.ComfortableGrid,
- ) {
- selectingDisplayMode = false
- onDisplayModeChange(LibraryDisplayMode.ComfortableGrid)
- }
- RadioMenuItem(
- text = { Text(text = stringResource(MR.strings.action_display_grid)) },
- isChecked = displayMode == LibraryDisplayMode.CompactGrid,
- ) {
- selectingDisplayMode = false
- onDisplayModeChange(LibraryDisplayMode.CompactGrid)
- }
- RadioMenuItem(
- text = { Text(text = stringResource(MR.strings.action_display_list)) },
- isChecked = displayMode == LibraryDisplayMode.List,
- ) {
- selectingDisplayMode = false
- onDisplayModeChange(LibraryDisplayMode.List)
- }
- }
- },
- scrollBehavior = scrollBehavior,
- )
- }
|