Skip to content

Commit

Permalink
Merge pull request #217 from woocommerce/feature/113-login-notification
Browse files Browse the repository at this point in the history
Display login notification + Notification channel config
  • Loading branch information
AmandaRiu authored Jun 1, 2018
2 parents 3c35b82 + 3b1b282 commit ebd0664
Show file tree
Hide file tree
Showing 13 changed files with 125 additions and 51 deletions.
12 changes: 6 additions & 6 deletions WordPressLoginFlow/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {

defaultConfig {
minSdkVersion 16
targetSdkVersion 25
targetSdkVersion 26
versionCode 2
versionName "1.1"

Expand All @@ -31,12 +31,12 @@ android {
}

dependencies {
implementation ('org.wordpress:utils:1.20.1') {
implementation ('org.wordpress:utils:1.20.3') {
exclude group: "com.mcxiaoke.volley"
}

implementation 'com.android.support:appcompat-v7:27.1.0'
implementation 'com.android.support:design:27.1.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'

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

Expand All @@ -47,7 +47,7 @@ dependencies {
exclude group: "org.wordpress", module: "utils"
}
} else {
implementation("com.github.wordpress-mobile.WordPress-FluxC-Android:fluxc:918a9975bd5ac329006d39042b1312cc112781f6") {
implementation("com.github.wordpress-mobile.WordPress-FluxC-Android:fluxc:d4e583f21840111065f12e743cbf31de4307266b") {
exclude group: "com.android.support"
exclude group: "org.wordpress", module: "utils"
}
Expand All @@ -63,7 +63,7 @@ dependencies {
implementation 'com.google.dagger:dagger-android-support:2.11'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'

lintChecks 'org.wordpress:lint:1.0.0'
lintChecks 'org.wordpress:lint:1.0.1'
}

// Add properties named "wp.xxx" to our BuildConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,19 @@ public interface LoginAnalyticsListener {
void trackMagicLinkRequested();
void trackMagicLinkRequestFormViewed();
void trackPasswordFormViewed();
void trackSignupCanceled();
void trackSignupEmailButtonTapped();
void trackSignupEmailToLogin();
void trackSignupGoogleButtonTapped();
void trackSignupMagicLinkFailed();
void trackSignupMagicLinkOpened();
void trackSignupMagicLinkOpenEmailClientClicked();
void trackSignupMagicLinkSent();
void trackSignupMagicLinkSucceeded();
void trackSignupSocial2faNeeded();
void trackSignupSocialAccountsNeedConnecting();
void trackSignupSocialButtonFailure();
void trackSignupSocialToLogin();
void trackSignupTermsOfServiceTapped();
void trackSocialAccountsNeedConnecting();
void trackSocialButtonClick();
void trackSocialButtonFailure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public void onAccountChanged(OnAccountChanged event) {
} else if (event.causeOfChange == AccountAction.FETCH_SETTINGS) {
// The user's account settings have also been fetched and stored - now we can fetch the user's sites
mDispatcher.dispatch(SiteActionBuilder.newFetchSitesAction());
mDispatcher.dispatch(AccountActionBuilder.newFetchSubscriptionsAction());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
import android.util.Patterns;
import android.view.ContextThemeWrapper;
Expand Down Expand Up @@ -140,7 +141,6 @@ public void onClick(View view) {

LinearLayout googleLoginButton = rootView.findViewById(R.id.login_google_button);
googleLoginButton.setOnClickListener(new OnClickListener() {
@SuppressWarnings("PrivateMemberAccessBetweenOuterAndInnerClass")
@Override
public void onClick(View view) {
mAnalyticsListener.trackSocialButtonClick();
Expand Down Expand Up @@ -196,11 +196,25 @@ public void onClick(View view) {

@Override
protected void setupBottomButtons(Button secondaryButton, Button primaryButton) {
secondaryButton.setVisibility(View.GONE);
if (mLoginListener.getLoginMode() == LoginMode.JETPACK_STATS) {
secondaryButton.setText(Html.fromHtml(String.format(getResources().getString(
R.string.login_email_button_signup), "<u>", "</u>")));
secondaryButton.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
mLoginListener.doStartSignup();
mGoogleApiClient.stopAutoManage(getActivity());

if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
});
} else {
secondaryButton.setVisibility(View.GONE);
}

primaryButton.setOnClickListener(new OnClickListener() {
@SuppressWarnings("PrivateMemberAccessBetweenOuterAndInnerClass")
public void onClick(View v) {
public void onClick(View view) {
next(getCleanedEmail());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface SelfSignedSSLCallback {
void helpMagicLinkRequest(String email);

// Login Magic Link Sent callbacks
void openEmailClient();
void openEmailClient(boolean isLogin);
void helpMagicLinkSent(String email);

// Login email password callbacks
Expand Down Expand Up @@ -65,9 +65,8 @@ void saveCredentialsInSmartLock(@Nullable String username, @Nullable String pass
// TODO This should have a more generic name, it more or less means any kind of login was finished
void startPostLoginServices();

void setHelpContext(String faqId, String faqSection);

// Signup
void doStartSignup();
void helpSignupEmailScreen(String email);
void helpSignupMagicLinkScreen(String email);
void showSignupMagicLink(String email);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
import org.greenrobot.eventbus.ThreadMode;
import org.wordpress.android.fluxc.Dispatcher;
import org.wordpress.android.fluxc.generated.AuthenticationActionBuilder;
import org.wordpress.android.fluxc.store.AccountStore.OnAuthEmailSent;
import org.wordpress.android.fluxc.store.AccountStore;
import org.wordpress.android.fluxc.store.AccountStore.AuthEmailPayload;
import org.wordpress.android.fluxc.store.AccountStore.AuthEmailPayloadSource;
import org.wordpress.android.fluxc.store.AccountStore.OnAuthEmailSent;
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.GravatarUtils;
import org.wordpress.android.util.NetworkUtils;
Expand All @@ -49,27 +51,34 @@ public class LoginMagicLinkRequestFragment extends Fragment {
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_IS_JETPACK_CONNECT = "ARG_IS_JETPACK_CONNECT";
private static final String ARG_JETPACK_CONNECT_SOURCE = "ARG_JETPACK_CONNECT_SOURCE";

private static final String ERROR_KEY = "error";

private LoginListener mLoginListener;

private String mEmail;
private String mJetpackConnectSource;

private View mAvatarProgressBar;
private Button mRequestMagicLinkButton;
private ProgressDialog mProgressDialog;

private boolean mInProgress;
private boolean mIsJetpackConnect;

@Inject protected Dispatcher mDispatcher;

@Inject protected LoginAnalyticsListener mAnalyticsListener;

public static LoginMagicLinkRequestFragment newInstance(String email) {
public static LoginMagicLinkRequestFragment newInstance(String email, boolean isJetpackConnect,
String jetpackConnectSource) {
LoginMagicLinkRequestFragment fragment = new LoginMagicLinkRequestFragment();
Bundle args = new Bundle();
args.putString(ARG_EMAIL_ADDRESS, email);
args.putBoolean(ARG_IS_JETPACK_CONNECT, isJetpackConnect);
args.putString(ARG_JETPACK_CONNECT_SOURCE, jetpackConnectSource);
fragment.setArguments(args);
return fragment;
}
Expand All @@ -91,6 +100,8 @@ public void onCreate(Bundle savedInstanceState) {

if (getArguments() != null) {
mEmail = getArguments().getString(ARG_EMAIL_ADDRESS);
mIsJetpackConnect = getArguments().getBoolean(ARG_IS_JETPACK_CONNECT);
mJetpackConnectSource = getArguments().getString(ARG_JETPACK_CONNECT_SOURCE);
}

setHasOptionsMenu(true);
Expand All @@ -106,7 +117,9 @@ public void onClick(View v) {
if (mLoginListener != null) {
if (NetworkUtils.checkConnection(getActivity())) {
showMagicLinkRequestProgressDialog();
AuthEmailPayload authEmailPayload = new AuthEmailPayload(mEmail, false, null, null);
AuthEmailPayloadSource source = getAuthEmailPayloadSource();
AuthEmailPayload authEmailPayload = new AuthEmailPayload(mEmail, false,
mIsJetpackConnect ? AccountStore.AuthEmailPayloadFlow.JETPACK : null, source);
mDispatcher.dispatch(AuthenticationActionBuilder.newSendAuthEmailAction(authEmailPayload));
}
}
Expand Down Expand Up @@ -227,6 +240,20 @@ public void onStop() {
mDispatcher.unregister(this);
}

private AuthEmailPayloadSource getAuthEmailPayloadSource() {
if (mJetpackConnectSource != null) {
if (mJetpackConnectSource.equalsIgnoreCase(AuthEmailPayloadSource.NOTIFICATIONS.toString())) {
return AuthEmailPayloadSource.NOTIFICATIONS;
} else if (mJetpackConnectSource.equalsIgnoreCase(AuthEmailPayloadSource.STATS.toString())) {
return AuthEmailPayloadSource.STATS;
} else {
return null;
}
} else {
return null;
}
}

private void showMagicLinkRequestProgressDialog() {
startProgress(getString(R.string.login_magic_link_email_requesting));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
@Override
public void onClick(View v) {
if (mLoginListener != null) {
mLoginListener.openEmailClient();
mLoginListener.openEmailClient(true);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,6 @@ public class LoginSiteAddressFragment extends LoginBaseFormFragment<LoginListene

public static final String TAG = "login_site_address_fragment_tag";

private static final String XMLRPC_BLOCKED_HELPSHIFT_FAQ_SECTION = "10";
private static final String XMLRPC_BLOCKED_HELPSHIFT_FAQ_ID = "102";

private static final String MISSING_XMLRPC_METHOD_HELPSHIFT_FAQ_SECTION = "10";
private static final String MISSING_XMLRPC_METHOD_HELPSHIFT_FAQ_ID = "11";

private static final String NO_SITE_HELPSHIFT_FAQ_SECTION = "10";
private static final String NO_SITE_HELPSHIFT_FAQ_ID = "2"; // Using the same as in INVALID URL

private WPLoginInputRow mSiteAddressInput;

private String mRequestedSiteAddress;
Expand Down Expand Up @@ -156,7 +147,7 @@ protected void discover() {
}

if (TextUtils.isEmpty(mSiteAddressInput.getEditText().getText())) {
showError(R.string.login_empty_site_url, null, null);
showError(R.string.login_empty_site_url);
return;
}

Expand Down Expand Up @@ -188,12 +179,10 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mSiteAddressInput.setError(null);
mLoginListener.setHelpContext(null, null);
}

private void showError(int messageId, String faqId, String faqSection) {
private void showError(int messageId) {
mSiteAddressInput.setError(getString(messageId));
mLoginListener.setHelpContext(faqId, faqSection);
}

@Override
Expand Down Expand Up @@ -227,26 +216,23 @@ public void certificateTrusted() {
askForHttpAuthCredentials(failedEndpoint);
break;
case NO_SITE_ERROR:
showError(R.string.no_site_error, NO_SITE_HELPSHIFT_FAQ_ID, NO_SITE_HELPSHIFT_FAQ_SECTION);
showError(R.string.no_site_error);
break;
case INVALID_URL:
showError(R.string.invalid_site_url_message, null, null);
showError(R.string.invalid_site_url_message);
mAnalyticsListener.trackInsertedInvalidUrl();
break;
case MISSING_XMLRPC_METHOD:
showError(R.string.xmlrpc_missing_method_error,
MISSING_XMLRPC_METHOD_HELPSHIFT_FAQ_ID, MISSING_XMLRPC_METHOD_HELPSHIFT_FAQ_SECTION);
showError(R.string.xmlrpc_missing_method_error);
break;
case XMLRPC_BLOCKED:
showError(R.string.xmlrpc_post_blocked_error,
XMLRPC_BLOCKED_HELPSHIFT_FAQ_ID, XMLRPC_BLOCKED_HELPSHIFT_FAQ_SECTION);
showError(R.string.xmlrpc_post_blocked_error);
break;
case XMLRPC_FORBIDDEN:
showError(R.string.xmlrpc_endpoint_forbidden_error,
XMLRPC_BLOCKED_HELPSHIFT_FAQ_ID, XMLRPC_BLOCKED_HELPSHIFT_FAQ_SECTION);
showError(R.string.xmlrpc_endpoint_forbidden_error);
break;
case GENERIC_ERROR:
showError(R.string.error_generic, null, null);
showError(R.string.error_generic);
break;
}
}
Expand Down Expand Up @@ -285,7 +271,7 @@ public void onWPComSiteFetched(OnWPComSiteFetched event) {
if (event.isError()) {
// Not a WordPress.com or Jetpack site
if (mLoginListener.getLoginMode() == LoginMode.WPCOM_LOGIN_ONLY) {
showError(R.string.enter_wpcom_or_jetpack_site, null, null);
showError(R.string.enter_wpcom_or_jetpack_site);
endProgress();
} else {
// Start the discovery process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ public String getStepName() {

private static class LoginNotification {
static Notification progress(Context context, int progress) {
return AutoForegroundNotification.progress(context, progress,
return AutoForegroundNotification.progress(context,
context.getString(R.string.login_notification_channel_id),
progress,
R.string.notification_login_title_in_progress,
R.string.notification_logging_in,
R.drawable.login_notification_icon,
Expand All @@ -122,6 +124,7 @@ static Notification progress(Context context, int progress) {

static Notification success(Context context) {
return AutoForegroundNotification.success(context,
context.getString(R.string.login_notification_channel_id),
R.string.notification_login_title_success,
R.string.notification_logged_in,
R.drawable.login_notification_icon,
Expand All @@ -130,6 +133,7 @@ static Notification success(Context context) {

static Notification failure(Context context, @StringRes int content) {
return AutoForegroundNotification.failure(context,
context.getString(R.string.login_notification_channel_id),
R.string.notification_login_title_stopped,
content,
R.drawable.login_notification_icon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ public void onSocialChanged(OnSocialChanged event) {
switch (event.error.type) {
// WordPress account exists with input email address, and two-factor authentication is required.
case TWO_STEP_ENABLED:
mAnalyticsListener.trackSignupSocial2faNeeded();
mAnalyticsListener.trackSignupSocialToLogin();
mLoginListener.showSignupToLoginMessage();
// Dispatch social login action to retrieve data required for two-factor authentication.
Expand Down
Loading

0 comments on commit ebd0664

Please sign in to comment.