From 9ad4ca9d7719c7db96c841a2536eff4eee7ce7cc Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Thu, 24 Oct 2024 23:34:32 +0700 Subject: [PATCH 1/7] reuse AppBar for Manga screen --- .../kanade/presentation/manga/MangaScreen.kt | 26 +-- .../manga/components/MangaToolbar.kt | 204 ++++++++---------- 2 files changed, 102 insertions(+), 128 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt index 3115d04578..50ad8d4951 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt @@ -265,14 +265,13 @@ private fun MangaScreenSmallImpl( ) } - val internalOnBackPressed = { + BackHandler(onBack = { if (isAnySelected) { onAllChapterSelected(false) } else { onBackClicked() } - } - BackHandler(onBack = internalOnBackPressed) + }) Scaffold( topBar = { @@ -285,29 +284,25 @@ private fun MangaScreenSmallImpl( val isFirstItemScrolled by remember { derivedStateOf { chapterListState.firstVisibleItemScrollOffset > 0 } } - val animatedTitleAlpha by animateFloatAsState( - if (!isFirstItemVisible) 1f else 0f, - label = "Top Bar Title", - ) val animatedBgAlpha by animateFloatAsState( if (!isFirstItemVisible || isFirstItemScrolled) 1f else 0f, label = "Top Bar Background", ) MangaToolbar( title = state.manga.title, - titleAlphaProvider = { animatedTitleAlpha }, - backgroundAlphaProvider = { animatedBgAlpha }, hasFilters = state.filterActive, - onBackClicked = internalOnBackPressed, + navigateUp = onBackClicked, onClickFilter = onFilterClicked, onClickShare = onShareClicked, onClickDownload = onDownloadActionClicked, onClickEditCategory = onEditCategoryClicked, onClickRefresh = onRefresh, onClickMigrate = onMigrateClicked, + onCancelActionMode = { onAllChapterSelected(false) }, actionModeCounter = selectedChapterCount, onSelectAll = { onAllChapterSelected(true) }, onInvertSelection = { onInvertSelection() }, + backgroundAlphaProvider = { animatedBgAlpha }, ) }, bottomBar = { @@ -515,14 +510,13 @@ fun MangaScreenLargeImpl( val chapterListState = rememberLazyListState() - val internalOnBackPressed = { + BackHandler(onBack = { if (isAnySelected) { onAllChapterSelected(false) } else { onBackClicked() } - } - BackHandler(onBack = internalOnBackPressed) + }) Scaffold( topBar = { @@ -532,19 +526,19 @@ fun MangaScreenLargeImpl( MangaToolbar( modifier = Modifier.onSizeChanged { topBarHeight = it.height }, title = state.manga.title, - titleAlphaProvider = { if (isAnySelected) 1f else 0f }, - backgroundAlphaProvider = { 1f }, hasFilters = state.filterActive, - onBackClicked = internalOnBackPressed, + navigateUp = onBackClicked, onClickFilter = onFilterButtonClicked, onClickShare = onShareClicked, onClickDownload = onDownloadActionClicked, onClickEditCategory = onEditCategoryClicked, onClickRefresh = onRefresh, onClickMigrate = onMigrateClicked, + onCancelActionMode = { onAllChapterSelected(false) }, actionModeCounter = selectedChapterCount, onSelectAll = { onAllChapterSelected(true) }, onInvertSelection = { onInvertSelection() }, + backgroundAlphaProvider = { 1f }, ) }, bottomBar = { 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 4415bbf278..9d812f98e4 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 @@ -1,31 +1,24 @@ package eu.kanade.presentation.manga.components -import androidx.compose.foundation.layout.Column 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.FilterList import androidx.compose.material.icons.outlined.FlipToBack import androidx.compose.material.icons.outlined.SelectAll -import androidx.compose.material3.IconButton import androidx.compose.material3.LocalContentColor 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.runtime.Composable +import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -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.UpIcon import eu.kanade.presentation.manga.DownloadAction import kotlinx.collections.immutable.persistentListOf import tachiyomi.i18n.MR @@ -35,9 +28,8 @@ import tachiyomi.presentation.core.theme.active @Composable fun MangaToolbar( title: String, - titleAlphaProvider: () -> Float, hasFilters: Boolean, - onBackClicked: () -> Unit, + navigateUp: () -> Unit, onClickFilter: () -> Unit, onClickShare: (() -> Unit)?, onClickDownload: ((DownloadAction) -> Unit)?, @@ -47,118 +39,106 @@ fun MangaToolbar( // For action mode actionModeCounter: Int, + onCancelActionMode: () -> Unit, onSelectAll: () -> Unit, onInvertSelection: () -> Unit, modifier: Modifier = Modifier, - backgroundAlphaProvider: () -> Float = titleAlphaProvider, + backgroundAlphaProvider: () -> Float, ) { - Column( + val isActionMode by remember(actionModeCounter) { + derivedStateOf { actionModeCounter > 0 } + } + AppBar( modifier = modifier, - ) { - val isActionMode = actionModeCounter > 0 - TopAppBar( - title = { - Text( - text = if (isActionMode) actionModeCounter.toString() else title, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - color = LocalContentColor.current.copy(alpha = if (isActionMode) 1f else titleAlphaProvider()), + title = title, + navigateUp = navigateUp, + actionModeCounter = actionModeCounter, + onCancelActionMode = onCancelActionMode, + actionModeActions = { + 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, + ), + ), + ) + }, + 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( + } + + val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current + AppBarActions( + actions = persistentListOf().builder() + .apply { + if (onClickDownload != null) { + add( + AppBar.Action( + title = stringResource(MR.strings.manga_download), + icon = Icons.Outlined.Download, + onClick = { downloadExpanded = !downloadExpanded }, + ), + ) + } + add( AppBar.Action( - title = stringResource(MR.strings.action_select_all), - icon = Icons.Outlined.SelectAll, - onClick = onSelectAll, + title = stringResource(MR.strings.action_filter), + icon = Icons.Outlined.FilterList, + iconTint = filterTint, + onClick = onClickFilter, ), - AppBar.Action( - title = stringResource(MR.strings.action_select_inverse), - icon = Icons.Outlined.FlipToBack, - onClick = onInvertSelection, + ) + add( + AppBar.OverflowAction( + title = stringResource(MR.strings.action_webview_refresh), + onClick = onClickRefresh, ), - ), - ) - } else { - var downloadExpanded by remember { mutableStateOf(false) } - if (onClickDownload != null) { - val onDismissRequest = { downloadExpanded = false } - DownloadDropdownMenu( - expanded = downloadExpanded, - onDismissRequest = onDismissRequest, - onDownloadClicked = onClickDownload, ) + if (onClickEditCategory != null) { + add( + AppBar.OverflowAction( + title = stringResource(MR.strings.action_edit_categories), + onClick = onClickEditCategory, + ), + ) + } + if (onClickMigrate != null) { + add( + AppBar.OverflowAction( + title = stringResource(MR.strings.action_migrate), + onClick = onClickMigrate, + ), + ) + } + if (onClickShare != null) { + add( + AppBar.OverflowAction( + title = stringResource(MR.strings.action_share), + onClick = onClickShare, + ), + ) + } } - - val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current - AppBarActions( - actions = persistentListOf().builder() - .apply { - if (onClickDownload != null) { - add( - AppBar.Action( - title = stringResource(MR.strings.manga_download), - icon = Icons.Outlined.Download, - onClick = { downloadExpanded = !downloadExpanded }, - ), - ) - } - add( - AppBar.Action( - title = stringResource(MR.strings.action_filter), - icon = Icons.Outlined.FilterList, - iconTint = filterTint, - onClick = onClickFilter, - ), - ) - add( - AppBar.OverflowAction( - title = stringResource(MR.strings.action_webview_refresh), - onClick = onClickRefresh, - ), - ) - if (onClickEditCategory != null) { - add( - AppBar.OverflowAction( - title = stringResource(MR.strings.action_edit_categories), - onClick = onClickEditCategory, - ), - ) - } - if (onClickMigrate != null) { - add( - AppBar.OverflowAction( - title = stringResource(MR.strings.action_migrate), - onClick = onClickMigrate, - ), - ) - } - if (onClickShare != null) { - add( - AppBar.OverflowAction( - title = stringResource(MR.strings.action_share), - onClick = onClickShare, - ), - ) - } - } - .build(), - ) - } - }, - colors = TopAppBarDefaults.topAppBarColors( - containerColor = MaterialTheme.colorScheme - .surfaceColorAtElevation(3.dp) - .copy(alpha = if (isActionMode) 1f else backgroundAlphaProvider()), - ), - ) - } + .build(), + ) + }, + backgroundColor = MaterialTheme.colorScheme + .surfaceColorAtElevation(3.dp) + .copy(alpha = if (isActionMode) 1f else backgroundAlphaProvider()), + ) } From 990760e72aee9fbe063f2733b35e0ef93ba622b9 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Sun, 27 Oct 2024 16:06:55 +0700 Subject: [PATCH 2/7] force recomposition everytimes actionModeCounter is changed --- .../eu/kanade/presentation/manga/components/MangaToolbar.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 9d812f98e4..6885bfce54 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.material3.LocalContentColor import androidx.compose.material3.MaterialTheme import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable -import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -46,9 +45,7 @@ fun MangaToolbar( modifier: Modifier = Modifier, backgroundAlphaProvider: () -> Float, ) { - val isActionMode by remember(actionModeCounter) { - derivedStateOf { actionModeCounter > 0 } - } + val isActionMode = remember(actionModeCounter) { actionModeCounter > 0 } AppBar( modifier = modifier, title = title, From 7b6ef537b3ad0298047ce2ba1ab5eb0cd43fc1ea Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Fri, 1 Nov 2024 22:34:06 +0700 Subject: [PATCH 3/7] update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e653d9a0..e13a646b11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Bangumi search now shows the score and summary of a search result ([@MajorTanya](https://github.com/MajorTanya)) ([#1396](https://github.com/mihonapp/mihon/pull/1396)) - Extension repo URLs are now auto-formatted ([@AntsyLich](https://github.com/AntsyLich), [@MajorTanya](https://github.com/MajorTanya)) +### Other +- Make `MangaScreen` reuse `AppBar` + ## [v0.17.0] - 2024-10-26 ### Added - Option to disable reader zoom out ([@Splintorien](https://github.com/Splintorien)) ([#302](https://github.com/mihonapp/mihon/pull/302)) From 3557e9415ee131fc6ea5853c5b5de41df42b5e91 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Fri, 1 Nov 2024 22:38:55 +0700 Subject: [PATCH 4/7] add name --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e13a646b11..9bc1553034 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Extension repo URLs are now auto-formatted ([@AntsyLich](https://github.com/AntsyLich), [@MajorTanya](https://github.com/MajorTanya)) ### Other -- Make `MangaScreen` reuse `AppBar` +- Make `MangaScreen` reuse `AppBar` ([@cuong-tran](https://github.com/cuong-tran) ## [v0.17.0] - 2024-10-26 ### Added From c3bfaff4f3d1c8d02acc4dee56dc75fafc59c712 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Fri, 1 Nov 2024 22:41:29 +0700 Subject: [PATCH 5/7] fix changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bc1553034..c42ff617b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Extension repo URLs are now auto-formatted ([@AntsyLich](https://github.com/AntsyLich), [@MajorTanya](https://github.com/MajorTanya)) ### Other -- Make `MangaScreen` reuse `AppBar` ([@cuong-tran](https://github.com/cuong-tran) +- Make `MangaScreen` reuse `AppBar` ([@cuong-tran](https://github.com/cuong-tran)) ## [v0.17.0] - 2024-10-26 ### Added From aadbd9a714c1a0410f204c98531e0c2cbf1759ad Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Sat, 2 Nov 2024 00:57:57 +0700 Subject: [PATCH 6/7] Update CHANGELOG.md Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c42ff617b2..06529fd356 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Extension repo URLs are now auto-formatted ([@AntsyLich](https://github.com/AntsyLich), [@MajorTanya](https://github.com/MajorTanya)) ### Other -- Make `MangaScreen` reuse `AppBar` ([@cuong-tran](https://github.com/cuong-tran)) +- Reuse `AppBar` in `MangaScreen` ([@cuong-tran](https://github.com/cuong-tran)) ([#1367](https://github.com/mihonapp/mihon/pull/1367)) ## [v0.17.0] - 2024-10-26 ### Added From d5d69706e86611d82e1657aa33b38c9290c64ba7 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Thu, 7 Nov 2024 23:30:28 +0700 Subject: [PATCH 7/7] remove changelog update --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06529fd356..e3e653d9a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,9 +23,6 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co - Bangumi search now shows the score and summary of a search result ([@MajorTanya](https://github.com/MajorTanya)) ([#1396](https://github.com/mihonapp/mihon/pull/1396)) - Extension repo URLs are now auto-formatted ([@AntsyLich](https://github.com/AntsyLich), [@MajorTanya](https://github.com/MajorTanya)) -### Other -- Reuse `AppBar` in `MangaScreen` ([@cuong-tran](https://github.com/cuong-tran)) ([#1367](https://github.com/mihonapp/mihon/pull/1367)) - ## [v0.17.0] - 2024-10-26 ### Added - Option to disable reader zoom out ([@Splintorien](https://github.com/Splintorien)) ([#302](https://github.com/mihonapp/mihon/pull/302))