Skip to content

Commit

Permalink
Merge pull request #41 from wordpress-mobile/merge/uls-changes
Browse files Browse the repository at this point in the history
Merge Unified Login & Signup changes from WPAndroid
  • Loading branch information
renanferrari authored Jul 27, 2020
2 parents 2870ce2 + 746cb77 commit 9403863
Show file tree
Hide file tree
Showing 65 changed files with 1,727 additions and 970 deletions.
45 changes: 29 additions & 16 deletions WordPressLoginFlow/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
buildscript {
ext {
kotlin_version = '1.3.61'
kotlin_ktx_version = '1.2.0'
daggerVersion = '2.22.1'
appCompatVersion = '1.0.2'
}
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'

repositories {
google()
Expand All @@ -17,12 +27,12 @@ repositories {
}

android {
compileSdkVersion 28
buildToolsVersion "28.0.3"
compileSdkVersion 29
buildToolsVersion "29.0.2"

defaultConfig {
minSdkVersion 17
targetSdkVersion 28
minSdkVersion 21
targetSdkVersion 29
versionCode 2
versionName "1.1"

Expand All @@ -31,17 +41,20 @@ android {
}

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

implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0'
implementation 'androidx.media:media:1.0.1'
implementation "androidx.appcompat:appcompat:$appCompatVersion"
implementation 'androidx.vectordrawable:vectordrawable-animated:1.1.0'
implementation 'androidx.media:media:1.1.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'com.google.android.material:material:1.1.0'

implementation "androidx.core:core-ktx:$kotlin_ktx_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

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

// Share FluxC version from host project if defined, otherwise fallback to default
Expand All @@ -58,21 +71,21 @@ dependencies {
}

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

// Dagger
implementation 'com.google.dagger:dagger:2.22.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.22.1'
implementation "com.google.dagger:dagger:$daggerVersion"
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
compileOnly 'org.glassfish:javax.annotation:10.0-b28'
implementation 'com.google.dagger:dagger-android-support:2.22.1'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.22.1'
implementation "com.google.dagger:dagger-android-support:$daggerVersion"
kapt "com.google.dagger:dagger-android-processor:$daggerVersion"

lintChecks 'org.wordpress:lint:1.0.1'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.27.0'
testImplementation 'androidx.arch.core:core-testing:2.0.1'
testImplementation 'org.robolectric:robolectric:4.3'
testImplementation 'org.mockito:mockito-core:2.28.2'
testImplementation 'androidx.arch.core:core-testing:2.1.0'
testImplementation 'org.robolectric:robolectric:4.3.1'
testImplementation 'org.assertj:assertj-core:3.11.1'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.wordpress.android.util.AppLog;
import org.wordpress.android.util.AppLog.T;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.inject.Inject;

import static android.app.Activity.RESULT_OK;
Expand Down Expand Up @@ -52,7 +55,7 @@ public class GoogleFragment extends Fragment implements ConnectionCallbacks, OnC
protected String mIdToken;
protected String mPhotoUrl;

protected static final String SERVICE_TYPE_GOOGLE = "google";
public static final String SERVICE_TYPE_GOOGLE = "google";

@Inject protected Dispatcher mDispatcher;
@Inject protected SiteStore mSiteStore;
Expand Down Expand Up @@ -246,4 +249,13 @@ public void onActivityResult(int request, int result, Intent data) {
break;
}
}

// Remove scale from photo URL path string. Current URL matches /s96-c, which returns a 96 x 96
// pixel image. Removing /s96-c from the string returns a 512 x 512 pixel image. Using regular
// expressions may help if the photo URL scale value in the returned path changes.
protected String removeScaleFromGooglePhotoUrl(String photoUrl) {
Pattern pattern = Pattern.compile("(/s[0-9]+-c)");
Matcher matcher = pattern.matcher(photoUrl);
return matcher.find() ? photoUrl.replace(matcher.group(1), "") : photoUrl;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;

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

Expand Down Expand Up @@ -89,7 +91,7 @@ public class Login2FaFragment extends LoginBaseFormFragment<LoginListener> imple

ArrayList<Integer> mOldSitesIDs;

private Button mSecondaryButton;
private Button mOtpButton;
private String mEmailAddress;
private String mIdToken;
private String mNonce;
Expand Down Expand Up @@ -172,29 +174,35 @@ protected void setupContent(ViewGroup rootView) {

// restrict the allowed input chars to just numbers
m2FaInput.getEditText().setKeyListener(DigitsKeyListener.getInstance("0123456789"));
}

@Override
protected void setupBottomButtons(Button secondaryButton, Button primaryButton) {
secondaryButton.setText(R.string.login_text_otp);
secondaryButton.setOnClickListener(new OnClickListener() {
mOtpButton = rootView.findViewById(R.id.login_otp_button);
mOtpButton.setText(mSentSmsCode ? R.string.login_text_otp_another : R.string.login_text_otp);
mOtpButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isAdded()) {
mAnalyticsListener.trackSendCodeWithTextClicked();
doAuthAction(R.string.requesting_otp, "", true);
}
}
});
secondaryButton.setText(getString(mSentSmsCode ? R.string.login_text_otp_another : R.string.login_text_otp));
mSecondaryButton = secondaryButton;
}

@Override
protected void setupBottomButtons(Button secondaryButton, Button primaryButton) {
secondaryButton.setVisibility(View.GONE);
primaryButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
next();
}
});
}

@Override
protected void buildToolbar(Toolbar toolbar, ActionBar actionBar) {
actionBar.setTitle(R.string.log_in);
}

@Override
protected EditText getEditTextToFocusOnStart() {
return m2FaInput.getEditText();
Expand Down Expand Up @@ -278,6 +286,7 @@ public void onResume() {
}

protected void next() {
mAnalyticsListener.trackSubmit2faCodeClicked();
if (TextUtils.isEmpty(m2FaInput.getEditText().getText())) {
show2FaError(getString(R.string.login_empty_2fa));
return;
Expand Down Expand Up @@ -368,6 +377,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
}

private void show2FaError(String message) {
mAnalyticsListener.trackFailure(message);
m2FaInput.setError(message);
}

Expand All @@ -389,14 +399,15 @@ private void handleAuthError(AuthenticationErrorType error, String errorMessage)
// TODO: FluxC: could be specific?
default:
AppLog.e(T.NUX, "Server response: " + errorMessage);

mAnalyticsListener.trackFailure(errorMessage);
ToastUtils.showToast(getActivity(),
errorMessage == null ? getString(R.string.error_generic) : errorMessage);
break;
}
}

private void showErrorDialog(String message) {
mAnalyticsListener.trackFailure(message);
AlertDialog dialog = new MaterialAlertDialogBuilder(getActivity())
.setMessage(message)
.setPositiveButton(R.string.login_error_button, null)
Expand Down Expand Up @@ -514,7 +525,7 @@ protected void onLoginFinished() {

private void setTextForSms() {
mLabel.setText(getString(R.string.enter_verification_code_sms, mPhoneNumber));
mSecondaryButton.setText(getString(R.string.login_text_otp_another));
mOtpButton.setText(getString(R.string.login_text_otp_another));
mSentSmsCode = true;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.wordpress.android.login

import java.util.Locale

interface LoginAnalyticsListener {
fun trackAnalyticsSignIn(isWpcomLogin: Boolean)
fun trackCreatedAccount(username: String?, email: String?, source: CreatedAccountSource)
fun trackEmailFormViewed()
fun trackInsertedInvalidUrl()
fun trackLoginAccessed()
fun trackLoginAutofillCredentialsFilled()
fun trackLoginAutofillCredentialsUpdated()
fun trackLoginFailed(errorContext: String?, errorType: String?, errorDescription: String?)
fun trackLoginForgotPasswordClicked()
fun trackLoginMagicLinkExited()
fun trackLoginMagicLinkOpened()
fun trackLoginMagicLinkOpenEmailClientClicked()
fun trackLoginMagicLinkSucceeded()
fun trackLoginSocial2faNeeded()
fun trackLoginSocialSuccess()
fun trackMagicLinkFailed(properties: Map<String, *>)
fun trackSignupMagicLinkOpenEmailClientViewed()
fun trackLoginMagicLinkOpenEmailClientViewed()
fun trackMagicLinkRequested()
fun trackMagicLinkRequestFormViewed()
fun trackPasswordFormViewed()
fun trackSignupCanceled()
fun trackSignupEmailButtonTapped()
fun trackSignupEmailToLogin()
fun trackSignupGoogleButtonTapped()
fun trackSignupMagicLinkFailed()
fun trackSignupMagicLinkOpened()
fun trackSignupMagicLinkOpenEmailClientClicked()
fun trackSignupMagicLinkSent()
fun trackSignupMagicLinkSucceeded()
fun trackSignupSocialAccountsNeedConnecting()
fun trackSignupSocialButtonFailure()
fun trackSignupSocialToLogin()
fun trackSignupTermsOfServiceTapped()
fun trackSocialButtonStart()
fun trackSocialAccountsNeedConnecting()
fun trackSocialButtonClick()
fun trackSocialButtonFailure()
fun trackSocialConnectFailure()
fun trackSocialConnectSuccess()
fun trackSocialErrorUnknownUser()
fun trackSocialFailure(errorContext: String?, errorType: String?, errorDescription: String?)
fun trackTwoFactorFormViewed()
fun trackUrlFormViewed()
fun trackUrlHelpScreenViewed()
fun trackUsernamePasswordFormViewed()
fun trackWpComBackgroundServiceUpdate(properties: Map<String, *>)
fun trackConnectedSiteInfoRequested(url: String?)
fun trackConnectedSiteInfoFailed(url: String?, errorContext: String?, errorType: String?, errorDescription: String?)
fun trackConnectedSiteInfoSucceeded(properties: Map<String, *>)
fun trackFailure(message: String?)
fun trackSendCodeWithTextClicked()
fun trackSubmit2faCodeClicked()
fun trackSubmitClicked()
fun trackRequestMagicLinkClick()
fun trackLoginWithPasswordClick()
fun trackShowHelpClick()
fun trackDismissDialog()
fun trackSelectEmailField()
fun trackPickEmailFromHint()
fun trackShowEmailHints()
fun emailFormScreenResumed()
fun trackEmailSignupConfirmationViewed()
fun trackSocialSignupConfirmationViewed()
fun trackCreateAccountClick()

enum class CreatedAccountSource {
EMAIL,
GOOGLE;

fun asPropertyMap() = hashMapOf<String, Any>(
"source" to name.toLowerCase(Locale.ROOT)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public void onDiscoverySucceeded(OnDiscoveryResponse event) {
}

private void handleDiscoveryError(DiscoveryError error, final String failedEndpoint) {
mAnalyticsListener.trackFailure(error.name() + " - " + failedEndpoint);
if (error == DiscoveryError.WORDPRESS_COM_SITE) {
mLoginBaseDiscoveryListener.handleWpComDiscoveryError(failedEndpoint);
} else {
Expand Down
Loading

0 comments on commit 9403863

Please sign in to comment.