Merge pull request #3564 from nextcloud/moveThumbnailCache

Migrate thumbnail cache from external to internal cache location
This commit is contained in:
Andy Scherzinger 2019-02-05 17:56:15 +01:00 committed by GitHub
commit fbdc024092
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 24 deletions

View file

@ -1 +1 @@
533
526

View file

@ -110,8 +110,7 @@ public final class PassCodeManager {
}
private void setUnlockTimestamp(Activity activity) {
Long timestamp = System.currentTimeMillis();
PreferenceManager.setLockTimestamp(activity, timestamp);
PreferenceManager.setLockTimestamp(activity, System.currentTimeMillis());
}
private boolean passCodeShouldBeRequested(Long timestamp) {
@ -120,7 +119,7 @@ public final class PassCodeManager {
}
private boolean passCodeIsEnabled() {
return PreferenceManager.getLockPreference(MainApp.getAppContext()).equals(Preferences.LOCK_PASSCODE);
return Preferences.LOCK_PASSCODE.equals(PreferenceManager.getLockPreference(MainApp.getAppContext()));
}
private boolean deviceCredentialsShouldBeRequested(Long timestamp, Activity activity) {
@ -129,7 +128,7 @@ public final class PassCodeManager {
}
private boolean deviceCredentialsAreEnabled(Activity activity) {
return PreferenceManager.getLockPreference(MainApp.getAppContext()).equals(Preferences.LOCK_DEVICE_CREDENTIALS)
return Preferences.LOCK_DEVICE_CREDENTIALS.equals(PreferenceManager.getLockPreference(MainApp.getAppContext()))
|| Build.VERSION.SDK_INT >= Build.VERSION_CODES.M &&
(PreferenceManager.isUseFingerprint(MainApp.getAppContext())
&& DeviceCredentialUtils.areCredentialsAvailable(activity));

View file

@ -259,7 +259,7 @@ public class FileDataStorageManager {
* @return the parent file
*/
public OCFile saveFileWithParent(OCFile file, Context context) {
if (file.getParentId() == 0 && !file.getRemotePath().equals("/")) {
if (file.getParentId() == 0 && !"/".equals(file.getRemotePath())) {
String remotePath = file.getRemotePath();
String parentPath = remotePath.substring(0, remotePath.lastIndexOf(file.getFileName()));

View file

@ -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();
File cacheDir = MainApp.getAppContext().getCacheDir();
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 {
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);
}

View file

@ -197,7 +197,7 @@ public class PassCodeActivity extends AppCompatActivity {
private void onPassCodeEditTextFocusChange(final int passCodeIndex) {
for (int i = 0; i < passCodeIndex; i++) {
if (mPassCodeEditTexts[i].getText().toString().equals("")) {
if ("".equals(mPassCodeEditTexts[i].getText().toString())) {
mPassCodeEditTexts[i].requestFocus();
break;
}

View file

@ -1,4 +1,4 @@
/*
/*
* Nextcloud Android client application
*
* @author Tobias Kaminsky

View file

@ -345,6 +345,24 @@ public final class FileStorageUtils {
}
}
public static boolean copyDirs(File sourceFolder, File targetFolder) {
if (!targetFolder.mkdirs()) {
return false;
}
for (File f : sourceFolder.listFiles()) {
if (f.isDirectory()) {
if (!copyDirs(f, new File(targetFolder, f.getName()))) {
return false;
}
} else if (!FileStorageUtils.copyFile(f, new File(targetFolder, f.getName()))) {
return false;
}
}
return true;
}
public static void deleteRecursively(File file, FileDataStorageManager storageManager) {
if (file.isDirectory()) {
for (File child : file.listFiles()) {
@ -356,6 +374,16 @@ public final class FileStorageUtils {
file.delete();
}
public static boolean deleteRecursive(File file) {
boolean res = true;
if (file.isDirectory()) {
for (File c : file.listFiles()) {
res = deleteRecursive(c) && res;
}
}
return file.delete() && res;
}
public static void checkIfFileFinishedSaving(OCFile file) {
long lastModified = 0;
long lastSize = 0;