Background tracker update during Library update (#5166)

* add preference to auto update trackers during library update

* also update trackers when updating chapters and preference is set

* remove unnecessary launch/join

* perform tracking update within the same chapter update loop to avoid double notifications
This commit is contained in:
Gauthier 2021-05-25 10:26:41 +08:00 committed by GitHub
parent 3d89a317c1
commit e76e903060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 19 deletions

View File

@ -21,6 +21,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Companion.start
import eu.kanade.tachiyomi.data.notification.Notifications
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.track.TrackManager
import eu.kanade.tachiyomi.data.track.TrackService
import eu.kanade.tachiyomi.data.track.UnattendedTrackService
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SManga
@ -273,6 +274,7 @@ class LibraryUpdateService(
val newUpdates = mutableListOf<Pair<LibraryManga, Array<Chapter>>>()
val failedUpdates = mutableListOf<Pair<Manga, String?>>()
var hasDownloads = false
val loggedServices by lazy { trackManager.services.filter { it.isLogged } }
mangaToUpdate.forEach { manga ->
if (updateJob?.isActive != true) {
@ -301,6 +303,10 @@ class LibraryUpdateService(
}
failedUpdates.add(manga to errorMessage)
}
if (preferences.autoUpdateTrackers()) {
updateTrackings(manga, loggedServices)
}
}
notifier.cancelProgressNotification()
@ -409,6 +415,13 @@ class LibraryUpdateService(
notifier.showProgressNotification(manga, progressCount++, mangaToUpdate.size)
// Update the tracking details.
updateTrackings(manga, loggedServices)
}
notifier.cancelProgressNotification()
}
private suspend fun updateTrackings(manga: LibraryManga, loggedServices: List<TrackService>) {
db.getTracks(manga).executeAsBlocking()
.map { track ->
supervisorScope {
@ -433,9 +446,6 @@ class LibraryUpdateService(
.awaitAll()
}
notifier.cancelProgressNotification()
}
/**
* Writes basic file of update errors to cache dir.
*/

View File

@ -168,6 +168,8 @@ object PreferenceKeys {
const val autoUpdateMetadata = "auto_update_metadata"
const val autoUpdateTrackers = "auto_update_trackers"
const val showLibraryUpdateErrors = "show_library_update_errors"
const val downloadNew = "download_new"

View File

@ -79,6 +79,8 @@ class PreferencesHelper(val context: Context) {
fun autoUpdateMetadata() = prefs.getBoolean(Keys.autoUpdateMetadata, false)
fun autoUpdateTrackers() = prefs.getBoolean(Keys.autoUpdateTrackers, false)
fun showLibraryUpdateErrors() = prefs.getBoolean(Keys.showLibraryUpdateErrors, false)
fun clear() = prefs.edit { clear() }

View File

@ -241,6 +241,12 @@ class SettingsLibraryController : SettingsController() {
summaryRes = R.string.pref_library_update_refresh_metadata_summary
defaultValue = false
}
switchPreference {
key = Keys.autoUpdateTrackers
titleRes = R.string.pref_library_update_refresh_trackers
summaryRes = R.string.pref_library_update_refresh_trackers_summary
defaultValue = false
}
switchPreference {
key = Keys.showLibraryUpdateErrors
titleRes = R.string.pref_library_update_error_notification

View File

@ -218,6 +218,8 @@
<string name="pref_update_only_non_completed">Only update ongoing manga</string>
<string name="pref_library_update_refresh_metadata">Automatically refresh metadata</string>
<string name="pref_library_update_refresh_metadata_summary">Check for new cover and details when updating library</string>
<string name="pref_library_update_refresh_trackers">Automatically update trackers</string>
<string name="pref_library_update_refresh_trackers_summary">Update trackers when updating library</string>
<string name="pref_library_update_error_notification">Show update errors notifications</string>
<string name="default_category">Default category</string>