Fix force close when no more mangas found

This commit is contained in:
inorichi 2015-10-12 23:53:27 +02:00
parent 0278531e51
commit 0febdfb715
2 changed files with 31 additions and 8 deletions

View file

@ -2,6 +2,7 @@ package eu.kanade.mangafeed.presenter;
import android.content.Intent;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject;
@ -31,6 +32,7 @@ public class CatalogueListPresenter extends BasePresenter {
@Inject DatabaseHelper db;
private String mSearchName;
private boolean mSearchMode;
private final int SEARCH_TIMEOUT = 1000;
private Subscription mMangaFetchSubscription;
@ -81,7 +83,7 @@ public class CatalogueListPresenter extends BasePresenter {
.flatMap(Observable::from)
.map(this::networkToLocalManga)
.toList()
.subscribe(adapter::setItems);
.subscribe(adapter::addItems);
subscriptions.add(mMangaSearchSubscription);
}
@ -101,6 +103,8 @@ public class CatalogueListPresenter extends BasePresenter {
}
private void initializeSearch() {
mSearchName = "";
mSearchMode = false;
mSearchViewPublishSubject = PublishSubject.create();
mSearchViewSubscription = Observable.switchOnNext(mSearchViewPublishSubject)
.debounce(SEARCH_TIMEOUT, TimeUnit.MILLISECONDS)
@ -114,24 +118,39 @@ public class CatalogueListPresenter extends BasePresenter {
}
private void queryFromSearch(String query) {
// If search button clicked
if (mSearchName.equals("") && query.equals("")) {
return;
}
// If going to search mode
else if (mSearchName.equals("") && !query.equals("")) {
mSearchMode = true;
mSearchName = query;
if (!isSearchMode()) {
adapter.setItems(new ArrayList<>());
getMangasFromSearch(1);
}
// If going to normal mode
else if (!mSearchName.equals("") && query.equals("")) {
mSearchMode = false;
mSearchName = query;
adapter.setItems(new ArrayList<>());
getMangasFromSource(1);
} else {
}
// If query changes
else {
mSearchName = query;
adapter.setItems(new ArrayList<>());
getMangasFromSearch(1);
}
view.setScrollListener();
}
public void loadMoreMangas(int page) {
if (!isSearchMode()) {
if (!mSearchMode) {
getMangasFromSource(page);
} else {
getMangasFromSearch(page);
}
}
private boolean isSearchMode() {
return !mSearchName.equals("");
}
}

View file

@ -113,6 +113,10 @@ public class Batoto extends Source {
}
private List<Manga> parseMangasFromHtml(String unparsedHtml) {
if (unparsedHtml.contains("No (more) comics found!")) {
return new ArrayList<>();
}
Document parsedDocument = Jsoup.parse(unparsedHtml);
List<Manga> updatedMangaList = new ArrayList<>();