Skip to content

Commit

Permalink
Fix login prompts despite being logged in to trackers in Manga screen
Browse files Browse the repository at this point in the history
  • Loading branch information
AntsyLich committed Jul 8, 2024
1 parent 2092c81 commit cbcd8bd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
38 changes: 14 additions & 24 deletions app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaScreenModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -192,16 +190,6 @@ class MangaScreenModel(
}
}

screenModelScope.launchIO {
trackerManager.loggedInTrackersFlow()
.distinctUntilChanged()
.collectLatest { trackers ->
updateSuccessState {
it.copy(loggedInTracker = trackers)
}
}
}

observeDownloads()

screenModelScope.launchIO {
Expand Down Expand Up @@ -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,
)
}
}
}
}
Expand Down Expand Up @@ -1062,11 +1055,11 @@ class MangaScreenModel(
val chapters: List<ChapterList.Item>,
val availableScanlators: Set<String>,
val excludedScanlators: Set<String>,
val trackItems: List<TrackItem> = emptyList(),
val trackingCount: Int = 0,
val hasLoggedInTrackers: Boolean = false,
val isRefreshingData: Boolean = false,
val dialog: Dialog? = null,
val hasPromptedToAddBefore: Boolean = false,
val loggedInTracker: List<Tracker> = emptyList(),
) : State {
val processedChapters by lazy {
chapters.applyFilters(manga).toList()
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit cbcd8bd

Please sign in to comment.