From 13b4f5c38557b8461cc359724276c198d9e2bfd5 Mon Sep 17 00:00:00 2001 From: inorichi Date: Tue, 13 Oct 2015 16:47:27 +0200 Subject: [PATCH] Fix incorrect batoto thumbnail url. Create a function to copy the manga from network to local. --- .../kanade/mangafeed/data/models/Manga.java | 45 ++++++++++++------- .../presenter/CatalogueListPresenter.java | 19 ++++++++ .../eu/kanade/mangafeed/sources/Batoto.java | 2 +- 3 files changed, 49 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java b/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java index 12b12b2aa..b71f75df5 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/models/Manga.java @@ -15,64 +15,49 @@ public class Manga { @StorIOSQLiteColumn(name = MangasTable.COLUMN_ID, key = true) public Long id; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_SOURCE) public int source; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_URL) public String url; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_ARTIST) public String artist; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_AUTHOR) public String author; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_DESCRIPTION) public String description; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_GENRE) public String genre; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_TITLE) public String title; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_STATUS) public String status; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_THUMBNAIL_URL) public String thumbnail_url; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_RANK) public int rank; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_LAST_UPDATE) public long last_update; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_INITIALIZED) public boolean initialized; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_VIEWER) public int viewer; - @NonNull @StorIOSQLiteColumn(name = MangasTable.COLUMN_CHAPTER_ORDER) public int chapter_order; - @NonNull - public int unread = 0; + public int unread; public Manga() {} @@ -100,6 +85,34 @@ public class Manga { return new Manga(title, author, artist, url, description, genre, status, rank, thumbnail_url); } + public static void copyFromNetwork(Manga local, Manga network) { + if (network.title != null) + local.title = network.title; + + if (network.author != null) + local.author = network.author; + + if (network.artist != null) + local.artist = network.artist; + + if (network.url != null) + local.url = network.url; + + if (network.description != null) + local.description = network.description; + + if (network.genre != null) + local.genre = network.genre; + + if (network.status != null) + local.status = network.status; + + if (network.thumbnail_url != null) + local.thumbnail_url = network.thumbnail_url; + + local.initialized = true; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java index e8526ce42..496466445 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java @@ -97,6 +97,25 @@ public class CatalogueListPresenter extends BasePresenter { return localManga; } + private Observable getMangaDetails(Manga manga) { + Observable mangaObs = Observable.just(manga); + if (!manga.initialized) { + return mangaObs + .subscribeOn(Schedulers.io()) + .flatMap(localManga -> { + Timber.e("Request " + localManga.url); + return selectedSource.pullMangaFromNetwork(localManga.url); + }) + .flatMap(networkManga -> { + Manga.copyFromNetwork(manga, networkManga); + Timber.w("Net manga " + manga.thumbnail_url); + db.insertMangaBlock(manga); + return Observable.just(manga); + }); + } + return mangaObs; + } + public void onQueryTextChange(String query) { if (mSearchViewPublishSubject != null) mSearchViewPublishSubject.onNext(Observable.just(query)); diff --git a/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java b/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java index f811f461b..73de744a2 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java +++ b/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java @@ -187,7 +187,7 @@ public class Batoto extends Source { Elements artistElements = parsedDocument.select("a[href^=http://bato.to/search?artist_name]"); Element descriptionElement = parsedDocument.select("tr").get(5); Elements genreElements = parsedDocument.select("img[src=http://bato.to/forums/public/style_images/master/bullet_black.png]"); - Element thumbnailUrlElement = parsedDocument.select("img[src^=http://img.batoto.net/forums/uploads/]").first(); + Element thumbnailUrlElement = parsedDocument.select("img[src^=http://img.bato.to/forums/uploads/]").first(); Manga newManga = new Manga(); newManga.url = mangaUrl;