From 5ca7c39751c29e396f59e66addcfb482bcae6e7d Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 21 May 2023 11:02:56 -0400 Subject: [PATCH] Replace Cascade with our own somewhat janky implementation --- app/build.gradle.kts | 1 - .../presentation/components/AdaptiveSheet.kt | 23 ++-- .../presentation/components/DropdownMenu.kt | 45 +++---- .../manga/components/MangaToolbar.kt | 34 +++--- .../ui/download/DownloadQueueScreen.kt | 115 ++++++++++-------- gradle/libs.versions.toml | 1 - i18n/src/main/res/values/strings.xml | 1 - 7 files changed, 118 insertions(+), 102 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 282b29324..7a20ae0db 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -237,7 +237,6 @@ dependencies { implementation(libs.bundles.richtext) implementation(libs.aboutLibraries.compose) implementation(libs.bundles.voyager) - implementation(libs.compose.cascade) implementation(libs.compose.materialmotion) implementation(libs.compose.simpleicons) diff --git a/app/src/main/java/eu/kanade/presentation/components/AdaptiveSheet.kt b/app/src/main/java/eu/kanade/presentation/components/AdaptiveSheet.kt index 08a200b50..3589b8fa6 100644 --- a/app/src/main/java/eu/kanade/presentation/components/AdaptiveSheet.kt +++ b/app/src/main/java/eu/kanade/presentation/components/AdaptiveSheet.kt @@ -9,8 +9,8 @@ import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.WindowInsetsSides import androidx.compose.foundation.layout.asPaddingValues -import androidx.compose.foundation.layout.navigationBars import androidx.compose.foundation.layout.only +import androidx.compose.foundation.layout.safeContent import androidx.compose.runtime.Composable import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp @@ -82,12 +82,15 @@ fun AdaptiveSheet( content: @Composable (PaddingValues) -> Unit, ) { val isTabletUi = isTabletUi() + val contentPadding = if (isTabletUi) { + PaddingValues() + } else { + WindowInsets.safeContent.only(WindowInsetsSides.Bottom).asPaddingValues() + } + Dialog( onDismissRequest = onDismissRequest, - properties = DialogProperties( - usePlatformDefaultWidth = false, - decorFitsSystemWindows = false, - ), + properties = dialogProperties, ) { AdaptiveSheetImpl( isTabletUi = isTabletUi, @@ -95,12 +98,12 @@ fun AdaptiveSheet( enableSwipeDismiss = enableSwipeDismiss, onDismissRequest = onDismissRequest, ) { - val contentPadding = if (isTabletUi) { - PaddingValues() - } else { - WindowInsets.navigationBars.only(WindowInsetsSides.Bottom).asPaddingValues() - } content(contentPadding) } } } + +private val dialogProperties = DialogProperties( + usePlatformDefaultWidth = false, + decorFitsSystemWindows = false, +) diff --git a/app/src/main/java/eu/kanade/presentation/components/DropdownMenu.kt b/app/src/main/java/eu/kanade/presentation/components/DropdownMenu.kt index 057d89766..14cd82117 100644 --- a/app/src/main/java/eu/kanade/presentation/components/DropdownMenu.kt +++ b/app/src/main/java/eu/kanade/presentation/components/DropdownMenu.kt @@ -1,15 +1,14 @@ package eu.kanade.presentation.components -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.ColumnScope import androidx.compose.foundation.layout.sizeIn import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.outlined.MoreVert +import androidx.compose.material.icons.outlined.ArrowLeft +import androidx.compose.material.icons.outlined.ArrowRight import androidx.compose.material.icons.outlined.RadioButtonChecked import androidx.compose.material.icons.outlined.RadioButtonUnchecked import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -17,13 +16,13 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.DpOffset +import androidx.compose.ui.unit.LayoutDirection import androidx.compose.ui.unit.dp import androidx.compose.ui.window.PopupProperties import eu.kanade.tachiyomi.R -import me.saket.cascade.CascadeColumnScope -import me.saket.cascade.CascadeDropdownMenu import androidx.compose.material3.DropdownMenu as ComposeDropdownMenu @Composable @@ -72,25 +71,29 @@ fun RadioMenuItem( } @Composable -fun OverflowMenu( - content: @Composable CascadeColumnScope.(() -> Unit) -> Unit, +fun NestedMenuItem( + text: @Composable () -> Unit, + children: @Composable ColumnScope.(() -> Unit) -> Unit, ) { - var moreExpanded by remember { mutableStateOf(false) } - val closeMenu = { moreExpanded = false } + var nestedExpanded by remember { mutableStateOf(false) } + val closeMenu = { nestedExpanded = false } + val isLtr = LocalLayoutDirection.current == LayoutDirection.Ltr - Box { - IconButton(onClick = { moreExpanded = !moreExpanded }) { + DropdownMenuItem( + text = text, + onClick = { nestedExpanded = true }, + trailingIcon = { Icon( - imageVector = Icons.Outlined.MoreVert, - contentDescription = stringResource(R.string.abc_action_menu_overflow_description), + imageVector = if (isLtr) Icons.Outlined.ArrowRight else Icons.Outlined.ArrowLeft, + contentDescription = null, ) - } - CascadeDropdownMenu( - expanded = moreExpanded, - onDismissRequest = closeMenu, - offset = DpOffset(8.dp, (-56).dp), - ) { - content(closeMenu) - } + }, + ) + + DropdownMenu( + expanded = nestedExpanded, + onDismissRequest = closeMenu, + ) { + children(closeMenu) } } 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 bb758c299..533a36bb2 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,6 +1,5 @@ package eu.kanade.presentation.manga.components -import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.ArrowBack @@ -18,8 +17,10 @@ import androidx.compose.material3.TopAppBar import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable +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.draw.alpha import androidx.compose.ui.res.stringResource @@ -89,27 +90,28 @@ fun MangaToolbar( ), ) } else { + var downloadExpanded by remember { mutableStateOf(false) } if (onClickDownload != null) { - val (downloadExpanded, onDownloadExpanded) = remember { mutableStateOf(false) } - Box { - IconButton(onClick = { onDownloadExpanded(!downloadExpanded) }) { - Icon( - imageVector = Icons.Outlined.Download, - contentDescription = stringResource(R.string.manga_download), - ) - } - val onDismissRequest = { onDownloadExpanded(false) } - DownloadDropdownMenu( - expanded = downloadExpanded, - onDismissRequest = onDismissRequest, - onDownloadClicked = onClickDownload, - ) - } + val onDismissRequest = { downloadExpanded = false } + DownloadDropdownMenu( + expanded = downloadExpanded, + onDismissRequest = onDismissRequest, + onDownloadClicked = onClickDownload, + ) } val filterTint = if (hasFilters) MaterialTheme.colorScheme.active else LocalContentColor.current AppBarActions( actions = buildList { + if (onClickDownload != null) { + add( + AppBar.Action( + title = stringResource(R.string.manga_download), + icon = Icons.Outlined.Download, + onClick = { downloadExpanded = !downloadExpanded }, + ), + ) + } add( AppBar.Action( title = stringResource(R.string.action_filter), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreen.kt index 4f4265ba7..143185634 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadQueueScreen.kt @@ -12,6 +12,8 @@ import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.PlayArrow import androidx.compose.material.icons.outlined.Pause +import androidx.compose.material.icons.outlined.Sort +import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text @@ -47,7 +49,9 @@ import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow import eu.kanade.presentation.components.AppBar -import eu.kanade.presentation.components.OverflowMenu +import eu.kanade.presentation.components.AppBarActions +import eu.kanade.presentation.components.DropdownMenu +import eu.kanade.presentation.components.NestedMenuItem import eu.kanade.presentation.util.Screen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.DownloadListBinding @@ -120,70 +124,77 @@ object DownloadQueueScreen : Screen() { navigateUp = navigator::pop, actions = { if (downloadList.isNotEmpty()) { - OverflowMenu { closeMenu -> - DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_reorganize_by)) }, - children = { + var sortExpanded by remember { mutableStateOf(false) } + val onDismissRequest = { sortExpanded = false } + DropdownMenu( + expanded = sortExpanded, + onDismissRequest = onDismissRequest, + ) { + NestedMenuItem( + text = { Text(text = stringResource(R.string.action_order_by_upload_date)) }, + children = { closeMenu -> DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_order_by_upload_date)) }, - children = { - androidx.compose.material3.DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_newest)) }, - onClick = { - screenModel.reorderQueue( - { it.download.chapter.dateUpload }, - true, - ) - closeMenu() - }, - ) - androidx.compose.material3.DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_oldest)) }, - onClick = { - screenModel.reorderQueue( - { it.download.chapter.dateUpload }, - false, - ) - closeMenu() - }, + text = { Text(text = stringResource(R.string.action_newest)) }, + onClick = { + screenModel.reorderQueue( + { it.download.chapter.dateUpload }, + true, ) + closeMenu() }, ) DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_order_by_chapter_number)) }, - children = { - androidx.compose.material3.DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_asc)) }, - onClick = { - screenModel.reorderQueue( - { it.download.chapter.chapterNumber }, - false, - ) - closeMenu() - }, - ) - androidx.compose.material3.DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_desc)) }, - onClick = { - screenModel.reorderQueue( - { it.download.chapter.chapterNumber }, - true, - ) - closeMenu() - }, + text = { Text(text = stringResource(R.string.action_oldest)) }, + onClick = { + screenModel.reorderQueue( + { it.download.chapter.dateUpload }, + false, ) + closeMenu() }, ) }, ) - androidx.compose.material3.DropdownMenuItem( - text = { Text(text = stringResource(R.string.action_cancel_all)) }, - onClick = { - screenModel.clearQueue() - closeMenu() + NestedMenuItem( + text = { Text(text = stringResource(R.string.action_order_by_chapter_number)) }, + children = { closeMenu -> + DropdownMenuItem( + text = { Text(text = stringResource(R.string.action_asc)) }, + onClick = { + screenModel.reorderQueue( + { it.download.chapter.chapterNumber }, + false, + ) + closeMenu() + }, + ) + DropdownMenuItem( + text = { Text(text = stringResource(R.string.action_desc)) }, + onClick = { + screenModel.reorderQueue( + { it.download.chapter.chapterNumber }, + true, + ) + closeMenu() + }, + ) }, ) } + + AppBarActions( + listOf( + AppBar.Action( + title = stringResource(R.string.action_sort), + icon = Icons.Outlined.Sort, + onClick = { sortExpanded = true }, + ), + AppBar.OverflowAction( + title = stringResource(R.string.action_cancel_all), + onClick = { screenModel.clearQueue() }, + ), + ), + ) } }, scrollBehavior = scrollBehavior, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0f2da7fce..d0c6f00e0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -60,7 +60,6 @@ flexible-adapter-ui = "com.github.arkon.FlexibleAdapter:flexible-adapter-ui:c801 photoview = "com.github.chrisbanes:PhotoView:2.3.0" directionalviewpager = "com.github.tachiyomiorg:DirectionalViewPager:1.0.0" insetter = "dev.chrisbanes.insetter:insetter:0.6.1" -compose-cascade = "me.saket.cascade:cascade-compose:2.0.0-rc02" compose-materialmotion = "io.github.fornewid:material-motion-compose-core:0.12.3" compose-simpleicons = "br.com.devsrsouza.compose.icons.android:simple-icons:1.0.0" diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index c3c468062..c68f38a03 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -120,7 +120,6 @@ Cancel all Cancel all for this series Sort - Reorder By upload date By chapter number Newest