Skip to content

Commit

Permalink
Merge pull request #932 from firebase/version-2.4.0-release
Browse files Browse the repository at this point in the history
Version 2.4.0 release
  • Loading branch information
samtstern committed Sep 28, 2017
2 parents 29f8885 + 118ce9b commit e25ff29
Show file tree
Hide file tree
Showing 19 changed files with 258 additions and 68 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ libraries.
```groovy
dependencies {
// FirebaseUI Database only
compile 'com.firebaseui:firebase-ui-database:2.3.0'
compile 'com.firebaseui:firebase-ui-database:2.4.0'
// FirebaseUI Auth only
compile 'com.firebaseui:firebase-ui-auth:2.3.0'
compile 'com.firebaseui:firebase-ui-auth:2.4.0'
// FirebaseUI Storage only
compile 'com.firebaseui:firebase-ui-storage:2.3.0'
compile 'com.firebaseui:firebase-ui-storage:2.4.0'
// Single target that includes all FirebaseUI libraries above
compile 'com.firebaseui:firebase-ui:2.3.0'
compile 'com.firebaseui:firebase-ui:2.4.0'
}
```

Expand Down Expand Up @@ -91,6 +91,7 @@ For convenience, here are some recent examples:

| FirebaseUI Version | Firebase/Play Services Version |
|--------------------|--------------------------------|
| 2.4.0 | 11.4.0 |
| 2.3.0 | 11.0.4 |
| 2.2.0 | 11.0.4 |
| 2.1.1 | 11.0.2 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void signIn(View view) {
.setTosUrl(getSelectedTosUrl())
.setPrivacyPolicyUrl(getSelectedPrivacyPolicyUrl())
.setIsSmartLockEnabled(mEnableCredentialSelector.isChecked(),
mEnableHintSelector.isChecked())
mEnableHintSelector.isChecked())
.setAllowNewEmailAccounts(mAllowNewEmailAccounts.isChecked())
.build(),
RC_SIGN_IN);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.firebase.uidemo.database;

import android.os.Bundle;
import android.view.View;

import com.firebase.ui.database.FirebaseIndexRecyclerAdapter;
Expand All @@ -13,12 +12,6 @@
public class ChatIndexActivity extends ChatActivity {
private DatabaseReference mChatIndicesRef;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mChatIndicesRef = FirebaseDatabase.getInstance().getReference().child("chatIndices");
}

@Override
public void onClick(View v) {
String uid = FirebaseAuth.getInstance().getCurrentUser().getUid();
Expand All @@ -34,6 +27,11 @@ public void onClick(View v) {

@Override
protected FirebaseRecyclerAdapter<Chat, ChatHolder> getAdapter() {
mChatIndicesRef = FirebaseDatabase.getInstance()
.getReference()
.child("chatIndices")
.child(FirebaseAuth.getInstance().getCurrentUser().getUid());

return new FirebaseIndexRecyclerAdapter<Chat, ChatHolder>(
Chat.class,
R.layout.message,
Expand Down
32 changes: 30 additions & 2 deletions auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ Gradle, add the dependency:
```groovy
dependencies {
// ...
compile 'com.firebaseui:firebase-ui-auth:2.3.0'
compile 'com.firebaseui:firebase-ui-auth:2.4.0'
// Required only if Facebook login support is required
compile('com.facebook.android:facebook-android-sdk:4.22.1')
compile('com.facebook.android:facebook-android-sdk:4.26.0')
// Required only if Twitter login support is required
compile("com.twitter.sdk.android:twitter-core:3.0.0@aar") { transitive = true }
Expand Down Expand Up @@ -256,6 +256,34 @@ startActivityForResult(
RC_SIGN_IN);
```

When using the phone verification provider and the number is known in advance, it is possible to
provide a default phone number (in international format) that will be used to prepopulate the
country code and phone number input fields. The user is still able to edit the number if desired.

```java
// Use a Bundle to hold the default number, and pass it to the Builder via setParams:
Bundle params = new Bundle();
params.putString(AuthUI.EXTRA_DEFAULT_PHONE_NUMBER, "+123456789");
IdpConfig phoneConfigWithDefaultNumber =
new IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER)
.setParams(params)
.build();
```

It is also possible to set a default country code along with a national number if a specific country
is your app's target audience. This will take precedence over the full default phone number if both
are provided.

```java
Bundle params = new Bundle();
params.putString(AuthUI.EXTRA_DEFAULT_COUNTRY_CODE, "ca");
params.putString(AuthUI.EXTRA_DEFAULT_NATIONAL_NUMBER, "23456789");
IdpConfig phoneConfigWithDefaultCountryAndNationalNumber =
new IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER)
.setParams(params)
.build();
```

#### Handling the sign-in response

##### Response codes
Expand Down
4 changes: 0 additions & 4 deletions auth/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />

<meta-data
android:name="io.fabric.ApiKey"
android:value="@string/twitter_consumer_secret" />

<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_application_id" />
Expand Down
43 changes: 39 additions & 4 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.CallSuper;
Expand All @@ -28,6 +29,7 @@

import com.facebook.login.LoginManager;
import com.firebase.ui.auth.provider.TwitterProvider;
import com.firebase.ui.auth.ui.ExtraConstants;
import com.firebase.ui.auth.ui.FlowParameters;
import com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity;
import com.firebase.ui.auth.util.GoogleSignInHelper;
Expand Down Expand Up @@ -104,6 +106,21 @@ public class AuthUI {
*/
public static final String PHONE_VERIFICATION_PROVIDER = PhoneAuthProvider.PROVIDER_ID;

/**
* Bundle key for the default full phone number parameter.
*/
public static final String EXTRA_DEFAULT_PHONE_NUMBER = ExtraConstants.EXTRA_PHONE;

/**
* Bundle key for the default phone country code parameter.
*/
public static final String EXTRA_DEFAULT_COUNTRY_CODE = ExtraConstants.EXTRA_COUNTRY_CODE;

/**
* Bundle key for the default national phone number parameter.
*/
public static final String EXTRA_DEFAULT_NATIONAL_NUMBER = ExtraConstants.EXTRA_NATIONAL_NUMBER;

/**
* Default value for logo resource, omits the logo from the {@link AuthMethodPickerActivity}.
*/
Expand Down Expand Up @@ -269,15 +286,21 @@ public SignInIntentBuilder createSignInIntentBuilder() {
public static class IdpConfig implements Parcelable {
private final String mProviderId;
private final List<String> mScopes;
private final Bundle mParams;

private IdpConfig(@SupportedProvider @NonNull String providerId, List<String> scopes) {
private IdpConfig(
@SupportedProvider @NonNull String providerId,
List<String> scopes,
Bundle params) {
mProviderId = providerId;
mScopes = Collections.unmodifiableList(scopes);
mParams = params;
}

private IdpConfig(Parcel in) {
mProviderId = in.readString();
mScopes = Collections.unmodifiableList(in.createStringArrayList());
mParams = in.readBundle(getClass().getClassLoader());
}

@SupportedProvider
Expand All @@ -289,6 +312,10 @@ public List<String> getScopes() {
return mScopes;
}

public Bundle getParams() {
return mParams;
}

public static final Creator<IdpConfig> CREATOR = new Creator<IdpConfig>() {
@Override
public IdpConfig createFromParcel(Parcel in) {
Expand All @@ -310,6 +337,7 @@ public int describeContents() {
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(mProviderId);
parcel.writeStringList(mScopes);
parcel.writeBundle(mParams);
}

@Override
Expand All @@ -332,12 +360,14 @@ public String toString() {
return "IdpConfig{" +
"mProviderId='" + mProviderId + '\'' +
", mScopes=" + mScopes +
", mParams=" + mParams +
'}';
}

public static class Builder {
@SupportedProvider private String mProviderId;
private List<String> mScopes = new ArrayList<>();
private Bundle mParams = new Bundle();

/**
* Builds the configuration parameters for an identity provider.
Expand Down Expand Up @@ -372,8 +402,13 @@ public Builder setPermissions(List<String> permissions) {
return this;
}

public Builder setParams(Bundle params) {
mParams = params;
return this;
}

public IdpConfig build() {
return new IdpConfig(mProviderId, mScopes);
return new IdpConfig(mProviderId, mScopes, mParams);
}
}
}
Expand Down Expand Up @@ -448,8 +483,8 @@ public T setAvailableProviders(@NonNull List<IdpConfig> idpConfigs) {
for (IdpConfig config : idpConfigs) {
if (mProviders.contains(config)) {
throw new IllegalArgumentException("Each provider can only be set once. "
+ config.getProviderId()
+ " was set twice.");
+ config.getProviderId()
+ " was set twice.");
} else {
mProviders.add(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.LayoutRes;

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.R;
import com.firebase.ui.auth.ui.FlowParameters;
import com.firebase.ui.auth.ui.phone.PhoneVerificationActivity;
Expand Down Expand Up @@ -34,8 +36,16 @@ public int getButtonLayout() {

@Override
public void startLogin(Activity activity) {

Bundle params = null;
for (AuthUI.IdpConfig idpConfig : mFlowParameters.providerInfo) {
if (idpConfig.getProviderId().equals(AuthUI.PHONE_VERIFICATION_PROVIDER)) {
params = idpConfig.getParams();
}
}

activity.startActivityForResult(
PhoneVerificationActivity.createIntent(activity, mFlowParameters, null),
PhoneVerificationActivity.createIntent(activity, mFlowParameters, params),
RC_PHONE_FLOW);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ public class ExtraConstants {
public static final String EXTRA_USER = "extra_user";
public static final String EXTRA_EMAIL = "extra_email";
public static final String EXTRA_PHONE = "extra_phone_number";
public static final String EXTRA_COUNTRY_CODE = "extra_country_code";
public static final String EXTRA_NATIONAL_NUMBER = "extra_national_number";
public static final String HAS_EXISTING_INSTANCE = "has_existing_instance";
public static final String EXTRA_PARAMS = "extra_params";
}
12 changes: 9 additions & 3 deletions auth/src/main/java/com/firebase/ui/auth/ui/ImeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ public static void setImeOnDoneListener(EditText doneEditText,
doneEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
if (event != null
&& event.getKeyCode() == KeyEvent.KEYCODE_ENTER
|| actionId == EditorInfo.IME_ACTION_DONE) {
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
if (event.getAction() == KeyEvent.ACTION_UP) {
listener.onDonePressed();
}

// We need to return true even if we didn't handle the event to continue
// receiving future callbacks.
return true;
} else if (actionId == EditorInfo.IME_ACTION_DONE) {
listener.onDonePressed();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,23 @@ public final class CompletableProgressDialog extends DialogFragment {

public static CompletableProgressDialog show(FragmentManager manager) {
CompletableProgressDialog dialog = new CompletableProgressDialog();
dialog.show(manager, TAG);
dialog.showAllowingStateLoss(manager, TAG);
return dialog;
}

/**
* This method is adapted from {@link #show(FragmentManager, String)}
*/
public void showAllowingStateLoss(FragmentManager manager, String tag) {
// This prevents us from hitting FragmentManager.checkStateLoss() which
// throws a runtime exception if state has already been saved.
if (manager.isStateSaved()) {
return;
}

show(manager, tag);
}

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Expand All @@ -60,12 +73,18 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {

public void onComplete(String msg) {
setMessage(msg);
mProgress.setVisibility(View.GONE);
mSuccessImage.setVisibility(View.VISIBLE);

if (mProgress != null) {
mProgress.setVisibility(View.GONE);
}

if (mSuccessImage != null) {
mSuccessImage.setVisibility(View.VISIBLE);
}
}

public void setMessage(CharSequence message) {
if (mProgress != null) {
if (mProgress != null && mMessageView != null) {
mMessageView.setText(message);
} else {
mMessage = message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,22 @@ protected static PhoneNumber getPhoneNumber(@NonNull String providedPhoneNumber)
return new PhoneNumber(phoneNumber, countryIso, countryCode);
}

static PhoneNumber getPhoneNumber(
@NonNull String providedCountryIso, @NonNull String providedNationalNumber) {
Integer countryCode = getCountryCode(providedCountryIso);
if (countryCode == null) {
// Invalid ISO supplied:
countryCode = DEFAULT_COUNTRY_CODE_INT;
providedCountryIso = DEFAULT_COUNTRY_CODE;
}

// National number shouldn't include '+', but just in case:
providedNationalNumber = stripPlusSign(providedNationalNumber);

return new PhoneNumber(
providedNationalNumber, providedCountryIso, String.valueOf(countryCode));
}

private static String countryIsoForCountryCode(String countryCode) {
final List<String> countries = CountryCodeToRegionCodeMap.get(Integer.valueOf(countryCode));
if (countries != null) {
Expand Down Expand Up @@ -1337,6 +1353,10 @@ private static String stripCountryCode(String phoneNumber, String countryCode) {
return phoneNumber.replaceFirst("^\\+?" + countryCode, "");
}

private static String stripPlusSign(String phoneNumber) {
return phoneNumber.replaceFirst("^\\+?", "");
}

private static Locale getSimBasedLocale(@NonNull Context context) {
final TelephonyManager tm =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
Expand Down
Loading

0 comments on commit e25ff29

Please sign in to comment.