Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ```java
- @OnClick(R.id.sign_in_btn)
- public void onSignInButtonClicked(View view){
- DisplayUtility.hideKeyboard(getContext(), view);
- String username = mEmailInputLayout.getEditText().getText().toString();
- String password = mPasswordInputLayout.getEditText().getText().toString();
- final boolean emailIsValid = validateEmail(username);
- final boolean passwordIsValid = validatePassword(password);
- if(emailIsValid && passwordIsValid){
- mEmailInputLayout.setError(null);
- mPasswordInputLayout.setError(null);
- disableError(mEmailInputLayout);
- disableError(mPasswordInputLayout);
- // mEmailInputLayout.setErrorEnabled(false);
- // mPasswordInputLayout.setErrorEnabled(false);
- doLogin();
- return;
- } else if(emailIsValid){
- mEmailInputLayout.setError(null);
- disableError(mEmailInputLayout);
- // mEmailInputLayout.setErrorEnabled(false);
- } else if(passwordIsValid){
- mPasswordInputLayout.setError(null);
- disableError(mPasswordInputLayout);
- // mPasswordInputLayout.setErrorEnabled(false);
- }
- if(!emailIsValid){
- enableError(mEmailInputLayout);
- // mEmailInputLayout.setErrorEnabled(true);
- mEmailInputLayout.setError("Not a valid email address!");
- }
- if(!passwordIsValid){
- enableError(mPasswordInputLayout);
- // mPasswordInputLayout.setErrorEnabled(true);
- mPasswordInputLayout.setError("Not a valid password!");
- }
- }
- private void enableError(TextInputLayout textInputLayout){
- if (textInputLayout.getChildCount() == 2)
- textInputLayout.getChildAt(1).setVisibility(View.VISIBLE);
- }
- private void disableError(TextInputLayout textInputLayout){
- if (textInputLayout.getChildCount() == 2)
- textInputLayout.getChildAt(1).setVisibility(View.GONE);
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement