|
@@ -115,19 +115,29 @@ public final class ThumbnailsCacheManager {
|
|
|
|
|
|
if (mThumbnailCache == null) {
|
|
|
try {
|
|
|
- // Check if media is mounted or storage is built-in, if so,
|
|
|
- // try and use external cache dir; otherwise use internal cache dir
|
|
|
- File cacheDir = MainApp.getAppContext().getExternalCacheDir();
|
|
|
-
|
|
|
- if (cacheDir != null) {
|
|
|
- String cachePath = cacheDir.getPath() + File.separator + CACHE_FOLDER;
|
|
|
- Log_OC.d(TAG, "create dir: " + cachePath);
|
|
|
- File diskCacheDir = new File(cachePath);
|
|
|
- mThumbnailCache = new DiskLruImageCache(diskCacheDir, DISK_CACHE_SIZE, mCompressFormat,
|
|
|
- mCompressQuality);
|
|
|
- } else {
|
|
|
+ File cacheDir = MainApp.getAppContext().getCacheDir();
|
|
|
+
|
|
|
+ if (cacheDir == null) {
|
|
|
throw new FileNotFoundException("Thumbnail cache could not be opened");
|
|
|
}
|
|
|
+
|
|
|
+ String cachePath = cacheDir.getPath() + File.separator + CACHE_FOLDER;
|
|
|
+ Log_OC.d(TAG, "thumbnail cache dir: " + cachePath);
|
|
|
+ File diskCacheDir = new File(cachePath);
|
|
|
+
|
|
|
+ // migrate from external cache to internal cache
|
|
|
+ File oldCacheDir = MainApp.getAppContext().getExternalCacheDir();
|
|
|
+
|
|
|
+ if (oldCacheDir != null && oldCacheDir.exists()) {
|
|
|
+ String cacheOldPath = oldCacheDir.getPath() + File.separator + CACHE_FOLDER;
|
|
|
+ File diskOldCacheDir = new File(cacheOldPath);
|
|
|
+
|
|
|
+ FileStorageUtils.copyDirs(diskOldCacheDir, diskCacheDir);
|
|
|
+ FileStorageUtils.deleteRecursive(diskOldCacheDir);
|
|
|
+ }
|
|
|
+
|
|
|
+ mThumbnailCache = new DiskLruImageCache(diskCacheDir, DISK_CACHE_SIZE, mCompressFormat,
|
|
|
+ mCompressQuality);
|
|
|
} catch (Exception e) {
|
|
|
Log_OC.d(TAG, e.getMessage());
|
|
|
mThumbnailCache = null;
|
|
@@ -279,7 +289,7 @@ public final class ThumbnailsCacheManager {
|
|
|
|
|
|
if (bitmap != null) {
|
|
|
// Handle PNG
|
|
|
- if (file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) {
|
|
|
+ if (PNG_MIMETYPE.equalsIgnoreCase(file.getMimeType())) {
|
|
|
bitmap = handlePNG(bitmap, pxW, pxH);
|
|
|
}
|
|
|
|
|
@@ -308,7 +318,7 @@ public final class ThumbnailsCacheManager {
|
|
|
}
|
|
|
|
|
|
// Handle PNG
|
|
|
- if (thumbnail != null && file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) {
|
|
|
+ if (thumbnail != null && PNG_MIMETYPE.equalsIgnoreCase(file.getMimeType())) {
|
|
|
thumbnail = handlePNG(thumbnail, thumbnail.getWidth(), thumbnail.getHeight());
|
|
|
}
|
|
|
|
|
@@ -526,7 +536,7 @@ public final class ThumbnailsCacheManager {
|
|
|
|
|
|
if (bitmap != null) {
|
|
|
// Handle PNG
|
|
|
- if (ocFile.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) {
|
|
|
+ if (PNG_MIMETYPE.equalsIgnoreCase(ocFile.getMimeType())) {
|
|
|
bitmap = handlePNG(bitmap, pxW, pxH);
|
|
|
}
|
|
|
|
|
@@ -578,7 +588,7 @@ public final class ThumbnailsCacheManager {
|
|
|
}
|
|
|
|
|
|
// Handle PNG
|
|
|
- if (file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) {
|
|
|
+ if (PNG_MIMETYPE.equalsIgnoreCase(file.getMimeType())) {
|
|
|
thumbnail = handlePNG(thumbnail, pxW, pxH);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -1163,7 +1173,7 @@ public final class ThumbnailsCacheManager {
|
|
|
|
|
|
if (bitmap != null) {
|
|
|
// Handle PNG
|
|
|
- if (file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) {
|
|
|
+ if (PNG_MIMETYPE.equalsIgnoreCase(file.getMimeType())) {
|
|
|
bitmap = handlePNG(bitmap, pxW, pxH);
|
|
|
}
|
|
|
|
|
@@ -1204,7 +1214,7 @@ public final class ThumbnailsCacheManager {
|
|
|
// Add thumbnail to cache
|
|
|
if (thumbnail != null) {
|
|
|
// Handle PNG
|
|
|
- if (file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) {
|
|
|
+ if (PNG_MIMETYPE.equalsIgnoreCase(file.getMimeType())) {
|
|
|
thumbnail = handlePNG(thumbnail, pxW, pxH);
|
|
|
}
|
|
|
|