-
Notifications
You must be signed in to change notification settings - Fork 704
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
Conversation
@m-sameer Fix the Travis Build Error |
de7aae1
to
96fcdf5
Compare
@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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
build.gradle
Outdated
google() | ||
jcenter() |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
9e535b8
to
3c4515e
Compare
@miPlodder Please review. |
@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)) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. 😕
@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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-sameer And update the GIF after changing the solution. |
The errors are cleared on the login button click.
The GIF is already up to date. |
return false; | ||
} else if (password == null || password.isEmpty()) { | ||
credentialValid = false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
app/src/main/java/org/mifos/mobilebanking/presenters/LoginPresenter.java
Outdated
Show resolved
Hide resolved
@miPlodder The requested changes have been incorporated. |
@m-sameer Good job |
@miPlodder Thank you! |
Fixes #895
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 anythingIf you have multiple commits please combine them into one commit by squashing them.