use proper system cache directory for storing cache files

This commit is contained in:
Andrew Dolgov 2012-10-14 16:37:20 +04:00
parent e80c14c8f5
commit 8b7a937678
5 changed files with 27 additions and 15 deletions

View File

@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6

View File

@ -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();

View File

@ -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));
}
}
}

View File

@ -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;

View File

@ -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();