Merge d5d69706e86611d82e1657aa33b38c9290c64ba7 into 4a7fe44e0e50049d4704c76901974bbcfa773663

This commit is contained in:
Cuong-Tran 2024-12-25 00:50:56 +07:00 committed by GitHub
commit 66c6c2fa36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 103 additions and 132 deletions

View File

@ -265,14 +265,13 @@ private fun MangaScreenSmallImpl(
) )
} }
val internalOnBackPressed = { BackHandler(onBack = {
if (isAnySelected) { if (isAnySelected) {
onAllChapterSelected(false) onAllChapterSelected(false)
} else { } else {
onBackClicked() onBackClicked()
} }
} })
BackHandler(onBack = internalOnBackPressed)
Scaffold( Scaffold(
topBar = { topBar = {
@ -285,29 +284,25 @@ private fun MangaScreenSmallImpl(
val isFirstItemScrolled by remember { val isFirstItemScrolled by remember {
derivedStateOf { chapterListState.firstVisibleItemScrollOffset > 0 } derivedStateOf { chapterListState.firstVisibleItemScrollOffset > 0 }
} }
val animatedTitleAlpha by animateFloatAsState(
if (!isFirstItemVisible) 1f else 0f,
label = "Top Bar Title",
)
val animatedBgAlpha by animateFloatAsState( val animatedBgAlpha by animateFloatAsState(
if (!isFirstItemVisible || isFirstItemScrolled) 1f else 0f, if (!isFirstItemVisible || isFirstItemScrolled) 1f else 0f,
label = "Top Bar Background", label = "Top Bar Background",
) )
MangaToolbar( MangaToolbar(
title = state.manga.title, title = state.manga.title,
titleAlphaProvider = { animatedTitleAlpha },
backgroundAlphaProvider = { animatedBgAlpha },
hasFilters = state.filterActive, hasFilters = state.filterActive,
onBackClicked = internalOnBackPressed, navigateUp = onBackClicked,
onClickFilter = onFilterClicked, onClickFilter = onFilterClicked,
onClickShare = onShareClicked, onClickShare = onShareClicked,
onClickDownload = onDownloadActionClicked, onClickDownload = onDownloadActionClicked,
onClickEditCategory = onEditCategoryClicked, onClickEditCategory = onEditCategoryClicked,
onClickRefresh = onRefresh, onClickRefresh = onRefresh,
onClickMigrate = onMigrateClicked, onClickMigrate = onMigrateClicked,
onCancelActionMode = { onAllChapterSelected(false) },
actionModeCounter = selectedChapterCount, actionModeCounter = selectedChapterCount,
onSelectAll = { onAllChapterSelected(true) }, onSelectAll = { onAllChapterSelected(true) },
onInvertSelection = { onInvertSelection() }, onInvertSelection = { onInvertSelection() },
backgroundAlphaProvider = { animatedBgAlpha },
) )
}, },
bottomBar = { bottomBar = {
@ -515,14 +510,13 @@ fun MangaScreenLargeImpl(
val chapterListState = rememberLazyListState() val chapterListState = rememberLazyListState()
val internalOnBackPressed = { BackHandler(onBack = {
if (isAnySelected) { if (isAnySelected) {
onAllChapterSelected(false) onAllChapterSelected(false)
} else { } else {
onBackClicked() onBackClicked()
} }
} })
BackHandler(onBack = internalOnBackPressed)
Scaffold( Scaffold(
topBar = { topBar = {
@ -532,19 +526,19 @@ fun MangaScreenLargeImpl(
MangaToolbar( MangaToolbar(
modifier = Modifier.onSizeChanged { topBarHeight = it.height }, modifier = Modifier.onSizeChanged { topBarHeight = it.height },
title = state.manga.title, title = state.manga.title,
titleAlphaProvider = { if (isAnySelected) 1f else 0f },
backgroundAlphaProvider = { 1f },
hasFilters = state.filterActive, hasFilters = state.filterActive,
onBackClicked = internalOnBackPressed, navigateUp = onBackClicked,
onClickFilter = onFilterButtonClicked, onClickFilter = onFilterButtonClicked,
onClickShare = onShareClicked, onClickShare = onShareClicked,
onClickDownload = onDownloadActionClicked, onClickDownload = onDownloadActionClicked,
onClickEditCategory = onEditCategoryClicked, onClickEditCategory = onEditCategoryClicked,
onClickRefresh = onRefresh, onClickRefresh = onRefresh,
onClickMigrate = onMigrateClicked, onClickMigrate = onMigrateClicked,
onCancelActionMode = { onAllChapterSelected(false) },
actionModeCounter = selectedChapterCount, actionModeCounter = selectedChapterCount,
onSelectAll = { onAllChapterSelected(true) }, onSelectAll = { onAllChapterSelected(true) },
onInvertSelection = { onInvertSelection() }, onInvertSelection = { onInvertSelection() },
backgroundAlphaProvider = { 1f },
) )
}, },
bottomBar = { bottomBar = {

View File

@ -1,18 +1,12 @@
package eu.kanade.presentation.manga.components package eu.kanade.presentation.manga.components
import androidx.compose.foundation.layout.Column
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Close
import androidx.compose.material.icons.outlined.Download 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.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.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@ -20,12 +14,10 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp 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.UpIcon
import eu.kanade.presentation.manga.DownloadAction import eu.kanade.presentation.manga.DownloadAction
import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentListOf
import tachiyomi.i18n.MR import tachiyomi.i18n.MR
@ -35,9 +27,8 @@ import tachiyomi.presentation.core.theme.active
@Composable @Composable
fun MangaToolbar( fun MangaToolbar(
title: String, title: String,
titleAlphaProvider: () -> Float,
hasFilters: Boolean, hasFilters: Boolean,
onBackClicked: () -> Unit, navigateUp: () -> Unit,
onClickFilter: () -> Unit, onClickFilter: () -> Unit,
onClickShare: (() -> Unit)?, onClickShare: (() -> Unit)?,
onClickDownload: ((DownloadAction) -> Unit)?, onClickDownload: ((DownloadAction) -> Unit)?,
@ -47,118 +38,104 @@ fun MangaToolbar(
// For action mode // For action mode
actionModeCounter: Int, actionModeCounter: Int,
onCancelActionMode: () -> Unit,
onSelectAll: () -> Unit, onSelectAll: () -> Unit,
onInvertSelection: () -> Unit, onInvertSelection: () -> Unit,
modifier: Modifier = Modifier, modifier: Modifier = Modifier,
backgroundAlphaProvider: () -> Float = titleAlphaProvider, backgroundAlphaProvider: () -> Float,
) { ) {
Column( val isActionMode = remember(actionModeCounter) { actionModeCounter > 0 }
AppBar(
modifier = modifier, modifier = modifier,
) { title = title,
val isActionMode = actionModeCounter > 0 navigateUp = navigateUp,
TopAppBar( actionModeCounter = actionModeCounter,
title = { onCancelActionMode = onCancelActionMode,
Text( actionModeActions = {
text = if (isActionMode) actionModeCounter.toString() else title, AppBarActions(
maxLines = 1, persistentListOf(
overflow = TextOverflow.Ellipsis, AppBar.Action(
color = LocalContentColor.current.copy(alpha = if (isActionMode) 1f else titleAlphaProvider()), title = stringResource(MR.strings.action_select_all),
icon = Icons.Outlined.SelectAll,
onClick = onSelectAll,
),
AppBar.Action(
title = stringResource(MR.strings.action_select_inverse),
icon = Icons.Outlined.FlipToBack,
onClick = onInvertSelection,
),
),
)
},
actions = {
var downloadExpanded by remember { mutableStateOf(false) }
if (onClickDownload != null) {
val onDismissRequest = { downloadExpanded = false }
DownloadDropdownMenu(
expanded = downloadExpanded,
onDismissRequest = onDismissRequest,
onDownloadClicked = onClickDownload,
) )
}, }
navigationIcon = {
IconButton(onClick = onBackClicked) {
UpIcon(navigationIcon = Icons.Outlined.Close.takeIf { isActionMode })
}
},
actions = {
if (isActionMode) {
AppBarActions(
persistentListOf(
AppBar.Action(
title = stringResource(MR.strings.action_select_all),
icon = Icons.Outlined.SelectAll,
onClick = onSelectAll,
),
AppBar.Action(
title = stringResource(MR.strings.action_select_inverse),
icon = Icons.Outlined.FlipToBack,
onClick = onInvertSelection,
),
),
)
} else {
var downloadExpanded by remember { mutableStateOf(false) }
if (onClickDownload != null) {
val onDismissRequest = { downloadExpanded = false }
DownloadDropdownMenu(
expanded = downloadExpanded,
onDismissRequest = onDismissRequest,
onDownloadClicked = onClickDownload,
)
}
val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current
AppBarActions( AppBarActions(
actions = persistentListOf<AppBar.AppBarAction>().builder() actions = persistentListOf<AppBar.AppBarAction>().builder()
.apply { .apply {
if (onClickDownload != null) { if (onClickDownload != null) {
add( add(
AppBar.Action( AppBar.Action(
title = stringResource(MR.strings.manga_download), title = stringResource(MR.strings.manga_download),
icon = Icons.Outlined.Download, icon = Icons.Outlined.Download,
onClick = { downloadExpanded = !downloadExpanded }, onClick = { downloadExpanded = !downloadExpanded },
), ),
) )
} }
add( add(
AppBar.Action( AppBar.Action(
title = stringResource(MR.strings.action_filter), title = stringResource(MR.strings.action_filter),
icon = Icons.Outlined.FilterList, icon = Icons.Outlined.FilterList,
iconTint = filterTint, iconTint = filterTint,
onClick = onClickFilter, onClick = onClickFilter,
), ),
) )
add( add(
AppBar.OverflowAction( AppBar.OverflowAction(
title = stringResource(MR.strings.action_webview_refresh), title = stringResource(MR.strings.action_webview_refresh),
onClick = onClickRefresh, onClick = onClickRefresh,
), ),
) )
if (onClickEditCategory != null) { if (onClickEditCategory != null) {
add( add(
AppBar.OverflowAction( AppBar.OverflowAction(
title = stringResource(MR.strings.action_edit_categories), title = stringResource(MR.strings.action_edit_categories),
onClick = onClickEditCategory, onClick = onClickEditCategory,
), ),
) )
} }
if (onClickMigrate != null) { if (onClickMigrate != null) {
add( add(
AppBar.OverflowAction( AppBar.OverflowAction(
title = stringResource(MR.strings.action_migrate), title = stringResource(MR.strings.action_migrate),
onClick = onClickMigrate, onClick = onClickMigrate,
), ),
) )
} }
if (onClickShare != null) { if (onClickShare != null) {
add( add(
AppBar.OverflowAction( AppBar.OverflowAction(
title = stringResource(MR.strings.action_share), title = stringResource(MR.strings.action_share),
onClick = onClickShare, onClick = onClickShare,
), ),
) )
} }
} }
.build(), .build(),
) )
} },
}, backgroundColor = MaterialTheme.colorScheme
colors = TopAppBarDefaults.topAppBarColors( .surfaceColorAtElevation(3.dp)
containerColor = MaterialTheme.colorScheme .copy(alpha = if (isActionMode) 1f else backgroundAlphaProvider()),
.surfaceColorAtElevation(3.dp) )
.copy(alpha = if (isActionMode) 1f else backgroundAlphaProvider()),
),
)
}
} }