diff options
author | Andrew Dolgov <[email protected]> | 2012-10-14 16:37:20 +0400 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2012-10-14 16:37:20 +0400 |
commit | 8b7a93767869134d4b82adb835edebce974825f4 (patch) | |
tree | 631ca9d37ded43816116dc9f3fb11d235a981fa0 /src/org | |
parent | e80c14c8f598b5ad83ec22d8848f342f196439ce (diff) |
use proper system cache directory for storing cache files
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/fox/ttrss/FeedsFragment.java | 6 | ||||
-rw-r--r-- | src/org/fox/ttrss/offline/OfflineArticleFragment.java | 4 | ||||
-rw-r--r-- | src/org/fox/ttrss/offline/OfflineDownloadService.java | 4 | ||||
-rw-r--r-- | src/org/fox/ttrss/util/ImageCacheService.java | 17 |
4 files changed, 16 insertions, 15 deletions
diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java index a6dcf056..1b1cec44 100644 --- a/src/org/fox/ttrss/FeedsFragment.java +++ b/src/org/fox/ttrss/FeedsFragment.java @@ -69,7 +69,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh private FeedsActivity m_activity;
private Feed m_selectedFeed;
private FeedCategory m_activeCategory;
- private static final String ICON_PATH = "/data/org.fox.ttrss/icons/";
+ private static final String ICON_PATH = "/icons/";
private boolean m_enableFeedIcons;
private boolean m_feedIconsChecked = false;
@@ -514,7 +514,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh if (m_enableFeedIcons) {
- File storage = Environment.getExternalStorageDirectory();
+ File storage = m_activity.getExternalCacheDir();
File iconFile = new File(storage.getAbsolutePath() + ICON_PATH + feed.id + ".ico");
if (iconFile.exists()) {
@@ -570,7 +570,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh protected Integer doInBackground(FeedList... params) {
try {
- File storage = Environment.getExternalStorageDirectory();
+ File storage = m_activity.getExternalCacheDir();
final File iconPath = new File(storage.getAbsolutePath() + ICON_PATH);
if (!iconPath.exists()) iconPath.mkdirs();
diff --git a/src/org/fox/ttrss/offline/OfflineArticleFragment.java b/src/org/fox/ttrss/offline/OfflineArticleFragment.java index 65933b61..a1b22094 100644 --- a/src/org/fox/ttrss/offline/OfflineArticleFragment.java +++ b/src/org/fox/ttrss/offline/OfflineArticleFragment.java @@ -202,8 +202,8 @@ public class OfflineArticleFragment extends Fragment { for (Element img : images) {
String url = img.attr("src");
- if (ImageCacheService.isUrlCached(url)) {
- img.attr("src", "file://" + ImageCacheService.getCacheFileName(url));
+ if (ImageCacheService.isUrlCached(m_activity, url)) {
+ img.attr("src", "file://" + ImageCacheService.getCacheFileName(m_activity, url));
}
}
}
diff --git a/src/org/fox/ttrss/offline/OfflineDownloadService.java b/src/org/fox/ttrss/offline/OfflineDownloadService.java index b2e3ecb0..c3a0444c 100644 --- a/src/org/fox/ttrss/offline/OfflineDownloadService.java +++ b/src/org/fox/ttrss/offline/OfflineDownloadService.java @@ -402,7 +402,7 @@ public class OfflineDownloadService extends Service { String url = img.attr("src");
if (url.indexOf("://") != -1) {
- if (!ImageCacheService.isUrlCached(url)) {
+ if (!ImageCacheService.isUrlCached(OfflineDownloadService.this, url)) {
Intent intent = new Intent(OfflineDownloadService.this,
ImageCacheService.class);
@@ -472,7 +472,7 @@ public class OfflineDownloadService extends Service { m_sessionId = intent.getStringExtra("sessionId");
if (!m_downloadInProgress) {
- if (m_downloadImages) ImageCacheService.cleanupCache(false);
+ if (m_downloadImages) ImageCacheService.cleanupCache(this, false);
updateNotification(R.string.notify_downloading_init);
m_downloadInProgress = true;
diff --git a/src/org/fox/ttrss/util/ImageCacheService.java b/src/org/fox/ttrss/util/ImageCacheService.java index b699c569..96342d60 100644 --- a/src/org/fox/ttrss/util/ImageCacheService.java +++ b/src/org/fox/ttrss/util/ImageCacheService.java @@ -20,6 +20,7 @@ import android.app.IntentService; import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
+import android.content.Context;
import android.content.Intent;
import android.os.Environment;
@@ -30,7 +31,7 @@ public class ImageCacheService extends IntentService { public static final int NOTIFY_DOWNLOADING = 1;
- private static final String CACHE_PATH = "/data/org.fox.ttrss/image-cache/";
+ private static final String CACHE_PATH = "/image-cache/";
private int m_imagesDownloaded = 0;
@@ -57,29 +58,29 @@ public class ImageCacheService extends IntentService { m_nmgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
}
- public static boolean isUrlCached(String url) {
+ public static boolean isUrlCached(Context context, String url) {
String hashedUrl = md5(url);
- File storage = Environment.getExternalStorageDirectory();
+ File storage = context.getExternalCacheDir();
File file = new File(storage.getAbsolutePath() + CACHE_PATH + "/" + hashedUrl + ".png");
return file.exists();
}
- public static String getCacheFileName(String url) {
+ public static String getCacheFileName(Context context, String url) {
String hashedUrl = md5(url);
- File storage = Environment.getExternalStorageDirectory();
+ File storage = context.getExternalCacheDir();
File file = new File(storage.getAbsolutePath() + CACHE_PATH + "/" + hashedUrl + ".png");
return file.getAbsolutePath();
}
- public static void cleanupCache(boolean deleteAll) {
+ public static void cleanupCache(Context context, boolean deleteAll) {
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
- File storage = Environment.getExternalStorageDirectory();
+ File storage = context.getExternalCacheDir();
File cachePath = new File(storage.getAbsolutePath() + CACHE_PATH);
long now = new Date().getTime();
@@ -155,7 +156,7 @@ public class ImageCacheService extends IntentService { String hashedUrl = md5(url);
- File storage = Environment.getExternalStorageDirectory();
+ File storage = getExternalCacheDir();
File cachePath = new File(storage.getAbsolutePath() + CACHE_PATH);
if (!cachePath.exists()) cachePath.mkdirs();
|