Merge branch 'setup_multiaccount' into setup_app_name
authormasensio <masensio@solidgear.es>
Fri, 18 Oct 2013 10:32:22 +0000 (12:32 +0200)
committermasensio <masensio@solidgear.es>
Fri, 18 Oct 2013 10:32:22 +0000 (12:32 +0200)
Conflicts:
res/values/setup.xml
src/com/owncloud/android/authentication/AccountAuthenticator.java

1  2 
res/values/setup.xml
res/values/strings.xml
src/com/owncloud/android/authentication/AccountAuthenticator.java
src/com/owncloud/android/authentication/AuthenticatorActivity.java
src/com/owncloud/android/ui/activity/AccountSelectActivity.java

@@@ -17,9 -7,7 +17,12 @@@
      <string name="auth_method_oauth2">off</string>
      <string name="auth_method_saml_web_sso">off</string>
      
 +    <!-- Colors -->
 +    <color name="background_color">#F7F7F7</color>
 +    <color name="actionbar_start_color">#1D2D44</color>
 +    <color name="actionbar_end_color">#1D2D44</color>
 +    
+     <!-- Multiaccount support -->
+     <bool name="multiaccount_support">true</bool>
+     
  </resources>
Simple merge
@@@ -22,9 -22,12 +22,15 @@@ import android.accounts.*
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
+ import android.os.Handler;
+ import android.widget.Toast;
  import com.owncloud.android.Log_OC;
 +import com.owncloud.android.MainApp;
 +
+ import com.owncloud.android.R;
++
  /**
   *  Authenticator for ownCloud accounts.
   * 
@@@ -102,25 -107,49 +111,49 @@@ public class AccountAuthenticator exten
              throws NetworkErrorException {
          Log_OC.i(TAG, "Adding account with type " + accountType
                  + " and auth token " + authTokenType);
-         try {
-             validateAccountType(accountType);
-         } catch (AuthenticatorException e) {
-             Log_OC.e(TAG, "Failed to validate account type " + accountType + ": "
-                     + e.getMessage());
-             e.printStackTrace();
-             return e.getFailureBundle();
-         }
-         final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
-         intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
-         intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType);
-         intent.putExtra(KEY_REQUIRED_FEATURES, requiredFeatures);
-         intent.putExtra(KEY_LOGIN_OPTIONS, options);
-         intent.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_CREATE);
-         setIntentFlags(intent);
          
          final Bundle bundle = new Bundle();
-         bundle.putParcelable(AccountManager.KEY_INTENT, intent);
+         
+         AccountManager accountManager = AccountManager.get(mContext);
 -        Account[] accounts = accountManager.getAccountsByType(ACCOUNT_TYPE);
++        Account[] accounts = accountManager.getAccountsByType(MainApp.getAccountType());
+         
+         if (mContext.getResources().getBoolean(R.bool.multiaccount_support) || accounts.length < 1) {
+             try {
+                 validateAccountType(accountType);
+             } catch (AuthenticatorException e) {
+                 Log_OC.e(TAG, "Failed to validate account type " + accountType + ": "
+                         + e.getMessage());
+                 e.printStackTrace();
+                 return e.getFailureBundle();
+             }
+             
+             final Intent intent = new Intent(mContext, AuthenticatorActivity.class);
+             intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
+             intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType);
+             intent.putExtra(KEY_REQUIRED_FEATURES, requiredFeatures);
+             intent.putExtra(KEY_LOGIN_OPTIONS, options);
+             intent.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_CREATE);
+             setIntentFlags(intent);
+             
+             bundle.putParcelable(AccountManager.KEY_INTENT, intent);
+         
+         } else {
+             // Return an error
+             bundle.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION);
+             bundle.putString(AccountManager.KEY_ERROR_MESSAGE, mContext.getString(R.string.auth_unsupported_multiaccount));
+            
+             mHandler.post(new Runnable() {
+                 @Override
+                 public void run() {
+                     Toast.makeText(mContext, R.string.auth_unsupported_multiaccount, Toast.LENGTH_SHORT).show();
+                 }
+             });
+             
+         }
+         
          return bundle;
      }