use proper system cache directory for storing cache files
This commit is contained in:
parent
e80c14c8f5
commit
8b7a937678
11
.settings/org.eclipse.jdt.core.prefs
Normal file
11
.settings/org.eclipse.jdt.core.prefs
Normal 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
|
@ -69,7 +69,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
|
|||||||
private FeedsActivity m_activity;
|
private FeedsActivity m_activity;
|
||||||
private Feed m_selectedFeed;
|
private Feed m_selectedFeed;
|
||||||
private FeedCategory m_activeCategory;
|
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_enableFeedIcons;
|
||||||
private boolean m_feedIconsChecked = false;
|
private boolean m_feedIconsChecked = false;
|
||||||
|
|
||||||
@ -514,7 +514,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
|
|||||||
|
|
||||||
if (m_enableFeedIcons) {
|
if (m_enableFeedIcons) {
|
||||||
|
|
||||||
File storage = Environment.getExternalStorageDirectory();
|
File storage = m_activity.getExternalCacheDir();
|
||||||
|
|
||||||
File iconFile = new File(storage.getAbsolutePath() + ICON_PATH + feed.id + ".ico");
|
File iconFile = new File(storage.getAbsolutePath() + ICON_PATH + feed.id + ".ico");
|
||||||
if (iconFile.exists()) {
|
if (iconFile.exists()) {
|
||||||
@ -570,7 +570,7 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
|
|||||||
protected Integer doInBackground(FeedList... params) {
|
protected Integer doInBackground(FeedList... params) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
File storage = Environment.getExternalStorageDirectory();
|
File storage = m_activity.getExternalCacheDir();
|
||||||
final File iconPath = new File(storage.getAbsolutePath() + ICON_PATH);
|
final File iconPath = new File(storage.getAbsolutePath() + ICON_PATH);
|
||||||
if (!iconPath.exists()) iconPath.mkdirs();
|
if (!iconPath.exists()) iconPath.mkdirs();
|
||||||
|
|
||||||
|
@ -202,8 +202,8 @@ public class OfflineArticleFragment extends Fragment {
|
|||||||
for (Element img : images) {
|
for (Element img : images) {
|
||||||
String url = img.attr("src");
|
String url = img.attr("src");
|
||||||
|
|
||||||
if (ImageCacheService.isUrlCached(url)) {
|
if (ImageCacheService.isUrlCached(m_activity, url)) {
|
||||||
img.attr("src", "file://" + ImageCacheService.getCacheFileName(url));
|
img.attr("src", "file://" + ImageCacheService.getCacheFileName(m_activity, url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -402,7 +402,7 @@ public class OfflineDownloadService extends Service {
|
|||||||
String url = img.attr("src");
|
String url = img.attr("src");
|
||||||
|
|
||||||
if (url.indexOf("://") != -1) {
|
if (url.indexOf("://") != -1) {
|
||||||
if (!ImageCacheService.isUrlCached(url)) {
|
if (!ImageCacheService.isUrlCached(OfflineDownloadService.this, url)) {
|
||||||
Intent intent = new Intent(OfflineDownloadService.this,
|
Intent intent = new Intent(OfflineDownloadService.this,
|
||||||
ImageCacheService.class);
|
ImageCacheService.class);
|
||||||
|
|
||||||
@ -472,7 +472,7 @@ public class OfflineDownloadService extends Service {
|
|||||||
m_sessionId = intent.getStringExtra("sessionId");
|
m_sessionId = intent.getStringExtra("sessionId");
|
||||||
|
|
||||||
if (!m_downloadInProgress) {
|
if (!m_downloadInProgress) {
|
||||||
if (m_downloadImages) ImageCacheService.cleanupCache(false);
|
if (m_downloadImages) ImageCacheService.cleanupCache(this, false);
|
||||||
|
|
||||||
updateNotification(R.string.notify_downloading_init);
|
updateNotification(R.string.notify_downloading_init);
|
||||||
m_downloadInProgress = true;
|
m_downloadInProgress = true;
|
||||||
|
@ -20,6 +20,7 @@ import android.app.IntentService;
|
|||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
@ -30,7 +31,7 @@ public class ImageCacheService extends IntentService {
|
|||||||
|
|
||||||
public static final int NOTIFY_DOWNLOADING = 1;
|
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;
|
private int m_imagesDownloaded = 0;
|
||||||
|
|
||||||
@ -57,29 +58,29 @@ public class ImageCacheService extends IntentService {
|
|||||||
m_nmgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
m_nmgr = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isUrlCached(String url) {
|
public static boolean isUrlCached(Context context, String url) {
|
||||||
String hashedUrl = md5(url);
|
String hashedUrl = md5(url);
|
||||||
|
|
||||||
File storage = Environment.getExternalStorageDirectory();
|
File storage = context.getExternalCacheDir();
|
||||||
|
|
||||||
File file = new File(storage.getAbsolutePath() + CACHE_PATH + "/" + hashedUrl + ".png");
|
File file = new File(storage.getAbsolutePath() + CACHE_PATH + "/" + hashedUrl + ".png");
|
||||||
|
|
||||||
return file.exists();
|
return file.exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCacheFileName(String url) {
|
public static String getCacheFileName(Context context, String url) {
|
||||||
String hashedUrl = md5(url);
|
String hashedUrl = md5(url);
|
||||||
|
|
||||||
File storage = Environment.getExternalStorageDirectory();
|
File storage = context.getExternalCacheDir();
|
||||||
|
|
||||||
File file = new File(storage.getAbsolutePath() + CACHE_PATH + "/" + hashedUrl + ".png");
|
File file = new File(storage.getAbsolutePath() + CACHE_PATH + "/" + hashedUrl + ".png");
|
||||||
|
|
||||||
return file.getAbsolutePath();
|
return file.getAbsolutePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void cleanupCache(boolean deleteAll) {
|
public static void cleanupCache(Context context, boolean deleteAll) {
|
||||||
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||||
File storage = Environment.getExternalStorageDirectory();
|
File storage = context.getExternalCacheDir();
|
||||||
File cachePath = new File(storage.getAbsolutePath() + CACHE_PATH);
|
File cachePath = new File(storage.getAbsolutePath() + CACHE_PATH);
|
||||||
|
|
||||||
long now = new Date().getTime();
|
long now = new Date().getTime();
|
||||||
@ -155,7 +156,7 @@ public class ImageCacheService extends IntentService {
|
|||||||
|
|
||||||
String hashedUrl = md5(url);
|
String hashedUrl = md5(url);
|
||||||
|
|
||||||
File storage = Environment.getExternalStorageDirectory();
|
File storage = getExternalCacheDir();
|
||||||
File cachePath = new File(storage.getAbsolutePath() + CACHE_PATH);
|
File cachePath = new File(storage.getAbsolutePath() + CACHE_PATH);
|
||||||
if (!cachePath.exists()) cachePath.mkdirs();
|
if (!cachePath.exists()) cachePath.mkdirs();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user