From 51358673b75c4d4bf1d729a38090ce96ee16bf7a Mon Sep 17 00:00:00 2001 From: Florens Douwes Date: Mon, 26 May 2014 22:18:56 +0200 Subject: [PATCH] Store cache files on the dir returned by getExternalCacheDir, if available. Closes #7 --- .../src/main/java/com/android/volley/toolbox/Volley.java | 7 +++++-- .../app/src/main/java/org/floens/chan/ChanApplication.java | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Clover/app/src/main/java/com/android/volley/toolbox/Volley.java b/Clover/app/src/main/java/com/android/volley/toolbox/Volley.java index 0e04e876..0be1c734 100644 --- a/Clover/app/src/main/java/com/android/volley/toolbox/Volley.java +++ b/Clover/app/src/main/java/com/android/volley/toolbox/Volley.java @@ -30,7 +30,8 @@ import java.io.File; public class Volley { /** Default on-disk cache directory. */ - private static final String DEFAULT_CACHE_DIR = "volley"; + public static final String DEFAULT_CACHE_DIR = "volley"; + /** * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it. @@ -40,8 +41,10 @@ public class Volley { * @return A started {@link RequestQueue} instance. */ public static RequestQueue newRequestQueue(Context context, HttpStack stack) { - File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR); + return newRequestQueue(context, stack, new File(context.getCacheDir(), DEFAULT_CACHE_DIR)); + } + public static RequestQueue newRequestQueue(Context context, HttpStack stack, File cacheDir) { String userAgent = "volley/0"; try { String packageName = context.getPackageName(); diff --git a/Clover/app/src/main/java/org/floens/chan/ChanApplication.java b/Clover/app/src/main/java/org/floens/chan/ChanApplication.java index d52fd04e..982f5baf 100644 --- a/Clover/app/src/main/java/org/floens/chan/ChanApplication.java +++ b/Clover/app/src/main/java/org/floens/chan/ChanApplication.java @@ -37,6 +37,7 @@ import org.floens.chan.service.WatchService; import org.floens.chan.utils.IconCache; import org.floens.chan.utils.ThemeHelper; +import java.io.File; import java.lang.reflect.Field; public class ChanApplication extends Application implements PinListener { @@ -108,7 +109,8 @@ public class ChanApplication extends Application implements PinListener { IconCache.createIcons(this); - volleyRequestQueue = Volley.newRequestQueue(this); + File cacheDir = new File(getExternalCacheDir() != null ? getExternalCacheDir() : getCacheDir(), Volley.DEFAULT_CACHE_DIR); + volleyRequestQueue = Volley.newRequestQueue(this, null, cacheDir); imageLoader = new ImageLoader(volleyRequestQueue, new BitmapLruImageCache(1024 * 1024 * 8)); databaseManager = new DatabaseManager(this);