Keep trying to fetch metalinks despite errors

This commit is contained in:
mhutti1 2017-01-08 23:13:05 +00:00
parent 0d4994a2b9
commit 90c1bd9b0a

View File

@ -32,6 +32,7 @@ import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.Request;
@ -165,7 +166,7 @@ public class DownloadService extends Service {
private void downloadBook(String url, int notificationID, LibraryNetworkEntity.Book book) {
downloadFragment.addDownload(notificationID, book, KIWIX_ROOT + StorageUtils.getFileNameFromUrl(book.getUrl()));
kiwixService.getMetaLinks(url)
kiwixService.getMetaLinks(url).retryWhen(errors -> errors.flatMap(error -> Observable.timer(5, TimeUnit.SECONDS)))
.subscribeOn(AndroidSchedulers.mainThread())
.flatMap(metaLink -> getMetaLinkContentLength(metaLink.getRelevantUrl().getValue()))
.flatMap(pair -> Observable.from(ChunkUtils.getChunks(pair.first, pair.second, notificationID)))