From 393b4916f61c2e44f482cf734d85c430a651e952 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Thu, 11 Feb 2016 22:59:24 +0100 Subject: [PATCH] Show batoto staff notice if updating chapters failed --- .../eu/kanade/tachiyomi/data/source/base/Source.java | 7 ++++++- .../tachiyomi/data/source/online/english/Batoto.java | 11 +++++++++++ .../tachiyomi/ui/manga/chapter/ChaptersFragment.java | 4 ++-- .../tachiyomi/ui/manga/chapter/ChaptersPresenter.java | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java b/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java index 417d60bd1..4550c70b2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java @@ -34,6 +34,8 @@ public abstract class Source extends BaseSource { protected Headers requestHeaders; protected LazyHeaders glideHeaders; + protected String lastError; + public Source() {} public Source(Context context) { @@ -88,7 +90,7 @@ public abstract class Source extends BaseSource { List chapters = parseHtmlToChapters(unparsedHtml); return !chapters.isEmpty() ? 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; } + public String getLastError() { + return lastError; + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.java b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.java index 5d96d361a..376665469 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.regex.Matcher; 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.Manga; 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.Page; import eu.kanade.tachiyomi.util.Parser; +import eu.kanade.tachiyomi.util.ToastUtil; import okhttp3.FormBody; import okhttp3.Headers; 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 LOGIN_URL = BASE_URL + "/forums/index.php?app=core&module=global§ion=login"; + public static final Pattern staffNotice = Pattern.compile("=+Batoto Staff Notice=+([^=]+)=+", Pattern.CASE_INSENSITIVE); + private Pattern datePattern; private Map dateFields; @@ -204,6 +208,13 @@ public class Batoto extends LoginSource { @Override protected List parseHtmlToChapters(String unparsedHtml) { + Matcher matcher = staffNotice.matcher(unparsedHtml); + if (matcher.find()) { + this.lastError = matcher.group(1); + } else { + lastError = ""; + } + Document parsedDocument = Jsoup.parse(unparsedHtml); List chapterList = new ArrayList<>(); diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java index d17d02f64..82dff1b82 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.java @@ -161,9 +161,9 @@ public class ChaptersFragment extends BaseRxFragment implemen swipeRefresh.setRefreshing(false); } - public void onFetchChaptersError() { + public void onFetchChaptersError(Throwable error) { swipeRefresh.setRefreshing(false); - ToastUtil.showShort(getContext(), R.string.fetch_chapters_error); + ToastUtil.showShort(getContext(), error.getMessage()); } public boolean isCatalogueManga() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java index bb5cfbada..5ef4de1a5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersPresenter.java @@ -67,7 +67,7 @@ public class ChaptersPresenter extends BasePresenter { startableFirst(FETCH_CHAPTERS, this::getOnlineChaptersObs, (view, result) -> view.onFetchChaptersDone(), - (view, error) -> view.onFetchChaptersError()); + (view, error) -> view.onFetchChaptersError(error)); startableLatestCache(CHAPTER_STATUS_CHANGES, this::getChapterStatusObs,