From 5ca5555fe63827ef917d07c7a899b26028191b16 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Thu, 15 Feb 2018 14:17:14 +0100 Subject: [PATCH] If no thumbnail exists, check if resized version exist and generate thumbnail out of it Signed-off-by: tobiasKaminsky --- .../datamodel/ThumbnailsCacheManager.java | 68 ++++++++++--------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java b/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index 733fbecfa2..d448db227f 100644 --- a/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@ -529,10 +529,16 @@ public class ThumbnailsCacheManager { } } else { - // Download thumbnail from server - OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount); + // check if resized version is available + String resizedImageKey = PREFIX_RESIZED_IMAGE + String.valueOf(file.getRemoteId()); + Bitmap resizedImage = getBitmapFromDiskCache(resizedImageKey); - if (mClient != null) { + if (resizedImage != null) { + thumbnail = ThumbnailUtils.extractThumbnail(resizedImage, pxW, pxH); + } else { + //Download thumbnail from server + OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount); + if (mClient != null) { if (serverOCVersion.supportsRemoteThumbnails()) { getMethod = null; try { @@ -545,40 +551,40 @@ public class ThumbnailsCacheManager { getMethod.setRequestHeader("Cookie", "nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true"); - getMethod.setRequestHeader(RemoteOperation.OCS_API_HEADER, - RemoteOperation.OCS_API_HEADER_VALUE); + getMethod.setRequestHeader(RemoteOperation.OCS_API_HEADER, + RemoteOperation.OCS_API_HEADER_VALUE); - int status = mClient.executeMethod(getMethod); - if (status == HttpStatus.SC_OK) { - InputStream inputStream = getMethod.getResponseBodyAsStream(); - Bitmap bitmap = BitmapFactory.decodeStream(inputStream); - thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH); - } else { - mClient.exhaustResponse(getMethod.getResponseBodyAsStream()); - } + int status = mClient.executeMethod(getMethod); + if (status == HttpStatus.SC_OK) { + InputStream inputStream = getMethod.getResponseBodyAsStream(); + Bitmap bitmap = BitmapFactory.decodeStream(inputStream); + thumbnail = ThumbnailUtils.extractThumbnail(bitmap, pxW, pxH); + } else { + mClient.exhaustResponse(getMethod.getResponseBodyAsStream()); + } - // Handle PNG - if (file.getMimetype().equalsIgnoreCase(PNG_MIMETYPE)) { - thumbnail = handlePNG(thumbnail, pxW, pxH); - } - - // Add thumbnail to cache - if (thumbnail != null) { - Log_OC.d(TAG, "add thumbnail to cache: " + file.getFileName()); - addBitmapToCache(imageKey, thumbnail); - } - - } catch (Exception e) { - Log_OC.d(TAG, e.getMessage(), e); - } finally { - if (getMethod != null) { - getMethod.releaseConnection(); + // Handle PNG + if (file.getMimetype().equalsIgnoreCase(PNG_MIMETYPE)) { + thumbnail = handlePNG(thumbnail, pxW, pxH); + } + } catch (Exception e) { + Log_OC.d(TAG, e.getMessage(), e); + } finally { + if (getMethod != null) { + getMethod.releaseConnection(); + } } + } else { + Log_OC.d(TAG, "Server too old"); } - } else { - Log_OC.d(TAG, "Server too old"); } } + + // Add thumbnail to cache + if (thumbnail != null) { + Log_OC.d(TAG, "add thumbnail to cache: " + file.getFileName()); + addBitmapToCache(imageKey, thumbnail); + } } }