From bcd90be5254fbb3bbf0878a321d89620beb71707 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 13 May 2023 10:04:22 -0400 Subject: [PATCH] Use AppBarActions in more places Related to #8270 --- .../presentation/history/HistoryScreen.kt | 21 +++++---- .../library/components/LibraryToolbar.kt | 21 ++++++--- .../manga/components/MangaToolbar.kt | 28 +++++++----- .../settings/screen/debug/WorkerInfoScreen.kt | 22 +++++++--- .../presentation/updates/UpdatesScreen.kt | 44 ++++++++++--------- 5 files changed, 83 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt b/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt index 44e7d2dd9c..e74a57aa90 100644 --- a/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/history/HistoryScreen.kt @@ -5,8 +5,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.items import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.DeleteSweep -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState import androidx.compose.runtime.Composable @@ -14,6 +12,8 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource import eu.kanade.domain.ui.UiPreferences +import eu.kanade.presentation.components.AppBar +import eu.kanade.presentation.components.AppBarActions import eu.kanade.presentation.components.AppBarTitle import eu.kanade.presentation.components.RelativeDateHeader import eu.kanade.presentation.components.SearchToolbar @@ -47,12 +47,17 @@ fun HistoryScreen( searchQuery = state.searchQuery, onChangeSearchQuery = onSearchQueryChange, actions = { - IconButton(onClick = { onDialogChange(HistoryScreenModel.Dialog.DeleteAll) }) { - Icon( - Icons.Outlined.DeleteSweep, - contentDescription = stringResource(R.string.pref_clear_history), - ) - } + AppBarActions( + listOf( + AppBar.Action( + title = stringResource(R.string.pref_clear_history), + icon = Icons.Outlined.DeleteSweep, + onClick = { + onDialogChange(HistoryScreenModel.Dialog.DeleteAll) + }, + ), + ), + ) }, scrollBehavior = scrollBehavior, ) 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 9da8ae1ebc..1f64614b87 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 @@ -21,6 +21,7 @@ import androidx.compose.ui.res.stringResource 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 @@ -139,12 +140,20 @@ private fun LibrarySelectionToolbar( AppBar( titleContent = { Text(text = "$selectedCount") }, actions = { - IconButton(onClick = onClickSelectAll) { - Icon(Icons.Outlined.SelectAll, contentDescription = stringResource(R.string.action_select_all)) - } - IconButton(onClick = onClickInvertSelection) { - Icon(Icons.Outlined.FlipToBack, contentDescription = stringResource(R.string.action_select_inverse)) - } + AppBarActions( + listOf( + AppBar.Action( + title = stringResource(R.string.action_select_all), + icon = Icons.Outlined.SelectAll, + onClick = onClickSelectAll, + ), + AppBar.Action( + title = stringResource(R.string.action_select_inverse), + icon = Icons.Outlined.FlipToBack, + onClick = onClickInvertSelection, + ), + ), + ) }, isActionMode = true, onCancelActionMode = onClickUnselectAll, 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 04a63dddd6..de22c92ae7 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 @@ -26,6 +26,8 @@ import androidx.compose.ui.draw.alpha import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow 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 @@ -74,18 +76,20 @@ fun MangaToolbar( }, actions = { if (isActionMode) { - IconButton(onClick = onSelectAll) { - Icon( - imageVector = Icons.Outlined.SelectAll, - contentDescription = stringResource(R.string.action_select_all), - ) - } - IconButton(onClick = onInvertSelection) { - Icon( - imageVector = Icons.Outlined.FlipToBack, - contentDescription = stringResource(R.string.action_select_inverse), - ) - } + AppBarActions( + listOf( + AppBar.Action( + title = stringResource(R.string.action_select_all), + icon = Icons.Outlined.SelectAll, + onClick = onSelectAll, + ), + AppBar.Action( + title = stringResource(R.string.action_select_inverse), + icon = Icons.Outlined.FlipToBack, + onClick = onInvertSelection, + ), + ), + ) } else { if (onClickDownload != null) { val (downloadExpanded, onDownloadExpanded) = remember { mutableStateOf(false) } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/WorkerInfoScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/WorkerInfoScreen.kt index 5dd6e5a077..b5d348dd0f 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/WorkerInfoScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/debug/WorkerInfoScreen.kt @@ -18,6 +18,7 @@ import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.unit.dp import androidx.compose.ui.util.fastForEach @@ -29,7 +30,10 @@ import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.core.screen.Screen import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow +import eu.kanade.presentation.components.AppBar +import eu.kanade.presentation.components.AppBarActions import eu.kanade.presentation.util.ioCoroutineScope +import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.system.workManager import kotlinx.coroutines.flow.SharingStarted @@ -63,13 +67,17 @@ object WorkerInfoScreen : Screen { } }, actions = { - IconButton( - onClick = { - context.copyToClipboard(title, enqueued + finished + running) - }, - ) { - Icon(imageVector = Icons.Default.ContentCopy, contentDescription = null) - } + AppBarActions( + listOf( + AppBar.Action( + title = stringResource(R.string.action_copy_to_clipboard), + icon = Icons.Default.ContentCopy, + onClick = { + context.copyToClipboard(title, enqueued + finished + running) + }, + ), + ), + ) }, scrollBehavior = it, ) diff --git a/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt b/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt index f8fa342ea4..010e84995e 100644 --- a/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/updates/UpdatesScreen.kt @@ -7,8 +7,6 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.FlipToBack import androidx.compose.material.icons.outlined.Refresh import androidx.compose.material.icons.outlined.SelectAll -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.TopAppBarScrollBehavior @@ -24,6 +22,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.util.fastAll import androidx.compose.ui.util.fastAny import eu.kanade.presentation.components.AppBar +import eu.kanade.presentation.components.AppBarActions import eu.kanade.presentation.manga.components.ChapterDownloadAction import eu.kanade.presentation.manga.components.MangaBottomActionMenu import eu.kanade.tachiyomi.R @@ -144,28 +143,33 @@ private fun UpdatesAppBar( modifier = modifier, title = stringResource(R.string.label_recent_updates), actions = { - IconButton(onClick = onUpdateLibrary) { - Icon( - imageVector = Icons.Outlined.Refresh, - contentDescription = stringResource(R.string.action_update_library), - ) - } + AppBarActions( + listOf( + AppBar.Action( + title = stringResource(R.string.action_update_library), + icon = Icons.Outlined.Refresh, + onClick = onUpdateLibrary, + ), + ), + ) }, actionModeCounter = actionModeCounter, onCancelActionMode = onCancelActionMode, actionModeActions = { - IconButton(onClick = onSelectAll) { - Icon( - imageVector = Icons.Outlined.SelectAll, - contentDescription = stringResource(R.string.action_select_all), - ) - } - IconButton(onClick = onInvertSelection) { - Icon( - imageVector = Icons.Outlined.FlipToBack, - contentDescription = stringResource(R.string.action_select_inverse), - ) - } + AppBarActions( + listOf( + AppBar.Action( + title = stringResource(R.string.action_select_all), + icon = Icons.Outlined.SelectAll, + onClick = onSelectAll, + ), + AppBar.Action( + title = stringResource(R.string.action_select_inverse), + icon = Icons.Outlined.FlipToBack, + onClick = onInvertSelection, + ), + ), + ) }, scrollBehavior = scrollBehavior, )