Skip to content

Commit

Permalink
Version 6.4.0
Browse files Browse the repository at this point in the history
Version 6.4.0
  • Loading branch information
samtstern committed Nov 2, 2020
2 parents 5fb0fc1 + 873f550 commit 241aeb6
Show file tree
Hide file tree
Showing 14 changed files with 240 additions and 24 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ libraries.
```groovy
dependencies {
// FirebaseUI for Firebase Realtime Database
implementation 'com.firebaseui:firebase-ui-database:6.3.0'
implementation 'com.firebaseui:firebase-ui-database:6.4.0'
// FirebaseUI for Cloud Firestore
implementation 'com.firebaseui:firebase-ui-firestore:6.3.0'
implementation 'com.firebaseui:firebase-ui-firestore:6.4.0'
// FirebaseUI for Firebase Auth
implementation 'com.firebaseui:firebase-ui-auth:6.3.0'
implementation 'com.firebaseui:firebase-ui-auth:6.4.0'
// FirebaseUI for Cloud Storage
implementation 'com.firebaseui:firebase-ui-storage:6.3.0'
implementation 'com.firebaseui:firebase-ui-storage:6.4.0'
}
```

Expand Down
2 changes: 1 addition & 1 deletion auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Gradle, add the dependency:
```groovy
dependencies {
// ...
implementation 'com.firebaseui:firebase-ui-auth:6.3.0'
implementation 'com.firebaseui:firebase-ui-auth:6.4.0'
// Required only if Facebook login support is required
// Find the latest Facebook SDK releases here: https://github.com/facebook/facebook-android-sdk/blob/master/CHANGELOG.md
Expand Down
60 changes: 59 additions & 1 deletion auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1201,14 +1201,17 @@ public GenericOAuthProviderBuilder setCustomParameters(
@SuppressWarnings(value = "unchecked")
private abstract class AuthIntentBuilder<T extends AuthIntentBuilder> {
final List<IdpConfig> mProviders = new ArrayList<>();
IdpConfig mDefaultProvider = null;
int mLogo = NO_LOGO;
int mTheme = getDefaultTheme();
String mTosUrl;
String mPrivacyPolicyUrl;
boolean mAlwaysShowProviderChoice = false;
boolean mLockOrientation = false;
boolean mEnableCredentials = true;
boolean mEnableHints = true;
AuthMethodPickerLayout mAuthMethodPickerLayout = null;
ActionCodeSettings mPasswordSettings = null;

/**
* Specifies the theme to use for the application flow. If no theme is specified, a
Expand Down Expand Up @@ -1270,7 +1273,7 @@ public T setTosAndPrivacyPolicyUrls(@NonNull String tosUrl,
}

/**
* Specified the set of supported authentication providers. At least one provider must
* Specifies the set of supported authentication providers. At least one provider must
* be specified. There may only be one instance of each provider. Anonymous provider cannot
* be the only provider specified.
* <p>
Expand Down Expand Up @@ -1307,6 +1310,29 @@ public T setAvailableProviders(@NonNull List<IdpConfig> idpConfigs) {
return (T) this;
}

/**
* Specifies the default authentication provider, bypassing the provider selection screen.
* The provider here must already be included via {@link #setAvailableProviders(List)}, and
* this method is incompatible with {@link #setAlwaysShowSignInMethodScreen(boolean)}.
*
* @param config the default {@link IdpConfig} to use.
*/
@NonNull
public T setDefaultProvider(@Nullable IdpConfig config) {
if (config != null) {
if (!mProviders.contains(config)) {
throw new IllegalStateException(
"Default provider not in available providers list.");
}
if (mAlwaysShowProviderChoice) {
throw new IllegalStateException(
"Can't set default provider and always show provider choice.");
}
}
mDefaultProvider = config;
return (T) this;
}

/**
* Enables or disables the use of Smart Lock for Passwords in the sign in flow. To
* (en)disable hint selector and credential selector independently use {@link
Expand Down Expand Up @@ -1359,10 +1385,39 @@ public T setAuthMethodPickerLayout(@NonNull AuthMethodPickerLayout authMethodPic
*/
@NonNull
public T setAlwaysShowSignInMethodScreen(boolean alwaysShow) {
if (alwaysShow && mDefaultProvider != null) {
throw new IllegalStateException(
"Can't show provider choice with a default provider.");
}
mAlwaysShowProviderChoice = alwaysShow;
return (T) this;
}

/**
* Enable or disables the orientation for small devices to be locked in
* Portrait orientation
* <p>
* <p>This is false by default.
*
* @param lockOrientation if true, force the activities to be in Portrait orientation.
*/
@NonNull
public T setLockOrientation(boolean lockOrientation) {
mLockOrientation = lockOrientation;
return (T) this;
}

/**
* Set custom settings for the RecoverPasswordActivity.
*
* @param passwordSettings to allow additional state via a continue URL.
*/
@NonNull
public T setResetPasswordSettings(ActionCodeSettings passwordSettings) {
mPasswordSettings = passwordSettings;
return (T) this;
}

@CallSuper
@NonNull
public Intent build() {
Expand Down Expand Up @@ -1431,6 +1486,7 @@ protected FlowParameters getFlowParams() {
return new FlowParameters(
mApp.getName(),
mProviders,
mDefaultProvider,
mTheme,
mLogo,
mTosUrl,
Expand All @@ -1439,7 +1495,9 @@ protected FlowParameters getFlowParams() {
mEnableHints,
mEnableAnonymousUpgrade,
mAlwaysShowProviderChoice,
mLockOrientation,
mEmailLink,
mPasswordSettings,
mAuthMethodPickerLayout);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.firebase.ui.auth.AuthUI.IdpConfig;
import com.firebase.ui.auth.util.ExtraConstants;
import com.firebase.ui.auth.util.Preconditions;
import com.google.firebase.auth.ActionCodeSettings;

import java.util.Collections;
import java.util.List;
Expand All @@ -44,6 +45,7 @@ public class FlowParameters implements Parcelable {
public FlowParameters createFromParcel(Parcel in) {
String appName = in.readString();
List<IdpConfig> providerInfo = in.createTypedArrayList(IdpConfig.CREATOR);
IdpConfig defaultProvider = in.readParcelable(IdpConfig.class.getClassLoader());
int themeId = in.readInt();
int logoId = in.readInt();
String termsOfServiceUrl = in.readString();
Expand All @@ -52,12 +54,15 @@ public FlowParameters createFromParcel(Parcel in) {
boolean enableHints = in.readInt() != 0;
boolean enableAnonymousUpgrade = in.readInt() != 0;
boolean alwaysShowProviderChoice = in.readInt() != 0;
boolean lockOrientation = in.readInt() != 0;
String emailLink = in.readString();
ActionCodeSettings passwordResetSettings = in.readParcelable(ActionCodeSettings.class.getClassLoader());
AuthMethodPickerLayout customLayout = in.readParcelable(AuthMethodPickerLayout.class.getClassLoader());

return new FlowParameters(
appName,
providerInfo,
defaultProvider,
themeId,
logoId,
termsOfServiceUrl,
Expand All @@ -66,7 +71,9 @@ public FlowParameters createFromParcel(Parcel in) {
enableHints,
enableAnonymousUpgrade,
alwaysShowProviderChoice,
lockOrientation,
emailLink,
passwordResetSettings,
customLayout);
}

Expand All @@ -82,6 +89,9 @@ public FlowParameters[] newArray(int size) {
@NonNull
public final List<IdpConfig> providers;

@Nullable
public final IdpConfig defaultProvider;

@StyleRes
public final int themeId;

Expand All @@ -97,17 +107,22 @@ public FlowParameters[] newArray(int size) {
@Nullable
public String emailLink;

@Nullable
public final ActionCodeSettings passwordResetSettings;

public final boolean enableCredentials;
public final boolean enableHints;
public final boolean enableAnonymousUpgrade;
public final boolean alwaysShowProviderChoice;
public final boolean lockOrientation;

@Nullable
public final AuthMethodPickerLayout authMethodPickerLayout;

public FlowParameters(
@NonNull String appName,
@NonNull List<IdpConfig> providers,
@Nullable IdpConfig defaultProvider,
@StyleRes int themeId,
@DrawableRes int logoId,
@Nullable String termsOfServiceUrl,
Expand All @@ -116,11 +131,14 @@ public FlowParameters(
boolean enableHints,
boolean enableAnonymousUpgrade,
boolean alwaysShowProviderChoice,
boolean lockOrientation,
@Nullable String emailLink,
@Nullable ActionCodeSettings passwordResetSettings,
@Nullable AuthMethodPickerLayout authMethodPickerLayout) {
this.appName = Preconditions.checkNotNull(appName, "appName cannot be null");
this.providers = Collections.unmodifiableList(
Preconditions.checkNotNull(providers, "providers cannot be null"));
this.defaultProvider = defaultProvider;
this.themeId = themeId;
this.logoId = logoId;
this.termsOfServiceUrl = termsOfServiceUrl;
Expand All @@ -129,7 +147,9 @@ public FlowParameters(
this.enableHints = enableHints;
this.enableAnonymousUpgrade = enableAnonymousUpgrade;
this.alwaysShowProviderChoice = alwaysShowProviderChoice;
this.lockOrientation = lockOrientation;
this.emailLink = emailLink;
this.passwordResetSettings = passwordResetSettings;
this.authMethodPickerLayout = authMethodPickerLayout;
}

Expand All @@ -144,6 +164,7 @@ public static FlowParameters fromIntent(Intent intent) {
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(appName);
dest.writeTypedList(providers);
dest.writeParcelable(defaultProvider, flags);
dest.writeInt(themeId);
dest.writeInt(logoId);
dest.writeString(termsOfServiceUrl);
Expand All @@ -152,7 +173,9 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(enableHints ? 1 : 0);
dest.writeInt(enableAnonymousUpgrade ? 1 : 0);
dest.writeInt(alwaysShowProviderChoice ? 1 : 0);
dest.writeInt(lockOrientation ? 1 : 0);
dest.writeString(emailLink);
dest.writeParcelable(passwordResetSettings, flags);
dest.writeParcelable(authMethodPickerLayout, flags);
}

Expand All @@ -178,6 +201,10 @@ public boolean isAnonymousUpgradeEnabled() {
}

public boolean shouldShowProviderChoice() {
return !isSingleProviderFlow() || alwaysShowProviderChoice;
return defaultProvider == null && (!isSingleProviderFlow() || alwaysShowProviderChoice);
}

public IdpConfig getDefaultOrFirstProvider() {
return defaultProvider != null ? defaultProvider : providers.get(0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ protected void handleNormalSignInFlow(final FirebaseAuth auth,
@Override
public void onSuccess(@NonNull AuthResult authResult) {
handleSuccess(provider.getProviderId(),
authResult.getUser(), (OAuthCredential)
authResult.getCredential());
authResult.getUser(),
(OAuthCredential) authResult.getCredential(),
authResult.getAdditionalUserInfo().isNewUser());
}
})
.addOnFailureListener(
Expand Down Expand Up @@ -135,8 +136,9 @@ private void handleAnonymousUpgradeFlow(final FirebaseAuth auth,
@Override
public void onSuccess(@NonNull AuthResult authResult) {
handleSuccess(provider.getProviderId(),
authResult.getUser(), (OAuthCredential)
authResult.getCredential());
authResult.getUser(),
(OAuthCredential) authResult.getCredential(),
authResult.getAdditionalUserInfo().isNewUser());
}
})
.addOnFailureListener(
Expand Down Expand Up @@ -221,6 +223,7 @@ protected OAuthProvider buildOAuthProvider(String providerId) {
protected void handleSuccess(@NonNull String providerId,
@NonNull FirebaseUser user,
@NonNull OAuthCredential credential,
boolean isNewUser,
boolean setPendingCredential) {
IdpResponse.Builder response = new IdpResponse.Builder(
new User.Builder(
Expand All @@ -234,14 +237,16 @@ protected void handleSuccess(@NonNull String providerId,
if (setPendingCredential) {
response.setPendingCredential(credential);
}
response.setNewUser(isNewUser);

setResult(Resource.<IdpResponse>forSuccess(response.build()));
}

protected void handleSuccess(@NonNull String providerId,
@NonNull FirebaseUser user,
@NonNull OAuthCredential credential) {
handleSuccess(providerId, user, credential, /* setPendingCredential= */false);
@NonNull OAuthCredential credential,
boolean isNewUser) {
handleSuccess(providerId, user, credential, isNewUser, /* setPendingCredential= */true);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ public void onComplete(@NonNull Task<CredentialRequestResponse> task) {
}

private void startAuthMethodChoice() {
// If there is only one provider selected, launch the flow directly
if (!getArguments().shouldShowProviderChoice()) {
AuthUI.IdpConfig firstIdpConfig = getArguments().providers.get(0);
AuthUI.IdpConfig firstIdpConfig = getArguments().getDefaultOrFirstProvider();
String firstProvider = firstIdpConfig.getProviderId();
switch (firstProvider) {
case EMAIL_LINK_PROVIDER:
Expand Down
11 changes: 11 additions & 0 deletions auth/src/main/java/com/firebase/ui/auth/ui/AppCompatBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.firebase.ui.auth.ui;

import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo;
import android.os.Bundle;

import com.firebase.ui.auth.R;
Expand All @@ -31,6 +33,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.FirebaseUI); // Provides default values
setTheme(getFlowParams().themeId);

if (getFlowParams().lockOrientation) {
lockOrientation();
}
}

protected void switchFragment(@NonNull Fragment fragment,
Expand All @@ -53,4 +59,9 @@ protected void switchFragment(@NonNull Fragment fragment,
protected void switchFragment(@NonNull Fragment fragment, int fragmentId, @NonNull String tag) {
switchFragment(fragment, fragmentId, tag, false, false);
}

@SuppressLint("SourceLockedOrientationActivity")
private void lockOrientation() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import com.firebase.ui.auth.viewmodel.ResourceObserver;
import com.firebase.ui.auth.viewmodel.email.RecoverPasswordHandler;
import com.google.android.material.textfield.TextInputLayout;
import com.google.firebase.auth.ActionCodeSettings;
import com.google.firebase.auth.FirebaseAuthInvalidCredentialsException;
import com.google.firebase.auth.FirebaseAuthInvalidUserException;

Expand Down Expand Up @@ -118,10 +119,18 @@ public void onClick(View view) {
@Override
public void onDonePressed() {
if (mEmailFieldValidator.validate(mEmailEditText.getText())) {
mHandler.startReset(mEmailEditText.getText().toString());
if (getFlowParams().passwordResetSettings != null) {
resetPassword(mEmailEditText.getText().toString(), getFlowParams().passwordResetSettings);
}
else {
resetPassword(mEmailEditText.getText().toString(), null);
}
}
}

private void resetPassword(String email, @Nullable ActionCodeSettings passwordResetSettings) {
mHandler.startReset(email, passwordResetSettings);
}
private void showEmailSentDialog(String email) {
new AlertDialog.Builder(this)
.setTitle(R.string.fui_title_confirm_recover_password)
Expand Down
Loading

0 comments on commit 241aeb6

Please sign in to comment.