Merge branch 'zmatsuo-detailThumbnail' into develop
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / fragment / FileDetailFragment.java
index b5fce44..f87ee0a 100644 (file)
@@ -22,6 +22,8 @@
 package com.owncloud.android.ui.fragment;
 
 import android.accounts.Account;
+
+import android.graphics.Bitmap;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.Menu;
@@ -38,6 +40,7 @@ import android.widget.TextView;
 import com.owncloud.android.R;
 import com.owncloud.android.datamodel.FileDataStorageManager;
 import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.datamodel.ThumbnailsCacheManager;
 import com.owncloud.android.files.FileMenuFilter;
 import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder;
 import com.owncloud.android.files.services.FileUploader.FileUploaderBinder;
@@ -48,6 +51,7 @@ import com.owncloud.android.ui.activity.FileDisplayActivity;
 import com.owncloud.android.ui.dialog.RemoveFileDialogFragment;
 import com.owncloud.android.ui.dialog.RenameFileDialogFragment;
 import com.owncloud.android.utils.DisplayUtils;
+import com.owncloud.android.utils.MimetypeIconUtil;
 
 import java.lang.ref.WeakReference;
 
@@ -131,6 +135,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
         if (mLayout == R.layout.file_details_fragment) {
             mView.findViewById(R.id.fdFavorite).setOnClickListener(this);
             ProgressBar progressBar = (ProgressBar)mView.findViewById(R.id.fdProgressBar);
+            DisplayUtils.colorPreLollipopHorizontalProgressBar(progressBar);
             mProgressListener = new ProgressListener(progressBar);
             mView.findViewById(R.id.fdCancelBtn).setOnClickListener(this);
         }
@@ -337,7 +342,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
 
             // set file details
             setFilename(file.getFileName());
-            setFiletype(file.getMimetype(), file.getFileName());
+            setFiletype(file);
             setFilesize(file.getFileLength());
 
             setTimeModified(file.getModificationTimestamp());
@@ -391,18 +396,31 @@ public class FileDetailFragment extends FileFragment implements OnClickListener
 
     /**
      * Updates the MIME type in view
-     * @param mimetype      MIME type to set
-     * @param filename      Name of the file, to deduce the icon to use in case the MIME type is not precise enough
+     * @param file : An {@link OCFile}
      */
-    private void setFiletype(String mimetype, String filename) {
+    private void setFiletype(OCFile file) {
+        String mimetype = file.getMimetype();
         TextView tv = (TextView) getView().findViewById(R.id.fdType);
         if (tv != null) {
+                       // mimetype      MIME type to set
             String printableMimetype = DisplayUtils.convertMIMEtoPrettyPrint(mimetype);
             tv.setText(printableMimetype);
         }
         ImageView iv = (ImageView) getView().findViewById(R.id.fdIcon);
         if (iv != null) {
-            iv.setImageResource(DisplayUtils.getFileTypeIconId(mimetype, filename));
+                       Bitmap thumbnail = null;
+            if (file.isImage()) {
+                String tagId = String.valueOf(file.getRemoteId());
+                thumbnail = ThumbnailsCacheManager.getBitmapFromDiskCache(tagId);
+                       }
+                       if (thumbnail != null) {
+                               // Display thumbnail
+                               iv.setImageBitmap(thumbnail);
+                       } else {
+                               // Name of the file, to deduce the icon to use in case the MIME type is not precise enough
+                               String filename = file.getFileName();
+                iv.setImageResource(MimetypeIconUtil.getFileTypeIconId(mimetype, filename));
+                       }
         }
     }