OC-460:URL-input GONE. OC-394
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index c1ca605..ce704ca 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_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
@@ -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
-\r
+    \r
     private String mHostBaseUrl;\r
     private OwnCloudVersion mDiscoveredVersion;\r
 \r
@@ -141,6 +141,10 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
     private TextView mOAuthAuthEndpointText;\r
     private TextView mOAuthTokenEndpointText;\r
+    \r
+    private boolean mRefreshButtonEnabled;\r
+    \r
+    private boolean mHostUrlInputEnabled;\r
 \r
 \r
     /**\r
@@ -163,6 +167,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check);\r
         mOkButton = findViewById(R.id.buttonOK);\r
         mAuthStatusLayout = (TextView) findViewById(R.id.auth_status_text); \r
+        \r
+        /// set Host Url Input Enabled\r
+        mHostUrlInputEnabled = getResources().getBoolean(R.bool.show_server_url_input);\r
 \r
         /// complete label for 'register account' button\r
         Button b = (Button) findViewById(R.id.account_register);\r
@@ -176,6 +183,12 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         mAction = getIntent().getByteExtra(EXTRA_ACTION, ACTION_CREATE); \r
         mAccount = null;\r
         mHostBaseUrl = "";\r
+        if (!mHostUrlInputEnabled)\r
+        {\r
+            mHostUrlInput.setText(getString(R.string.server_url));\r
+            mHostUrlInput.setVisibility(View.GONE);\r
+            checkOcServer();\r
+        }\r
 \r
         if (savedInstanceState == null) {\r
             /// connection state and info\r
@@ -231,13 +244,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
-            }\r
+            }            \r
+            \r
+            // refresh button enabled\r
+            mRefreshButtonEnabled = savedInstanceState.getBoolean(KEY_REFRESH_BUTTON_ENABLED);\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
@@ -286,7 +302,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         });\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
@@ -295,7 +311,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 }\r
                 return true;\r
             }\r
-        });\r
+        });
     }\r
 \r
     /**\r
@@ -331,6 +347,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         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
@@ -407,6 +426,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
         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
@@ -439,7 +461,12 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
 \r
     private void checkOcServer() {\r
-        String uri = mHostUrlInput.getText().toString().trim();\r
+        String uri = trimUrlWebdav(mHostUrlInput.getText().toString().trim());\r
+        \r
+        if (!mHostUrlInputEnabled){\r
+            uri = getString(R.string.server_url);\r
+        }\r
+        \r
         mServerIsValid = false;\r
         mServerIsChecked = false;\r
         mOkButton.setEnabled(false);\r
@@ -681,15 +708,33 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 } else {\r
                     url = "http://" + url;\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
+\r
         }\r
+        Log_OC.d(TAG, "URL Normalize " + url);\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
@@ -1166,10 +1211,12 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \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
+        mRefreshButtonEnabled = false;\r
     }\r
 \r
     /**\r