diff --git a/app/src/main/java/eu/kanade/domain/track/interactor/AddTracks.kt b/app/src/main/java/eu/kanade/domain/track/interactor/AddTracks.kt index 5a56889fb..45340e44a 100644 --- a/app/src/main/java/eu/kanade/domain/track/interactor/AddTracks.kt +++ b/app/src/main/java/eu/kanade/domain/track/interactor/AddTracks.kt @@ -17,31 +17,29 @@ class AddTracks( private val syncChapterProgressWithTrack: SyncChapterProgressWithTrack, ) { - suspend fun bindEnhancedTracks(manga: Manga, source: Source) { - withNonCancellableContext { - getTracks.await(manga.id) - .filterIsInstance() - .filter { it.accept(source) } - .forEach { service -> - try { - service.match(manga)?.let { track -> - track.manga_id = manga.id - (service as Tracker).bind(track) - insertTrack.await(track.toDomainTrack()!!) + suspend fun bindEnhancedTracks(manga: Manga, source: Source) = withNonCancellableContext { + getTracks.await(manga.id) + .filterIsInstance() + .filter { it.accept(source) } + .forEach { service -> + try { + service.match(manga)?.let { track -> + track.manga_id = manga.id + (service as Tracker).bind(track) + insertTrack.await(track.toDomainTrack()!!) - syncChapterProgressWithTrack.await( - manga.id, - track.toDomainTrack()!!, - service, - ) - } - } catch (e: Exception) { - logcat( - LogPriority.WARN, - e, - ) { "Could not match manga: ${manga.title} with service $service" } + syncChapterProgressWithTrack.await( + manga.id, + track.toDomainTrack()!!, + service, + ) } + } catch (e: Exception) { + logcat( + LogPriority.WARN, + e, + ) { "Could not match manga: ${manga.title} with service $service" } } - } + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoryTab.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoryTab.kt index a6a08ff8c..2306216a7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoryTab.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/history/HistoryTab.kt @@ -116,7 +116,7 @@ object HistoryTab : Tab { } } - suspend fun openChapter(context: Context, chapter: Chapter?) { + private suspend fun openChapter(context: Context, chapter: Chapter?) { if (chapter != null) { val intent = ReaderActivity.newIntent(context, chapter.mangaId, chapter.id) context.startActivity(intent) 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 9e94a2605..8d1bace7d 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 @@ -15,6 +15,7 @@ import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.model.downloadedFilter import eu.kanade.domain.manga.model.toSManga +import eu.kanade.domain.track.interactor.AddTracks import eu.kanade.domain.ui.UiPreferences import eu.kanade.presentation.manga.DownloadAction import eu.kanade.presentation.manga.components.ChapterDownloadAction @@ -24,7 +25,6 @@ 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 @@ -97,6 +97,7 @@ class MangaScreenModel( private val syncChaptersWithSource: SyncChaptersWithSource = Injekt.get(), private val getCategories: GetCategories = Injekt.get(), private val getTracks: GetTracks = Injekt.get(), + private val addTracks: AddTracks = Injekt.get(), private val setMangaCategories: SetMangaCategories = Injekt.get(), private val mangaRepository: MangaRepository = Injekt.get(), val snackbarHostState: SnackbarHostState = SnackbarHostState(), @@ -315,24 +316,7 @@ class MangaScreenModel( } // Finally match with enhanced tracking when available - val source = state.source - state.trackItems - .map { it.tracker } - .filterIsInstance() - .filter { it.accept(source) } - .forEach { service -> - launchIO { - try { - service.match(manga)?.let { track -> - (service as Tracker).register(track, mangaId) - } - } catch (e: Exception) { - logcat(LogPriority.WARN, e) { - "Could not match manga: ${manga.title} with service $service" - } - } - } - } + addTracks.bindEnhancedTracks(manga, state.source) } } }