Search mangas from source (unusable yet)
This commit is contained in:
parent
66ab8caf76
commit
0278531e51
3 changed files with 33 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<Manga> parsePopularMangasFromHtml(String unparsedHtml) {
|
||||
private List<Manga> parseMangasFromHtml(String unparsedHtml) {
|
||||
Document parsedDocument = Jsoup.parse(unparsedHtml);
|
||||
|
||||
List<Manga> updatedMangaList = new ArrayList<>();
|
||||
|
@ -121,6 +127,16 @@ public class Batoto extends Source {
|
|||
return updatedMangaList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Manga> parsePopularMangasFromHtml(String unparsedHtml) {
|
||||
return parseMangasFromHtml(unparsedHtml);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Manga> parseSearchFromHtml(String unparsedHtml) {
|
||||
return parseMangasFromHtml(unparsedHtml);
|
||||
}
|
||||
|
||||
private Manga constructMangaFromHtmlBlock(Element htmlBlock) {
|
||||
Manga mangaFromHtmlBlock = new Manga();
|
||||
|
||||
|
|
|
@ -40,6 +40,12 @@ public abstract class Source {
|
|||
.flatMap(response -> Observable.just(parsePopularMangasFromHtml(response)));
|
||||
}
|
||||
|
||||
public Observable<List<Manga>> 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<Manga> 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<Manga> parsePopularMangasFromHtml(String unparsedHtml);
|
||||
protected abstract List<Manga> parseSearchFromHtml(String unparsedHtml);
|
||||
protected abstract Manga parseHtmlToManga(String mangaUrl, String unparsedHtml);
|
||||
protected abstract List<Chapter> parseHtmlToChapters(String unparsedHtml);
|
||||
protected abstract List<String> parseHtmlToPageUrls(String unparsedHtml);
|
||||
|
|
Reference in a new issue