Skip to content

Commit

Permalink
Merge pull request #446 from auth0/update-dependencies
Browse files Browse the repository at this point in the history
Fix ValidatedInputView border color on focus change
  • Loading branch information
lbalmaceda authored Oct 19, 2017
2 parents 699e0da + 2a09c9a commit 7f84d31
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 58 deletions.
4 changes: 2 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand All @@ -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();
}
});
}
Expand Down Expand Up @@ -225,7 +225,7 @@ private void notifyEmailChanged(String emailInput) {
private Runnable uiUpdater = new Runnable() {
@Override
public void run() {
updateBorder(hasValidInput);
updateBorder();
}
};

Expand Down Expand Up @@ -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();
}

Expand All @@ -333,7 +331,8 @@ private void createBackground() {
*/
public void setDataType(@DataType int type) {
dataType = type;
updateBorder(true);
hasValidInput = true;
updateBorder();
setupInputValidation();
}

Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down
73 changes: 42 additions & 31 deletions lib/src/test/java/com/auth0/android/lock/WebProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,20 @@
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;
import org.junit.Test;
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;

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;
Expand Down Expand Up @@ -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()));
}

Expand All @@ -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()));
}

Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit 7f84d31

Please sign in to comment.