Avoid use of queues to delay recursion
[pub/Android/ownCloud.git] / src / eu / alefzero / owncloud / ui / fragment / FileDetailFragment.java
index 627c26a..505ff6c 100644 (file)
@@ -27,6 +27,8 @@ import android.content.IntentFilter;
 import android.graphics.Bitmap;\r
 import android.graphics.BitmapFactory;\r
 import android.graphics.BitmapFactory.Options;\r
 import android.graphics.Bitmap;\r
 import android.graphics.BitmapFactory;\r
 import android.graphics.BitmapFactory.Options;\r
+import android.graphics.drawable.BitmapDrawable;\r
+import android.graphics.drawable.Drawable;\r
 import android.net.Uri;\r
 import android.os.Bundle;\r
 import android.util.Log;\r
 import android.net.Uri;\r
 import android.os.Bundle;\r
 import android.util.Log;\r
@@ -44,10 +46,8 @@ import com.actionbarsherlock.app.SherlockFragment;
 \r
 import eu.alefzero.owncloud.DisplayUtils;\r
 import eu.alefzero.owncloud.R;\r
 \r
 import eu.alefzero.owncloud.DisplayUtils;\r
 import eu.alefzero.owncloud.R;\r
-import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
 import eu.alefzero.owncloud.datamodel.OCFile;\r
 import eu.alefzero.owncloud.files.services.FileDownloader;\r
 import eu.alefzero.owncloud.datamodel.OCFile;\r
 import eu.alefzero.owncloud.files.services.FileDownloader;\r
-import eu.alefzero.owncloud.utils.OwnCloudVersion;\r
 \r
 /**\r
  * This Fragment is used to display the details about a file.\r
 \r
 /**\r
  * This Fragment is used to display the details about a file.\r
@@ -165,6 +165,17 @@ public class FileDetailFragment extends SherlockFragment implements
         getActivity().startService(i);\r
     }\r
 \r
         getActivity().startService(i);\r
     }\r
 \r
+\r
+    /**\r
+     * Check if the fragment was created with an empty layout. An empty fragment can't show file details, must be replaced.\r
+     * \r
+     * @return  True when the fragment was created with the empty layout.\r
+     */\r
+    public boolean isEmpty() {\r
+        return mLayout == R.layout.file_details_empty;\r
+    }\r
+\r
+    \r
     /**\r
      * Can be used to get the file that is currently being displayed.\r
      * @return The file on the screen.\r
     /**\r
      * Can be used to get the file that is currently being displayed.\r
      * @return The file on the screen.\r
@@ -190,7 +201,8 @@ public class FileDetailFragment extends SherlockFragment implements
      */\r
     public void updateFileDetails() {\r
 \r
      */\r
     public void updateFileDetails() {\r
 \r
-        if (mFile != null && mLayout == R.layout.file_details_fragment) {\r
+        if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) {\r
+            \r
             Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
             // set file details\r
             setFilename(mFile.getFileName());\r
             Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
             // set file details\r
             setFilename(mFile.getFileName());\r
@@ -203,8 +215,8 @@ public class FileDetailFragment extends SherlockFragment implements
            \r
             setTimeModified(mFile.getModificationTimestamp());\r
             \r
            \r
             setTimeModified(mFile.getModificationTimestamp());\r
             \r
-            // Update preview\r
             if (mFile.getStoragePath() != null) {\r
             if (mFile.getStoragePath() != null) {\r
+                // Update preview\r
                 ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview);\r
                 try {\r
                     if (mFile.getMimetype().startsWith("image/")) {\r
                 ImageView preview = (ImageView) getView().findViewById(R.id.fdPreview);\r
                 try {\r
                     if (mFile.getMimetype().startsWith("image/")) {\r
@@ -220,17 +232,21 @@ public class FileDetailFragment extends SherlockFragment implements
 \r
                         Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
 \r
 \r
                         Bitmap bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
 \r
-                        int width = options.outWidth;\r
-                        int height = options.outHeight;\r
-                        int scale = 1;\r
-                        if (width >= 2048 || height >= 2048) {\r
-                            scale = (int) (Math.ceil(Math.max(height, width)/2048.));\r
-                            options.inSampleSize = scale;\r
-                            bmp.recycle();\r
+                        if (bmp != null) {\r
+                            int width = options.outWidth;\r
+                            int height = options.outHeight;\r
+                            int scale = 1;\r
+                            if (width >= 2048 || height >= 2048) {\r
+                                scale = (int) (Math.ceil(Math.max(height, width)/2048.));\r
+                                options.inSampleSize = scale;\r
+                                bmp.recycle();\r
 \r
 \r
-                            bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
+                                bmp = BitmapFactory.decodeFile(mFile.getStoragePath(), options);\r
+                            }\r
+                        }\r
+                        if (bmp != null) {\r
+                            preview.setImageBitmap(bmp);\r
                         }\r
                         }\r
-                        preview.setImageBitmap(bmp);\r
                     }\r
                 } catch (OutOfMemoryError e) {\r
                     preview.setVisibility(View.INVISIBLE);\r
                     }\r
                 } catch (OutOfMemoryError e) {\r
                     preview.setVisibility(View.INVISIBLE);\r
@@ -244,6 +260,8 @@ public class FileDetailFragment extends SherlockFragment implements
                     preview.setVisibility(View.INVISIBLE);\r
                     Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength(), t);\r
                 }\r
                     preview.setVisibility(View.INVISIBLE);\r
                     Log.e(TAG, "Unexpected error while creating image preview " + mFile.getFileLength(), t);\r
                 }\r
+                \r
+                // Change download button to open button\r
                 downloadButton.setText(R.string.filedetails_open);\r
                 downloadButton.setOnClickListener(new OnClickListener() {\r
                     @Override\r
                 downloadButton.setText(R.string.filedetails_open);\r
                 downloadButton.setOnClickListener(new OnClickListener() {\r
                     @Override\r
@@ -262,7 +280,7 @@ public class FileDetailFragment extends SherlockFragment implements
                             try {\r
                                 Intent i = new Intent(Intent.ACTION_VIEW);\r
                                 mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));\r
                             try {\r
                                 Intent i = new Intent(Intent.ACTION_VIEW);\r
                                 mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1));\r
-                                if (mimeType != mFile.getMimetype()) {\r
+                                if (mimeType != null && !mimeType.equals(mFile.getMimetype())) {\r
                                     i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mimeType);\r
                                     i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
                                     startActivity(i);\r
                                     i.setDataAndType(Uri.parse("file://"+mFile.getStoragePath()), mimeType);\r
                                     i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
                                     startActivity(i);\r
@@ -294,6 +312,7 @@ public class FileDetailFragment extends SherlockFragment implements
         }\r
     }\r
     \r
         }\r
     }\r
     \r
+    \r
     /**\r
      * Updates the filename in view\r
      * @param filename to set\r
     /**\r
      * Updates the filename in view\r
      * @param filename to set\r
@@ -387,5 +406,4 @@ public class FileDetailFragment extends SherlockFragment implements
         \r
     }\r
     \r
         \r
     }\r
     \r
-\r
 }\r
 }\r