瀏覽代碼

Merge pull request #2183 from nextcloud/generateThumbnailFromResizedImage

If no thumbnail exists, check if resized version exist and use this
Andy Scherzinger 7 年之前
父節點
當前提交
7ef227cb03
共有 1 個文件被更改,包括 14 次插入11 次删除
  1. 14 11
      src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

+ 14 - 11
src/main/java/com/owncloud/android/datamodel/ThumbnailsCacheManager.java

@@ -529,11 +529,15 @@ 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 (serverOCVersion.supportsRemoteThumbnails()) {
+                    if (resizedImage != null) {
+                        thumbnail = ThumbnailUtils.extractThumbnail(resizedImage, pxW, pxH);
+                    } else {
+                        // Download thumbnail from server
+                        if (mClient != null && AccountUtils.getServerVersion(mAccount).supportsRemoteThumbnails()) {
                             getMethod = null;
                             try {
                                 // thumbnail
@@ -561,13 +565,6 @@ public class ThumbnailsCacheManager {
                                 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 {
@@ -579,6 +576,12 @@ public class ThumbnailsCacheManager {
                             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);
+                    }
                 }
             }