From 3561392d245bcc7a45b7bd84dbfa2218a23d0fdc Mon Sep 17 00:00:00 2001 From: inorichi Date: Tue, 27 Oct 2015 18:40:13 +0100 Subject: [PATCH] Retry calls --- .../mangafeed/data/helpers/NetworkHelper.java | 4 +-- .../mangafeed/presenter/ReaderPresenter.java | 28 +++++++++++-------- .../kanade/mangafeed/sources/base/Source.java | 3 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java b/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java index a581c70cde..7ce568d620 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/helpers/NetworkHelper.java @@ -30,7 +30,7 @@ public final class NetworkHelper { } public Observable getResponse(final String url, final Headers headers, final CacheControl cacheControl) { - return Observable.create(subscriber -> { + return Observable.create(subscriber -> { try { if (!subscriber.isUnsubscribed()) { Request request = new Request.Builder() @@ -44,7 +44,7 @@ public final class NetworkHelper { } catch (Throwable e) { subscriber.onError(e); } - }); + }).retry(3); } public Observable mapResponseToString(final Response response) { diff --git a/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java b/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java index 74037f8a37..46248f8251 100644 --- a/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/presenter/ReaderPresenter.java @@ -23,6 +23,7 @@ import icepick.State; import rx.Observable; import rx.android.schedulers.AndroidSchedulers; import rx.schedulers.Schedulers; +import timber.log.Timber; public class ReaderPresenter extends BasePresenter { @@ -45,9 +46,9 @@ public class ReaderPresenter extends BasePresenter { () -> getPageListObservable() .doOnNext(pages -> pageList = pages) .doOnCompleted(() -> start(GET_PAGE_IMAGES)), - (view, pages) -> { - view.onPageListReady(pages); - }); + (view, pages) -> view.onPageListReady(pages), + (view, error) -> Timber.e("An error occurred while downloading page list") + ); restartableReplay(GET_PAGE_IMAGES, this::getPageImagesObservable, @@ -56,7 +57,8 @@ public class ReaderPresenter extends BasePresenter { if (page.getPageNumber() == savedSelectedPage) { view.setCurrentPage(savedSelectedPage); } - }); + }, + (view, error) -> Timber.e("An error occurred while downloading an image")); } @Override @@ -110,15 +112,17 @@ public class ReaderPresenter extends BasePresenter { } private Observable downloadImage(Page page) { - FutureTarget future = glideDownloader.load(page.getImageUrl()) - .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL); + if (page.getImageUrl() != null) { + FutureTarget future = glideDownloader.load(page.getImageUrl()) + .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL); - try { - File cacheFile = future.get(); - page.setImagePath(cacheFile.getCanonicalPath()); - page.setStatus(Page.READY); - } catch (Exception e) { - page.setStatus(Page.ERROR); + try { + File cacheFile = future.get(); + page.setImagePath(cacheFile.getCanonicalPath()); + page.setStatus(Page.READY); + } catch (Exception e) { + page.setStatus(Page.ERROR); + } } return Observable.just(page); diff --git a/app/src/main/java/eu/kanade/mangafeed/sources/base/Source.java b/app/src/main/java/eu/kanade/mangafeed/sources/base/Source.java index 0c43b47f8e..edcbf9ca5f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/base/Source.java +++ b/app/src/main/java/eu/kanade/mangafeed/sources/base/Source.java @@ -103,7 +103,8 @@ public abstract class Source extends BaseSource { } public void savePageList(String chapterUrl, List pages) { - mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages); + if (pages != null) + mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages); } private List convertToPages(List pageUrls) {