Skip to content

Commit

Permalink
Squashed 'libs/login/' changes from f58a4c88ab..cfc0675d21
Browse files Browse the repository at this point in the history
cfc0675d21 Add title to the layout override for the site help dialog
63fc73efa0 Use wrap_content for image width so wider images will scale better
68b0c58437 Merge commit '8487e6f4cfee09193f48b803fcf1eb2252355022' into darkmode/login-theme-1
c826be2ccb Merge pull request #35 from wordpress-mobile/feature/login-style-changes-v2
1f6c6e4bca Gutenberg/integrate release 1.25.0 with dark mode (#11580)
1d668f54a5 Merge pull request #11537 from wordpress-mobile/fix/10930-email-error-dissapears-on-rotation
fd6665242f store the res id instead of the boolean so it supports multiple errors.
858decb8b1 utilized runnable that's posted when the UI has been drawn.
ab37113dbf removed clearing in text watcher.
3691e848b8 Fixed config change issues.
fd0c8c97e8 Merge pull request #34 from wordpress-mobile/merge/WordPress-Android/11492
c134376ee6 Merge commit 'e80a69322fe65ad994bee1854a2343c2089af323' into issue/fix-login-subtree
526919648d Ignore onDiscoverySucceeded events if LoginBaseDiscoveryFragment is detached
775f096826 Revert "Feature/material theme and Dark Theme support (#11469)" (#11486)
65d5c8f67b Feature/material theme and Dark Theme support (#11469)
e80a69322f Merge pull request #33 from wordpress-mobile/merge/WordPress-Android/11051
40824a4333 Merge commit '0c3930794ed0c77e4926d334674e85263ef2a651' into update_login_lib_with_signup_sheet_nav_bar_buttons_visibility_fix
fec863d2f8 Resolved merge conflict by removing SignupBottomSheetDialog.java file.
f2d8c102ad Merge branch 'develop' into issue/10908-navigation-bar-buttons-not-visible-with-signup-sheet
7e46000166 Fix validation in input of Email
fccc72b9a4 Merge pull request #32 from wordpress-mobile/merge/WordPress-Android/11172
d634c91e9f Merge commit '371f14160a780fbd7797d71921859d0fee5764d5' into update-login-lib-with-password-toggle-fix
cd81dd1ce9 Add custom selector for password button
8f444b2d13 Merge branch 'issue/10908-navigation-bar-buttons-not-visible-with-signup-sheet' of https://github.com/wordpress-mobile/WordPress-Android into issue/10908-navigation-bar-buttons-not-visible-with-signup-sheet
b53dda144c Add null check for design_bottom_sheet layout
521d09f42c Update libs/login/WordPressLoginFlow/src/main/java/org/wordpress/android/login/widgets/WPBottomSheetDialogFragment.java
7178f5c123 Show full width navigation bar and restrict max width for large screens
8a768d3dd2 Partial fix for terms of service announcement bering read twice.
989fb1d5a2 Remove empty line after brace
2d5d733080 Extract parts of code from onCreateView to onViewCreated
a24d5289ab Eliminate setRetainInstance(true)
2e71a00135 Remove dialog.setOnDismissListener
cfff7a060d Avoid using a parameter in Fragment's constructor
8b09b2d836 Convert BottomSheetDialog to BottomSheetDialogFragment and update styles
a87d595f7a Merge pull request #1796 from woocommerce/release/merge-3.3
f18c390619 Fix signup bottom sheet navigation bar buttons not visible issue
4f4657fb64 Add requested changes
e407a7f304 Revert erroneously deleted code during merge
821d29b90b Revert erroneously deleted code during merge
188cc0ee64 Check if view is null before accessing property
1a4414eec7 Merge commit 'bd659986940153549bfc26a8f6a4104bf748fe3c' into hotfix/1778-npe
d2b8135e1e Added logic to fetch the correct SiteModel from the local db for the incoming url
d80e8e616d Remove whitespaces
b18703520d Issue/10930 email address error is preserved on rotation
3421ca9534 Merge branch 'develop' into test
a20471e8c1 Merge branch 'develop' of https://github.com/woocommerce/woocommerce-android into feature/refund-by-items-master
7757f052b7 Merge branch 'develop' into feature/edit-product-master
f869be0bfc Merge branch 'feature/refund-by-items-master' into 0nko/refund-items-list
ea896f6172 Merge pull request #10833 from wordpress-mobile/issue/10832-fix-npe-in-login-fragment
64678168e4 check if listener is null before handling discovery error
1de03a5522 check if listener is null before handling discovery error
a6e0946af0 Update gradle plugin to version 3.5.3
a23213aa25 Fixed wrong key variable
c89899f001 Updated Glide version to 4.10.0 in the login module
2dd431ccdd Updated Glide version in the login lib
e3211148cd Merge pull request #10787 from wordpress-mobile/anitaa/woo-login-changes
00f6bd2e62 Added flag that checks if login has started.
d5e8683cf6 Added period to login with site credentials
eee4c53fa7 Fixed bug when the forgot password url in username password screen was not valid
2810b14e28 Upgrade gradle plugin to version 3.5.2
daf7384622 Merge pull request #1552 from woocommerce/login-lib-changes
f75cbaaacd Merge commit '4e588147352f8fe88f1417a03a00114dd7d51640' into login-lib-changes
b2d28c652d Add signup flow name parameter to signup auth email request

git-subtree-dir: libs/login
git-subtree-split: cfc0675d2167b938369cf1896083453a593e9b8e
  • Loading branch information
AmandaRiu committed May 23, 2020
1 parent 5835122 commit d4d2d89
Show file tree
Hide file tree
Showing 50 changed files with 787 additions and 706 deletions.
8 changes: 4 additions & 4 deletions WordPressLoginFlow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:3.5.3'
}
}

Expand Down 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 All @@ -57,8 +57,8 @@ dependencies {
}
}

implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'

// Dagger
implementation 'com.google.dagger:dagger:2.22.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 @@ -157,7 +156,7 @@ public void onClick(View v) {
View avatarContainerView = view.findViewById(R.id.avatar_container);

LayoutParams lp = avatarContainerView.getLayoutParams();
lp.width = getContext().getResources().getDimensionPixelSize(R.dimen.magic_link_sent_illustration_sz);
lp.width = LayoutParams.WRAP_CONTENT;
lp.height = getContext().getResources().getDimensionPixelSize(R.dimen.magic_link_sent_illustration_sz);
avatarContainerView.setLayoutParams(lp);

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,8 +47,12 @@ public void onAttach(Context context) {
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder alert = new AlertDialog.Builder(new ContextThemeWrapper(getActivity(), R.style.LoginTheme));
alert.setTitle(R.string.login_site_address_help_title);
AlertDialog.Builder alert = new MaterialAlertDialogBuilder(getActivity());
if (mLoginListener.getLoginMode() != LoginMode.WOO_LOGIN_MODE) {
// Only set the title if not the woo app, since the woo app specifies an override
// layout that includes the title.
alert.setTitle(R.string.login_site_address_help_title);
}

//noinspection InflateParams
alert.setView(getActivity().getLayoutInflater().inflate(R.layout.login_alert_site_address_help, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
public class LoginUsernamePasswordFragment extends LoginBaseDiscoveryFragment implements TextWatcher,
OnEditorCommitListener, LoginBaseDiscoveryFragment.LoginBaseDiscoveryListener {
private static final String KEY_LOGIN_FINISHED = "KEY_LOGIN_FINISHED";
private static final String KEY_LOGIN_STARTED = "KEY_LOGIN_STARTED";
private static final String KEY_REQUESTED_USERNAME = "KEY_REQUESTED_USERNAME";
private static final String KEY_REQUESTED_PASSWORD = "KEY_REQUESTED_PASSWORD";
private static final String KEY_OLD_SITES_IDS = "KEY_OLD_SITES_IDS";
Expand All @@ -77,6 +78,7 @@ public class LoginUsernamePasswordFragment extends LoginBaseDiscoveryFragment im

private boolean mAuthFailed;
private boolean mLoginFinished;
private boolean mLoginStarted;

private String mRequestedUsername;
private String mRequestedPassword;
Expand Down Expand Up @@ -154,9 +156,8 @@ protected void setupContent(ViewGroup rootView) {
siteAddressView.setText(UrlUtils.removeScheme(UrlUtils.removeXmlrpcSuffix(mInputSiteAddress)));
siteAddressView.setVisibility(mInputSiteAddress != null ? View.VISIBLE : View.GONE);

String inputSiteAddressWithoutProtocol = UrlUtils.removeScheme(mInputSiteAddress);
mInputSiteAddressWithoutSuffix = (mEndpointAddress == null || mEndpointAddress.isEmpty())
? inputSiteAddressWithoutProtocol : UrlUtils.removeXmlrpcSuffix(mEndpointAddress);
? mInputSiteAddress : UrlUtils.removeXmlrpcSuffix(mEndpointAddress);

mUsernameInput = rootView.findViewById(R.id.login_username_row);
mUsernameInput.setText(mInputUsername);
Expand Down Expand Up @@ -192,6 +193,9 @@ public void onClick(View v) {
if (mIsWpcom) {
mLoginListener.forgotPassword(FORGOT_PASSWORD_URL_WPCOM);
} else {
if (!mInputSiteAddressWithoutSuffix.endsWith("/")) {
mInputSiteAddressWithoutSuffix += "/";
}
mLoginListener.forgotPassword(mInputSiteAddressWithoutSuffix);
}
}
Expand Down Expand Up @@ -241,6 +245,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {

if (savedInstanceState != null) {
mLoginFinished = savedInstanceState.getBoolean(KEY_LOGIN_FINISHED);
mLoginStarted = savedInstanceState.getBoolean(KEY_LOGIN_STARTED);

mRequestedUsername = savedInstanceState.getString(KEY_REQUESTED_USERNAME);
mRequestedPassword = savedInstanceState.getString(KEY_REQUESTED_PASSWORD);
Expand All @@ -266,6 +271,7 @@ public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);

outState.putBoolean(KEY_LOGIN_FINISHED, mLoginFinished);
outState.putBoolean(KEY_LOGIN_STARTED, mLoginStarted);
outState.putString(KEY_REQUESTED_USERNAME, mRequestedUsername);
outState.putString(KEY_REQUESTED_PASSWORD, mRequestedPassword);
outState.putIntegerArrayList(KEY_OLD_SITES_IDS, mOldSitesIDs);
Expand All @@ -291,6 +297,7 @@ protected void next() {
return;
}

mLoginStarted = true;
startProgress();

mRequestedUsername = getCleanedUsername();
Expand Down Expand Up @@ -509,6 +516,7 @@ public void onAuthenticationChanged(OnAuthenticationChanged event) {
}

if (event.isError()) {
mLoginStarted = false;
if (mRequestedUsername == null) {
// just bail since the operation was cancelled
return;
Expand Down Expand Up @@ -563,11 +571,12 @@ private void finishLogin() {
@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onSiteChanged(OnSiteChanged event) {
if (!isAdded() || mLoginFinished) {
if (!isAdded() || mLoginFinished || !mLoginStarted) {
return;
}

if (event.isError()) {
mLoginStarted = false;
if (mRequestedUsername == null) {
// just bail since the operation was cancelled
return;
Expand Down
Loading

0 comments on commit d4d2d89

Please sign in to comment.