Skip to content

Commit

Permalink
Merge pull request #11537 from wordpress-mobile/fix/10930-email-error…
Browse files Browse the repository at this point in the history
…-dissapears-on-rotation

Fix/10930 email error dissapears on rotation - continued
  • Loading branch information
ashiagr authored Apr 2, 2020
2 parents b9ed6cc + 709c35e commit b4f632a
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class LoginEmailFragment extends LoginBaseFormFragment<LoginListener> imp
private static final String KEY_IS_SOCIAL = "KEY_IS_SOCIAL";
private static final String KEY_OLD_SITES_IDS = "KEY_OLD_SITES_IDS";
private static final String KEY_REQUESTED_EMAIL = "KEY_REQUESTED_EMAIL";
private static final String KEY_EMAIL_ERROR_RES = "KEY_EMAIL_ERROR_RES";
private static final String LOG_TAG = LoginEmailFragment.class.getSimpleName();
private static final int GOOGLE_API_CLIENT_ID = 1002;
private static final int EMAIL_CREDENTIALS_REQUEST_CODE = 25100;
Expand All @@ -78,6 +79,7 @@ public class LoginEmailFragment extends LoginBaseFormFragment<LoginListener> imp
private String mGoogleEmail;
private String mRequestedEmail;
private boolean mIsSocialLogin;
private Integer mCurrentEmailErrorRes = null;

protected WPLoginInputRow mEmailInput;
protected boolean mHasDismissedEmailHints;
Expand Down Expand Up @@ -135,7 +137,12 @@ protected void setupContent(ViewGroup rootView) {
if (BuildConfig.DEBUG) {
mEmailInput.getEditText().setText(BuildConfig.DEBUG_WPCOM_LOGIN_EMAIL);
}
mEmailInput.addTextChangedListener(this);
mEmailInput.post(new Runnable() {
@Override public void run() {
mEmailInput.addTextChangedListener(LoginEmailFragment.this);
}
});

mEmailInput.setOnEditorCommitListener(this);
mEmailInput.getEditText().setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
Expand Down Expand Up @@ -288,6 +295,7 @@ public void onStart() {
.enableAutoManage(getActivity(), GOOGLE_API_CLIENT_ID, LoginEmailFragment.this)
.addApi(Auth.CREDENTIALS_API)
.build();
showEmailError();
}

@Override
Expand All @@ -312,6 +320,9 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
mIsSocialLogin = savedInstanceState.getBoolean(KEY_IS_SOCIAL);
mIsDisplayingEmailHints = savedInstanceState.getBoolean(KEY_IS_DISPLAYING_EMAIL_HINTS);
mHasDismissedEmailHints = savedInstanceState.getBoolean(KEY_HAS_DISMISSED_EMAIL_HINTS);
if (savedInstanceState.containsKey(KEY_EMAIL_ERROR_RES)) {
mCurrentEmailErrorRes = savedInstanceState.getInt(KEY_EMAIL_ERROR_RES);
}
} else {
mAnalyticsListener.trackEmailFormViewed();
}
Expand All @@ -326,6 +337,9 @@ public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(KEY_IS_SOCIAL, mIsSocialLogin);
outState.putBoolean(KEY_IS_DISPLAYING_EMAIL_HINTS, mIsDisplayingEmailHints);
outState.putBoolean(KEY_HAS_DISMISSED_EMAIL_HINTS, mHasDismissedEmailHints);
if (mCurrentEmailErrorRes != null) {
outState.putInt(KEY_EMAIL_ERROR_RES, mCurrentEmailErrorRes);
}
}

protected void next(String email) {
Expand All @@ -334,6 +348,7 @@ protected void next(String email) {
}

if (isValidEmail(email)) {
clearEmailError();
startProgress();
mRequestedEmail = email;
mDispatcher.dispatch(AccountActionBuilder.newIsAvailableEmailAction(email));
Expand All @@ -342,6 +357,20 @@ protected void next(String email) {
}
}

/**
* This is cleared every time the text is changed or the email is valid so that if the user rotates the device, they
* don't receive an unnecessary warning from a previous error.
*/
private void clearEmailError() {
mCurrentEmailErrorRes = null;
}

private void showEmailError() {
if (mCurrentEmailErrorRes != null) {
showEmailError(mCurrentEmailErrorRes);
}
}

@Override
public void onDetach() {
super.onDetach();
Expand Down Expand Up @@ -376,9 +405,11 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
public void onTextChanged(CharSequence s, int start, int before, int count) {
mEmailInput.setError(null);
mIsSocialLogin = false;
clearEmailError();
}

private void showEmailError(int messageId) {
mCurrentEmailErrorRes = messageId;
mEmailInput.setError(getString(messageId));
}

Expand Down

0 comments on commit b4f632a

Please sign in to comment.