Merge branch 'remove_ActionBarSherlock' into navigationDrawer_update
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index ccb0f85..3ab7690 100644 (file)
@@ -42,6 +42,7 @@ import android.os.Bundle;
 import android.os.Handler;\r
 import android.os.IBinder;\r
 import android.preference.PreferenceManager;\r
 import android.os.Handler;\r
 import android.os.IBinder;\r
 import android.preference.PreferenceManager;\r
+import android.support.v4.app.DialogFragment;\r
 import android.support.v4.app.Fragment;\r
 import android.support.v4.app.FragmentManager;\r
 import android.support.v4.app.FragmentTransaction;\r
 import android.support.v4.app.Fragment;\r
 import android.support.v4.app.FragmentManager;\r
 import android.support.v4.app.FragmentTransaction;\r
@@ -65,7 +66,6 @@ import android.widget.TextView;
 import android.widget.TextView.OnEditorActionListener;\r
 import android.widget.Toast;\r
 \r
 import android.widget.TextView.OnEditorActionListener;\r
 import android.widget.Toast;\r
 \r
-import com.actionbarsherlock.app.SherlockDialogFragment;\r
 import com.owncloud.android.MainApp;\r
 import com.owncloud.android.R;\r
 import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
 import com.owncloud.android.MainApp;\r
 import com.owncloud.android.R;\r
 import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
@@ -189,8 +189,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     /// Identifier of operation in progress which result shouldn't be lost \r
     private long mWaitingForOpId = Long.MAX_VALUE;\r
 \r
     /// Identifier of operation in progress which result shouldn't be lost \r
     private long mWaitingForOpId = Long.MAX_VALUE;\r
 \r
-    private final String BASIC_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType());\r
-    private final String OAUTH_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType());\r
+    private final String BASIC_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypePass(\r
+            MainApp.getAccountType());\r
+    private final String OAUTH_TOKEN_TYPE = AccountTypeUtils.getAuthTokenTypeAccessToken(\r
+            MainApp.getAccountType());\r
     private final String SAML_TOKEN_TYPE =\r
             AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType());\r
 \r
     private final String SAML_TOKEN_TYPE =\r
             AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType());\r
 \r
@@ -908,7 +910,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);\r
 \r
         /// validate credentials accessing the root folder\r
         dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);\r
 \r
         /// validate credentials accessing the root folder\r
-        OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(username, password);\r
+        OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBasicCredentials(username,\r
+                password);\r
         accessRootFolder(credentials);\r
     }\r
 \r
         accessRootFolder(credentials);\r
     }\r
 \r
@@ -1016,7 +1019,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 \r
                     } catch (AccountNotFoundException e) {\r
                         Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);\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
+                        Toast.makeText(this, R.string.auth_account_does_not_exist,\r
+                                Toast.LENGTH_SHORT).show();\r
                         finish();\r
                     }\r
                 }\r
                         finish();\r
                     }\r
                 }\r
@@ -1120,13 +1124,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 \r
     // TODO remove, if possible\r
     private String trimUrlWebdav(String url){       \r
 \r
     // TODO remove, if possible\r
     private String trimUrlWebdav(String url){       \r
-        if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0)){\r
-            url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0.length());             \r
-        } else if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_2_0)){\r
-            url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_2_0.length());             \r
-        } else if (url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_1_2)){\r
-            url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_1_2.length());             \r
-        } \r
+        if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0_AND_LATER)){\r
+            url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0_AND_LATER.length());\r
+        }\r
         return (url != null ? url : "");\r
     }\r
 \r
         return (url != null ? url : "");\r
     }\r
 \r
@@ -1328,7 +1328,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
 \r
             /// validate token accessing to root folder / getting session\r
             Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
 \r
             /// validate token accessing to root folder / getting session\r
-            OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBearerCredentials(mAuthToken);\r
+            OwnCloudCredentials credentials = OwnCloudCredentialsFactory.newBearerCredentials(\r
+                    mAuthToken);\r
             accessRootFolder(credentials);\r
 \r
         } else {\r
             accessRootFolder(credentials);\r
 \r
         } else {\r
@@ -1365,7 +1366,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
 \r
                 } catch (AccountNotFoundException e) {\r
                     Log_OC.e(TAG, "Account " + mAccount + " was removed!", e);\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
+                    Toast.makeText(this, R.string.auth_account_does_not_exist,\r
+                            Toast.LENGTH_SHORT).show();\r
                     finish();\r
                 }\r
             }\r
                     finish();\r
                 }\r
             }\r
@@ -1488,6 +1490,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
                 );\r
             }\r
 \r
                 );\r
             }\r
 \r
+            // include account version with the new account\r
+            mAccountMgr.setUserData(\r
+                mAccount,\r
+                Constants.KEY_OC_ACCOUNT_VERSION,\r
+                Integer.toString(AccountUtils.ACCOUNT_VERSION)\r
+            );\r
+\r
             /// add the new account as default in preferences, if there is none already\r
             Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);\r
             if (defaultAccount == null) {\r
             /// add the new account as default in preferences, if there is none already\r
             Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);\r
             if (defaultAccount == null) {\r
@@ -1713,8 +1722,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             mAuthToken = sessionCookie;\r
             getRemoteUserNameOperation(sessionCookie, true);\r
             Fragment fd = getSupportFragmentManager().findFragmentByTag(SAML_DIALOG_TAG);\r
             mAuthToken = sessionCookie;\r
             getRemoteUserNameOperation(sessionCookie, true);\r
             Fragment fd = getSupportFragmentManager().findFragmentByTag(SAML_DIALOG_TAG);\r
-            if (fd != null && fd instanceof SherlockDialogFragment) {\r
-                Dialog d = ((SherlockDialogFragment)fd).getDialog();\r
+            if (fd != null && fd instanceof DialogFragment) {\r
+                Dialog d = ((DialogFragment)fd).getDialog();\r
                 if (d != null && d.isShowing()) {\r
                     d.dismiss();\r
                 }\r
                 if (d != null && d.isShowing()) {\r
                     d.dismiss();\r
                 }\r
@@ -1816,8 +1825,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     \r
     private void dismissDialog(String dialogTag){\r
         Fragment frag = getSupportFragmentManager().findFragmentByTag(dialogTag);\r
     \r
     private void dismissDialog(String dialogTag){\r
         Fragment frag = getSupportFragmentManager().findFragmentByTag(dialogTag);\r
-        if (frag != null && frag instanceof SherlockDialogFragment) {\r
-            SherlockDialogFragment dialog = (SherlockDialogFragment) frag;\r
+        if (frag != null && frag instanceof DialogFragment) {\r
+            DialogFragment dialog = (DialogFragment) frag;\r
             dialog.dismiss();\r
         }\r
     }\r
             dialog.dismiss();\r
         }\r
     }\r