From d4bb092543e030ddf89677499a65a668c0f95f7d Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 26 Feb 2016 18:29:08 +0100 Subject: [PATCH] Allow custom parsing of chapter number on sources --- .../eu/kanade/tachiyomi/data/database/DatabaseHelper.java | 4 +++- .../eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt | 5 +++-- .../java/eu/kanade/tachiyomi/data/source/base/Source.java | 5 +++++ .../kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.java b/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.java index 5c2c0c1ed..36b41a754 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/DatabaseHelper.java @@ -40,6 +40,7 @@ import eu.kanade.tachiyomi.data.database.tables.MangaCategoryTable; import eu.kanade.tachiyomi.data.database.tables.MangaSyncTable; import eu.kanade.tachiyomi.data.database.tables.MangaTable; import eu.kanade.tachiyomi.data.mangasync.base.MangaSyncService; +import eu.kanade.tachiyomi.data.source.base.Source; import eu.kanade.tachiyomi.util.ChapterRecognition; import rx.Observable; @@ -240,13 +241,14 @@ public class DatabaseHelper { } // Add new chapters or delete if the source deletes them - public Observable> insertOrRemoveChapters(Manga manga, List sourceChapters) { + public Observable> insertOrRemoveChapters(Manga manga, List sourceChapters, Source source) { List dbChapters = getChapters(manga).executeAsBlocking(); Observable> newChapters = Observable.from(sourceChapters) .filter(c -> !dbChapters.contains(c)) .doOnNext(c -> { c.manga_id = manga.id; + source.parseChapterNumber(c); ChapterRecognition.parseChapterNumber(c, manga); }) .toList(); diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt index c5a4a22d0..19d683d40 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateService.kt @@ -201,9 +201,10 @@ class LibraryUpdateService : Service() { * @return a pair of the inserted and removed chapters. */ fun updateManga(manga: Manga): Observable> { - return sourceManager.get(manga.source)!! + val source = sourceManager.get(manga.source) + return source!! .pullChaptersFromNetwork(manga.url) - .flatMap { db.insertOrRemoveChapters(manga, it) } + .flatMap { db.insertOrRemoveChapters(manga, it, source) } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java b/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java index 89e2738aa..0b4680a08 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java @@ -235,6 +235,11 @@ public abstract class Source extends BaseSource { return getId() + chapterUrl; } + // Overridable method to allow custom parsing. + public void parseChapterNumber(Chapter chapter) { + + } + protected LazyHeaders.Builder glideHeadersBuilder() { LazyHeaders.Builder builder = new LazyHeaders.Builder(); for (Map.Entry> entry : requestHeaders.toMultimap().entrySet()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java index b2e940448..8a86e277b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java @@ -119,7 +119,7 @@ public class ChaptersPresenter extends BasePresenter { private Observable> getOnlineChaptersObs() { return source.pullChaptersFromNetwork(manga.url) .subscribeOn(Schedulers.io()) - .flatMap(chapters -> db.insertOrRemoveChapters(manga, chapters)) + .flatMap(chapters -> db.insertOrRemoveChapters(manga, chapters, source)) .observeOn(AndroidSchedulers.mainThread()); }