mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-03 15:48:56 +01:00
Add update notifications for EH/EXH galleries
This commit is contained in:
@@ -26,9 +26,9 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
/**
|
||||
* @param chapters Cannot be an empty list!
|
||||
*
|
||||
* @return Pair<Accepted, Discarded>
|
||||
* @return Triple<Accepted, Discarded, HasNew>
|
||||
*/
|
||||
fun findAcceptedRootAndDiscardOthers(sourceId: Long, chapters: List<Chapter>): Single<Pair<ChapterChain, List<ChapterChain>>> {
|
||||
fun findAcceptedRootAndDiscardOthers(sourceId: Long, chapters: List<Chapter>): Single<Triple<ChapterChain, List<ChapterChain>, Boolean>> {
|
||||
// Find other chains
|
||||
val chainsObservable = Observable.merge(chapters.map { chapter ->
|
||||
db.getChapters(chapter.url).asRxSingle().toObservable()
|
||||
@@ -62,6 +62,8 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
val chainsAsChapters = chains.flatMap { it.chapters }
|
||||
|
||||
if(toDiscard.isNotEmpty()) {
|
||||
var new = false
|
||||
|
||||
// Copy chain chapters to curChapters
|
||||
val newChapters = toDiscard
|
||||
.flatMap { chain ->
|
||||
@@ -98,6 +100,7 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
existing.bookmark = existing.bookmark || chapter.bookmark
|
||||
curChapters
|
||||
} else if (chapter.date_upload > 0) { // Ignore chapters using the old system
|
||||
new = true
|
||||
curChapters + ChapterImpl().apply {
|
||||
manga_id = accepted.manga.id
|
||||
url = chapter.url
|
||||
@@ -145,8 +148,8 @@ class EHentaiUpdateHelper(context: Context) {
|
||||
db.setMangaCategories(newCategories, rootsToMutate.map { it.manga })
|
||||
}
|
||||
|
||||
newAccepted to toDiscard
|
||||
} else accepted to emptyList()
|
||||
Triple(newAccepted, toDiscard, new)
|
||||
} else Triple(accepted, emptyList(), false)
|
||||
}.toSingle()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.kizitonwose.time.hours
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateNotifier
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
@@ -49,6 +50,8 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
|
||||
private val updateHelper: EHentaiUpdateHelper by injectLazy()
|
||||
private val logger = XLog.tag("EHUpdater")
|
||||
|
||||
private val updateNotifier by lazy { LibraryUpdateNotifier(this) }
|
||||
|
||||
/**
|
||||
* This method is called if the system has determined that you must stop execution of your job
|
||||
* even before you've had a chance to call [.jobFinished].
|
||||
@@ -152,6 +155,7 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
|
||||
|
||||
var failuresThisIteration = 0
|
||||
var updatedThisIteration = 0
|
||||
val updatedManga = mutableListOf<Manga>()
|
||||
val modifiedThisIteration = mutableSetOf<Long>()
|
||||
|
||||
try {
|
||||
@@ -205,9 +209,13 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
|
||||
}
|
||||
|
||||
// Find accepted root and discard others
|
||||
val (acceptedRoot, discardedRoots) =
|
||||
val (acceptedRoot, discardedRoots, hasNew) =
|
||||
updateHelper.findAcceptedRootAndDiscardOthers(manga.source, chapters).await()
|
||||
|
||||
if(hasNew && updatedManga.none { it.id == acceptedRoot.manga.id }) {
|
||||
updatedManga += acceptedRoot.manga
|
||||
}
|
||||
|
||||
modifiedThisIteration += acceptedRoot.manga.id!!
|
||||
modifiedThisIteration += discardedRoots.map { it.manga.id!! }
|
||||
updatedThisIteration++
|
||||
@@ -222,6 +230,8 @@ class EHentaiUpdateWorker: JobService(), CoroutineScope {
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
updateNotifier.showResultNotification(updatedManga)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user