Merge branch 'fixed_contradicted_messages_in_login_view' into develop
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index c1ca605..3c34be6 100644 (file)
@@ -97,6 +97,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
     private static final String KEY_PASSWORD_VISIBLE = "PASSWORD_VISIBLE";\r
     private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
     private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
     private static final String KEY_PASSWORD_VISIBLE = "PASSWORD_VISIBLE";\r
     private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
     private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
+    private static final String KEY_REFRESH_BUTTON_ENABLED = "KEY_REFRESH_BUTTON_ENABLED";\r
 \r
     private static final String OAUTH_MODE_ON = "on";\r
     private static final String OAUTH_MODE_OFF = "off";\r
 \r
     private static final String OAUTH_MODE_ON = "on";\r
     private static final String OAUTH_MODE_OFF = "off";\r
@@ -109,8 +110,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
     public static final byte ACTION_CREATE = 0;\r
     public static final byte ACTION_UPDATE_TOKEN = 1;\r
 \r
     public static final byte ACTION_CREATE = 0;\r
     public static final byte ACTION_UPDATE_TOKEN = 1;\r
-\r
-\r
+    \r
     private String mHostBaseUrl;\r
     private OwnCloudVersion mDiscoveredVersion;\r
 \r
     private String mHostBaseUrl;\r
     private OwnCloudVersion mDiscoveredVersion;\r
 \r
@@ -141,6 +141,8 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
     private TextView mOAuthAuthEndpointText;\r
     private TextView mOAuthTokenEndpointText;\r
 \r
     private TextView mOAuthAuthEndpointText;\r
     private TextView mOAuthTokenEndpointText;\r
+    \r
+    private boolean mRefreshButtonEnabled;\r
 \r
 \r
     /**\r
 \r
 \r
     /**\r
@@ -231,13 +233,16 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             // check if server check was interrupted by a configuration change\r
             if (savedInstanceState.getBoolean(KEY_SERVER_CHECK_IN_PROGRESS, false)) {\r
                 checkOcServer();\r
             // check if server check was interrupted by a configuration change\r
             if (savedInstanceState.getBoolean(KEY_SERVER_CHECK_IN_PROGRESS, false)) {\r
                 checkOcServer();\r
-            }\r
+            }            \r
+            \r
+            // refresh button enabled\r
+            mRefreshButtonEnabled = savedInstanceState.getBoolean(KEY_REFRESH_BUTTON_ENABLED);\r
 \r
         }\r
 \r
         showServerStatus();\r
         showAuthStatus();\r
 \r
         }\r
 \r
         showServerStatus();\r
         showAuthStatus();\r
-        if (mServerIsChecked && !mServerIsValid) showRefreshButton();\r
+        if (mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled) showRefreshButton();\r
         mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes\r
 \r
         if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) {\r
         mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes\r
 \r
         if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) {\r
@@ -286,7 +291,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         });\r
         mPasswordInput.setOnFocusChangeListener(this);\r
         mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE);\r
         });\r
         mPasswordInput.setOnFocusChangeListener(this);\r
         mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE);\r
-        mPasswordInput.setOnEditorActionListener(this);\r
+        mPasswordInput.setOnEditorActionListener(this);
         mPasswordInput.setOnTouchListener(new RightDrawableOnTouchListener() {\r
             @Override\r
             public boolean onDrawableTouch(final MotionEvent event) {\r
         mPasswordInput.setOnTouchListener(new RightDrawableOnTouchListener() {\r
             @Override\r
             public boolean onDrawableTouch(final MotionEvent event) {\r
@@ -295,7 +300,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 }\r
                 return true;\r
             }\r
                 }\r
                 return true;\r
             }\r
-        });\r
+        });
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r
@@ -331,6 +336,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         if (mAccount != null) {\r
             outState.putParcelable(KEY_ACCOUNT, mAccount);\r
         }\r
         if (mAccount != null) {\r
             outState.putParcelable(KEY_ACCOUNT, mAccount);\r
         }\r
+        \r
+        // refresh button enabled\r
+        outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, mRefreshButtonEnabled);\r
 \r
     }\r
 \r
 \r
     }\r
 \r
@@ -407,6 +415,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         if (view.getId() == R.id.hostUrlInput) {   \r
             if (!hasFocus) {\r
                 onUrlInputFocusLost((TextView) view);\r
         if (view.getId() == R.id.hostUrlInput) {   \r
             if (!hasFocus) {\r
                 onUrlInputFocusLost((TextView) view);\r
+                if (!mServerIsValid) {\r
+                    showRefreshButton();\r
+                }\r
             }\r
             else {\r
                 hideRefreshButton();\r
             }\r
             else {\r
                 hideRefreshButton();\r
@@ -439,7 +450,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
 \r
     private void checkOcServer() {\r
 \r
 \r
     private void checkOcServer() {\r
-        String uri = mHostUrlInput.getText().toString().trim();\r
+        String uri = trimUrlWebdav(mHostUrlInput.getText().toString().trim());\r
         mServerIsValid = false;\r
         mServerIsChecked = false;\r
         mOkButton.setEnabled(false);\r
         mServerIsValid = false;\r
         mServerIsChecked = false;\r
         mOkButton.setEnabled(false);\r
@@ -681,15 +692,33 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 } else {\r
                     url = "http://" + url;\r
                 }\r
                 } else {\r
                     url = "http://" + url;\r
                 }\r
-\r
             }\r
             }\r
+\r
+            // OC-208: Add suffix remote.php/webdav to normalize (OC-34)            \r
+            url = trimUrlWebdav(url);\r
+\r
             if (url.endsWith("/")) {\r
                 url = url.substring(0, url.length() - 1);\r
             }\r
             if (url.endsWith("/")) {\r
                 url = url.substring(0, url.length() - 1);\r
             }\r
+\r
         }\r
         }\r
+        Log_OC.d(TAG, "URL Normalize " + url);\r
         return (url != null ? url : "");\r
     }\r
 \r
         return (url != null ? url : "");\r
     }\r
 \r
+\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
+        return (url != null ? url : "");\r
+    }\r
+    \r
+    \r
     /**\r
      * Chooses the right icon and text to show to the user for the received operation result.\r
      * \r
     /**\r
      * Chooses the right icon and text to show to the user for the received operation result.\r
      * \r
@@ -1166,10 +1195,12 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
     private void showRefreshButton() {\r
         mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0);\r
 \r
     private void showRefreshButton() {\r
         mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_action_refresh_black, 0);\r
+        mRefreshButtonEnabled = true;\r
     }\r
 \r
     private void hideRefreshButton() {\r
         mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
     }\r
 \r
     private void hideRefreshButton() {\r
         mHostUrlInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
+        mRefreshButtonEnabled = false;\r
     }\r
 \r
     /**\r
     }\r
 \r
     /**\r