X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/16403b27226058d3dbdc0ecd4813f2fe1770e54a..14a60a13e7a23e64098aecbc7fbc927706faf336:/src/com/owncloud/android/authentication/AuthenticatorActivity.java diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index b79e3d17..375ef3b1 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -89,7 +89,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT"; private static final String KEY_OC_VERSION = "OC_VERSION"; private static final String KEY_ACCOUNT = "ACCOUNT"; - private static final String KEY_SERVER_CHECKED_AND_VALID = "SERVER_CHECKED_AND_VALID"; + private static final String KEY_SERVER_VALID = "SERVER_VALID"; + private static final String KEY_SERVER_CHECKED = "SERVER_CHECKED"; private static final String KEY_SERVER_CHECK_IN_PROGRESS = "SERVER_CHECK_IN_PROGRESS"; private static final String KEY_SERVER_STATUS_TEXT = "SERVER_STATUS_TEXT"; private static final String KEY_SERVER_STATUS_ICON = "SERVER_STATUS_ICON"; @@ -114,7 +115,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private OwnCloudVersion mDiscoveredVersion; private int mServerStatusText, mServerStatusIcon; - private boolean mServerCheckedAndValid, mIsSslConn; + private boolean mServerIsChecked, mServerIsValid, mIsSslConn; private int mAuthStatusText, mAuthStatusIcon; private final Handler mHandler = new Handler(); @@ -142,8 +143,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private TextView mOAuthAuthEndpointText; private TextView mOAuthTokenEndpointText; - private HostUrlWatcher mHostUrlChangedListener; - /** * {@inheritDoc} @@ -183,7 +182,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (savedInstanceState == null) { /// connection state and info mServerStatusText = mServerStatusIcon = 0; - mServerCheckedAndValid = false; + mServerIsValid = false; + mServerIsChecked = false; mIsSslConn = false; mAuthStatusText = mAuthStatusIcon = 0; @@ -209,7 +209,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } else { /// connection state and info - mServerCheckedAndValid = savedInstanceState.getBoolean(KEY_SERVER_CHECKED_AND_VALID); + mServerIsValid = savedInstanceState.getBoolean(KEY_SERVER_VALID); + mServerIsChecked = savedInstanceState.getBoolean(KEY_SERVER_CHECKED); mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT); mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON); mIsSslConn = savedInstanceState.getBoolean(KEY_IS_SSL_CONN); @@ -235,6 +236,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity showServerStatus(); showAuthStatus(); + if (mServerIsChecked && !mServerIsValid) showRefreshButton(); + mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) { mOAuth2Check.setVisibility(View.GONE); @@ -245,7 +248,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mHostUrlInput.setEnabled(false); mUsernameInput.setEnabled(false); mOAuth2Check.setVisibility(View.GONE); - if (!mServerCheckedAndValid && mOcServerChkOperation == null) { + if (!mServerIsValid && mOcServerChkOperation == null) { checkOcServer(); } } @@ -262,25 +265,27 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity return true; } }); + mHostUrlInput.addTextChangedListener(new TextWatcher() { + + @Override + public void afterTextChanged(Editable s) { + if (!mHostBaseUrl.equals(normalizeUrl(mHostUrlInput.getText().toString()))) { + mOkButton.setEnabled(false); + } + } + + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) {} + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) {} + + }); mPasswordInput.setOnFocusChangeListener(this); mPasswordInput.setImeOptions(EditorInfo.IME_ACTION_DONE); mPasswordInput.setOnEditorActionListener(this); } - @Override - protected void onStart() { - super.onStart(); - //mHostUrlChangedListener = new HostUrlWatcher(); - //mHostUrlInput.addTextChangedListener(mHostUrlChangedListener); - } - - @Override - protected void onStop() { - super.onStop(); - mHostUrlInput.removeTextChangedListener(mHostUrlChangedListener); - } - - /** * Saves relevant state before {@link #onPause()} * @@ -296,8 +301,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /// connection state and info outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText); outState.putInt(KEY_SERVER_STATUS_ICON, mServerStatusIcon); - outState.putBoolean(KEY_SERVER_CHECKED_AND_VALID, mServerCheckedAndValid); - outState.putBoolean(KEY_SERVER_CHECK_IN_PROGRESS, (!mServerCheckedAndValid && mOcServerChkOperation != null)); + outState.putBoolean(KEY_SERVER_VALID, mServerIsValid); + outState.putBoolean(KEY_SERVER_CHECKED, mServerIsChecked); + outState.putBoolean(KEY_SERVER_CHECK_IN_PROGRESS, (!mServerIsValid && mOcServerChkOperation != null)); outState.putBoolean(KEY_IS_SSL_CONN, mIsSslConn); outState.putInt(KEY_AUTH_STATUS_ICON, mAuthStatusIcon); outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText); @@ -408,13 +414,16 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private void onUrlInputFocusLost(TextView hostInput) { if (!mHostBaseUrl.equals(normalizeUrl(mHostUrlInput.getText().toString()))) { checkOcServer(); + } else { + mOkButton.setEnabled(mServerIsValid); } } private void checkOcServer() { String uri = mHostUrlInput.getText().toString().trim(); - mServerCheckedAndValid = false; + mServerIsValid = false; + mServerIsChecked = false; mOkButton.setEnabled(false); mDiscoveredVersion = null; hideRefreshButton(); @@ -585,12 +594,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private void onOcServerCheckFinish(OwnCloudServerCheckOperation operation, RemoteOperationResult result) { if (operation.equals(mOcServerChkOperation)) { /// save result state - mServerCheckedAndValid = result.isSuccess(); + mServerIsChecked = true; + mServerIsValid = result.isSuccess(); mIsSslConn = (result.getCode() == ResultCode.OK_SSL); mOcServerChkOperation = null; /// update status icon and text - if (mServerCheckedAndValid) { + if (mServerIsValid) { hideRefreshButton(); } else { showRefreshButton(); @@ -609,7 +619,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mHostBaseUrl = normalizeUrl(mHostUrlInput.getText().toString()); /// allow or not the user try to access the server - mOkButton.setEnabled(mServerCheckedAndValid); + mOkButton.setEnabled(mServerIsValid); } // else nothing ; only the last check operation is considered; // multiple can be triggered if the user amends a URL before a previous check can be triggered @@ -632,7 +642,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity url = url.substring(0, url.length() - 1); } } - return url; + return (url != null ? url : ""); } /** @@ -1231,24 +1241,4 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity public abstract boolean onDrawableTouch(final MotionEvent event); } - - private class HostUrlWatcher implements TextWatcher { - - @Override - public void afterTextChanged(Editable s) { - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - if (mServerCheckedAndValid) { - mServerCheckedAndValid = false; - mOkButton.setEnabled(false); // avoids that the 'connect' button can be clicked if the test was previously passed - } - } - - } }