From 44609c494c11c1b5112b6edec1898cd5d171fa11 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 20 May 2023 22:46:16 -0400 Subject: [PATCH] Use AppBarActions in more places --- .../kanade/presentation/components/AppBar.kt | 4 + .../library/components/LibraryToolbar.kt | 53 +++++------- .../manga/components/MangaCoverDialog.kt | 32 +++++--- .../manga/components/MangaToolbar.kt | 80 +++++++++---------- 4 files changed, 86 insertions(+), 83 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/components/AppBar.kt b/app/src/main/java/eu/kanade/presentation/components/AppBar.kt index b04bfadf94..614281684f 100644 --- a/app/src/main/java/eu/kanade/presentation/components/AppBar.kt +++ b/app/src/main/java/eu/kanade/presentation/components/AppBar.kt @@ -16,6 +16,7 @@ import androidx.compose.material.icons.outlined.Search import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme import androidx.compose.material3.PlainTooltipBox import androidx.compose.material3.Text @@ -33,6 +34,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester +import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.SolidColor import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.platform.LocalFocusManager @@ -190,6 +192,7 @@ fun AppBarActions( ) { Icon( imageVector = it.icon, + tint = it.iconTint ?: LocalContentColor.current, contentDescription = it.title, ) } @@ -363,6 +366,7 @@ sealed interface AppBar { data class Action( val title: String, val icon: ImageVector, + val iconTint: Color? = null, val onClick: () -> Unit, val enabled: Boolean = true, ) : AppBarAction diff --git a/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt b/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt index 1f64614b87..f19397e2f1 100644 --- a/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt +++ b/app/src/main/java/eu/kanade/presentation/library/components/LibraryToolbar.kt @@ -6,9 +6,6 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.FilterList import androidx.compose.material.icons.outlined.FlipToBack import androidx.compose.material.icons.outlined.SelectAll -import androidx.compose.material3.DropdownMenuItem -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text @@ -22,7 +19,6 @@ import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.sp import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.AppBarActions -import eu.kanade.presentation.components.OverflowMenu import eu.kanade.presentation.components.SearchToolbar import eu.kanade.tachiyomi.R import tachiyomi.presentation.core.components.Pill @@ -98,33 +94,28 @@ private fun LibraryRegularToolbar( onChangeSearchQuery = onSearchQueryChange, actions = { val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current - IconButton(onClick = onClickFilter) { - Icon(Icons.Outlined.FilterList, contentDescription = stringResource(R.string.action_filter), tint = filterTint) - } - - OverflowMenu { closeMenu -> - DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_update_library)) }, - onClick = { - onClickGlobalUpdate() - closeMenu() - }, - ) - DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_update_category)) }, - onClick = { - onClickRefresh() - closeMenu() - }, - ) - DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_open_random_manga)) }, - onClick = { - onClickOpenRandomManga() - closeMenu() - }, - ) - } + AppBarActions( + listOf( + AppBar.Action( + title = stringResource(R.string.action_filter), + icon = Icons.Outlined.FilterList, + iconTint = filterTint, + onClick = onClickFilter, + ), + AppBar.OverflowAction( + title = stringResource(R.string.action_update_library), + onClick = onClickGlobalUpdate, + ), + AppBar.OverflowAction( + title = stringResource(R.string.action_update_category), + onClick = onClickRefresh, + ), + AppBar.OverflowAction( + title = stringResource(R.string.action_open_random_manga), + onClick = onClickOpenRandomManga, + ), + ), + ) }, scrollBehavior = scrollBehavior, ) diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaCoverDialog.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaCoverDialog.kt index 31944447eb..43e9ac1581 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaCoverDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaCoverDialog.kt @@ -43,6 +43,8 @@ import coil.imageLoader import coil.request.CachePolicy import coil.request.ImageRequest import coil.size.Size +import eu.kanade.presentation.components.AppBar +import eu.kanade.presentation.components.AppBarActions import eu.kanade.presentation.components.DropdownMenu import eu.kanade.presentation.manga.EditCoverAction import eu.kanade.tachiyomi.R @@ -88,18 +90,24 @@ fun MangaCoverDialog( } Spacer(modifier = Modifier.weight(1f)) ActionsPill { - IconButton(onClick = onShareClick) { - Icon( - imageVector = Icons.Outlined.Share, - contentDescription = stringResource(R.string.action_share), - ) - } - IconButton(onClick = onSaveClick) { - Icon( - imageVector = Icons.Outlined.Save, - contentDescription = stringResource(R.string.action_save), - ) - } + AppBarActions( + actions = buildList { + add( + AppBar.Action( + title = stringResource(R.string.action_share), + icon = Icons.Outlined.Share, + onClick = onShareClick, + ), + ) + add( + AppBar.Action( + title = stringResource(R.string.action_save), + icon = Icons.Outlined.Save, + onClick = onSaveClick, + ), + ) + }, + ) if (onEditClick != null) { Box { var expanded by remember { mutableStateOf(false) } diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaToolbar.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaToolbar.kt index de22c92ae7..bb758c2994 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaToolbar.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaToolbar.kt @@ -9,7 +9,6 @@ import androidx.compose.material.icons.outlined.Download import androidx.compose.material.icons.outlined.FilterList import androidx.compose.material.icons.outlined.FlipToBack import androidx.compose.material.icons.outlined.SelectAll -import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.LocalContentColor @@ -29,7 +28,6 @@ import androidx.compose.ui.unit.dp import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.components.AppBarActions import eu.kanade.presentation.components.DownloadDropdownMenu -import eu.kanade.presentation.components.OverflowMenu import eu.kanade.presentation.manga.DownloadAction import eu.kanade.tachiyomi.R import tachiyomi.presentation.core.theme.active @@ -110,46 +108,48 @@ fun MangaToolbar( } val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current - IconButton(onClick = onClickFilter) { - Icon(Icons.Outlined.FilterList, contentDescription = stringResource(R.string.action_filter), tint = filterTint) - } - - OverflowMenu { closeMenu -> - DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_webview_refresh)) }, - onClick = { - onClickRefresh() - closeMenu() - }, - ) - if (onClickEditCategory != null) { - DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_edit_categories)) }, - onClick = { - onClickEditCategory() - closeMenu() - }, + AppBarActions( + actions = buildList { + add( + AppBar.Action( + title = stringResource(R.string.action_filter), + icon = Icons.Outlined.FilterList, + iconTint = filterTint, + onClick = onClickFilter, + ), ) - } - if (onClickMigrate != null) { - DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_migrate)) }, - onClick = { - onClickMigrate() - closeMenu() - }, + add( + AppBar.OverflowAction( + title = stringResource(R.string.action_webview_refresh), + onClick = onClickRefresh, + ), ) - } - if (onClickShare != null) { - DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_share)) }, - onClick = { - onClickShare() - closeMenu() - }, - ) - } - } + if (onClickEditCategory != null) { + add( + AppBar.OverflowAction( + title = stringResource(R.string.action_edit_categories), + onClick = onClickEditCategory, + ), + ) + } + if (onClickMigrate != null) { + add( + AppBar.OverflowAction( + title = stringResource(R.string.action_migrate), + onClick = onClickMigrate, + ), + ) + } + if (onClickShare != null) { + add( + AppBar.OverflowAction( + title = stringResource(R.string.action_share), + onClick = onClickShare, + ), + ) + } + }, + ) } }, colors = TopAppBarDefaults.topAppBarColors(