From 3a0b3de1754452cc0e10426c79820baa74d30b63 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 10 Dec 2023 11:58:20 -0500 Subject: [PATCH] Always show trackers action in MangaScreen Goes to tracker settings to log in if none are set up. --- .../kanade/presentation/manga/MangaScreen.kt | 6 +-- .../manga/components/MangaInfoHeader.kt | 24 ++++++------ .../kanade/tachiyomi/ui/manga/MangaScreen.kt | 9 ++++- .../tachiyomi/ui/manga/MangaScreenModel.kt | 3 -- .../eu/kanade/tachiyomi/ui/more/MoreTab.kt | 8 ++-- .../tachiyomi/ui/more/OnboardingScreen.kt | 2 +- .../tachiyomi/ui/setting/SettingsScreen.kt | 39 +++++++++---------- 7 files changed, 45 insertions(+), 46 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 dda12b12b7..18fbbc3f51 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/MangaScreen.kt @@ -96,7 +96,7 @@ fun MangaScreen( onAddToLibraryClicked: () -> Unit, onWebViewClicked: (() -> Unit)?, onWebViewLongClicked: (() -> Unit)?, - onTrackingClicked: (() -> Unit)?, + onTrackingClicked: () -> Unit, // For tags menu onTagSearch: (String) -> Unit, @@ -229,7 +229,7 @@ private fun MangaScreenSmallImpl( onAddToLibraryClicked: () -> Unit, onWebViewClicked: (() -> Unit)?, onWebViewLongClicked: (() -> Unit)?, - onTrackingClicked: (() -> Unit)?, + onTrackingClicked: () -> Unit, // For tags menu onTagSearch: (String) -> Unit, @@ -481,7 +481,7 @@ fun MangaScreenLargeImpl( onAddToLibraryClicked: () -> Unit, onWebViewClicked: (() -> Unit)?, onWebViewLongClicked: (() -> Unit)?, - onTrackingClicked: (() -> Unit)?, + onTrackingClicked: () -> Unit, // For tags menu onTagSearch: (String) -> Unit, diff --git a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt index e844e8d943..a643a15b2e 100644 --- a/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt +++ b/app/src/main/java/eu/kanade/presentation/manga/components/MangaInfoHeader.kt @@ -169,7 +169,7 @@ fun MangaActionRow( onAddToLibraryClicked: () -> Unit, onWebViewClicked: (() -> Unit)?, onWebViewLongClicked: (() -> Unit)?, - onTrackingClicked: (() -> Unit)?, + onTrackingClicked: () -> Unit, onEditIntervalClicked: (() -> Unit)?, onEditCategory: (() -> Unit)?, modifier: Modifier = Modifier, @@ -200,18 +200,16 @@ fun MangaActionRow( onClick = onEditIntervalClicked, ) } - if (onTrackingClicked != null) { - MangaActionButton( - title = if (trackingCount == 0) { - stringResource(MR.strings.manga_tracking_tab) - } else { - pluralStringResource(MR.plurals.num_trackers, count = trackingCount, trackingCount) - }, - icon = if (trackingCount == 0) Icons.Outlined.Sync else Icons.Outlined.Done, - color = if (trackingCount == 0) defaultActionButtonColor else MaterialTheme.colorScheme.primary, - onClick = onTrackingClicked, - ) - } + MangaActionButton( + title = if (trackingCount == 0) { + stringResource(MR.strings.manga_tracking_tab) + } else { + pluralStringResource(MR.plurals.num_trackers, count = trackingCount, trackingCount) + }, + icon = if (trackingCount == 0) Icons.Outlined.Sync else Icons.Outlined.Done, + color = if (trackingCount == 0) defaultActionButtonColor else MaterialTheme.colorScheme.primary, + onClick = onTrackingClicked, + ) if (onWebViewClicked != null) { MangaActionButton( title = stringResource(MR.strings.action_web_view), diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt index f792581de5..7b9b18ed6a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreen.kt @@ -47,6 +47,7 @@ import eu.kanade.tachiyomi.ui.category.CategoryScreen import eu.kanade.tachiyomi.ui.home.HomeScreen import eu.kanade.tachiyomi.ui.manga.track.TrackInfoDialogHomeScreen import eu.kanade.tachiyomi.ui.reader.ReaderActivity +import eu.kanade.tachiyomi.ui.setting.SettingsScreen import eu.kanade.tachiyomi.ui.webview.WebViewScreen import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.system.toShareIntent @@ -130,7 +131,13 @@ class MangaScreen( screenModel.source, ) }.takeIf { isHttpSource }, - onTrackingClicked = screenModel::showTrackDialog.takeIf { successState.trackingAvailable }, + onTrackingClicked = { + if (successState.trackingCount == 0) { + navigator.push(SettingsScreen(SettingsScreen.Destination.Tracking)) + } else { + screenModel.showTrackDialog() + } + }, onTagSearch = { scope.launch { performGenreSearch(navigator, it, screenModel.source!!) } }, onFilterButtonClicked = screenModel::showSettingsDialog, onRefresh = screenModel::fetchAllFromSource, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt index 73c64e12b8..cc38de7795 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt @@ -1090,9 +1090,6 @@ class MangaScreenModel( val filterActive: Boolean get() = scanlatorFilterActive || manga.chaptersFiltered() - val trackingAvailable: Boolean - get() = trackItems.isNotEmpty() - val trackingCount: Int get() = trackItems.count { it.track != null } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreTab.kt index 8d5fa13135..3ca8418adc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreTab.kt @@ -53,7 +53,7 @@ object MoreTab : Tab { } override suspend fun onReselect(navigator: Navigator) { - navigator.push(SettingsScreen.toMainScreen()) + navigator.push(SettingsScreen()) } @Composable @@ -72,9 +72,9 @@ object MoreTab : Tab { onClickDownloadQueue = { navigator.push(DownloadQueueScreen) }, onClickCategories = { navigator.push(CategoryScreen()) }, onClickStats = { navigator.push(StatsScreen()) }, - onClickDataAndStorage = { navigator.push(SettingsScreen.toDataAndStorageScreen()) }, - onClickSettings = { navigator.push(SettingsScreen.toMainScreen()) }, - onClickAbout = { navigator.push(SettingsScreen.toAboutScreen()) }, + onClickDataAndStorage = { navigator.push(SettingsScreen(SettingsScreen.Destination.DataAndStorage)) }, + onClickSettings = { navigator.push(SettingsScreen()) }, + onClickAbout = { navigator.push(SettingsScreen(SettingsScreen.Destination.About)) }, ) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/OnboardingScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/OnboardingScreen.kt index 037edd9f56..72e0919548 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/OnboardingScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/OnboardingScreen.kt @@ -34,7 +34,7 @@ class OnboardingScreen : Screen() { onComplete = { finishOnboarding() }, onRestoreBackup = { finishOnboarding() - navigator.push(SettingsScreen.toDataAndStorageScreen()) + navigator.push(SettingsScreen(SettingsScreen.Destination.DataAndStorage)) }, ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsScreen.kt index 5b2dcedb23..5ac3e07166 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsScreen.kt @@ -15,6 +15,7 @@ import cafe.adriel.voyager.navigator.currentOrThrow import eu.kanade.presentation.more.settings.screen.SettingsAppearanceScreen import eu.kanade.presentation.more.settings.screen.SettingsDataScreen import eu.kanade.presentation.more.settings.screen.SettingsMainScreen +import eu.kanade.presentation.more.settings.screen.SettingsTrackingScreen import eu.kanade.presentation.more.settings.screen.about.AboutScreen import eu.kanade.presentation.util.DefaultNavigatorScreenTransition import eu.kanade.presentation.util.LocalBackPress @@ -22,9 +23,8 @@ import eu.kanade.presentation.util.Screen import eu.kanade.presentation.util.isTabletUi import tachiyomi.presentation.core.components.TwoPanelBox -class SettingsScreen private constructor( - val toDataAndStorage: Boolean, - val toAbout: Boolean, +class SettingsScreen( + private val destination: Destination = Destination.Main, ) : Screen() { @Composable @@ -32,12 +32,11 @@ class SettingsScreen private constructor( val parentNavigator = LocalNavigator.currentOrThrow if (!isTabletUi()) { Navigator( - screen = if (toDataAndStorage) { - SettingsDataScreen - } else if (toAbout) { - AboutScreen - } else { - SettingsMainScreen + screen = when (destination) { + Destination.Main -> SettingsMainScreen + Destination.About -> AboutScreen + Destination.DataAndStorage -> SettingsDataScreen + Destination.Tracking -> SettingsTrackingScreen }, content = { val pop: () -> Unit = { @@ -54,12 +53,11 @@ class SettingsScreen private constructor( ) } else { Navigator( - screen = if (toDataAndStorage) { - SettingsDataScreen - } else if (toAbout) { - AboutScreen - } else { - SettingsAppearanceScreen + screen = when (destination) { + Destination.Main -> SettingsAppearanceScreen + Destination.About -> AboutScreen + Destination.DataAndStorage -> SettingsDataScreen + Destination.Tracking -> SettingsTrackingScreen }, ) { val insets = WindowInsets.systemBars.only(WindowInsetsSides.Horizontal) @@ -78,11 +76,10 @@ class SettingsScreen private constructor( } } - companion object { - fun toMainScreen() = SettingsScreen(toDataAndStorage = false, toAbout = false) - - fun toDataAndStorageScreen() = SettingsScreen(toDataAndStorage = true, toAbout = false) - - fun toAboutScreen() = SettingsScreen(toDataAndStorage = false, toAbout = true) + sealed interface Destination { + data object Main : Destination + data object About : Destination + data object DataAndStorage : Destination + data object Tracking : Destination } }