mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-25 02:18:24 +01:00
Retry calls
This commit is contained in:
parent
68e5efb02b
commit
3561392d24
@ -30,7 +30,7 @@ public final class NetworkHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Observable<Response> getResponse(final String url, final Headers headers, final CacheControl cacheControl) {
|
public Observable<Response> getResponse(final String url, final Headers headers, final CacheControl cacheControl) {
|
||||||
return Observable.create(subscriber -> {
|
return Observable.<Response>create(subscriber -> {
|
||||||
try {
|
try {
|
||||||
if (!subscriber.isUnsubscribed()) {
|
if (!subscriber.isUnsubscribed()) {
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
@ -44,7 +44,7 @@ public final class NetworkHelper {
|
|||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
subscriber.onError(e);
|
subscriber.onError(e);
|
||||||
}
|
}
|
||||||
});
|
}).retry(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Observable<String> mapResponseToString(final Response response) {
|
public Observable<String> mapResponseToString(final Response response) {
|
||||||
|
@ -23,6 +23,7 @@ import icepick.State;
|
|||||||
import rx.Observable;
|
import rx.Observable;
|
||||||
import rx.android.schedulers.AndroidSchedulers;
|
import rx.android.schedulers.AndroidSchedulers;
|
||||||
import rx.schedulers.Schedulers;
|
import rx.schedulers.Schedulers;
|
||||||
|
import timber.log.Timber;
|
||||||
|
|
||||||
public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
||||||
|
|
||||||
@ -45,9 +46,9 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||||||
() -> getPageListObservable()
|
() -> getPageListObservable()
|
||||||
.doOnNext(pages -> pageList = pages)
|
.doOnNext(pages -> pageList = pages)
|
||||||
.doOnCompleted(() -> start(GET_PAGE_IMAGES)),
|
.doOnCompleted(() -> start(GET_PAGE_IMAGES)),
|
||||||
(view, pages) -> {
|
(view, pages) -> view.onPageListReady(pages),
|
||||||
view.onPageListReady(pages);
|
(view, error) -> Timber.e("An error occurred while downloading page list")
|
||||||
});
|
);
|
||||||
|
|
||||||
restartableReplay(GET_PAGE_IMAGES,
|
restartableReplay(GET_PAGE_IMAGES,
|
||||||
this::getPageImagesObservable,
|
this::getPageImagesObservable,
|
||||||
@ -56,7 +57,8 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||||||
if (page.getPageNumber() == savedSelectedPage) {
|
if (page.getPageNumber() == savedSelectedPage) {
|
||||||
view.setCurrentPage(savedSelectedPage);
|
view.setCurrentPage(savedSelectedPage);
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
(view, error) -> Timber.e("An error occurred while downloading an image"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -110,6 +112,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Observable<Page> downloadImage(Page page) {
|
private Observable<Page> downloadImage(Page page) {
|
||||||
|
if (page.getImageUrl() != null) {
|
||||||
FutureTarget<File> future = glideDownloader.load(page.getImageUrl())
|
FutureTarget<File> future = glideDownloader.load(page.getImageUrl())
|
||||||
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
|
.downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL);
|
||||||
|
|
||||||
@ -120,6 +123,7 @@ public class ReaderPresenter extends BasePresenter<ReaderActivity> {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
page.setStatus(Page.ERROR);
|
page.setStatus(Page.ERROR);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Observable.just(page);
|
return Observable.just(page);
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,7 @@ public abstract class Source extends BaseSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void savePageList(String chapterUrl, List<Page> pages) {
|
public void savePageList(String chapterUrl, List<Page> pages) {
|
||||||
|
if (pages != null)
|
||||||
mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages);
|
mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user