BrowseSourceToolbar: Match display mode dropdown to stable and change toolbar icon based on display mode (#8200)

* BrowseSourceToolbar: Match display mode dropdown to stable and change toolbar icon based on display mode

* Review changes

* Review changes 2
This commit is contained in:
zbue 2022-10-15 23:16:01 +08:00 committed by GitHub
parent 147455f99c
commit 3d7e44726d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 31 deletions

View File

@ -3,13 +3,11 @@ package eu.kanade.presentation.browse.components
import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ViewList
import androidx.compose.material.icons.filled.ViewModule import androidx.compose.material.icons.filled.ViewModule
import androidx.compose.material.icons.outlined.Check
import androidx.compose.material.icons.outlined.Help import androidx.compose.material.icons.outlined.Help
import androidx.compose.material.icons.outlined.Public import androidx.compose.material.icons.outlined.Public
import androidx.compose.material.icons.outlined.Search import androidx.compose.material.icons.outlined.Search
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBarScrollBehavior import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -26,6 +24,7 @@ import eu.kanade.presentation.browse.BrowseSourceState
import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.AppBar
import eu.kanade.presentation.components.AppBarActions import eu.kanade.presentation.components.AppBarActions
import eu.kanade.presentation.components.DropdownMenu import eu.kanade.presentation.components.DropdownMenu
import eu.kanade.presentation.components.RadioButton
import eu.kanade.presentation.components.SearchToolbar import eu.kanade.presentation.components.SearchToolbar
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.CatalogueSource
@ -98,7 +97,7 @@ fun BrowseSourceRegularToolbar(
), ),
AppBar.Action( AppBar.Action(
title = stringResource(R.string.action_display_mode), title = stringResource(R.string.action_display_mode),
icon = Icons.Filled.ViewModule, icon = if (displayMode == LibraryDisplayMode.List) Icons.Filled.ViewList else Icons.Filled.ViewModule,
onClick = { selectingDisplayMode = true }, onClick = { selectingDisplayMode = true },
), ),
if (isLocalSource) { if (isLocalSource) {
@ -120,41 +119,20 @@ fun BrowseSourceRegularToolbar(
expanded = selectingDisplayMode, expanded = selectingDisplayMode,
onDismissRequest = { selectingDisplayMode = false }, onDismissRequest = { selectingDisplayMode = false },
) { ) {
DropdownMenuItem( RadioButton(
text = { Text(text = stringResource(R.string.action_display_comfortable_grid)) }, text = { Text(text = stringResource(R.string.action_display_comfortable_grid)) },
onClick = { onDisplayModeChange(LibraryDisplayMode.ComfortableGrid) }, onClick = { onDisplayModeChange(LibraryDisplayMode.ComfortableGrid) },
trailingIcon = { isChecked = displayMode == LibraryDisplayMode.ComfortableGrid,
if (displayMode == LibraryDisplayMode.ComfortableGrid) {
Icon(
imageVector = Icons.Outlined.Check,
contentDescription = "",
)
}
},
) )
DropdownMenuItem( RadioButton(
text = { Text(text = stringResource(R.string.action_display_grid)) }, text = { Text(text = stringResource(R.string.action_display_grid)) },
onClick = { onDisplayModeChange(LibraryDisplayMode.CompactGrid) }, onClick = { onDisplayModeChange(LibraryDisplayMode.CompactGrid) },
trailingIcon = { isChecked = displayMode == LibraryDisplayMode.CompactGrid,
if (displayMode == LibraryDisplayMode.CompactGrid) {
Icon(
imageVector = Icons.Outlined.Check,
contentDescription = "",
)
}
},
) )
DropdownMenuItem( RadioButton(
text = { Text(text = stringResource(R.string.action_display_list)) }, text = { Text(text = stringResource(R.string.action_display_list)) },
onClick = { onDisplayModeChange(LibraryDisplayMode.List) }, onClick = { onDisplayModeChange(LibraryDisplayMode.List) },
trailingIcon = { isChecked = displayMode == LibraryDisplayMode.List,
if (displayMode == LibraryDisplayMode.List) {
Icon(
imageVector = Icons.Outlined.Check,
contentDescription = "",
)
}
},
) )
} }
}, },

View File

@ -2,6 +2,11 @@ package eu.kanade.presentation.components
import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.sizeIn import androidx.compose.foundation.layout.sizeIn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.RadioButtonChecked
import androidx.compose.material.icons.outlined.RadioButtonUnchecked
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.DpOffset
@ -26,3 +31,28 @@ fun DropdownMenu(
content = content, content = content,
) )
} }
@Composable
fun RadioButton(
text: @Composable () -> Unit,
onClick: () -> Unit,
isChecked: Boolean,
) {
DropdownMenuItem(
text = text,
onClick = onClick,
trailingIcon = {
if (isChecked) {
Icon(
imageVector = Icons.Outlined.RadioButtonChecked,
contentDescription = "",
)
} else {
Icon(
imageVector = Icons.Outlined.RadioButtonUnchecked,
contentDescription = "",
)
}
},
)
}