Fix incorrect batoto thumbnail url. Create a function to copy the manga from network to local.

This commit is contained in:
inorichi 2015-10-13 16:47:27 +02:00
parent 82ac2b3223
commit 13b4f5c385
3 changed files with 49 additions and 17 deletions

View File

@ -15,64 +15,49 @@ public class Manga {
@StorIOSQLiteColumn(name = MangasTable.COLUMN_ID, key = true) @StorIOSQLiteColumn(name = MangasTable.COLUMN_ID, key = true)
public Long id; public Long id;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_SOURCE) @StorIOSQLiteColumn(name = MangasTable.COLUMN_SOURCE)
public int source; public int source;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_URL) @StorIOSQLiteColumn(name = MangasTable.COLUMN_URL)
public String url; public String url;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_ARTIST) @StorIOSQLiteColumn(name = MangasTable.COLUMN_ARTIST)
public String artist; public String artist;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_AUTHOR) @StorIOSQLiteColumn(name = MangasTable.COLUMN_AUTHOR)
public String author; public String author;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_DESCRIPTION) @StorIOSQLiteColumn(name = MangasTable.COLUMN_DESCRIPTION)
public String description; public String description;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_GENRE) @StorIOSQLiteColumn(name = MangasTable.COLUMN_GENRE)
public String genre; public String genre;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_TITLE) @StorIOSQLiteColumn(name = MangasTable.COLUMN_TITLE)
public String title; public String title;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_STATUS) @StorIOSQLiteColumn(name = MangasTable.COLUMN_STATUS)
public String status; public String status;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_THUMBNAIL_URL) @StorIOSQLiteColumn(name = MangasTable.COLUMN_THUMBNAIL_URL)
public String thumbnail_url; public String thumbnail_url;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_RANK) @StorIOSQLiteColumn(name = MangasTable.COLUMN_RANK)
public int rank; public int rank;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_LAST_UPDATE) @StorIOSQLiteColumn(name = MangasTable.COLUMN_LAST_UPDATE)
public long last_update; public long last_update;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_INITIALIZED) @StorIOSQLiteColumn(name = MangasTable.COLUMN_INITIALIZED)
public boolean initialized; public boolean initialized;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_VIEWER) @StorIOSQLiteColumn(name = MangasTable.COLUMN_VIEWER)
public int viewer; public int viewer;
@NonNull
@StorIOSQLiteColumn(name = MangasTable.COLUMN_CHAPTER_ORDER) @StorIOSQLiteColumn(name = MangasTable.COLUMN_CHAPTER_ORDER)
public int chapter_order; public int chapter_order;
@NonNull public int unread;
public int unread = 0;
public Manga() {} public Manga() {}
@ -100,6 +85,34 @@ public class Manga {
return new Manga(title, author, artist, url, description, genre, status, rank, thumbnail_url); 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 @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;

View File

@ -97,6 +97,25 @@ public class CatalogueListPresenter extends BasePresenter {
return localManga; return localManga;
} }
private Observable<Manga> getMangaDetails(Manga manga) {
Observable<Manga> 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) { public void onQueryTextChange(String query) {
if (mSearchViewPublishSubject != null) if (mSearchViewPublishSubject != null)
mSearchViewPublishSubject.onNext(Observable.just(query)); mSearchViewPublishSubject.onNext(Observable.just(query));

View File

@ -187,7 +187,7 @@ public class Batoto extends Source {
Elements artistElements = parsedDocument.select("a[href^=http://bato.to/search?artist_name]"); Elements artistElements = parsedDocument.select("a[href^=http://bato.to/search?artist_name]");
Element descriptionElement = parsedDocument.select("tr").get(5); Element descriptionElement = parsedDocument.select("tr").get(5);
Elements genreElements = parsedDocument.select("img[src=http://bato.to/forums/public/style_images/master/bullet_black.png]"); 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(); Manga newManga = new Manga();
newManga.url = mangaUrl; newManga.url = mangaUrl;