Use AppBarActions in more places

This commit is contained in:
arkon 2023-05-20 22:46:16 -04:00
parent 0810d3db69
commit 44609c494c
4 changed files with 86 additions and 83 deletions

View File

@ -16,6 +16,7 @@ import androidx.compose.material.icons.outlined.Search
import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.PlainTooltipBox import androidx.compose.material3.PlainTooltipBox
import androidx.compose.material3.Text import androidx.compose.material3.Text
@ -33,6 +34,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.FocusRequester
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.SolidColor
import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.platform.LocalFocusManager
@ -190,6 +192,7 @@ fun AppBarActions(
) { ) {
Icon( Icon(
imageVector = it.icon, imageVector = it.icon,
tint = it.iconTint ?: LocalContentColor.current,
contentDescription = it.title, contentDescription = it.title,
) )
} }
@ -363,6 +366,7 @@ sealed interface AppBar {
data class Action( data class Action(
val title: String, val title: String,
val icon: ImageVector, val icon: ImageVector,
val iconTint: Color? = null,
val onClick: () -> Unit, val onClick: () -> Unit,
val enabled: Boolean = true, val enabled: Boolean = true,
) : AppBarAction ) : AppBarAction

View File

@ -6,9 +6,6 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.FilterList import androidx.compose.material.icons.outlined.FilterList
import androidx.compose.material.icons.outlined.FlipToBack import androidx.compose.material.icons.outlined.FlipToBack
import androidx.compose.material.icons.outlined.SelectAll 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.LocalContentColor
import androidx.compose.material3.MaterialTheme import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text import androidx.compose.material3.Text
@ -22,7 +19,6 @@ import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
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.OverflowMenu
import eu.kanade.presentation.components.SearchToolbar import eu.kanade.presentation.components.SearchToolbar
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import tachiyomi.presentation.core.components.Pill import tachiyomi.presentation.core.components.Pill
@ -98,33 +94,28 @@ private fun LibraryRegularToolbar(
onChangeSearchQuery = onSearchQueryChange, onChangeSearchQuery = onSearchQueryChange,
actions = { actions = {
val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current
IconButton(onClick = onClickFilter) { AppBarActions(
Icon(Icons.Outlined.FilterList, contentDescription = stringResource(R.string.action_filter), tint = filterTint) listOf(
} AppBar.Action(
title = stringResource(R.string.action_filter),
OverflowMenu { closeMenu -> icon = Icons.Outlined.FilterList,
DropdownMenuItem( iconTint = filterTint,
text = { Text(text = stringResource(R.string.action_update_library)) }, onClick = onClickFilter,
onClick = { ),
onClickGlobalUpdate() AppBar.OverflowAction(
closeMenu() title = stringResource(R.string.action_update_library),
}, onClick = onClickGlobalUpdate,
) ),
DropdownMenuItem( AppBar.OverflowAction(
text = { Text(text = stringResource(R.string.action_update_category)) }, title = stringResource(R.string.action_update_category),
onClick = { onClick = onClickRefresh,
onClickRefresh() ),
closeMenu() AppBar.OverflowAction(
}, title = stringResource(R.string.action_open_random_manga),
) onClick = onClickOpenRandomManga,
DropdownMenuItem( ),
text = { Text(text = stringResource(R.string.action_open_random_manga)) }, ),
onClick = { )
onClickOpenRandomManga()
closeMenu()
},
)
}
}, },
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,
) )

View File

@ -43,6 +43,8 @@ import coil.imageLoader
import coil.request.CachePolicy import coil.request.CachePolicy
import coil.request.ImageRequest import coil.request.ImageRequest
import coil.size.Size 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.components.DropdownMenu
import eu.kanade.presentation.manga.EditCoverAction import eu.kanade.presentation.manga.EditCoverAction
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -88,18 +90,24 @@ fun MangaCoverDialog(
} }
Spacer(modifier = Modifier.weight(1f)) Spacer(modifier = Modifier.weight(1f))
ActionsPill { ActionsPill {
IconButton(onClick = onShareClick) { AppBarActions(
Icon( actions = buildList {
imageVector = Icons.Outlined.Share, add(
contentDescription = stringResource(R.string.action_share), AppBar.Action(
) title = stringResource(R.string.action_share),
} icon = Icons.Outlined.Share,
IconButton(onClick = onSaveClick) { onClick = onShareClick,
Icon( ),
imageVector = Icons.Outlined.Save, )
contentDescription = stringResource(R.string.action_save), add(
) AppBar.Action(
} title = stringResource(R.string.action_save),
icon = Icons.Outlined.Save,
onClick = onSaveClick,
),
)
},
)
if (onEditClick != null) { if (onEditClick != null) {
Box { Box {
var expanded by remember { mutableStateOf(false) } var expanded by remember { mutableStateOf(false) }

View File

@ -9,7 +9,6 @@ import androidx.compose.material.icons.outlined.Download
import androidx.compose.material.icons.outlined.FilterList import androidx.compose.material.icons.outlined.FilterList
import androidx.compose.material.icons.outlined.FlipToBack import androidx.compose.material.icons.outlined.FlipToBack
import androidx.compose.material.icons.outlined.SelectAll import androidx.compose.material.icons.outlined.SelectAll
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Icon import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor 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.AppBar
import eu.kanade.presentation.components.AppBarActions import eu.kanade.presentation.components.AppBarActions
import eu.kanade.presentation.components.DownloadDropdownMenu import eu.kanade.presentation.components.DownloadDropdownMenu
import eu.kanade.presentation.components.OverflowMenu
import eu.kanade.presentation.manga.DownloadAction import eu.kanade.presentation.manga.DownloadAction
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import tachiyomi.presentation.core.theme.active import tachiyomi.presentation.core.theme.active
@ -110,46 +108,48 @@ fun MangaToolbar(
} }
val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current
IconButton(onClick = onClickFilter) { AppBarActions(
Icon(Icons.Outlined.FilterList, contentDescription = stringResource(R.string.action_filter), tint = filterTint) actions = buildList {
} add(
AppBar.Action(
OverflowMenu { closeMenu -> title = stringResource(R.string.action_filter),
DropdownMenuItem( icon = Icons.Outlined.FilterList,
text = { Text(text = stringResource(R.string.action_webview_refresh)) }, iconTint = filterTint,
onClick = { onClick = onClickFilter,
onClickRefresh() ),
closeMenu()
},
)
if (onClickEditCategory != null) {
DropdownMenuItem(
text = { Text(text = stringResource(R.string.action_edit_categories)) },
onClick = {
onClickEditCategory()
closeMenu()
},
) )
} add(
if (onClickMigrate != null) { AppBar.OverflowAction(
DropdownMenuItem( title = stringResource(R.string.action_webview_refresh),
text = { Text(text = stringResource(R.string.action_migrate)) }, onClick = onClickRefresh,
onClick = { ),
onClickMigrate()
closeMenu()
},
) )
} if (onClickEditCategory != null) {
if (onClickShare != null) { add(
DropdownMenuItem( AppBar.OverflowAction(
text = { Text(text = stringResource(R.string.action_share)) }, title = stringResource(R.string.action_edit_categories),
onClick = { onClick = onClickEditCategory,
onClickShare() ),
closeMenu() )
}, }
) 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( colors = TopAppBarDefaults.topAppBarColors(