From d26049155c5c02ceb1068e6533f7914ec3b9d2a3 Mon Sep 17 00:00:00 2001 From: inorichi Date: Wed, 28 Oct 2015 14:03:58 +0100 Subject: [PATCH] Increase cache size --- .../mangafeed/data/caches/CacheManager.java | 30 +------------------ .../kanade/mangafeed/sources/base/Source.java | 19 +++++++----- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java b/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java index 395f30ebf..f43b1f1e5 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java @@ -3,8 +3,6 @@ package eu.kanade.mangafeed.data.caches; import android.content.Context; import com.bumptech.glide.Glide; -import com.bumptech.glide.request.FutureTarget; -import com.bumptech.glide.request.target.Target; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import com.jakewharton.disklrucache.DiskLruCache; @@ -16,9 +14,6 @@ import java.io.IOException; import java.io.OutputStream; import java.lang.reflect.Type; import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; import eu.kanade.mangafeed.data.models.Page; import eu.kanade.mangafeed.util.DiskUtils; @@ -31,7 +26,7 @@ public class CacheManager { private static final String PARAMETER_CACHE_DIRECTORY = "chapter_disk_cache"; private static final int PARAMETER_APP_VERSION = 1; private static final int PARAMETER_VALUE_COUNT = 1; - private static final long PARAMETER_CACHE_SIZE = 10 * 1024 * 1024; + private static final long PARAMETER_CACHE_SIZE = 100 * 1024 * 1024; private static final int READ_TIMEOUT = 60; private Context mContext; @@ -55,29 +50,6 @@ public class CacheManager { } } - public Observable cacheImagesFromUrls(final List imageUrls) { - return Observable.create(subscriber -> { - try { - for (String imageUrl : imageUrls) { - if (!subscriber.isUnsubscribed()) { - subscriber.onNext(cacheImageFromUrl(imageUrl)); - } - } - subscriber.onCompleted(); - } catch (Throwable e) { - subscriber.onError(e); - } - }); - } - - private File cacheImageFromUrl(String imageUrl) throws InterruptedException, ExecutionException, TimeoutException { - FutureTarget cacheFutureTarget = Glide.with(mContext) - .load(imageUrl) - .downloadOnly(Target.SIZE_ORIGINAL, Target.SIZE_ORIGINAL); - - return cacheFutureTarget.get(READ_TIMEOUT, TimeUnit.SECONDS); - } - public Observable clearImageCache() { return Observable.create(subscriber -> { try { 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 a403d936f..98429d1db 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 @@ -108,13 +108,8 @@ public abstract class Source extends BaseSource { return obs; if (!mCacheManager.isImageInCache(page.getImageUrl())) { - obs = mNetworkService.getProgressResponse(page.getImageUrl(), mRequestHeaders, page) - .flatMap(resp -> { - if (!mCacheManager.putImageToDiskCache(page.getImageUrl(), resp)) { - throw new IllegalStateException("Unable to save image"); - } - return Observable.just(page); - }); + page.setStatus(Page.DOWNLOAD); + obs = cacheImage(page); } return obs.flatMap(p -> { @@ -127,6 +122,16 @@ public abstract class Source extends BaseSource { }); } + private Observable cacheImage(final Page page) { + return mNetworkService.getProgressResponse(page.getImageUrl(), mRequestHeaders, page) + .flatMap(resp -> { + if (!mCacheManager.putImageToDiskCache(page.getImageUrl(), resp)) { + throw new IllegalStateException("Unable to save image"); + } + return Observable.just(page); + }); + } + public void savePageList(String chapterUrl, List pages) { if (pages != null) mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages);