Don't show update progress notifications if job isn't active anymore (closes #5844)

This commit is contained in:
arkon 2021-09-04 10:24:55 -04:00
parent 2d3a1b6a9e
commit 7083b3d912

View file

@ -294,13 +294,11 @@ class LibraryUpdateService(
return@async
}
currentlyUpdatingManga.add(manga)
notifier.showProgressNotification(
withUpdateNotification(
currentlyUpdatingManga,
progressCount.get(),
mangaToUpdate.size
)
progressCount,
manga,
) { manga ->
try {
val (newChapters, _) = updateManga(manga)
@ -311,31 +309,31 @@ class LibraryUpdateService(
}
// Convert to the manga that contains new chapters
newUpdates.add(manga to newChapters.sortedByDescending { ch -> ch.source_order }.toTypedArray())
newUpdates.add(
manga to newChapters.sortedByDescending { ch -> ch.source_order }
.toTypedArray()
)
}
} catch (e: Throwable) {
val errorMessage = if (e is NoChaptersException) {
val errorMessage = when (e) {
is NoChaptersException -> {
getString(R.string.no_chapters_error)
} else if (e is SourceManager.SourceNotInstalledException) {
}
is SourceManager.SourceNotInstalledException -> {
// failedUpdates will already have the source, don't need to copy it into the message
getString(R.string.loader_not_implemented_error)
} else {
}
else -> {
e.message
}
}
failedUpdates.add(manga to errorMessage)
}
if (preferences.autoUpdateTrackers()) {
updateTrackings(manga, loggedServices)
}
currentlyUpdatingManga.remove(manga)
progressCount.andIncrement
notifier.showProgressNotification(
currentlyUpdatingManga,
progressCount.get(),
mangaToUpdate.size
)
}
}
}
}
@ -418,13 +416,11 @@ class LibraryUpdateService(
return@async
}
currentlyUpdatingManga.add(manga)
notifier.showProgressNotification(
withUpdateNotification(
currentlyUpdatingManga,
progressCount.get(),
mangaToUpdate.size
)
progressCount,
manga,
) { manga ->
sourceManager.get(manga.source)?.let { source ->
try {
val networkManga =
@ -452,6 +448,7 @@ class LibraryUpdateService(
}
}
}
}
.awaitAll()
}
@ -506,6 +503,38 @@ class LibraryUpdateService(
.awaitAll()
}
private suspend fun withUpdateNotification(
updatingManga: CopyOnWriteArrayList<LibraryManga>,
completed: AtomicInteger,
manga: LibraryManga,
block: suspend (LibraryManga) -> Unit,
) {
if (updateJob?.isActive != true) {
return
}
updatingManga.add(manga)
notifier.showProgressNotification(
updatingManga,
completed.get(),
mangaToUpdate.size
)
block(manga)
if (updateJob?.isActive != true) {
return
}
updatingManga.remove(manga)
completed.andIncrement
notifier.showProgressNotification(
updatingManga,
completed.get(),
mangaToUpdate.size
)
}
/**
* Writes basic file of update errors to cache dir.
*/