From f98095e6cbbd0cd65da967157b6e59b6329586b6 Mon Sep 17 00:00:00 2001 From: len Date: Sat, 12 Nov 2016 14:04:25 +0100 Subject: [PATCH] Allow to change chapter fields before inserting to database. Update Kotlin to 1.0.5 --- app/build.gradle | 2 +- .../tachiyomi/data/source/online/OnlineSource.kt | 10 ++++++++-- .../tachiyomi/data/source/online/russian/Mintmanga.kt | 2 +- .../tachiyomi/data/source/online/russian/Readmanga.kt | 2 +- .../java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c0586f2599..e80db108f2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -200,7 +200,7 @@ dependencies { } buildscript { - ext.kotlin_version = '1.0.4' + ext.kotlin_version = '1.0.5' repositories { mavenCentral() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt index cb77baa50b..84f0970d8d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/OnlineSource.kt @@ -461,8 +461,14 @@ abstract class OnlineSource() : Source { } - // Overridable method to allow custom parsing. - open fun parseChapterNumber(chapter: Chapter) { + /** + * Called before inserting a new chapter into database. Use it if you need to override chapter + * fields, like the title or the chapter number. Do not change anything to [manga]. + * + * @param chapter the chapter to be added. + * @param manga the manga of the chapter. + */ + open fun prepareNewChapter(chapter: Chapter, manga: Manga) { } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt index c56bf326bb..2c85c222e9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Mintmanga.kt @@ -90,7 +90,7 @@ class Mintmanga(override val id: Int) : ParsedOnlineSource() { } ?: 0 } - override fun parseChapterNumber(chapter: Chapter) { + override fun prepareNewChapter(chapter: Chapter, manga: Manga) { chapter.chapter_number = -2f } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt index 0775b1a1f8..82a1638e2e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/russian/Readmanga.kt @@ -93,7 +93,7 @@ class Readmanga(override val id: Int) : ParsedOnlineSource() { } ?: 0 } - override fun parseChapterNumber(chapter: Chapter) { + override fun prepareNewChapter(chapter: Chapter, manga: Manga) { chapter.chapter_number = -2f } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt index b654661759..249970a30c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt @@ -36,7 +36,7 @@ fun syncChaptersWithSource(db: DatabaseHelper, // Recognize number for new chapters. toAdd.forEach { if (source is OnlineSource) { - source.parseChapterNumber(it) + source.prepareNewChapter(it, manga) } ChapterRecognition.parseChapterNumber(it, manga) }