Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #895: Add error text below password EditText in LoginActivity #913

Merged
merged 1 commit into from
Jan 2, 2019

Conversation

m-sameer
Copy link
Contributor

@m-sameer m-sameer commented Oct 25, 2018

Fixes #895

20181029_184051 1

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Apply the AndroidStyle.xml style template to your code in Android Studio.

  • Run the unit tests with ./gradlew check to make sure you didn't break anything

  • If you have multiple commits please combine them into one commit by squashing them.

@luckyman20
Copy link
Collaborator

@m-sameer Fix the Travis Build Error

@m-sameer m-sameer force-pushed the issue#895 branch 2 times, most recently from de7aae1 to 96fcdf5 Compare October 25, 2018 19:08
@m-sameer
Copy link
Contributor Author

@luckyman20 Done. 😄

app/build.gradle Outdated
@@ -77,6 +77,9 @@ dependencies {
implementation "com.google.android.gms:play-services-oss-licenses:$rootProject.playServicesVersion"
implementation "com.isseiaoki:simplecropview:$rootProject.cropviewVersion"

// Multidex
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-sameer Remove it. PR #909 will be merged then you can pull that code and update your PR.

build.gradle Outdated
google()
jcenter()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this too.

@@ -178,22 +178,25 @@ private boolean isCredentialsValid(final String username, final String password)

final Resources resources = context.getResources();
final String correctUsername = username.replaceFirst("\\s++$", "").trim();
boolean usernameValid = true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-sameer Check your logic, no additional variable is required and no checks for passwords are added.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miPlodder If I don't use an additional variable for checking the username validity and return false directly the password EditText will not be checked. 😕
These are the minimal changes I can think of, can you suggest any?

Copy link
Collaborator

@miPlodder miPlodder Oct 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-sameer Then, don't return at that stage. Try to improve your solution and use a TextWatcher then you wouldn't be needing any additional variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miPlodder If I use a TextWatcher the credentials will be checked on every tap on the keyboard but they should be checked only when the login button is pressed. Also adding a listener will be more complicated and will add more lines than simply using a boolean variable.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-sameer It will give a better UX. Try to sign up/ sign in to any software, which one will you be convenient, the one which you get an instant feedback.

I know it will be more work. You don't worry about the deadline, I will extend it and don't focus on doing a high number of tasks, but focus on doing Quality tasks.

When free read this.

Copy link
Collaborator

@luckyman20 luckyman20 Oct 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-sameer @miPlodder I have another approach which might satisfy need of both of you.

You can add a onFocus of Password EditText and then check if username is null or not.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@luckyman20 That is what I'm talking. For example, if a user is entering his username, we don't want the validation/textwatcher to work. When he changes his focus to another field, then the textwatcher should be active. Now, when user edits his username, how the textwatcher will be active and showing all the relevant errors.

See Paypal mobile interface while signing up.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miPlodder I think we won't be needing a TextWatcher for this, we have to split the isCredentialsValid into two separate methods namely isUsernameValid and isPasswordValid and we will call isUsernameValid in onFocus of Password EditText and then call isPasswordValid in onSubmit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miPlodder I've added an OnFocusChangeListener which checks the credentials on focus change. Earlier I was checking the credentials on button click because the issue said Error text beneath EditText should be shown for all the EditText on clicking the Login Button.
I agree that we should strive to improve the UX and the link to the design website was helpful. :)
As you said, I'm focused on doing high-quality tasks rather than higher quantity.

@miPlodder @luckyman20 Thanks for your help.

@m-sameer m-sameer force-pushed the issue#895 branch 3 times, most recently from 9e535b8 to 3c4515e Compare October 28, 2018 09:05
@m-sameer
Copy link
Contributor Author

@miPlodder Please review.

@luckyman20
Copy link
Collaborator

@m-sameer Fix the travis build

@@ -75,7 +75,7 @@ public void detachView() {
*/
public void login(final String username, final String password) {
checkViewAttached();
if (isCredentialsValid(username, password)) {
if (isUsernameValid(username) & isPasswordValid(password)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build is failing because I'm using & here instead of &&. I cannot use short circuit and operation because both sides of the condition need to be called to show error on the username as well as the password field. @miPlodder As you said I'm not using any extra variables but this is failing on the findbugs check with the warning NS_DANGEROUS_NON_SHORT_CIRCUIT: Potentially dangerous use of non-short-circuit logic.

@@ -75,7 +75,7 @@ public void detachView() {
*/
public void login(final String username, final String password) {
checkViewAttached();
if (isCredentialsValid(username, password)) {
if ((isUsernameValid(username) | isPasswordValid(password)) == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use boolean functions and why are you doing Bitwise OR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I have mentioned before, if I use boolean and use logical && isPasswordValid will not be called if isUsernameValid return false as a result the error for the password field will not be shown.

Also, If I'm using boolean and bitwise & the build is failing with the error NS_DANGEROUS_NON_SHORT_CIRCUIT: Potentially dangerous use of non-short-circuit logic as we should not use bitwise operators for boolean values.

Bitwise operator is used to call both the methods in any case to show the error for both the fields (username and password).

Copy link
Collaborator

@miPlodder miPlodder Oct 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, good hack. But this is not a good way to do it. That is what Build is also trying to say. Try to see #907 and implement it. (not fully, but partially as that code has more features also)

Separating the methods for validation is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miPlodder That will require a boolean variable as I was doing it before. 😕

@m-sameer
Copy link
Contributor Author

@miPlodder I've updated the PR again using boolean variables and the approach is similar to #907. I've tried using many approaches, if anything is wrong with this one please let me know. The build is passing and there are no performance issues.

return false;
} else if (password == null || password.isEmpty()) {
credentialValid = false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-sameer Add else and hide errors there. See #907 for reference.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-sameer Remove this
and add else there remove the error.

@miPlodder
Copy link
Collaborator

@m-sameer And update the GIF after changing the solution.

@m-sameer
Copy link
Contributor Author

The errors are cleared on the login button click.

tilUsername.setErrorEnabled(false);
tilPassword.setErrorEnabled(false);

The GIF is already up to date.

return false;
} else if (password == null || password.isEmpty()) {
credentialValid = false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@m-sameer Remove this
and add else there remove the error.

@m-sameer
Copy link
Contributor Author

@miPlodder The requested changes have been incorporated.

@miPlodder miPlodder merged commit f4ec0b0 into openMF:development Jan 2, 2019
@miPlodder
Copy link
Collaborator

@m-sameer Good job

@m-sameer
Copy link
Contributor Author

m-sameer commented Jan 2, 2019

@miPlodder Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants