mirror of
https://git.mihon.tech/mihonapp/mihon
synced 2024-11-24 14:15:54 +03:00
Fix incorrect batoto thumbnail url. Create a function to copy the manga from network to local.
This commit is contained in:
parent
82ac2b3223
commit
13b4f5c385
3 changed files with 49 additions and 17 deletions
|
@ -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;
|
||||
|
|
|
@ -97,6 +97,25 @@ public class CatalogueListPresenter extends BasePresenter {
|
|||
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) {
|
||||
if (mSearchViewPublishSubject != null)
|
||||
mSearchViewPublishSubject.onNext(Observable.just(query));
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue