Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1413 from edx/LEARNER-7739
Browse files Browse the repository at this point in the history
Fields validations & exception handling on Login Screen
  • Loading branch information
omerhabib26 authored Jun 1, 2020
2 parents 33efcee + 85174f7 commit 808ddb8
Showing 1 changed file with 45 additions and 9 deletions.
54 changes: 45 additions & 9 deletions OpenEdXMobile/src/main/java/org/edx/mobile/view/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.View.OnClickListener;
Expand Down Expand Up @@ -110,6 +112,40 @@ public void onClick(View v) {
}
});

activityLoginBinding.emailEt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int start, int before, int after) {

}

@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int after) {

}

@Override
public void afterTextChanged(Editable editable) {
activityLoginBinding.usernameWrapper.setError(null);
}
});

activityLoginBinding.passwordEt.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int start, int before, int after) {

}

@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int after) {

}

@Override
public void afterTextChanged(Editable editable) {
activityLoginBinding.passwordWrapper.setError(null);
}
});

activityLoginBinding.endUserAgreementTv.setMovementMethod(LinkMovementMethod.getInstance());
activityLoginBinding.endUserAgreementTv.setText(TextUtils.generateLicenseText(getResources(), R.string.by_signing_in));

Expand Down Expand Up @@ -226,15 +262,15 @@ public void callServerForLogin() {
final String emailStr = activityLoginBinding.emailEt.getText().toString().trim();
final String passwordStr = activityLoginBinding.passwordEt.getText().toString().trim();

if (activityLoginBinding.emailEt != null && emailStr.length() == 0) {
showAlertDialog(getString(R.string.login_error),
getString(R.string.error_enter_email));
activityLoginBinding.emailEt.requestFocus();
} else if (activityLoginBinding.passwordEt != null && passwordStr.length() == 0) {
showAlertDialog(getString(R.string.login_error),
getString(R.string.error_enter_password));
if (passwordStr.length() == 0) {
activityLoginBinding.passwordWrapper.setError(getString(R.string.error_enter_password));
activityLoginBinding.passwordEt.requestFocus();
} else {
}
if (emailStr.length() == 0) {
activityLoginBinding.usernameWrapper.setError(getString(R.string.error_enter_email));
activityLoginBinding.emailEt.requestFocus();
}
if (emailStr.length() > 0 && passwordStr.length() > 0) {
activityLoginBinding.emailEt.setEnabled(false);
activityLoginBinding.passwordEt.setEnabled(false);
activityLoginBinding.forgotPasswordTv.setEnabled(false);
Expand All @@ -250,7 +286,7 @@ public void onSuccess(@NonNull AuthResponse result) {
@Override
public void onException(Exception ex) {
if (ex instanceof HttpStatusException &&
((HttpStatusException) ex).getStatusCode() == HttpStatus.UNAUTHORIZED) {
((HttpStatusException) ex).getStatusCode() == HttpStatus.BAD_REQUEST) {
onUserLoginFailure(new LoginException(new LoginErrorMessage(
getString(R.string.login_error),
getString(R.string.login_failed))), null, null);
Expand Down

0 comments on commit 808ddb8

Please sign in to comment.