Show batoto staff notice if updating chapters failed

This commit is contained in:
Robin Appelman 2016-02-11 22:59:24 +01:00
parent cb3c3af865
commit 393b4916f6
4 changed files with 20 additions and 4 deletions

View File

@ -34,6 +34,8 @@ public abstract class Source extends BaseSource {
protected Headers requestHeaders; protected Headers requestHeaders;
protected LazyHeaders glideHeaders; protected LazyHeaders glideHeaders;
protected String lastError;
public Source() {} public Source() {}
public Source(Context context) { public Source(Context context) {
@ -88,7 +90,7 @@ public abstract class Source extends BaseSource {
List<Chapter> chapters = parseHtmlToChapters(unparsedHtml); List<Chapter> chapters = parseHtmlToChapters(unparsedHtml);
return !chapters.isEmpty() ? return !chapters.isEmpty() ?
Observable.just(chapters) : Observable.just(chapters) :
Observable.error(new Exception("No chapters found")); Observable.error(new Exception((getLastError().equals("")) ? "No chapters found" : getLastError()));
}); });
} }
@ -216,4 +218,7 @@ public abstract class Source extends BaseSource {
return glideHeaders; return glideHeaders;
} }
public String getLastError() {
return lastError;
}
} }

View File

@ -24,6 +24,7 @@ import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import eu.kanade.tachiyomi.R;
import eu.kanade.tachiyomi.data.database.models.Chapter; import eu.kanade.tachiyomi.data.database.models.Chapter;
import eu.kanade.tachiyomi.data.database.models.Manga; import eu.kanade.tachiyomi.data.database.models.Manga;
import eu.kanade.tachiyomi.data.source.SourceManager; import eu.kanade.tachiyomi.data.source.SourceManager;
@ -31,6 +32,7 @@ import eu.kanade.tachiyomi.data.source.base.LoginSource;
import eu.kanade.tachiyomi.data.source.model.MangasPage; import eu.kanade.tachiyomi.data.source.model.MangasPage;
import eu.kanade.tachiyomi.data.source.model.Page; import eu.kanade.tachiyomi.data.source.model.Page;
import eu.kanade.tachiyomi.util.Parser; import eu.kanade.tachiyomi.util.Parser;
import eu.kanade.tachiyomi.util.ToastUtil;
import okhttp3.FormBody; import okhttp3.FormBody;
import okhttp3.Headers; import okhttp3.Headers;
import okhttp3.Response; import okhttp3.Response;
@ -47,6 +49,8 @@ public class Batoto extends LoginSource {
public static final String MANGA_URL = "/comic_pop?id=%s"; public static final String MANGA_URL = "/comic_pop?id=%s";
public static final String LOGIN_URL = BASE_URL + "/forums/index.php?app=core&module=global&section=login"; public static final String LOGIN_URL = BASE_URL + "/forums/index.php?app=core&module=global&section=login";
public static final Pattern staffNotice = Pattern.compile("=+Batoto Staff Notice=+([^=]+)=+", Pattern.CASE_INSENSITIVE);
private Pattern datePattern; private Pattern datePattern;
private Map<String, Integer> dateFields; private Map<String, Integer> dateFields;
@ -204,6 +208,13 @@ public class Batoto extends LoginSource {
@Override @Override
protected List<Chapter> parseHtmlToChapters(String unparsedHtml) { protected List<Chapter> parseHtmlToChapters(String unparsedHtml) {
Matcher matcher = staffNotice.matcher(unparsedHtml);
if (matcher.find()) {
this.lastError = matcher.group(1);
} else {
lastError = "";
}
Document parsedDocument = Jsoup.parse(unparsedHtml); Document parsedDocument = Jsoup.parse(unparsedHtml);
List<Chapter> chapterList = new ArrayList<>(); List<Chapter> chapterList = new ArrayList<>();

View File

@ -161,9 +161,9 @@ public class ChaptersFragment extends BaseRxFragment<ChaptersPresenter> implemen
swipeRefresh.setRefreshing(false); swipeRefresh.setRefreshing(false);
} }
public void onFetchChaptersError() { public void onFetchChaptersError(Throwable error) {
swipeRefresh.setRefreshing(false); swipeRefresh.setRefreshing(false);
ToastUtil.showShort(getContext(), R.string.fetch_chapters_error); ToastUtil.showShort(getContext(), error.getMessage());
} }
public boolean isCatalogueManga() { public boolean isCatalogueManga() {

View File

@ -67,7 +67,7 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
startableFirst(FETCH_CHAPTERS, startableFirst(FETCH_CHAPTERS,
this::getOnlineChaptersObs, this::getOnlineChaptersObs,
(view, result) -> view.onFetchChaptersDone(), (view, result) -> view.onFetchChaptersDone(),
(view, error) -> view.onFetchChaptersError()); (view, error) -> view.onFetchChaptersError(error));
startableLatestCache(CHAPTER_STATUS_CHANGES, startableLatestCache(CHAPTER_STATUS_CHANGES,
this::getChapterStatusObs, this::getChapterStatusObs,