|
@@ -253,48 +253,35 @@ class LibraryUpdateService(
|
|
|
val failedUpdates = mutableListOf<Pair<Manga, String?>>()
|
|
|
var hasDownloads = false
|
|
|
|
|
|
- mangaToUpdate
|
|
|
- .map { manga ->
|
|
|
- if (updateJob?.isActive != true) {
|
|
|
- return
|
|
|
- }
|
|
|
+ mangaToUpdate.forEach { manga ->
|
|
|
+ if (updateJob?.isActive != true) {
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
- // 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 {
|
|
|
- val newChapters = updateManga(manga).first
|
|
|
- Pair(manga, newChapters)
|
|
|
- } catch (e: Throwable) {
|
|
|
- // 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
|
|
|
+ try {
|
|
|
+ val (newChapters, _) = updateManga(manga)
|
|
|
+
|
|
|
+ if (newChapters.isNotEmpty()) {
|
|
|
+ if (manga.shouldDownloadNewChapters(db, preferences)) {
|
|
|
+ downloadChapters(manga, newChapters)
|
|
|
+ hasDownloads = true
|
|
|
}
|
|
|
- failedUpdates.add(Pair(manga, errorMessage))
|
|
|
- Pair(manga, emptyList())
|
|
|
+
|
|
|
+ // Convert to the manga that contains new chapters
|
|
|
+ newUpdates.add(manga to newChapters.sortedByDescending { ch -> ch.source_order }.toTypedArray())
|
|
|
}
|
|
|
- }
|
|
|
- // Filter out mangas without new chapters (or failed).
|
|
|
- .filter { (_, newChapters) -> newChapters.isNotEmpty() }
|
|
|
- .forEach { (manga, newChapters) ->
|
|
|
- if (manga.shouldDownloadNewChapters(db, preferences)) {
|
|
|
- downloadChapters(manga, newChapters)
|
|
|
- hasDownloads = true
|
|
|
+ } catch (e: Throwable) {
|
|
|
+ val errorMessage = if (e is NoChaptersException) {
|
|
|
+ getString(R.string.no_chapters_error)
|
|
|
+ } else {
|
|
|
+ e.message
|
|
|
}
|
|
|
-
|
|
|
- // Convert to the manga that contains new chapters.
|
|
|
- newUpdates.add(
|
|
|
- Pair(
|
|
|
- manga,
|
|
|
- newChapters.sortedByDescending { ch -> ch.source_order }.toTypedArray()
|
|
|
- )
|
|
|
- )
|
|
|
+ failedUpdates.add(manga to errorMessage)
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // Notify result of the overall update.
|
|
|
notifier.cancelProgressNotification()
|
|
|
|
|
|
if (newUpdates.isNotEmpty()) {
|