Skip to content

Commit

Permalink
Squashed 'libs/login/' changes from fec863d..c826be2
Browse files Browse the repository at this point in the history
c826be2 Merge pull request #35 from wordpress-mobile/feature/login-style-changes-v2
1f6c6e4 Gutenberg/integrate release 1.25.0 with dark mode (#11580)
1d668f5 Merge pull request #11537 from wordpress-mobile/fix/10930-email-error-dissapears-on-rotation
fd66652 store the res id instead of the boolean so it supports multiple errors.
858decb utilized runnable that's posted when the UI has been drawn.
ab37113 removed clearing in text watcher.
3691e84 Fixed config change issues.
fd0c8c9 Merge pull request #34 from wordpress-mobile/merge/WordPress-Android/11492
c134376 Merge commit 'e80a69322fe65ad994bee1854a2343c2089af323' into issue/fix-login-subtree
5269196 Ignore onDiscoverySucceeded events if LoginBaseDiscoveryFragment is detached
775f096 Revert "Feature/material theme and Dark Theme support (#11469)" (#11486)
65d5c8f Feature/material theme and Dark Theme support (#11469)
e80a693 Merge pull request #33 from wordpress-mobile/merge/WordPress-Android/11051
7e46000 Fix validation in input of Email
4f4657f Add requested changes
d80e8e6 Remove whitespaces
b187035 Issue/10930 email address error is preserved on rotation

git-subtree-dir: libs/login
git-subtree-split: c826be2
  • Loading branch information
AmandaRiu committed Apr 17, 2020
1 parent 0c39307 commit 8487e6f
Show file tree
Hide file tree
Showing 32 changed files with 540 additions and 589 deletions.
2 changes: 1 addition & 1 deletion WordPressLoginFlow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {
implementation 'androidx.media:media:1.0.1'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.android.material:material:1.1.0'

api 'com.google.android.gms:play-services-auth:15.0.1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
Expand All @@ -21,6 +20,8 @@
import androidx.annotation.StringRes;
import androidx.appcompat.app.AlertDialog;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.wordpress.android.fluxc.generated.AccountActionBuilder;
Expand All @@ -44,10 +45,10 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import dagger.android.support.AndroidSupportInjection;

import static android.content.Context.CLIPBOARD_SERVICE;

import dagger.android.support.AndroidSupportInjection;

public class Login2FaFragment extends LoginBaseFormFragment<LoginListener> implements TextWatcher,
OnEditorCommitListener {
private static final String KEY_2FA_TYPE = "KEY_2FA_TYPE";
Expand Down Expand Up @@ -396,7 +397,7 @@ private void handleAuthError(AuthenticationErrorType error, String errorMessage)
}

private void showErrorDialog(String message) {
AlertDialog dialog = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.LoginTheme))
AlertDialog dialog = new MaterialAlertDialogBuilder(getActivity())
.setMessage(message)
.setPositiveButton(R.string.login_error_button, null)
.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ void initiateDiscovery() {
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onDiscoverySucceeded(OnDiscoveryResponse event) {
if (mLoginBaseDiscoveryListener == null) {
// Ignore the event if the fragment is detached
return;
}
// hold the URL in a variable to use below otherwise it gets cleared up by endProgress
// bail if user canceled
String mRequestedSiteAddress = mLoginBaseDiscoveryListener.getRequestedSiteAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.text.Html;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
Expand All @@ -33,6 +32,7 @@
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
Expand Down 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,14 +405,16 @@ 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));
}

private void showErrorDialog(String message) {
AlertDialog dialog = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.LoginTheme))
AlertDialog dialog = new MaterialAlertDialogBuilder(getActivity())
.setMessage(message)
.setPositiveButton(R.string.login_error_button, null)
.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ContextThemeWrapper;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
Expand All @@ -18,6 +17,8 @@
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.wordpress.android.util.EditTextUtils;

public class LoginHttpAuthDialogFragment extends DialogFragment {
Expand Down Expand Up @@ -49,7 +50,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.LoginTheme));
AlertDialog.Builder alert = new MaterialAlertDialogBuilder(getActivity());
alert.setTitle(R.string.http_authorization_required);

//noinspection InflateParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class LoginMagicLinkRequestFragment extends Fragment {
public static final String TAG = "login_magic_link_request_fragment_tag";

private static final String KEY_IN_PROGRESS = "KEY_IN_PROGRESS";
private static final String KEY_GRAVATAR_IN_PROGRESS = "KEY_GRAVATAR_IN_PROGRESS";
private static final String ARG_EMAIL_ADDRESS = "ARG_EMAIL_ADDRESS";
private static final String ARG_MAGIC_LINK_SCHEME = "ARG_MAGIC_LINK_SCHEME";
private static final String ARG_IS_JETPACK_CONNECT = "ARG_IS_JETPACK_CONNECT";
Expand Down Expand Up @@ -224,9 +223,6 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
if (mInProgress) {
showMagicLinkRequestProgressDialog();
}

boolean gravatarInProgress = savedInstanceState.getBoolean(KEY_GRAVATAR_IN_PROGRESS);
mAvatarProgressBar.setVisibility(gravatarInProgress ? View.VISIBLE : View.GONE);
}
// important for accessibility - talkback
getActivity().setTitle(R.string.magic_link_login_title);
Expand All @@ -243,7 +239,6 @@ public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);

outState.putBoolean(KEY_IN_PROGRESS, mInProgress);
outState.putBoolean(KEY_GRAVATAR_IN_PROGRESS, mAvatarProgressBar.getVisibility() == View.VISIBLE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.ContextThemeWrapper;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.wordpress.android.fluxc.store.AccountStore;
import org.wordpress.android.fluxc.store.SiteStore;

Expand Down Expand Up @@ -46,7 +47,7 @@ public void onAttach(Context context) {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.LoginTheme));
AlertDialog.Builder alert = new MaterialAlertDialogBuilder(getActivity());
alert.setTitle(R.string.login_site_address_help_title);

//noinspection InflateParams
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
Expand All @@ -29,6 +28,7 @@
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
Expand Down Expand Up @@ -232,7 +232,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
}

protected void showErrorDialog(String message) {
AlertDialog dialog = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.LoginTheme))
AlertDialog dialog = new MaterialAlertDialogBuilder(getActivity())
.setMessage(message)
.setPositiveButton(R.string.login_error_button, null)
.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -20,6 +19,8 @@
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.wordpress.android.fluxc.Dispatcher;
Expand Down Expand Up @@ -231,7 +232,7 @@ public void onClick(DialogInterface dialog, int which) {
}
};

AlertDialog dialog = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.LoginTheme))
AlertDialog dialog = new MaterialAlertDialogBuilder(getActivity())
.setMessage(message)
.setNegativeButton(R.string.signup_magic_link_error_button_negative, dialogListener)
.setPositiveButton(R.string.signup_magic_link_error_button_positive, dialogListener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
import org.wordpress.android.login.R;

public class WPBottomSheetDialogFragment extends BottomSheetDialogFragment {
@Override
public int getTheme() {
return R.style.LoginTheme_BottomSheetDialogStyle;
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Expand Down
Loading

0 comments on commit 8487e6f

Please sign in to comment.