Fix: Download is started over and over when rotating the device
[pub/Android/ownCloud.git] / src / com / owncloud / android / ui / activity / FileDisplayActivity.java
index f65a05b..a96f634 100644 (file)
@@ -378,7 +378,7 @@ OnSslUntrustedCertListener, EditNameDialogListener {
         return null;
     }
 
-    protected FileFragment getSecondFragment() {
+    public FileFragment getSecondFragment() {
         Fragment second = getSupportFragmentManager().findFragmentByTag(FileDisplayActivity.TAG_SECOND_FRAGMENT);
         if (second != null) {
             return (FileFragment)second;
@@ -983,7 +983,11 @@ OnSslUntrustedCertListener, EditNameDialogListener {
                             Toast.LENGTH_LONG);
                     msg.show();
                 }
-                ((FileDetailFragment)details).updateFileDetails(false, false);
+                if (uploadWasFine || getFile().fileExists()) {
+                    ((FileDetailFragment)details).updateFileDetails(false, true);
+                } else {
+                    cleanSecondFragment();
+                }
                 
                 // Force the preview if the file is an image
                 if (uploadWasFine && PreviewImageFragment.canBePreviewed(getFile())) {
@@ -1024,6 +1028,7 @@ OnSslUntrustedCertListener, EditNameDialogListener {
             }
             
             removeStickyBroadcast(intent);
+            mWaitingToPreview = null;
         }
 
         private boolean isDescendant(String downloadedRemotePath) {
@@ -1293,6 +1298,9 @@ OnSslUntrustedCertListener, EditNameDialogListener {
             OCFile removedFile = operation.getFile();
             FileFragment second = getSecondFragment();
             if (second != null && removedFile.equals(second.getFile())) {
+                if (second instanceof PreviewMediaFragment) {
+                    ((PreviewMediaFragment)second).stopPreview(true);
+                }
                 cleanSecondFragment();
             }
             if (getStorageManager().getFileById(removedFile.getParentId()).equals(getCurrentDir())) {
@@ -1351,7 +1359,9 @@ OnSslUntrustedCertListener, EditNameDialogListener {
             FileFragment details = getSecondFragment();
             if (details != null && details instanceof FileDetailFragment && renamedFile.equals(details.getFile()) ) {
                 ((FileDetailFragment) details).updateFileDetails(renamedFile, getAccount());
+                showDetails(renamedFile);
             }
+
             if (getStorageManager().getFileById(renamedFile.getParentId()).equals(getCurrentDir())) {
                 refreshListOfFilesFragment();
             }
@@ -1563,10 +1573,12 @@ OnSslUntrustedCertListener, EditNameDialogListener {
         Account account = getAccount();
         if (mDownloaderBinder != null && mDownloaderBinder.isDownloading(account, file)) {
             mDownloaderBinder.cancel(account, file);
+            refreshListOfFilesFragment();
             onTransferStateChanged(file, false, false);
 
         } else if (mUploaderBinder != null && mUploaderBinder.isUploading(account, file)) {
             mUploaderBinder.cancel(account, file);
+            refreshListOfFilesFragment();
             if (!file.fileExists()) {
                 cleanSecondFragment();