App updated to OwnCloudAccount with deferred load of credentials
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index 03f6585..0c73540 100644 (file)
@@ -70,6 +70,7 @@ import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientList
 import com.owncloud.android.lib.common.OwnCloudAccount;\r
 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;\r
 import com.owncloud.android.lib.common.accounts.AccountTypeUtils;\r
+import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException;\r
 import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;\r
 import com.owncloud.android.lib.common.network.CertificateCombinedException;\r
 import com.owncloud.android.lib.common.operations.OnRemoteOperationListener;\r
@@ -1000,8 +1001,15 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                     showAuthStatus();\r
                     Log_OC.d(TAG, result.getLogMessage());\r
                 } else {\r
-                    updateAccountAuthentication();\r
-                    success = true;\r
+                    try {\r
+                        updateAccountAuthentication();\r
+                        success = true;\r
+\r
+                    } catch (AccountNotFoundException e) {\r
+                        Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);\r
+                        Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();\r
+                        finish();\r
+                    }\r
                 }\r
             }\r
 \r
@@ -1367,8 +1375,15 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 success = createAccount();\r
 \r
             } else {\r
-                updateAccountAuthentication();\r
-                success = true;\r
+                try {\r
+                    updateAccountAuthentication();\r
+                    success = true;\r
+\r
+                } catch (AccountNotFoundException e) {\r
+                    Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);\r
+                    Toast.makeText(this, R.string.auth_account_does_not_exist, Toast.LENGTH_SHORT).show();\r
+                    finish();\r
+                }\r
             }\r
 \r
             if (success) {\r
@@ -1417,16 +1432,11 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
      * Kills the session kept by OwnCloudClientManager so that a new one will created with\r
      * the new credentials when needed.\r
      */\r
-    private void updateAccountAuthentication() {\r
-\r
-        try {\r
-            OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(\r
-                new OwnCloudAccount(mAccount, this)     // TODO avoid this creation may block the main thread\r
-            );\r
-        } catch (Exception e) {\r
-            e.printStackTrace();\r
-        }\r
+    private void updateAccountAuthentication() throws AccountNotFoundException {\r
 \r
+        OwnCloudClientManagerFactory.getDefaultSingleton().removeClientFor(\r
+            new OwnCloudAccount(mAccount, this)\r
+        );\r
 \r
         Bundle response = new Bundle();\r
         response.putString(AccountManager.KEY_ACCOUNT_NAME, mAccount.name);\r