From 0278531e5166b4b3c95a8a5a431c4ef176a0bd03 Mon Sep 17 00:00:00 2001 From: inorichi Date: Mon, 12 Oct 2015 23:17:37 +0200 Subject: [PATCH] Search mangas from source (unusable yet) --- .../presenter/CatalogueListPresenter.java | 8 +++++++- .../eu/kanade/mangafeed/sources/Batoto.java | 20 +++++++++++++++++-- .../eu/kanade/mangafeed/sources/Source.java | 8 ++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) 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 ea3e240906..415e257f0f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/CatalogueListPresenter.java @@ -75,7 +75,13 @@ public class CatalogueListPresenter extends BasePresenter { public void getMangasFromSearch(int page) { subscriptions.remove(mMangaSearchSubscription); - // TODO fetch mangas from source + mMangaSearchSubscription = selectedSource.searchMangasFromNetwork(mSearchName, page) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .flatMap(Observable::from) + .map(this::networkToLocalManga) + .toList() + .subscribe(adapter::setItems); subscriptions.add(mMangaSearchSubscription); } 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 07c2565a4b..46647a77d9 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java +++ b/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java @@ -27,6 +27,8 @@ public class Batoto extends Source { public static final String BASE_URL = "www.bato.to"; public static final String INITIAL_UPDATE_URL = "http://bato.to/search_ajax?order_cond=views&order=desc&p="; + public static final String INITIAL_SEARCH_URL = "http://bato.to/search_ajax?"; + public Batoto(NetworkHelper networkService, CacheManager cacheManager) { super(networkService, cacheManager); @@ -99,14 +101,18 @@ public class Batoto extends Source { return INITIAL_UPDATE_URL + page; } + @Override + protected String getSearchUrl(String query, int page) { + return INITIAL_SEARCH_URL + "name=" + query + "&p=" + page; + } + @Override protected String getMangaUrl(String defaultMangaUrl) { String mangaId = defaultMangaUrl.substring(defaultMangaUrl.lastIndexOf("r") + 1); return "http://bato.to/comic_pop?id=" + mangaId; } - @Override - public List parsePopularMangasFromHtml(String unparsedHtml) { + private List parseMangasFromHtml(String unparsedHtml) { Document parsedDocument = Jsoup.parse(unparsedHtml); List updatedMangaList = new ArrayList<>(); @@ -121,6 +127,16 @@ public class Batoto extends Source { return updatedMangaList; } + @Override + public List parsePopularMangasFromHtml(String unparsedHtml) { + return parseMangasFromHtml(unparsedHtml); + } + + @Override + protected List parseSearchFromHtml(String unparsedHtml) { + return parseMangasFromHtml(unparsedHtml); + } + private Manga constructMangaFromHtmlBlock(Element htmlBlock) { Manga mangaFromHtmlBlock = new Manga(); diff --git a/app/src/main/java/eu/kanade/mangafeed/sources/Source.java b/app/src/main/java/eu/kanade/mangafeed/sources/Source.java index bbf3136a87..f3c1443442 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/Source.java +++ b/app/src/main/java/eu/kanade/mangafeed/sources/Source.java @@ -40,6 +40,12 @@ public abstract class Source { .flatMap(response -> Observable.just(parsePopularMangasFromHtml(response))); } + public Observable> searchMangasFromNetwork(String query, int page) { + return mNetworkService + .getStringResponse(getSearchUrl(query, page), mNetworkService.NULL_CACHE_CONTROL, mRequestHeaders) + .flatMap(response -> Observable.just(parseSearchFromHtml(response))); + } + // Get manga details from the source public Observable pullMangaFromNetwork(final String mangaUrl) { return mNetworkService @@ -98,7 +104,9 @@ public abstract class Source { public abstract int getSource(); protected abstract String getUrlFromPageNumber(int page); + protected abstract String getSearchUrl(String query, int page); protected abstract List parsePopularMangasFromHtml(String unparsedHtml); + protected abstract List parseSearchFromHtml(String unparsedHtml); protected abstract Manga parseHtmlToManga(String mangaUrl, String unparsedHtml); protected abstract List parseHtmlToChapters(String unparsedHtml); protected abstract List parseHtmlToPageUrls(String unparsedHtml);