Merge of master after sync_review was merged into it
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / fragment / FileDetailFragment.java
index 9338b93..47e75d3 100644 (file)
@@ -191,7 +191,7 @@ public class FileDetailFragment extends SherlockFragment implements
             mPreview = (ImageView)mView.findViewById(R.id.fdPreview);\r
         }\r
         \r
-        updateFileDetails();\r
+        updateFileDetails(false);\r
         return view;\r
     }\r
     \r
@@ -274,7 +274,6 @@ public class FileDetailFragment extends SherlockFragment implements
     public void onClick(View v) {\r
         switch (v.getId()) {\r
             case R.id.fdDownloadBtn: {\r
-                //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath())) {\r
                 FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();\r
                 FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();\r
                 if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) {\r
@@ -342,8 +341,7 @@ public class FileDetailFragment extends SherlockFragment implements
                 break;\r
             }\r
             case R.id.fdRenameBtn: {\r
-                EditNameDialog dialog = EditNameDialog.newInstance(mFile.getFileName());\r
-                dialog.setOnDismissListener(this);\r
+                EditNameDialog dialog = EditNameDialog.newInstance(getString(R.string.rename_dialog_title), mFile.getFileName(), this);\r
                 dialog.show(getFragmentManager(), "nameeditdialog");\r
                 break;\r
             }   \r
@@ -374,8 +372,13 @@ 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
-                        if (mimeType != null && !mimeType.equals(mFile.getMimetype())) {\r
-                            i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);\r
+                        if (mimeType == null || !mimeType.equals(mFile.getMimetype())) {\r
+                            if (mimeType != null) {\r
+                                i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), mimeType);\r
+                            } else {\r
+                                // desperate try\r
+                                i.setDataAndType(Uri.parse("file://"+ encodedStoragePath), "*/*");\r
+                            }\r
                             i.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);\r
                             startActivity(i);\r
                             toastIt = false;\r
@@ -475,14 +478,21 @@ public class FileDetailFragment extends SherlockFragment implements
             mStorageManager = new FileDataStorageManager(ocAccount, getActivity().getApplicationContext().getContentResolver());\r
         }\r
         mAccount = ocAccount;\r
-        updateFileDetails();\r
+        updateFileDetails(false);\r
     }\r
     \r
 \r
     /**\r
      * Updates the view with all relevant details about that file.\r
+     *\r
+     * TODO Remove parameter when the transferring state of files is kept in database. \r
+     * \r
+     * @param transferring      Flag signaling if the file should be considered as downloading or uploading, \r
+     *                          although {@link FileDownloaderBinder#isDownloading(Account, OCFile)}  and \r
+     *                          {@link FileUploaderBinder#isUploading(Account, OCFile)} return false.\r
+     * \r
      */\r
-    public void updateFileDetails() {\r
+    public void updateFileDetails(boolean transferring) {\r
 \r
         if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) {\r
             \r
@@ -504,7 +514,7 @@ public class FileDetailFragment extends SherlockFragment implements
             //if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || FileUploader.isUploading(mAccount, mFile.getRemotePath())) {\r
             FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder();\r
             FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder();\r
-            if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) {\r
+            if (transferring || (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) {\r
                 setButtonsForTransferring();\r
                 \r
             } else if (mFile.isDown()) {\r
@@ -517,9 +527,11 @@ public class FileDetailFragment extends SherlockFragment implements
                 setButtonsForDown();\r
                 \r
             } else {\r
+                // TODO load default preview image; when the local file is removed, the preview remains there\r
                 setButtonsForRemote();\r
             }\r
         }\r
+        getView().invalidate();\r
     }\r
     \r
     \r
@@ -602,7 +614,6 @@ public class FileDetailFragment extends SherlockFragment implements
         if (!isEmpty()) {\r
             Button downloadButton = (Button) getView().findViewById(R.id.fdDownloadBtn);\r
             downloadButton.setText(R.string.filedetails_sync_file);\r
-            //downloadButton.setEnabled(true);\r
         \r
             ((Button) getView().findViewById(R.id.fdOpenBtn)).setEnabled(true);\r
             ((Button) getView().findViewById(R.id.fdRenameBtn)).setEnabled(true);\r
@@ -687,7 +698,7 @@ public class FileDetailFragment extends SherlockFragment implements
                     if (downloadWasFine) {\r
                         mFile = mStorageManager.getFileByPath(downloadedRemotePath);\r
                     }\r
-                    updateFileDetails();    // it updates the buttons; must be called although !downloadWasFine\r
+                    updateFileDetails(false);    // it updates the buttons; must be called although !downloadWasFine\r
                 }\r
             }\r
         }\r
@@ -707,7 +718,6 @@ public class FileDetailFragment extends SherlockFragment implements
     private class UploadFinishReceiver extends BroadcastReceiver {\r
         @Override\r
         public void onReceive(Context context, Intent intent) {\r
-            Log.d(TAG, "Received broacast! : " + intent.getStringExtra(FileUploader.EXTRA_REMOTE_PATH));\r
             String accountName = intent.getStringExtra(FileUploader.ACCOUNT_NAME);\r
 \r
             if (!isEmpty() && accountName.equals(mAccount.name)) {\r
@@ -724,7 +734,7 @@ public class FileDetailFragment extends SherlockFragment implements
                         Toast msg = Toast.makeText(getActivity().getApplicationContext(), String.format(getString(R.string.filedetails_renamed_in_upload_msg), newName), Toast.LENGTH_LONG);\r
                         msg.show();\r
                     }\r
-                    updateFileDetails();    // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server\r
+                    updateFileDetails(false);    // it updates the buttons; must be called although !uploadWasFine; interrupted uploads still leave an incomplete file in the server\r
                 }\r
             }\r
         }\r
@@ -840,6 +850,7 @@ public class FileDetailFragment extends SherlockFragment implements
             String newFilename = dialog.getNewFilename();\r
             Log.d(TAG, "name edit dialog dismissed with new name " + newFilename);\r
             mLastRemoteOperation = new RenameFileOperation( mFile, \r
+                                                            mAccount, \r
                                                             newFilename, \r
                                                             new FileDataStorageManager(mAccount, getActivity().getContentResolver()));\r
             WebdavClient wc = OwnCloudClientUtils.createOwnCloudClient(mAccount, getSherlockActivity().getApplicationContext());\r