Merge branch 'develop' into operations_service
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index fc1e398..fb55c14 100644 (file)
@@ -67,8 +67,6 @@ import com.owncloud.android.R;
 import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
 import com.owncloud.android.lib.common.accounts.AccountTypeUtils;\r
 import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;\r
-import com.owncloud.android.lib.common.OwnCloudClientFactory;\r
-import com.owncloud.android.lib.common.OwnCloudClient;\r
 import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;\r
 import com.owncloud.android.operations.GetServerInfoOperation;\r
 import com.owncloud.android.operations.OAuth2GetAccessToken;\r
@@ -158,8 +156,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     private Thread mOperationThread;\r
     private GetServerInfoOperation mServerInfoOperation;\r
 \r
-    //private ExistenceCheckRemoteOperation mAuthCheckOperation;\r
     private int mExistenceCheckOpId = -1;\r
+    private int mGetUserNameOpId = -1;\r
     \r
     private Uri mNewCapturedUriFromOAuth2Redirection;\r
 \r
@@ -925,17 +923,16 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
                 onAuthorizationCheckFinish(result);\r
             }\r
         } else if (operation instanceof GetRemoteUserNameOperation) {\r
-            onGetUserNameFinish((GetRemoteUserNameOperation) operation, result);\r
-\r
+            onGetUserNameFinish(result);\r
         }\r
 \r
     }\r
 \r
-    private void onGetUserNameFinish(GetRemoteUserNameOperation operation, RemoteOperationResult result) {\r
-\r
+    private void onGetUserNameFinish(RemoteOperationResult result) {\r
+        mGetUserNameOpId = -1;\r
         if (result.isSuccess()) {\r
             boolean success = false;\r
-            String username = operation.getUserName();\r
+            String username = (String) result.getData().get(0);\r
 \r
             if ( mAction == ACTION_CREATE) {\r
                 mUsernameInput.setText(username);\r
@@ -1753,13 +1750,27 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         if (sessionCookie != null && sessionCookie.length() > 0) {\r
             mAuthToken = sessionCookie;\r
 \r
-            GetRemoteUserNameOperation getUserOperation = new GetRemoteUserNameOperation();            \r
-            OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl), getApplicationContext(), true);\r
-            client.setSsoSessionCookie(mAuthToken);\r
-            getUserOperation.execute(client, this, mHandler);\r
+//            GetRemoteUserNameOperation getUserOperation = new GetRemoteUserNameOperation();\r
+//            OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl), getApplicationContext(), true);\r
+//            client.setSsoSessionCookie(mAuthToken);\r
+//            getUserOperation.execute(client, this, mHandler);\r
+            boolean followRedirects = true;\r
+            getRemoteUserNameOperation(sessionCookie, followRedirects);\r
+        }\r
+    }\r
+    \r
+    private void getRemoteUserNameOperation(String sessionCookie, boolean followRedirects) {\r
+        \r
+        Intent getUserNameIntent = new Intent();\r
+        getUserNameIntent.setAction(OperationsService.ACTION_GET_USER_NAME);\r
+        getUserNameIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mHostBaseUrl);\r
+        getUserNameIntent.putExtra(OperationsService.EXTRA_COOKIE, sessionCookie);\r
+        getUserNameIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects);\r
+        \r
+        if (mOperationsServiceBinder != null) {\r
+            Log_OC.wtf(TAG, "starting getRemoteUserNameOperation..." );\r
+            mGetUserNameOpId = mOperationsServiceBinder.newOperation(getUserNameIntent);\r
         }\r
-\r
-\r
     }\r
 \r
 \r
@@ -1923,7 +1934,16 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
                     onAuthorizationCheckFinish(result);\r
                 }\r
             }\r
-        }\r
+        }if (mGetUserNameOpId != -1) {\r
+            RemoteOperationResult result = \r
+                    mOperationsServiceBinder.getOperationResultIfFinished(mGetUserNameOpId);\r
+            if (result != null) {\r
+                //Log_OC.wtf(TAG, "found result of operation finished while rotating");\r
+                onGetUserNameFinish(result);\r
+            }\r
+            \r
+        } \r
+        \r
     }\r
     \r
     /** \r