From 9c65d5adf2f8253bd845231f946c61f9eb027412 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Fri, 25 Oct 2024 03:24:09 +0700 Subject: [PATCH 1/5] update all trackers progress when new tracker is added --- .../domain/track/interactor/AddTracks.kt | 53 +++++++++++++++---- 1 file changed, 44 insertions(+), 9 deletions(-) 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 a5b6a0e1c0..ea389e406e 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 @@ -1,5 +1,6 @@ package eu.kanade.domain.track.interactor +import android.app.Application import eu.kanade.domain.track.model.toDbTrack import eu.kanade.domain.track.model.toDomainTrack import eu.kanade.tachiyomi.data.database.models.Track @@ -8,26 +9,28 @@ import eu.kanade.tachiyomi.data.track.Tracker import eu.kanade.tachiyomi.data.track.TrackerManager import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.util.lang.convertEpochMillisZone +import eu.kanade.tachiyomi.util.system.toast import logcat.LogPriority +import tachiyomi.core.common.i18n.stringResource import tachiyomi.core.common.util.lang.withIOContext import tachiyomi.core.common.util.lang.withNonCancellableContext +import tachiyomi.core.common.util.lang.withUIContext import tachiyomi.core.common.util.system.logcat import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId import tachiyomi.domain.history.interactor.GetHistory import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.track.interactor.InsertTrack +import tachiyomi.i18n.MR import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.time.ZoneOffset class AddTracks( private val insertTrack: InsertTrack, - private val syncChapterProgressWithTrack: SyncChapterProgressWithTrack, private val getChaptersByMangaId: GetChaptersByMangaId, private val trackerManager: TrackerManager, ) { - // TODO: update all trackers based on common data suspend fun bind(tracker: Tracker, item: Track, mangaId: Long) = withNonCancellableContext { withIOContext { val allChapters = getChaptersByMangaId.await(mangaId) @@ -73,7 +76,25 @@ class AddTracks( } } - syncChapterProgressWithTrack.await(mangaId, track, tracker) + val refreshTracks = Injekt.get() + val context = Injekt.get() + + refreshTracks.await(mangaId) + .filter { it.first != null } + .forEach { (track, e) -> + logcat(LogPriority.ERROR, e) { + "Failed to refresh track data mangaId=$mangaId for service ${track!!.id}" + } + withUIContext { + context.toast( + context.stringResource( + MR.strings.track_error, + track!!.name, + e.message ?: "", + ), + ) + } + } } } @@ -88,12 +109,6 @@ class AddTracks( track.manga_id = manga.id (service as Tracker).bind(track) insertTrack.await(track.toDomainTrack(idRequired = false)!!) - - syncChapterProgressWithTrack.await( - manga.id, - track.toDomainTrack(idRequired = false)!!, - service, - ) } } catch (e: Exception) { logcat( @@ -102,6 +117,26 @@ class AddTracks( ) { "Could not match manga: ${manga.title} with service $service" } } } + + val refreshTracks = Injekt.get() + val context = Injekt.get() + + refreshTracks.await(manga.id) + .filter { it.first != null } + .forEach { (track, e) -> + logcat(LogPriority.ERROR, e) { + "Failed to refresh track data mangaId=${manga.id} for service ${track!!.id}" + } + withUIContext { + context.toast( + context.stringResource( + MR.strings.track_error, + track!!.name, + e.message ?: "", + ), + ) + } + } } } } From 555bc597cef6d45fe178647da484d6eefee72881 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Fri, 25 Oct 2024 09:39:40 +0700 Subject: [PATCH 2/5] fix Factory --- .../main/java/eu/kanade/domain/track/interactor/AddTracks.kt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) 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 ea389e406e..8d5435aae5 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 @@ -27,6 +27,7 @@ import java.time.ZoneOffset class AddTracks( private val insertTrack: InsertTrack, + private val refreshTracks: RefreshTracks, private val getChaptersByMangaId: GetChaptersByMangaId, private val trackerManager: TrackerManager, ) { @@ -76,9 +77,7 @@ class AddTracks( } } - val refreshTracks = Injekt.get() val context = Injekt.get() - refreshTracks.await(mangaId) .filter { it.first != null } .forEach { (track, e) -> @@ -118,9 +117,7 @@ class AddTracks( } } - val refreshTracks = Injekt.get() val context = Injekt.get() - refreshTracks.await(manga.id) .filter { it.first != null } .forEach { (track, e) -> From 645f0ed8e84d7c288dd954f83baa630ccceaf301 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Fri, 1 Nov 2024 22:40:44 +0700 Subject: [PATCH 3/5] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e3e653d9a0..05f9ea026d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co ### Improved - Bangumi search now shows the score and summary of a search result ([@MajorTanya](https://github.com/MajorTanya)) ([#1396](https://github.com/mihonapp/mihon/pull/1396)) - Extension repo URLs are now auto-formatted ([@AntsyLich](https://github.com/AntsyLich), [@MajorTanya](https://github.com/MajorTanya)) +- Update all trackers' progress when adding a new tracker ([@cuong-tran](https://github.com/cuong-tran)) ## [v0.17.0] - 2024-10-26 ### Added From 3d274680863226cf7c82101d4b0069de8c3042d0 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Sat, 2 Nov 2024 01:00:27 +0700 Subject: [PATCH 4/5] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05f9ea026d..1700380c04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co ### Improved - Bangumi search now shows the score and summary of a search result ([@MajorTanya](https://github.com/MajorTanya)) ([#1396](https://github.com/mihonapp/mihon/pull/1396)) - Extension repo URLs are now auto-formatted ([@AntsyLich](https://github.com/AntsyLich), [@MajorTanya](https://github.com/MajorTanya)) -- Update all trackers' progress when adding a new tracker ([@cuong-tran](https://github.com/cuong-tran)) +- Update all trackers' progress when adding a new tracker ([@cuong-tran](https://github.com/cuong-tran)) ([#1372](https://github.com/mihonapp/mihon/pull/1372)) ## [v0.17.0] - 2024-10-26 ### Added From de85b1c54914378d3f51926019eea629bbd567f2 Mon Sep 17 00:00:00 2001 From: Cuong-Tran Date: Thu, 7 Nov 2024 23:27:59 +0700 Subject: [PATCH 5/5] remove changelog update --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1700380c04..e3e653d9a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,6 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co ### Improved - Bangumi search now shows the score and summary of a search result ([@MajorTanya](https://github.com/MajorTanya)) ([#1396](https://github.com/mihonapp/mihon/pull/1396)) - Extension repo URLs are now auto-formatted ([@AntsyLich](https://github.com/AntsyLich), [@MajorTanya](https://github.com/MajorTanya)) -- Update all trackers' progress when adding a new tracker ([@cuong-tran](https://github.com/cuong-tran)) ([#1372](https://github.com/mihonapp/mihon/pull/1372)) ## [v0.17.0] - 2024-10-26 ### Added