mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 20:17:48 +01:00
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:
parent
3d89a317c1
commit
e76e903060
5 changed files with 41 additions and 19 deletions
|
@ -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.notification.Notifications
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
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.data.track.UnattendedTrackService
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
|
@ -273,6 +274,7 @@ class LibraryUpdateService(
|
||||||
val newUpdates = mutableListOf<Pair<LibraryManga, Array<Chapter>>>()
|
val newUpdates = mutableListOf<Pair<LibraryManga, Array<Chapter>>>()
|
||||||
val failedUpdates = mutableListOf<Pair<Manga, String?>>()
|
val failedUpdates = mutableListOf<Pair<Manga, String?>>()
|
||||||
var hasDownloads = false
|
var hasDownloads = false
|
||||||
|
val loggedServices by lazy { trackManager.services.filter { it.isLogged } }
|
||||||
|
|
||||||
mangaToUpdate.forEach { manga ->
|
mangaToUpdate.forEach { manga ->
|
||||||
if (updateJob?.isActive != true) {
|
if (updateJob?.isActive != true) {
|
||||||
|
@ -301,6 +303,10 @@ class LibraryUpdateService(
|
||||||
}
|
}
|
||||||
failedUpdates.add(manga to errorMessage)
|
failedUpdates.add(manga to errorMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (preferences.autoUpdateTrackers()) {
|
||||||
|
updateTrackings(manga, loggedServices)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notifier.cancelProgressNotification()
|
notifier.cancelProgressNotification()
|
||||||
|
@ -409,6 +415,13 @@ class LibraryUpdateService(
|
||||||
notifier.showProgressNotification(manga, progressCount++, mangaToUpdate.size)
|
notifier.showProgressNotification(manga, progressCount++, mangaToUpdate.size)
|
||||||
|
|
||||||
// Update the tracking details.
|
// Update the tracking details.
|
||||||
|
updateTrackings(manga, loggedServices)
|
||||||
|
}
|
||||||
|
|
||||||
|
notifier.cancelProgressNotification()
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun updateTrackings(manga: LibraryManga, loggedServices: List<TrackService>) {
|
||||||
db.getTracks(manga).executeAsBlocking()
|
db.getTracks(manga).executeAsBlocking()
|
||||||
.map { track ->
|
.map { track ->
|
||||||
supervisorScope {
|
supervisorScope {
|
||||||
|
@ -433,9 +446,6 @@ class LibraryUpdateService(
|
||||||
.awaitAll()
|
.awaitAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
notifier.cancelProgressNotification()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes basic file of update errors to cache dir.
|
* Writes basic file of update errors to cache dir.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -168,6 +168,8 @@ object PreferenceKeys {
|
||||||
|
|
||||||
const val autoUpdateMetadata = "auto_update_metadata"
|
const val autoUpdateMetadata = "auto_update_metadata"
|
||||||
|
|
||||||
|
const val autoUpdateTrackers = "auto_update_trackers"
|
||||||
|
|
||||||
const val showLibraryUpdateErrors = "show_library_update_errors"
|
const val showLibraryUpdateErrors = "show_library_update_errors"
|
||||||
|
|
||||||
const val downloadNew = "download_new"
|
const val downloadNew = "download_new"
|
||||||
|
|
|
@ -79,6 +79,8 @@ class PreferencesHelper(val context: Context) {
|
||||||
|
|
||||||
fun autoUpdateMetadata() = prefs.getBoolean(Keys.autoUpdateMetadata, false)
|
fun autoUpdateMetadata() = prefs.getBoolean(Keys.autoUpdateMetadata, false)
|
||||||
|
|
||||||
|
fun autoUpdateTrackers() = prefs.getBoolean(Keys.autoUpdateTrackers, false)
|
||||||
|
|
||||||
fun showLibraryUpdateErrors() = prefs.getBoolean(Keys.showLibraryUpdateErrors, false)
|
fun showLibraryUpdateErrors() = prefs.getBoolean(Keys.showLibraryUpdateErrors, false)
|
||||||
|
|
||||||
fun clear() = prefs.edit { clear() }
|
fun clear() = prefs.edit { clear() }
|
||||||
|
|
|
@ -241,6 +241,12 @@ class SettingsLibraryController : SettingsController() {
|
||||||
summaryRes = R.string.pref_library_update_refresh_metadata_summary
|
summaryRes = R.string.pref_library_update_refresh_metadata_summary
|
||||||
defaultValue = false
|
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 {
|
switchPreference {
|
||||||
key = Keys.showLibraryUpdateErrors
|
key = Keys.showLibraryUpdateErrors
|
||||||
titleRes = R.string.pref_library_update_error_notification
|
titleRes = R.string.pref_library_update_error_notification
|
||||||
|
|
|
@ -218,6 +218,8 @@
|
||||||
<string name="pref_update_only_non_completed">Only update ongoing manga</string>
|
<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">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_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="pref_library_update_error_notification">Show update errors notifications</string>
|
||||||
|
|
||||||
<string name="default_category">Default category</string>
|
<string name="default_category">Default category</string>
|
||||||
|
|
Loading…
Reference in a new issue