|
@@ -3,11 +3,14 @@ package eu.kanade.tachiyomi.util.chapter
|
|
|
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.download.DownloadManager
|
|
|
import eu.kanade.tachiyomi.source.Source
|
|
|
import eu.kanade.tachiyomi.source.model.SChapter
|
|
|
import eu.kanade.tachiyomi.source.online.HttpSource
|
|
|
import java.util.Date
|
|
|
import java.util.TreeSet
|
|
|
+import uy.kohesive.injekt.Injekt
|
|
|
+import uy.kohesive.injekt.api.get
|
|
|
|
|
|
/**
|
|
|
* Helper method for syncing the list of chapters from the source with the ones from the database.
|
|
@@ -28,6 +31,8 @@ fun syncChaptersWithSource(
|
|
|
throw Exception("No chapters found")
|
|
|
}
|
|
|
|
|
|
+ val downloadManager: DownloadManager = Injekt.get()
|
|
|
+
|
|
|
// Chapters from db.
|
|
|
val dbChapters = db.getChapters(manga).executeAsBlocking()
|
|
|
|
|
@@ -60,6 +65,9 @@ fun syncChaptersWithSource(
|
|
|
ChapterRecognition.parseChapterNumber(sourceChapter, manga)
|
|
|
|
|
|
if (shouldUpdateDbChapter(dbChapter, sourceChapter)) {
|
|
|
+ if (dbChapter.name != sourceChapter.name && downloadManager.isChapterDownloaded(dbChapter, manga)) {
|
|
|
+ downloadManager.renameChapter(source, manga, dbChapter, sourceChapter)
|
|
|
+ }
|
|
|
dbChapter.scanlator = sourceChapter.scanlator
|
|
|
dbChapter.name = sourceChapter.name
|
|
|
dbChapter.date_upload = sourceChapter.date_upload
|