diff --git a/app/src/main/java/eu/kanade/domain/track/interactor/TrackChapter.kt b/app/src/main/java/eu/kanade/domain/track/interactor/TrackChapter.kt index fa6245f22..789a784ef 100644 --- a/app/src/main/java/eu/kanade/domain/track/interactor/TrackChapter.kt +++ b/app/src/main/java/eu/kanade/domain/track/interactor/TrackChapter.kt @@ -2,6 +2,7 @@ package eu.kanade.domain.track.interactor import android.content.Context import eu.kanade.domain.track.model.toDbTrack +import eu.kanade.domain.track.model.toDomainTrack import eu.kanade.domain.track.service.DelayedTrackingUpdateJob import eu.kanade.domain.track.store.DelayedTrackingStore import eu.kanade.tachiyomi.data.track.TrackerManager @@ -31,14 +32,17 @@ class TrackChapter( return@mapNotNull null } - val updatedTrack = track.copy(lastChapterRead = chapterNumber) async { runCatching { try { + val updatedTrack = service.refresh(track.toDbTrack()) + .toDomainTrack(idRequired = true)!! + .copy(lastChapterRead = chapterNumber) service.update(updatedTrack.toDbTrack(), true) insertTrack.await(updatedTrack) + delayedTrackingStore.remove(track.id) } catch (e: Exception) { - delayedTrackingStore.addItem(updatedTrack) + delayedTrackingStore.add(track.id, chapterNumber) DelayedTrackingUpdateJob.setupTask(context) throw e } diff --git a/app/src/main/java/eu/kanade/domain/track/service/DelayedTrackingUpdateJob.kt b/app/src/main/java/eu/kanade/domain/track/service/DelayedTrackingUpdateJob.kt index f578bd600..32be14241 100644 --- a/app/src/main/java/eu/kanade/domain/track/service/DelayedTrackingUpdateJob.kt +++ b/app/src/main/java/eu/kanade/domain/track/service/DelayedTrackingUpdateJob.kt @@ -8,21 +8,19 @@ import androidx.work.ExistingWorkPolicy import androidx.work.NetworkType import androidx.work.OneTimeWorkRequestBuilder import androidx.work.WorkerParameters -import eu.kanade.domain.track.model.toDbTrack +import eu.kanade.domain.track.interactor.TrackChapter import eu.kanade.domain.track.store.DelayedTrackingStore -import eu.kanade.tachiyomi.data.track.TrackerManager import eu.kanade.tachiyomi.util.system.workManager import logcat.LogPriority import tachiyomi.core.util.lang.withIOContext import tachiyomi.core.util.system.logcat import tachiyomi.domain.track.interactor.GetTracks -import tachiyomi.domain.track.interactor.InsertTrack import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import kotlin.time.Duration.Companion.minutes import kotlin.time.toJavaDuration -class DelayedTrackingUpdateJob(context: Context, workerParams: WorkerParameters) : +class DelayedTrackingUpdateJob(private val context: Context, workerParams: WorkerParameters) : CoroutineWorker(context, workerParams) { override suspend fun doWork(): Result { @@ -31,9 +29,8 @@ class DelayedTrackingUpdateJob(context: Context, workerParams: WorkerParameters) } val getTracks = Injekt.get() - val insertTrack = Injekt.get() + val trackChapter = Injekt.get() - val trackerManager = Injekt.get() val delayedTrackingStore = Injekt.get() withIOContext { @@ -46,17 +43,8 @@ class DelayedTrackingUpdateJob(context: Context, workerParams: WorkerParameters) track?.copy(lastChapterRead = it.lastChapterRead.toDouble()) } .forEach { track -> - try { - val service = trackerManager.get(track.syncId) - if (service != null && service.isLoggedIn) { - logcat(LogPriority.DEBUG) { "Updating delayed track item: ${track.id}, last chapter read: ${track.lastChapterRead}" } - service.update(track.toDbTrack(), true) - insertTrack.await(track) - } - delayedTrackingStore.remove(track.id) - } catch (e: Exception) { - logcat(LogPriority.ERROR, e) - } + logcat(LogPriority.DEBUG) { "Updating delayed track item: ${track.mangaId}, last chapter read: ${track.lastChapterRead}" } + trackChapter.await(context, track.mangaId, track.lastChapterRead) } } diff --git a/app/src/main/java/eu/kanade/domain/track/store/DelayedTrackingStore.kt b/app/src/main/java/eu/kanade/domain/track/store/DelayedTrackingStore.kt index d7fc6fa10..5ec27cbea 100644 --- a/app/src/main/java/eu/kanade/domain/track/store/DelayedTrackingStore.kt +++ b/app/src/main/java/eu/kanade/domain/track/store/DelayedTrackingStore.kt @@ -4,7 +4,6 @@ import android.content.Context import androidx.core.content.edit import logcat.LogPriority import tachiyomi.core.util.system.logcat -import tachiyomi.domain.track.model.Track class DelayedTrackingStore(context: Context) { @@ -13,13 +12,12 @@ class DelayedTrackingStore(context: Context) { */ private val preferences = context.getSharedPreferences("tracking_queue", Context.MODE_PRIVATE) - fun addItem(track: Track) { - val trackId = track.id.toString() - val lastChapterRead = preferences.getFloat(trackId, 0f) - if (track.lastChapterRead > lastChapterRead) { - logcat(LogPriority.DEBUG) { "Queuing track item: $trackId, last chapter read: ${track.lastChapterRead}" } + fun add(trackId: Long, lastChapterRead: Double) { + val previousLastChapterRead = preferences.getFloat(trackId.toString(), 0f) + if (lastChapterRead > previousLastChapterRead) { + logcat(LogPriority.DEBUG) { "Queuing track item: $trackId, last chapter read: $lastChapterRead" } preferences.edit { - putFloat(trackId, track.lastChapterRead.toFloat()) + putFloat(trackId.toString(), lastChapterRead.toFloat()) } } } diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt index cad067a98..1b5d6a5c3 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt @@ -34,7 +34,6 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.ChapterCache import eu.kanade.tachiyomi.data.download.DownloadCache import eu.kanade.tachiyomi.data.library.LibraryUpdateJob -import eu.kanade.tachiyomi.data.track.TrackerManager import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.NetworkPreferences import eu.kanade.tachiyomi.network.PREF_DOH_360 @@ -328,7 +327,6 @@ object SettingsAdvancedScreen : SearchableSettings { private fun getLibraryGroup(): Preference.PreferenceGroup { val scope = rememberCoroutineScope() val context = LocalContext.current - val trackerManager = remember { Injekt.get() } return Preference.PreferenceGroup( title = stringResource(R.string.label_library), @@ -337,12 +335,6 @@ object SettingsAdvancedScreen : SearchableSettings { title = stringResource(R.string.pref_refresh_library_covers), onClick = { LibraryUpdateJob.startNow(context, target = LibraryUpdateJob.Target.COVERS) }, ), - Preference.PreferenceItem.TextPreference( - title = stringResource(R.string.pref_refresh_library_tracking), - subtitle = stringResource(R.string.pref_refresh_library_tracking_summary), - enabled = trackerManager.hasLoggedIn(), - onClick = { LibraryUpdateJob.startNow(context, target = LibraryUpdateJob.Target.TRACKING) }, - ), Preference.PreferenceItem.TextPreference( title = stringResource(R.string.pref_reset_viewer_flags), subtitle = stringResource(R.string.pref_reset_viewer_flags_summary), diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt index 0e71d4cdb..6dc95d6b0 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsLibraryScreen.kt @@ -23,7 +23,6 @@ import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.widget.TriStateListDialog import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.library.LibraryUpdateJob -import eu.kanade.tachiyomi.data.track.TrackerManager import eu.kanade.tachiyomi.ui.category.CategoryScreen import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -197,12 +196,6 @@ object SettingsLibraryScreen : SearchableSettings { title = stringResource(R.string.pref_library_update_refresh_metadata), subtitle = stringResource(R.string.pref_library_update_refresh_metadata_summary), ), - Preference.PreferenceItem.SwitchPreference( - pref = libraryPreferences.autoUpdateTrackers(), - enabled = Injekt.get().hasLoggedIn(), - title = stringResource(R.string.pref_library_update_refresh_trackers), - subtitle = stringResource(R.string.pref_library_update_refresh_trackers_summary), - ), Preference.PreferenceItem.MultiSelectListPreference( pref = libraryPreferences.autoUpdateMangaRestrictions(), title = stringResource(R.string.pref_library_update_manga_restriction), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt index 651858332..3554722a0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt @@ -18,7 +18,6 @@ import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.model.copyFrom import eu.kanade.domain.manga.model.toSManga -import eu.kanade.domain.track.interactor.RefreshTracks import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.download.DownloadManager @@ -89,7 +88,6 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet private val updateManga: UpdateManga = Injekt.get() private val getCategories: GetCategories = Injekt.get() private val syncChaptersWithSource: SyncChaptersWithSource = Injekt.get() - private val refreshTracks: RefreshTracks = Injekt.get() private val fetchInterval: FetchInterval = Injekt.get() private val notifier = LibraryUpdateNotifier(context) @@ -131,7 +129,6 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet when (target) { Target.CHAPTERS -> updateChapterList() Target.COVERS -> updateCovers() - Target.TRACKING -> updateTrackings() } Result.success() } catch (e: Exception) { @@ -304,10 +301,6 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet } failedUpdates.add(manga to errorMessage) } - - if (libraryPreferences.autoUpdateTrackers().get()) { - refreshTracks(manga.id) - } } } } @@ -409,33 +402,6 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet notifier.cancelProgressNotification() } - /** - * Method that updates the metadata of the connected tracking services. It's called in a - * background thread, so it's safe to do heavy operations or network calls here. - */ - private suspend fun updateTrackings() { - coroutineScope { - var progressCount = 0 - - mangaToUpdate.forEach { libraryManga -> - ensureActive() - - val manga = libraryManga.manga - notifier.showProgressNotification(listOf(manga), progressCount++, mangaToUpdate.size) - refreshTracks(manga.id) - } - - notifier.cancelProgressNotification() - } - } - - private suspend fun refreshTracks(mangaId: Long) { - refreshTracks.await(mangaId).forEach { (_, e) -> - // Ignore errors and continue - logcat(LogPriority.ERROR, e) - } - } - private suspend fun withUpdateNotification( updatingManga: CopyOnWriteArrayList, completed: AtomicInteger, @@ -500,7 +466,6 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet enum class Target { CHAPTERS, // Manga chapters COVERS, // Manga covers - TRACKING, // Tracking metadata } companion object { diff --git a/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt b/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt index 8c853c759..8edfa7a27 100644 --- a/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt +++ b/domain/src/main/java/tachiyomi/domain/library/service/LibraryPreferences.kt @@ -50,8 +50,6 @@ class LibraryPreferences( fun autoUpdateMetadata() = preferenceStore.getBoolean("auto_update_metadata", false) - fun autoUpdateTrackers() = preferenceStore.getBoolean("auto_update_trackers", false) - fun showContinueReadingButton() = preferenceStore.getBoolean( "display_continue_reading_button", false, diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index 90eccfd8c..8c7ff8736 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -265,8 +265,6 @@ Automatically refresh metadata Check for new cover and details when updating library - Automatically refresh trackers - Update trackers when updating library Default category Always ask @@ -538,8 +536,6 @@ Clear WebView data WebView data cleared Refresh library covers - Refresh tracking - Updates status, score and last chapter read from the tracking services Reset per-series reader settings Resets reading mode and orientation of all series All reader settings reset