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 b4b82584e3..e500a04d37 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 @@ -138,7 +138,7 @@ class MangaScreen( ) }.takeIf { isHttpSource }, onTrackingClicked = { - if (successState.loggedInTracker.isEmpty()) { + if (!successState.hasLoggedInTrackers) { navigator.push(SettingsScreen(SettingsScreen.Destination.Tracking)) } else { screenModel.showTrackDialog() 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 682c45fcd6..99a1b16120 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 @@ -28,11 +28,9 @@ import eu.kanade.tachiyomi.data.download.DownloadCache import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.model.Download import eu.kanade.tachiyomi.data.track.EnhancedTracker -import eu.kanade.tachiyomi.data.track.Tracker import eu.kanade.tachiyomi.data.track.TrackerManager import eu.kanade.tachiyomi.network.HttpException import eu.kanade.tachiyomi.source.Source -import eu.kanade.tachiyomi.ui.manga.track.TrackItem import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.util.chapter.getNextUnread import eu.kanade.tachiyomi.util.removeCovers @@ -192,16 +190,6 @@ class MangaScreenModel( } } - screenModelScope.launchIO { - trackerManager.loggedInTrackersFlow() - .distinctUntilChanged() - .collectLatest { trackers -> - updateSuccessState { - it.copy(loggedInTracker = trackers) - } - } - } - observeDownloads() screenModelScope.launchIO { @@ -990,15 +978,20 @@ class MangaScreenModel( getTracks.subscribe(manga.id).catch { logcat(LogPriority.ERROR, it) }, trackerManager.loggedInTrackersFlow(), ) { mangaTracks, loggedInTrackers -> - loggedInTrackers - // Map to TrackItem - .map { service -> TrackItem(mangaTracks.find { it.trackerId == service.id }, service) } - // Show only if the service supports this manga's source - .filter { (it.tracker as? EnhancedTracker)?.accept(source!!) ?: true } + // Show only if the service supports this manga's source + val supportedTrackers = loggedInTrackers.filter { (it as? EnhancedTracker)?.accept(source!!) ?: true } + val supportedTrackerIds = supportedTrackers.map { it.id }.toHashSet() + val supportedTrackerTracks = mangaTracks.filter { it.trackerId in supportedTrackerIds } + supportedTrackerTracks.size to supportedTrackers.isNotEmpty() } .distinctUntilChanged() - .collectLatest { trackItems -> - updateSuccessState { it.copy(trackItems = trackItems) } + .collectLatest { (trackingCount, hasLoggedInTrackers) -> + updateSuccessState { + it.copy( + trackingCount = trackingCount, + hasLoggedInTrackers = hasLoggedInTrackers, + ) + } } } } @@ -1062,11 +1055,11 @@ class MangaScreenModel( val chapters: List, val availableScanlators: Set, val excludedScanlators: Set, - val trackItems: List = emptyList(), + val trackingCount: Int = 0, + val hasLoggedInTrackers: Boolean = false, val isRefreshingData: Boolean = false, val dialog: Dialog? = null, val hasPromptedToAddBefore: Boolean = false, - val loggedInTracker: List = emptyList(), ) : State { val processedChapters by lazy { chapters.applyFilters(manga).toList() @@ -1109,9 +1102,6 @@ class MangaScreenModel( val filterActive: Boolean get() = scanlatorFilterActive || manga.chaptersFiltered() - val trackingCount: Int - get() = trackItems.count { it.track != null } - /** * Applies the view filters to the list of chapters obtained from the database. * @return an observable of the list of chapters filtered and sorted.