diff --git a/lib/build.gradle b/lib/build.gradle index 2d2d3f195..49a0b5c42 100644 --- a/lib/build.gradle +++ b/lib/build.gradle @@ -39,9 +39,9 @@ dependencies { compile 'com.android.support:recyclerview-v7:25.3.1' compile 'com.android.support:support-v4:25.3.1' compile 'com.android.support:design:25.3.1' - compile 'com.google.code.gson:gson:2.8.0' + compile 'com.google.code.gson:gson:2.8.2' compile 'com.squareup:otto:1.3.8' - compile 'com.auth0.android:auth0:1.10.0' + compile 'com.auth0.android:auth0:1.11.0' testCompile 'junit:junit:4.12' testCompile 'org.hamcrest:hamcrest-library:1.3' testCompile 'org.robolectric:robolectric:3.1.2' diff --git a/lib/src/main/java/com/auth0/android/lock/views/ValidatedInputView.java b/lib/src/main/java/com/auth0/android/lock/views/ValidatedInputView.java index c3d1adb4a..b671046ef 100644 --- a/lib/src/main/java/com/auth0/android/lock/views/ValidatedInputView.java +++ b/lib/src/main/java/com/auth0/android/lock/views/ValidatedInputView.java @@ -84,7 +84,7 @@ public class ValidatedInputView extends LinearLayout { private ImageCheckbox showPasswordToggle; private IdentityListener identityListener; private int inputIcon; - private boolean hasValidInput; + private boolean hasValidInput = true; private boolean allowShowPassword = true; private View outline; private ShapeDrawable focusedOutlineBackground; @@ -148,7 +148,7 @@ private void init(AttributeSet attrs) { focusedOutlineBackground = ViewUtils.getRoundedOutlineBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_focused)); normalOutlineBackground = ViewUtils.getRoundedOutlineBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_normal)); errorOutlineBackground = ViewUtils.getRoundedOutlineBackground(getResources(), ContextCompat.getColor(getContext(), R.color.com_auth0_lock_input_field_border_error)); - updateBorder(true); + updateBorder(); setNextFocusRightId(R.id.com_auth0_lock_show_password_toggle); showPasswordToggle.setOnCheckedChangeListener(new ImageCheckbox.OnCheckedChangeListener() { @@ -173,7 +173,7 @@ public void onCheckedChanged(ImageButton view, boolean isChecked) { input.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { - updateBorder(true); + updateBorder(); } }); } @@ -225,7 +225,7 @@ private void notifyEmailChanged(String emailInput) { private Runnable uiUpdater = new Runnable() { @Override public void run() { - updateBorder(hasValidInput); + updateBorder(); } }; @@ -307,14 +307,12 @@ private void setupInputValidation() { /** * Updates the view knowing if the input is valid or not. - * - * @param isValid if the input is valid or not for this kind of DataType. */ @CallSuper - protected void updateBorder(boolean isValid) { + protected void updateBorder() { boolean isFocused = input.hasFocus() && !input.isInTouchMode(); - ViewUtils.setBackground(outline, isValid ? (isFocused ? focusedOutlineBackground : normalOutlineBackground) : errorOutlineBackground); - errorDescription.setVisibility(isValid ? GONE : VISIBLE); + ViewUtils.setBackground(outline, hasValidInput ? (isFocused ? focusedOutlineBackground : normalOutlineBackground) : errorOutlineBackground); + errorDescription.setVisibility(hasValidInput ? GONE : VISIBLE); requestLayout(); } @@ -333,7 +331,8 @@ private void createBackground() { */ public void setDataType(@DataType int type) { dataType = type; - updateBorder(true); + hasValidInput = true; + updateBorder(); setupInputValidation(); } @@ -348,15 +347,15 @@ protected int getDataType() { } /** - * Validates the input data and updates the icon. DataType must be set. + * Validates the input data and updates the border. DataType must be set. * Empty fields are considered valid. * * @return whether the data is valid or not. */ public boolean validate() { - boolean isValid = validate(true); - updateBorder(isValid); - return isValid; + hasValidInput = validate(true); + updateBorder(); + return hasValidInput; } /** @@ -481,7 +480,8 @@ public void setIcon(@DrawableRes int icon) { public void clearInput() { Log.v(TAG, "Input cleared and validation errors removed"); input.setText(""); - updateBorder(true); + hasValidInput = true; + updateBorder(); showPasswordToggle.setChecked(false); } diff --git a/lib/src/main/java/com/auth0/android/lock/views/ValidatedPasswordInputView.java b/lib/src/main/java/com/auth0/android/lock/views/ValidatedPasswordInputView.java index 7dc8d184d..dc1f4f457 100644 --- a/lib/src/main/java/com/auth0/android/lock/views/ValidatedPasswordInputView.java +++ b/lib/src/main/java/com/auth0/android/lock/views/ValidatedPasswordInputView.java @@ -10,6 +10,7 @@ public class ValidatedPasswordInputView extends ValidatedInputView { private static final String TAG = ValidatedPasswordInputView.class.getSimpleName(); private PasswordStrengthView strengthView; + private boolean hasValidInput = true; public ValidatedPasswordInputView(Context context) { super(context); @@ -35,20 +36,16 @@ public void init() { protected boolean validate(boolean validateEmptyFields) { String value = getText(); //Run strength validation to update ui - final boolean valid = strengthView.isValid(value); - if (!validateEmptyFields && value.isEmpty()) { - return true; - } - - Log.v(TAG, "Field validation results: Is valid? " + valid); - return valid; + hasValidInput = strengthView.isValid(value) || !validateEmptyFields && value.isEmpty(); + Log.v(TAG, "Field validation results: Is valid? " + hasValidInput); + return hasValidInput; } @Override - protected void updateBorder(boolean isValid) { - super.updateBorder(isValid); + protected void updateBorder() { + super.updateBorder(); if (strengthView != null && strengthView.isEnabled()) { - strengthView.setVisibility(!isValid || !getText().isEmpty() ? VISIBLE : GONE); + strengthView.setVisibility(!hasValidInput || !getText().isEmpty() ? VISIBLE : GONE); } } diff --git a/lib/src/test/java/com/auth0/android/lock/WebProviderTest.java b/lib/src/test/java/com/auth0/android/lock/WebProviderTest.java index f5cbd0fa2..fe38a54a2 100644 --- a/lib/src/test/java/com/auth0/android/lock/WebProviderTest.java +++ b/lib/src/test/java/com/auth0/android/lock/WebProviderTest.java @@ -8,7 +8,6 @@ import com.auth0.android.lock.internal.configuration.Options; import com.auth0.android.provider.AuthCallback; import com.auth0.android.provider.AuthenticationActivity; -import com.auth0.android.provider.WebAuthActivity; import org.junit.Before; import org.junit.Rule; @@ -16,7 +15,6 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; -import org.mockito.Mock; import org.robolectric.Robolectric; import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; @@ -24,7 +22,6 @@ import java.util.HashMap; import java.util.Map; -import static android.support.test.espresso.intent.matcher.IntentMatchers.hasAction; import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent; import static android.support.test.espresso.intent.matcher.UriMatchers.hasHost; import static android.support.test.espresso.intent.matcher.UriMatchers.hasParamWithValue; @@ -88,12 +85,15 @@ public void shouldStartWithCustomAuthenticationParameters() throws Exception { Intent intent = intentCaptor.getValue(); assertThat(intent, is(notNullValue())); - assertThat(intent.getData(), hasHost("domain.auth0.com")); - assertThat(intent.getData(), hasParamWithValue("custom-param-1", "value-1")); - assertThat(intent.getData(), hasParamWithValue("custom-param-2", "value-2")); - assertThat(intent.getData(), hasParamWithValue("client_id", "clientId")); - assertThat(intent.getData(), hasParamWithValue("connection", "my-connection")); - assertThat(intent.getData(), hasParamWithValue("audience", "https://me.auth0.com/myapi")); + + assertThat(intent.hasExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"), is(true)); + Uri authorizeUri = intent.getParcelableExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"); + assertThat(authorizeUri, hasHost("domain.auth0.com")); + assertThat(authorizeUri, hasParamWithValue("custom-param-1", "value-1")); + assertThat(authorizeUri, hasParamWithValue("custom-param-2", "value-2")); + assertThat(authorizeUri, hasParamWithValue("client_id", "clientId")); + assertThat(authorizeUri, hasParamWithValue("connection", "my-connection")); + assertThat(authorizeUri, hasParamWithValue("audience", "https://me.auth0.com/myapi")); assertThat(intent, hasComponent(AuthenticationActivity.class.getName())); } @@ -116,10 +116,13 @@ public void shouldStartWithCustomAudience() throws Exception { Intent intent = intentCaptor.getValue(); assertThat(intent, is(notNullValue())); - assertThat(intent.getData(), hasHost("domain.auth0.com")); - assertThat(intent.getData(), hasParamWithValue("client_id", "clientId")); - assertThat(intent.getData(), hasParamWithValue("connection", "my-connection")); - assertThat(intent.getData(), hasParamWithValue("audience", "https://me.auth0.com/myapi")); + + assertThat(intent.hasExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"), is(true)); + Uri authorizeUri = intent.getParcelableExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"); + assertThat(authorizeUri, hasHost("domain.auth0.com")); + assertThat(authorizeUri, hasParamWithValue("client_id", "clientId")); + assertThat(authorizeUri, hasParamWithValue("connection", "my-connection")); + assertThat(authorizeUri, hasParamWithValue("audience", "https://me.auth0.com/myapi")); assertThat(intent, hasComponent(AuthenticationActivity.class.getName())); } @@ -147,16 +150,20 @@ public void shouldStartBrowserWithOptions() throws Exception { Intent intent = intentCaptor.getValue(); assertThat(intent, is(notNullValue())); - assertThat(intent.getData().getQueryParameter("redirect_uri"), is(notNullValue())); - Uri redirectUri = Uri.parse(intent.getData().getQueryParameter("redirect_uri")); + assertThat(intent.hasExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"), is(true)); + Uri authorizeUri = intent.getParcelableExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"); + + assertThat(authorizeUri.getQueryParameter("redirect_uri"), is(notNullValue())); + Uri redirectUri = Uri.parse(authorizeUri.getQueryParameter("redirect_uri")); assertThat(redirectUri, hasScheme("auth0")); - assertThat(intent.getData(), hasHost("domain.auth0.com")); - assertThat(intent.getData(), hasParamWithValue("client_id", "clientId")); - assertThat(intent.getData(), hasParamWithValue("connection", "my-connection")); - assertThat(intent.getData(), hasParamWithValue("custom-param-1", "value-1")); - assertThat(intent.getData(), hasParamWithValue("custom-param-2", "value-2")); - assertThat(intent.getData(), hasParamWithValue("scope", "email profile photos")); - assertThat(intent.getData(), hasParamWithValue("connection_scope", "the connection scope")); + + assertThat(authorizeUri, hasHost("domain.auth0.com")); + assertThat(authorizeUri, hasParamWithValue("client_id", "clientId")); + assertThat(authorizeUri, hasParamWithValue("connection", "my-connection")); + assertThat(authorizeUri, hasParamWithValue("custom-param-1", "value-1")); + assertThat(authorizeUri, hasParamWithValue("custom-param-2", "value-2")); + assertThat(authorizeUri, hasParamWithValue("scope", "email profile photos")); + assertThat(authorizeUri, hasParamWithValue("connection_scope", "the connection scope")); assertThat(intent.hasExtra("com.auth0.android.EXTRA_USE_BROWSER"), is(true)); assertThat(intent.getBooleanExtra("com.auth0.android.EXTRA_USE_BROWSER", false), is(true)); assertThat(intent, hasComponent(AuthenticationActivity.class.getName())); @@ -186,16 +193,20 @@ public void shouldStartWebViewWithOptions() throws Exception { Intent intent = intentCaptor.getValue(); assertThat(intent, is(notNullValue())); - assertThat(intent.getData().getQueryParameter("redirect_uri"), is(notNullValue())); - Uri redirectUri = Uri.parse(intent.getData().getQueryParameter("redirect_uri")); + assertThat(intent.hasExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"), is(true)); + Uri authorizeUri = intent.getParcelableExtra("com.auth0.android.EXTRA_AUTHORIZE_URI"); + + assertThat(authorizeUri.getQueryParameter("redirect_uri"), is(notNullValue())); + Uri redirectUri = Uri.parse(authorizeUri.getQueryParameter("redirect_uri")); assertThat(redirectUri, hasScheme("auth0")); - assertThat(intent.getData(), hasHost("domain.auth0.com")); - assertThat(intent.getData(), hasParamWithValue("client_id", "clientId")); - assertThat(intent.getData(), hasParamWithValue("connection", "my-connection")); - assertThat(intent.getData(), hasParamWithValue("custom-param-1", "value-1")); - assertThat(intent.getData(), hasParamWithValue("custom-param-2", "value-2")); - assertThat(intent.getData(), hasParamWithValue("scope", "email profile photos")); - assertThat(intent.getData(), hasParamWithValue("connection_scope", "the connection scope")); + + assertThat(authorizeUri, hasHost("domain.auth0.com")); + assertThat(authorizeUri, hasParamWithValue("client_id", "clientId")); + assertThat(authorizeUri, hasParamWithValue("connection", "my-connection")); + assertThat(authorizeUri, hasParamWithValue("custom-param-1", "value-1")); + assertThat(authorizeUri, hasParamWithValue("custom-param-2", "value-2")); + assertThat(authorizeUri, hasParamWithValue("scope", "email profile photos")); + assertThat(authorizeUri, hasParamWithValue("connection_scope", "the connection scope")); assertThat(intent.hasExtra("com.auth0.android.EXTRA_USE_BROWSER"), is(true)); assertThat(intent.getBooleanExtra("com.auth0.android.EXTRA_USE_BROWSER", true), is(false)); assertThat(intent, hasComponent(AuthenticationActivity.class.getName()));