download new chapters changes (#3193)

* download new chapters changes

* move initialFetchChapters logic into onNextChapters

* refractor download new chapter logic to be more explicit
This commit is contained in:
MCAxiaz
2020-05-17 14:33:26 -07:00
committed by GitHub
parent 102a372df9
commit ed029c52ae
4 changed files with 38 additions and 31 deletions

View File

@@ -23,6 +23,7 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.util.chapter.syncChaptersWithSource
import eu.kanade.tachiyomi.util.prepUpdateCover
import eu.kanade.tachiyomi.util.shouldDownloadNewChapters
import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.acquireWakeLock
import eu.kanade.tachiyomi.util.system.isServiceRunning
@@ -256,10 +257,6 @@ class LibraryUpdateService(
val newUpdates = ArrayList<Pair<LibraryManga, Array<Chapter>>>()
// List containing failed updates
val failedUpdates = ArrayList<Pair<Manga, String?>>()
// List containing categories that get included in downloads.
val categoriesToDownload = preferences.downloadNewCategories().get().map(String::toInt)
// Boolean to determine if user wants to automatically download new chapters.
val downloadNew = preferences.downloadNew().get()
// Boolean to determine if DownloadManager has downloads
var hasDownloads = false
@@ -278,11 +275,7 @@ class LibraryUpdateService(
// Filter out mangas without new chapters (or failed).
.filter { pair -> pair.first.isNotEmpty() }
.doOnNext {
if (downloadNew && (
categoriesToDownload.isEmpty() ||
manga.category in categoriesToDownload
)
) {
if (manga.shouldDownloadNewChapters(db, preferences)) {
downloadChapters(manga, it.first)
hasDownloads = true
}
@@ -309,7 +302,7 @@ class LibraryUpdateService(
if (newUpdates.isNotEmpty()) {
notifier.showUpdateNotifications(newUpdates)
if (downloadNew && hasDownloads) {
if (hasDownloads) {
DownloadService.start(this)
}
}
@@ -326,14 +319,9 @@ class LibraryUpdateService(
}
private fun downloadChapters(manga: Manga, chapters: List<Chapter>) {
// we need to get the chapters from the db so we have chapter ids
val mangaChapters = db.getChapters(manga).executeAsBlocking()
val dbChapters = chapters.map {
mangaChapters.find { mangaChapter -> mangaChapter.url == it.url }!!
}
// We don't want to start downloading while the library is updating, because websites
// may don't like it and they could ban the user.
downloadManager.downloadChapters(manga, dbChapters, false)
downloadManager.downloadChapters(manga, chapters, false)
}
/**