From 8f36d698cf2ed9456de2388bbd9a9a53310124fa Mon Sep 17 00:00:00 2001 From: NerdNumber9 Date: Fri, 9 Aug 2019 09:48:31 -0400 Subject: [PATCH] Fix EHentai gallery update notifications for real --- app/src/main/java/exh/eh/EHentaiUpdateWorker.kt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/exh/eh/EHentaiUpdateWorker.kt b/app/src/main/java/exh/eh/EHentaiUpdateWorker.kt index 9b3de9f05..ab7b3ecff 100644 --- a/app/src/main/java/exh/eh/EHentaiUpdateWorker.kt +++ b/app/src/main/java/exh/eh/EHentaiUpdateWorker.kt @@ -181,7 +181,7 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope { continue } - val chapters = try { + val (new, chapters) = try { updateEntryAndGetChapters(manga) } catch (e: GalleryNotUpdatedException) { if (e.network) { @@ -212,7 +212,8 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope { val (acceptedRoot, discardedRoots, hasNew) = updateHelper.findAcceptedRootAndDiscardOthers(manga.source, chapters).await() - if(hasNew && updatedManga.none { it.id == acceptedRoot.manga.id }) { + if((new.isNotEmpty() && manga.id == acceptedRoot.manga.id) + || (hasNew && updatedManga.none { it.id == acceptedRoot.manga.id })) { updatedManga += acceptedRoot.manga } @@ -237,7 +238,8 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope { } } - suspend fun updateEntryAndGetChapters(manga: Manga): List { + // New, current + suspend fun updateEntryAndGetChapters(manga: Manga): Pair, List> { val source = sourceManager.get(manga.source) as? EHentai ?: throw GalleryNotUpdatedException(false, IllegalStateException("Missing EH-based source (${manga.source})!")) @@ -247,8 +249,8 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope { db.insertManga(manga).asRxSingle().await() val newChapters = source.fetchChapterList(manga).toSingle().await(Schedulers.io()) - syncChaptersWithSource(db, newChapters, manga, source) // Not suspending, but does block, maybe fix this? - return db.getChapters(manga).await() + val (new, _) = syncChaptersWithSource(db, newChapters, manga, source) // Not suspending, but does block, maybe fix this? + return new to db.getChapters(manga).await() } catch(t: Throwable) { if(t is EHentai.GalleryNotFoundException) { val meta = db.getFlatMetadataForManga(manga.id!!).await()?.raise()