Clean up LibraryUpdateService a bit
(cherry picked from commit 5af68186d6de62a5746d758977a9ca834c25f547) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt
This commit is contained in:
parent
a207b4b729
commit
cb1ea6f571
@ -342,51 +342,40 @@ class LibraryUpdateService(
|
|||||||
async {
|
async {
|
||||||
semaphore.withPermit {
|
semaphore.withPermit {
|
||||||
mangaInSource
|
mangaInSource
|
||||||
.map { manga ->
|
.onEach { manga ->
|
||||||
if (updateJob?.isActive != true) {
|
if (updateJob?.isActive != true) {
|
||||||
return@async
|
return@async
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify manga that will update.
|
|
||||||
notifier.showProgressNotification(manga, progressCount.andIncrement, mangaToUpdate.size)
|
notifier.showProgressNotification(manga, progressCount.andIncrement, mangaToUpdate.size)
|
||||||
|
|
||||||
// Update the chapters of the manga
|
|
||||||
try {
|
try {
|
||||||
val newChapters = updateManga(manga).first
|
val (newChapters, _) = updateManga(manga)
|
||||||
Pair(manga, newChapters)
|
|
||||||
} catch (e: Throwable) {
|
if (newChapters.isNotEmpty()) {
|
||||||
// If there's any error, return empty update and continue.
|
|
||||||
val errorMessage = if (e is NoChaptersException) {
|
|
||||||
getString(R.string.no_chapters_error)
|
|
||||||
} else {
|
|
||||||
e.message
|
|
||||||
}
|
|
||||||
failedUpdates.add(Pair(manga, errorMessage))
|
|
||||||
Pair(manga, emptyList())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Filter out mangas without new chapters (or failed).
|
|
||||||
.filter { (_, newChapters) -> newChapters.isNotEmpty() }
|
|
||||||
.forEach { (manga, newChapters) ->
|
|
||||||
if (manga.shouldDownloadNewChapters(db, preferences)) {
|
if (manga.shouldDownloadNewChapters(db, preferences)) {
|
||||||
downloadChapters(manga, newChapters)
|
downloadChapters(manga, newChapters)
|
||||||
hasDownloads = true
|
hasDownloads = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to the manga that contains new chapters.
|
// Convert to the manga that contains new chapters
|
||||||
newUpdates.add(
|
newUpdates.add(manga to newChapters.sortedByDescending { ch -> ch.source_order }
|
||||||
Pair(
|
.toTypedArray())
|
||||||
manga,
|
}
|
||||||
newChapters.sortedByDescending { ch -> ch.source_order }.toTypedArray()
|
} catch (e: Throwable) {
|
||||||
)
|
val errorMessage = if (e is NoChaptersException) {
|
||||||
)
|
getString(R.string.no_chapters_error)
|
||||||
|
} else {
|
||||||
|
e.message
|
||||||
|
}
|
||||||
|
failedUpdates.add(manga to errorMessage)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.awaitAll()
|
}.awaitAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify result of the overall update.
|
|
||||||
notifier.cancelProgressNotification()
|
notifier.cancelProgressNotification()
|
||||||
|
|
||||||
if (newUpdates.isNotEmpty()) {
|
if (newUpdates.isNotEmpty()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user