Skip to content

Commit

Permalink
Merge pull request #13319 from wordpress-mobile/merge/login-changes
Browse files Browse the repository at this point in the history
Merge latest changes from Login-Flow library
  • Loading branch information
renanferrari authored Nov 13, 2020
2 parents 255d929 + 786efce commit acf750f
Show file tree
Hide file tree
Showing 24 changed files with 435 additions and 405 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,10 @@ private void dismissSignupSheet() {
return mDispatchingAndroidInjector;
}

@Override public void startOver() {
// Not used in WordPress app
}

@Override
public void showHelpFindingConnectedEmail() {
// Not used in WordPress app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class UnifiedLoginTracker
currentFlow = Flow.values().find { it.value == value }
}

fun setStep(step: Step) {
currentStep = step
}

fun setFlowAndStep(flow: Flow, step: Step) {
currentFlow = flow
currentStep = step
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,4 +375,24 @@ public void trackSocialSignupConfirmationViewed() {
public void trackCreateAccountClick() {
mUnifiedLoginTracker.trackClick(Click.CREATE_ACCOUNT);
}

@Override public void emailPasswordFormScreenResumed() {
mUnifiedLoginTracker.setStep(Step.START);
}

@Override public void siteAddressFormScreenResumed() {
mUnifiedLoginTracker.setStep(Step.START);
}

@Override public void magicLinkRequestScreenResumed() {
mUnifiedLoginTracker.setStep(Step.START);
}

@Override public void magicLinkSentScreenResumed() {
mUnifiedLoginTracker.setStep(Step.MAGIC_LINK_REQUESTED);
}

@Override public void usernamePasswordScreenResumed() {
mUnifiedLoginTracker.setStep(Step.USERNAME_PASSWORD);
}
}
270 changes: 0 additions & 270 deletions WordPress/src/main/res/drawable/img_illustration_email_alert_120dp.xml

This file was deleted.

1 change: 0 additions & 1 deletion WordPress/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@

<!-- login -->
<dimen name="promo_indicator_bullet_size">4dp</dimen>
<dimen name="magic_link_sent_illustration_sz">120dp</dimen>

<dimen name="button_container_shadow_height">5dp</dimen>

Expand Down
9 changes: 0 additions & 9 deletions WordPress/src/main/res/values/drawables.xml

This file was deleted.

3 changes: 2 additions & 1 deletion WordPress/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2474,6 +2474,7 @@
<string name="login_site_address_help_content">Your site address appears in the bar at the top of the screen when you visit your site in Chrome.</string>
<string name="login_site_address_more_help">Need more help?</string>
<string name="login_find_your_site_adress">Find your site address</string>
<string name="login_find_your_connected_email">Find your connected email</string>
<string name="login_checking_site_address">Checking site address</string>
<string name="login_error_while_adding_site">Error while adding site. Error code: %s</string>
<string name="login_log_in_for_deeplink">Log in to WordPress.com to access the post.</string>
Expand All @@ -2488,6 +2489,7 @@
<string name="login_epilogue_mysites_other">My sites</string>
<string name="login_google_button_suffix">Log in with Google.</string>
<string name="continue_google_button_suffix">Continue with Google</string>
<string name="continue_site_credentials">Continue with store credentials</string>
<string name="login_or">or</string>
<string name="login_error_button">Close</string>
<string name="login_error_email_not_found_v2">There\'s no WordPress.com account matching this Google account.</string>
Expand All @@ -2498,7 +2500,6 @@
<string name="enter_wpcom_or_jetpack_site">Please enter a WordPress.com or Jetpack-connected self-hosted WordPress site</string>
<string name="enter_wordpress_site">The website at this address is not a WordPress site. For us to connect to it, the site must have WordPress installed.</string>
<string name="login_need_help_finding_connected_email">Need help finding the email you connected with?</string>
<string name="send_verification_email">Send verification email</string>
<string name="enter_credentials_for_site" tools:ignore="UnusedResources">Log in with your %1$s site credentials</string>
<string name="enter_account_info_for_site">Enter your account information for %1$s.</string>
<string name="enter_site_credentials_instead">Log in with site credentials.</string>
Expand Down
1 change: 1 addition & 0 deletions libs/login/WordPressLoginFlow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies {
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation "com.google.android.material:material:1.2.1"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

implementation "androidx.core:core-ktx:$kotlin_ktx_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
updateContinueButtonEnabledStatus();
}

private void show2FaError(String message) {
private void show2FaError(@Nullable String message) {
if (!TextUtils.isEmpty(message)) {
mAnalyticsListener.trackFailure(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ interface LoginAnalyticsListener {
fun trackEmailSignupConfirmationViewed()
fun trackSocialSignupConfirmationViewed()
fun trackCreateAccountClick()
fun emailPasswordFormScreenResumed()
fun siteAddressFormScreenResumed()
fun magicLinkRequestScreenResumed()
fun magicLinkSentScreenResumed()
fun usernamePasswordScreenResumed()

enum class CreatedAccountSource {
EMAIL,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ public void onDestroy() {
super.onDestroy();
}

@Override public void onDestroyView() {
mPrimaryButton = null;
mSecondaryButton = null;

if (mProgressDialog != null) {
mProgressDialog.setOnCancelListener(null);
mProgressDialog = null;
}
super.onDestroyView();
}

protected void startProgressIfNeeded() {
if (!isInProgress()) {
startProgress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ public class LoginEmailFragment extends LoginBaseFormFragment<LoginListener> imp
private static final String ARG_SIGNUP_FROM_LOGIN_ENABLED = "ARG_SIGNUP_FROM_LOGIN_ENABLED";
private static final String ARG_SITE_LOGIN_ENABLED = "ARG_SITE_LOGIN_ENABLED";
private static final String ARG_SHOULD_USE_NEW_LAYOUT = "ARG_SHOULD_USE_NEW_LAYOUT";
private static final String ARG_OPTIONAL_SITE_CREDS_LAYOUT = "ARG_OPTIONAL_SITE_CREDS_LAYOUT";
private static final String ARG_HIDE_TOS = "ARG_HIDE_TOS";

public static final String TAG = "login_email_fragment_tag";
public static final String TAG_SITE_CREDS_LAYOUT = "login_email_fragment_site_creds_layout_tag";
public static final int MAX_EMAIL_LENGTH = 100;

private ArrayList<Integer> mOldSitesIDs = new ArrayList<>();
Expand All @@ -97,6 +100,8 @@ public class LoginEmailFragment extends LoginBaseFormFragment<LoginListener> imp
private boolean mIsSignupFromLoginEnabled;
private boolean mIsSiteLoginEnabled;
private boolean mShouldUseNewLayout;
private boolean mOptionalSiteCredsLayout;
private boolean mHideTos;

protected WPLoginInputRow mEmailInput;
protected boolean mHasDismissedEmailHints;
Expand All @@ -111,26 +116,61 @@ public static LoginEmailFragment newInstance(String url) {
return fragment;
}

public static LoginEmailFragment newInstance(boolean isSignupFromLoginEnabled, boolean isSiteLoginEnabled,
public static LoginEmailFragment newInstance(String url, boolean optionalSiteCredsLayout) {
LoginEmailFragment fragment = new LoginEmailFragment();
Bundle args = new Bundle();
args.putString(ARG_LOGIN_SITE_URL, url);
args.putBoolean(ARG_OPTIONAL_SITE_CREDS_LAYOUT, optionalSiteCredsLayout);
fragment.setArguments(args);
return fragment;
}

public static LoginEmailFragment newInstance(boolean isSignupFromLoginEnabled,
boolean isSiteLoginEnabled,
boolean shouldUseNewLayout) {
return newInstance(isSignupFromLoginEnabled, isSiteLoginEnabled, shouldUseNewLayout, null);
return newInstance(
isSignupFromLoginEnabled, isSiteLoginEnabled, shouldUseNewLayout, null);
}

public static LoginEmailFragment newInstance(boolean isSignupFromLoginEnabled,
boolean isSiteLoginEnabled,
boolean shouldUseNewLayout,
boolean hideTos) {
LoginEmailFragment fragment = new LoginEmailFragment();
Bundle args = new Bundle();
args.putBoolean(ARG_SIGNUP_FROM_LOGIN_ENABLED, isSignupFromLoginEnabled);
args.putBoolean(ARG_SITE_LOGIN_ENABLED, isSiteLoginEnabled);
args.putBoolean(ARG_SHOULD_USE_NEW_LAYOUT, shouldUseNewLayout);
args.putBoolean(ARG_HIDE_TOS, hideTos);
args.putString(ARG_LOGIN_SITE_URL, null);
fragment.setArguments(args);
return fragment;
}

public static LoginEmailFragment newInstance(boolean isSignupFromLoginEnabled, boolean isSiteLoginEnabled,
boolean shouldUseNewLayout, String url) {
public static LoginEmailFragment newInstance(boolean isSignupFromLoginEnabled,
boolean isSiteLoginEnabled,
boolean shouldUseNewLayout,
String url) {
LoginEmailFragment fragment = new LoginEmailFragment();
Bundle args = new Bundle();
args.putBoolean(ARG_SIGNUP_FROM_LOGIN_ENABLED, isSignupFromLoginEnabled);
args.putBoolean(ARG_SITE_LOGIN_ENABLED, isSiteLoginEnabled);
args.putBoolean(ARG_SHOULD_USE_NEW_LAYOUT, shouldUseNewLayout);
args.putBoolean(ARG_HIDE_TOS, false);
args.putString(ARG_LOGIN_SITE_URL, url);
fragment.setArguments(args);
return fragment;
}

@Override
protected @LayoutRes int getContentLayout() {
return mShouldUseNewLayout ? R.layout.login_email_screen : R.layout.login_email_screen_old;
if (mShouldUseNewLayout) {
return R.layout.login_email_screen;
} else if (mOptionalSiteCredsLayout) {
return R.layout.login_email_optional_site_creds_screen;
} else {
return R.layout.login_email_screen_old;
}
}

@Override
Expand Down Expand Up @@ -159,7 +199,11 @@ protected void setupLabel(@NonNull TextView label) {
}
break;
case WOO_LOGIN_MODE:
label.setText(getString(R.string.enter_email_for_site, mLoginSiteUrl));
if (mOptionalSiteCredsLayout) {
label.setText(getString(R.string.enter_email_for_site, mLoginSiteUrl));
} else {
label.setText(getString(R.string.enter_email_wordpress_com));
}
break;
case JETPACK_STATS:
label.setText(R.string.login_to_to_connect_jetpack);
Expand All @@ -183,6 +227,11 @@ protected void setupContent(ViewGroup rootView) {
(Button) rootView.findViewById(R.id.continue_tos),
(Button) rootView.findViewById(R.id.continue_with_google_tos));
setupSocialButtons((Button) rootView.findViewById(R.id.continue_with_google));
} else if (mOptionalSiteCredsLayout) {
setupContinueButton((Button) rootView.findViewById(R.id.login_continue_button));
setupSiteCredsButton((Button) rootView.findViewById(R.id.login_site_creds));
setupFindEmailHelpButton(
(Button) rootView.findViewById(R.id.login_find_connected_email));
} else {
setupAlternativeButtons(
(LinearLayout) rootView.findViewById(R.id.login_google_button),
Expand Down Expand Up @@ -240,21 +289,38 @@ private void updateContinueButtonEnabledStatus() {
}
}

@Override public void onDestroyView() {
mEmailInput = null;

super.onDestroyView();
}

private void setupTosButtons(Button continueTosButton, Button continueWithGoogleTosButton) {
OnClickListener onClickListener = new OnClickListener() {
public void onClick(View view) {
Context context = getContext();
if ((context instanceof SignupSheetListener)) {
((SignupSheetListener) context).onSignupSheetTermsOfServiceClicked();
if (mHideTos) {
// Hide the TOS buttons
continueTosButton.setVisibility(View.GONE);
continueWithGoogleTosButton.setVisibility(View.GONE);
} else {
// Show the TOS buttons
continueTosButton.setVisibility(View.VISIBLE);
continueWithGoogleTosButton.setVisibility(View.VISIBLE);

OnClickListener onClickListener = new OnClickListener() {
public void onClick(View view) {
Context context = getContext();
if ((context instanceof SignupSheetListener)) {
((SignupSheetListener) context).onSignupSheetTermsOfServiceClicked();
}
}
}
};
};

continueTosButton.setOnClickListener(onClickListener);
continueTosButton.setText(formatTosText(R.string.continue_terms_of_service_text));
continueTosButton.setOnClickListener(onClickListener);
continueTosButton.setText(formatTosText(R.string.continue_terms_of_service_text));

continueWithGoogleTosButton.setOnClickListener(onClickListener);
continueWithGoogleTosButton.setText(formatTosText(R.string.continue_with_google_terms_of_service_text));
continueWithGoogleTosButton.setOnClickListener(onClickListener);
continueWithGoogleTosButton
.setText(formatTosText(R.string.continue_with_google_terms_of_service_text));
}
}

private void setupSocialButtons(Button continueWithGoogleButton) {
Expand All @@ -266,6 +332,22 @@ public void onClick(View view) {
});
}

private void setupSiteCredsButton(Button continueWithSiteCreds) {
continueWithSiteCreds.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
mLoginListener.loginViaSiteCredentials(mLoginSiteUrl);
}
});
}

private void setupFindEmailHelpButton(Button findConnectedEmail) {
findConnectedEmail.setOnClickListener(new OnClickListener() {
@Override public void onClick(View v) {
mLoginListener.showHelpFindingConnectedEmail();
}
});
}

private void setupAlternativeButtons(LinearLayout googleLoginButton, LinearLayout siteLoginButton) {
googleLoginButton.setOnClickListener(new OnClickListener() {
@Override
Expand Down Expand Up @@ -318,7 +400,7 @@ public void onClick(View view) {

@Override
protected void setupBottomButtons(Button secondaryButton, Button primaryButton) {
if (mShouldUseNewLayout) {
if (mShouldUseNewLayout || mOptionalSiteCredsLayout) {
secondaryButton.setVisibility(View.GONE);
primaryButton.setVisibility(View.GONE);
} else {
Expand Down Expand Up @@ -420,6 +502,8 @@ public void onCreate(Bundle savedInstanceState) {
mIsSignupFromLoginEnabled = args.getBoolean(ARG_SIGNUP_FROM_LOGIN_ENABLED, false);
mIsSiteLoginEnabled = args.getBoolean(ARG_SITE_LOGIN_ENABLED, true);
mShouldUseNewLayout = args.getBoolean(ARG_SHOULD_USE_NEW_LAYOUT, false);
mOptionalSiteCredsLayout = args.getBoolean(ARG_OPTIONAL_SITE_CREDS_LAYOUT, false);
mHideTos = args.getBoolean(ARG_HIDE_TOS, false);
}
}

Expand Down Expand Up @@ -468,7 +552,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
public void onResume() {
super.onResume();
mAnalyticsListener.emailFormScreenResumed();
if (mShouldUseNewLayout) {
if (mShouldUseNewLayout || mOptionalSiteCredsLayout) {
updateContinueButtonEnabledStatus();
}
}
Expand All @@ -491,6 +575,8 @@ public void onSaveInstanceState(Bundle outState) {
protected void buildToolbar(Toolbar toolbar, ActionBar actionBar) {
if (mShouldUseNewLayout) {
actionBar.setTitle(R.string.get_started);
} else if (mOptionalSiteCredsLayout) {
actionBar.setTitle(R.string.log_in);
} else {
super.buildToolbar(toolbar, actionBar);
}
Expand Down Expand Up @@ -561,7 +647,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
mEmailInput.setError(null);
mIsSocialLogin = false;
clearEmailError();
if (mShouldUseNewLayout) {
if (mShouldUseNewLayout || mOptionalSiteCredsLayout) {
updateContinueButtonEnabledStatus();
}
}
Expand Down Expand Up @@ -613,7 +699,18 @@ public void onAuthOptionsFetched(OnAuthOptionsFetched event) {
switch (event.error.type) {
case UNKNOWN_USER:
// This email does not correspond to an existing account
if (mIsSignupFromLoginEnabled) {

// Will be true if in the Woo app and currently in the WPcom login
// flow. We need to check this to know if we should display the
// 'No WPcom account found' error screen.
boolean isWooWPcomLoginFlow = false;
if (mLoginListener != null
&& mLoginListener.getLoginMode() == LoginMode.WOO_LOGIN_MODE
&& !mOptionalSiteCredsLayout) {
isWooWPcomLoginFlow = true;
}

if (mIsSignupFromLoginEnabled || isWooWPcomLoginFlow) {
if (mLoginListener != null) {
mLoginListener.gotUnregisteredEmail(email);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ public void onCreate(Bundle savedInstanceState) {
@Override
public void onResume() {
super.onResume();
mAnalyticsListener.emailPasswordFormScreenResumed();
updatePrimaryButtonEnabledStatus();

// connect to the Service. We'll receive updates via EventBus.
Expand Down
Loading

0 comments on commit acf750f

Please sign in to comment.