Skip to content

Commit d0cc3a8

Browse files
committed
add: generate resize image if image is deleted only locally, to save server request
Signed-off-by: alperozturk <[email protected]>
1 parent 63ed770 commit d0cc3a8

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

app/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,24 @@ private static Bitmap handlePNG(Bitmap source, int newWidth, int newHeight) {
13191319
return dest;
13201320
}
13211321

1322+
public static void generateResizedImage(OCFile file) {
1323+
Point p = getScreenDimension();
1324+
int pxW = p.x;
1325+
int pxH = p.y;
1326+
String imageKey = PREFIX_RESIZED_IMAGE + file.getRemoteId();
1327+
1328+
Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(file.getStoragePath(), pxW, pxH);
1329+
1330+
if (bitmap != null) {
1331+
// Handle PNG
1332+
if (PNG_MIMETYPE.equalsIgnoreCase(file.getMimeType())) {
1333+
bitmap = handlePNG(bitmap, pxW, pxH);
1334+
}
1335+
1336+
addThumbnailToCache(imageKey, bitmap, file.getStoragePath(), pxW, pxH);
1337+
}
1338+
}
1339+
13221340
public static void generateThumbnailFromOCFile(OCFile file, User user, Context context) {
13231341
int pxW;
13241342
int pxH;

app/src/main/java/com/owncloud/android/operations/RemoveFileOperation.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import com.owncloud.android.utils.MimeTypeUtil
3131
* @param context Android context.
3232
* @param storageManager Storage manager handling local file operations.
3333
*/
34+
@Suppress("LongParameterList")
3435
class RemoveFileOperation(
3536
val file: OCFile,
3637
private val onlyLocalCopy: Boolean,
@@ -53,14 +54,19 @@ class RemoveFileOperation(
5354
var result: RemoteOperationResult<*>? = null
5455
val operation: RemoteOperation<*>?
5556

56-
// Remove image from thumbnail cache
57-
if (MimeTypeUtil.isImage(file.mimeType)) {
58-
ThumbnailsCacheManager.removeFromCache(file)
59-
}
60-
6157
var localRemovalFailed = false
6258

63-
if (!onlyLocalCopy) {
59+
if (onlyLocalCopy) {
60+
// generate resize image if image is deleted only locally, to save server request
61+
if (MimeTypeUtil.isImage(file.mimeType)) {
62+
ThumbnailsCacheManager.generateResizedImage(file)
63+
}
64+
65+
localRemovalFailed = !storageManager.removeFile(file, false, true)
66+
if (!localRemovalFailed) {
67+
result = RemoteOperationResult<Any?>(RemoteOperationResult.ResultCode.OK)
68+
}
69+
} else {
6470
operation = if (file.isEncrypted) {
6571
val parent = storageManager.getFileById(file.parentId)
6672
if (parent == null) {
@@ -82,11 +88,6 @@ class RemoveFileOperation(
8288
if (result.isSuccess || result.code == RemoteOperationResult.ResultCode.FILE_NOT_FOUND) {
8389
localRemovalFailed = !storageManager.removeFile(file, true, true)
8490
}
85-
} else {
86-
localRemovalFailed = !storageManager.removeFile(file, false, true)
87-
if (!localRemovalFailed) {
88-
result = RemoteOperationResult<Any?>(RemoteOperationResult.ResultCode.OK)
89-
}
9091
}
9192

9293
if (localRemovalFailed) {

0 commit comments

Comments
 (0)