Merge pull request #197 from owncloud/fixed_crash_due_to_uploads_to_accounts_not_alre...
authorDavid A. Velasco <dvelasco@owncloud.com>
Wed, 26 Jun 2013 06:51:58 +0000 (23:51 -0700)
committerDavid A. Velasco <dvelasco@owncloud.com>
Wed, 26 Jun 2013 06:51:58 +0000 (23:51 -0700)
Fixed crash due to uploads to accounts not already existing

res/values/strings.xml
src/com/owncloud/android/authentication/AuthenticatorActivity.java
src/com/owncloud/android/operations/RemoteOperationResult.java
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

index b7a951a..708fbfb 100644 (file)
@@ -16,7 +16,7 @@
     <string name="main_wrn_accsetup">There is no account set up on your device. In order to use this App, you need to create one.</string>
     <string name="about_android">%1$s Android App</string>
     <string name="about_version">version %1$s</string>
-    <string name="actionbar_sync">Refresh</string>
+    <string name="actionbar_sync">Refresh account</string>
     <string name="actionbar_upload">Upload</string>
     <string name="actionbar_upload_from_apps">Content from other apps</string>
     <string name="actionbar_upload_files">Files</string>
@@ -80,7 +80,7 @@
     <string name="filedetails_created">Created:</string>
     <string name="filedetails_modified">Modified:</string>
     <string name="filedetails_download">Download</string>
-    <string name="filedetails_sync_file">Refresh</string>
+    <string name="filedetails_sync_file">Refresh file</string>
     <string name="filedetails_redownload">Redownload</string>
     <string name="filedetails_renamed_in_upload_msg">File was renamed to %1$s during upload</string>
     <string name="common_yes">Yes</string>
index 32ab860..5118552 100644 (file)
@@ -934,7 +934,33 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
             finish();\r
 \r
-        } else {\r
+        } else if (result.isServerFail() || result.isException()) {\r
+            /// if server fail or exception in authorization, the UI is updated as when a server check failed\r
+            mServerIsChecked = true;\r
+            mServerIsValid = false;\r
+            mIsSslConn = false;\r
+            mOcServerChkOperation = null;\r
+            mDiscoveredVersion = null;\r
+            mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString());\r
+\r
+            // update status icon and text\r
+            updateServerStatusIconAndText(result);\r
+            showServerStatus();\r
+            mAuthStatusIcon = 0;\r
+            mAuthStatusText = 0;\r
+            showAuthStatus();\r
+            \r
+            // update input controls state\r
+            showRefreshButton();\r
+            mOkButton.setEnabled(false);\r
+\r
+            // very special case (TODO: move to a common place for all the remote operations) (dangerous here?)\r
+            if (result.getCode() == ResultCode.SSL_RECOVERABLE_PEER_UNVERIFIED) {\r
+                mLastSslUntrustedServerResult = result;\r
+                showDialog(DIALOG_SSL_VALIDATOR); \r
+            }\r
+\r
+        } else {    // authorization fail due to client side - probably wrong credentials\r
             updateAuthStatusIconAndText(result);\r
             showAuthStatus();\r
             Log_OC.d(TAG, "Access failed: " + result.getLogMessage());\r
index 6f4f291..1fc0179 100644 (file)
@@ -287,4 +287,12 @@ public class RemoteOperationResult implements Serializable {
 
     }
 
+    public boolean isServerFail() {
+        return (mHttpCode >= HttpStatus.SC_INTERNAL_SERVER_ERROR);
+    }
+
+    public boolean isException() {
+        return (mException != null);
+    }
+
 }
index 9896a92..bcd62a3 100644 (file)
@@ -222,7 +222,14 @@ public class FileDisplayActivity extends FileActivity implements
             /// Check whether the 'main' OCFile handled by the Activity is contained in the current Account
             OCFile file = getFile();
             if (file != null) {
-                file = mStorageManager.getFileByPath(file.getRemotePath());   // currentDir = null if not in the current Account
+                if (file.isDown() && file.getLastSyncDateForProperties() == 0) {
+                    // upload in progress - right now, files are not inserted in the local cache until the upload is successful
+                    if (mStorageManager.getFileById(file.getParentId()) == null) {
+                        file = null;    // not able to know the directory where the file is uploading
+                    }
+                } else {
+                    file = mStorageManager.getFileByPath(file.getRemotePath());   // currentDir = null if not in the current Account
+                }
             }
             if (file == null) {
                 // fall back to root folder
@@ -273,7 +280,9 @@ public class FileDisplayActivity extends FileActivity implements
     private Fragment chooseInitialSecondFragment(OCFile file) {
         Fragment secondFragment = null;
         if (file != null && !file.isDirectory()) {
-            if (file.isDown() && PreviewMediaFragment.canBePreviewed(file)) {
+            if (file.isDown() && PreviewMediaFragment.canBePreviewed(file) 
+                    && file.getLastSyncDateForProperties() > 0  // temporal fix
+                    ) {
                 int startPlaybackPosition = getIntent().getIntExtra(PreviewVideoActivity.EXTRA_START_POSITION, 0);
                 boolean autoplay = getIntent().getBooleanExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, true);
                 secondFragment = new PreviewMediaFragment(file, getAccount(), startPlaybackPosition, autoplay);