-
- // Not found in disk cache
- if (thumbnail == null || mFile.needsUpdateThumbnail()) {
- // Converts dp to pixel
- Resources r = MainApp.getAppContext().getResources();
- int px = (int) Math.round(TypedValue.applyDimension(
- TypedValue.COMPLEX_UNIT_DIP, 150, r.getDisplayMetrics()
- ));
-
- if (mFile.isDown()){
+
+ // Check if mFile passed is an OCFile (for OCFile thumbs)
+ if (mFile instanceof AsyncTaskOCFile) {
+
+ // Not found in disk cache
+ if (thumbnail == null || mFile.getNeedsUpdateThumbnail()) {
+
+ int px = getThumbnailDimension();
+
+ if (mFile.getIsDown()) {
+ Bitmap bitmap = BitmapUtils.decodeSampledBitmapFromFile(
+ mFile.getPath(), px, px);
+
+ if (bitmap != null) {
+ thumbnail = addThumbnailToCache(imageKey, bitmap, mFile.getPath(), px);
+
+ mFile.setNeedsUpdateThumbnail(false);
+ mStorageManager.saveFile((OCFile) mFile.getFile());
+ }
+
+ } else {
+ // Download thumbnail from server
+ if (mClient != null && mServerVersion != null) {
+ OwnCloudVersion serverOCVersion = new OwnCloudVersion(mServerVersion);
+ if (serverOCVersion.compareTo(new OwnCloudVersion(MINOR_SERVER_VERSION_FOR_THUMBS)) >= 0) {
+ try {
+ int status = -1;
+
+ String uri = mClient.getBaseUri() + "/index.php/apps/files/api/v1/thumbnail/" +
+ px + "/" + px + Uri.encode(mFile.getRemotePath(), "/");
+ Log_OC.d("Thumbnail", "URI: " + uri);
+ GetMethod get = new GetMethod(uri);
+ status = mClient.executeMethod(get);
+ if (status == HttpStatus.SC_OK) {
+ byte[] bytes = get.getResponseBody();
+ Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
+ thumbnail = ThumbnailUtils.extractThumbnail(bitmap, px, px);
+
+ // Add thumbnail to cache
+ if (thumbnail != null) {
+ addBitmapToCache(imageKey, thumbnail);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } else {
+ Log_OC.d(TAG, "Server too old");
+ }
+ }
+ }
+ }
+ // Check if mFile passed is a File (for local thumbs)
+ } else if (mFile instanceof AsyncTaskFileLocal) {
+
+ // Not found in disk cache
+ if (thumbnail == null) {
+
+ int px = getThumbnailDimension();
+