Skip to content

Commit 32ee88f

Browse files
committed
Merge branch 'master' into version-3.0.0-dev
Change-Id: I35d763e9e3b77dd89baa0068d4c2e0f83d02d5ab
2 parents 34adac2 + e25ff29 commit 32ee88f

File tree

14 files changed

+217
-34
lines changed

14 files changed

+217
-34
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ libraries.
3939
```groovy
4040
dependencies {
4141
// FirebaseUI Database only
42-
compile 'com.firebaseui:firebase-ui-database:2.3.0'
42+
compile 'com.firebaseui:firebase-ui-database:2.4.0'
4343
4444
// FirebaseUI Auth only
45-
compile 'com.firebaseui:firebase-ui-auth:2.3.0'
45+
compile 'com.firebaseui:firebase-ui-auth:2.4.0'
4646
4747
// FirebaseUI Storage only
48-
compile 'com.firebaseui:firebase-ui-storage:2.3.0'
48+
compile 'com.firebaseui:firebase-ui-storage:2.4.0'
4949
5050
// Single target that includes all FirebaseUI libraries above
51-
compile 'com.firebaseui:firebase-ui:2.3.0'
51+
compile 'com.firebaseui:firebase-ui:2.4.0'
5252
}
5353
```
5454

@@ -91,6 +91,7 @@ For convenience, here are some recent examples:
9191

9292
| FirebaseUI Version | Firebase/Play Services Version |
9393
|--------------------|--------------------------------|
94+
| 2.4.0 | 11.4.0 |
9495
| 2.3.0 | 11.0.4 |
9596
| 2.2.0 | 11.0.4 |
9697
| 2.1.1 | 11.0.2 |

app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ public void signIn(View view) {
205205
.setTosUrl(getSelectedTosUrl())
206206
.setPrivacyPolicyUrl(getSelectedPrivacyPolicyUrl())
207207
.setIsSmartLockEnabled(mEnableCredentialSelector.isChecked(),
208-
mEnableHintSelector.isChecked())
208+
mEnableHintSelector.isChecked())
209209
.setAllowNewEmailAccounts(mAllowNewEmailAccounts.isChecked())
210210
.build(),
211211
RC_SIGN_IN);

auth/README.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ Gradle, add the dependency:
4646
```groovy
4747
dependencies {
4848
// ...
49-
compile 'com.firebaseui:firebase-ui-auth:2.3.0'
49+
compile 'com.firebaseui:firebase-ui-auth:2.4.0'
5050
5151
// Required only if Facebook login support is required
52-
compile('com.facebook.android:facebook-android-sdk:4.22.1')
52+
compile('com.facebook.android:facebook-android-sdk:4.26.0')
5353
5454
// Required only if Twitter login support is required
5555
compile("com.twitter.sdk.android:twitter-core:3.0.0@aar") { transitive = true }
@@ -256,6 +256,34 @@ startActivityForResult(
256256
RC_SIGN_IN);
257257
```
258258

259+
When using the phone verification provider and the number is known in advance, it is possible to
260+
provide a default phone number (in international format) that will be used to prepopulate the
261+
country code and phone number input fields. The user is still able to edit the number if desired.
262+
263+
```java
264+
// Use a Bundle to hold the default number, and pass it to the Builder via setParams:
265+
Bundle params = new Bundle();
266+
params.putString(AuthUI.EXTRA_DEFAULT_PHONE_NUMBER, "+123456789");
267+
IdpConfig phoneConfigWithDefaultNumber =
268+
new IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER)
269+
.setParams(params)
270+
.build();
271+
```
272+
273+
It is also possible to set a default country code along with a national number if a specific country
274+
is your app's target audience. This will take precedence over the full default phone number if both
275+
are provided.
276+
277+
```java
278+
Bundle params = new Bundle();
279+
params.putString(AuthUI.EXTRA_DEFAULT_COUNTRY_CODE, "ca");
280+
params.putString(AuthUI.EXTRA_DEFAULT_NATIONAL_NUMBER, "23456789");
281+
IdpConfig phoneConfigWithDefaultCountryAndNationalNumber =
282+
new IdpConfig.Builder(AuthUI.PHONE_VERIFICATION_PROVIDER)
283+
.setParams(params)
284+
.build();
285+
```
286+
259287
#### Handling the sign-in response
260288

261289
##### Response codes
@@ -417,6 +445,7 @@ Second, ensure the three standard AppCompat color resources are defined with you
417445
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
418446
<item name="colorAccent">@color/colorAccent</item>
419447
</style>
448+
```
420449

421450
If you would like more control over FirebaseUI's styling, you can define your own custom style
422451
to override certain or all styling attributes. For example, a green sign-in theme:

auth/src/main/java/com/firebase/ui/auth/AuthUI.java

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import android.app.Activity;
1818
import android.content.Intent;
19+
import android.os.Bundle;
1920
import android.os.Parcel;
2021
import android.os.Parcelable;
2122
import android.support.annotation.CallSuper;
@@ -28,6 +29,7 @@
2829

2930
import com.facebook.login.LoginManager;
3031
import com.firebase.ui.auth.provider.TwitterProvider;
32+
import com.firebase.ui.auth.ui.ExtraConstants;
3133
import com.firebase.ui.auth.ui.FlowParameters;
3234
import com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity;
3335
import com.firebase.ui.auth.util.GoogleSignInHelper;
@@ -104,6 +106,21 @@ public class AuthUI {
104106
*/
105107
public static final String PHONE_VERIFICATION_PROVIDER = PhoneAuthProvider.PROVIDER_ID;
106108

109+
/**
110+
* Bundle key for the default full phone number parameter.
111+
*/
112+
public static final String EXTRA_DEFAULT_PHONE_NUMBER = ExtraConstants.EXTRA_PHONE;
113+
114+
/**
115+
* Bundle key for the default phone country code parameter.
116+
*/
117+
public static final String EXTRA_DEFAULT_COUNTRY_CODE = ExtraConstants.EXTRA_COUNTRY_CODE;
118+
119+
/**
120+
* Bundle key for the default national phone number parameter.
121+
*/
122+
public static final String EXTRA_DEFAULT_NATIONAL_NUMBER = ExtraConstants.EXTRA_NATIONAL_NUMBER;
123+
107124
/**
108125
* Default value for logo resource, omits the logo from the {@link AuthMethodPickerActivity}.
109126
*/
@@ -269,15 +286,21 @@ public SignInIntentBuilder createSignInIntentBuilder() {
269286
public static class IdpConfig implements Parcelable {
270287
private final String mProviderId;
271288
private final List<String> mScopes;
289+
private final Bundle mParams;
272290

273-
private IdpConfig(@SupportedProvider @NonNull String providerId, List<String> scopes) {
291+
private IdpConfig(
292+
@SupportedProvider @NonNull String providerId,
293+
List<String> scopes,
294+
Bundle params) {
274295
mProviderId = providerId;
275296
mScopes = Collections.unmodifiableList(scopes);
297+
mParams = params;
276298
}
277299

278300
private IdpConfig(Parcel in) {
279301
mProviderId = in.readString();
280302
mScopes = Collections.unmodifiableList(in.createStringArrayList());
303+
mParams = in.readBundle(getClass().getClassLoader());
281304
}
282305

283306
@SupportedProvider
@@ -289,6 +312,10 @@ public List<String> getScopes() {
289312
return mScopes;
290313
}
291314

315+
public Bundle getParams() {
316+
return mParams;
317+
}
318+
292319
public static final Creator<IdpConfig> CREATOR = new Creator<IdpConfig>() {
293320
@Override
294321
public IdpConfig createFromParcel(Parcel in) {
@@ -310,6 +337,7 @@ public int describeContents() {
310337
public void writeToParcel(Parcel parcel, int i) {
311338
parcel.writeString(mProviderId);
312339
parcel.writeStringList(mScopes);
340+
parcel.writeBundle(mParams);
313341
}
314342

315343
@Override
@@ -332,12 +360,14 @@ public String toString() {
332360
return "IdpConfig{" +
333361
"mProviderId='" + mProviderId + '\'' +
334362
", mScopes=" + mScopes +
363+
", mParams=" + mParams +
335364
'}';
336365
}
337366

338367
public static class Builder {
339368
@SupportedProvider private String mProviderId;
340369
private List<String> mScopes = new ArrayList<>();
370+
private Bundle mParams = new Bundle();
341371

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

405+
public Builder setParams(Bundle params) {
406+
mParams = params;
407+
return this;
408+
}
409+
375410
public IdpConfig build() {
376-
return new IdpConfig(mProviderId, mScopes);
411+
return new IdpConfig(mProviderId, mScopes, mParams);
377412
}
378413
}
379414
}
@@ -448,8 +483,8 @@ public T setAvailableProviders(@NonNull List<IdpConfig> idpConfigs) {
448483
for (IdpConfig config : idpConfigs) {
449484
if (mProviders.contains(config)) {
450485
throw new IllegalArgumentException("Each provider can only be set once. "
451-
+ config.getProviderId()
452-
+ " was set twice.");
486+
+ config.getProviderId()
487+
+ " was set twice.");
453488
} else {
454489
mProviders.add(config);
455490
}

auth/src/main/java/com/firebase/ui/auth/provider/PhoneProvider.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import android.app.Activity;
44
import android.content.Context;
55
import android.content.Intent;
6+
import android.os.Bundle;
67
import android.support.annotation.LayoutRes;
78

9+
import com.firebase.ui.auth.AuthUI;
810
import com.firebase.ui.auth.R;
911
import com.firebase.ui.auth.ui.FlowParameters;
1012
import com.firebase.ui.auth.ui.phone.PhoneVerificationActivity;
@@ -34,8 +36,16 @@ public int getButtonLayout() {
3436

3537
@Override
3638
public void startLogin(Activity activity) {
39+
40+
Bundle params = null;
41+
for (AuthUI.IdpConfig idpConfig : mFlowParameters.providerInfo) {
42+
if (idpConfig.getProviderId().equals(AuthUI.PHONE_VERIFICATION_PROVIDER)) {
43+
params = idpConfig.getParams();
44+
}
45+
}
46+
3747
activity.startActivityForResult(
38-
PhoneVerificationActivity.createIntent(activity, mFlowParameters, null),
48+
PhoneVerificationActivity.createIntent(activity, mFlowParameters, params),
3949
RC_PHONE_FLOW);
4050
}
4151

auth/src/main/java/com/firebase/ui/auth/ui/ExtraConstants.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@ public class ExtraConstants {
2626
public static final String EXTRA_USER = "extra_user";
2727
public static final String EXTRA_EMAIL = "extra_email";
2828
public static final String EXTRA_PHONE = "extra_phone_number";
29+
public static final String EXTRA_COUNTRY_CODE = "extra_country_code";
30+
public static final String EXTRA_NATIONAL_NUMBER = "extra_national_number";
2931
public static final String HAS_EXISTING_INSTANCE = "has_existing_instance";
32+
public static final String EXTRA_PARAMS = "extra_params";
3033
}

auth/src/main/java/com/firebase/ui/auth/ui/phone/CompletableProgressDialog.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,23 @@ public final class CompletableProgressDialog extends DialogFragment {
3838

3939
public static CompletableProgressDialog show(FragmentManager manager) {
4040
CompletableProgressDialog dialog = new CompletableProgressDialog();
41-
dialog.show(manager, TAG);
41+
dialog.showAllowingStateLoss(manager, TAG);
4242
return dialog;
4343
}
4444

45+
/**
46+
* This method is adapted from {@link #show(FragmentManager, String)}
47+
*/
48+
public void showAllowingStateLoss(FragmentManager manager, String tag) {
49+
// This prevents us from hitting FragmentManager.checkStateLoss() which
50+
// throws a runtime exception if state has already been saved.
51+
if (manager.isStateSaved()) {
52+
return;
53+
}
54+
55+
show(manager, tag);
56+
}
57+
4558
@NonNull
4659
@Override
4760
public Dialog onCreateDialog(Bundle savedInstanceState) {
@@ -60,12 +73,18 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
6073

6174
public void onComplete(String msg) {
6275
setMessage(msg);
63-
mProgress.setVisibility(View.GONE);
64-
mSuccessImage.setVisibility(View.VISIBLE);
76+
77+
if (mProgress != null) {
78+
mProgress.setVisibility(View.GONE);
79+
}
80+
81+
if (mSuccessImage != null) {
82+
mSuccessImage.setVisibility(View.VISIBLE);
83+
}
6584
}
6685

6786
public void setMessage(CharSequence message) {
68-
if (mProgress != null) {
87+
if (mProgress != null && mMessageView != null) {
6988
mMessageView.setText(message);
7089
} else {
7190
mMessage = message;

auth/src/main/java/com/firebase/ui/auth/ui/phone/PhoneNumberUtils.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ protected static PhoneNumber getPhoneNumber(@NonNull String providedPhoneNumber)
138138
return new PhoneNumber(phoneNumber, countryIso, countryCode);
139139
}
140140

141+
static PhoneNumber getPhoneNumber(
142+
@NonNull String providedCountryIso, @NonNull String providedNationalNumber) {
143+
Integer countryCode = getCountryCode(providedCountryIso);
144+
if (countryCode == null) {
145+
// Invalid ISO supplied:
146+
countryCode = DEFAULT_COUNTRY_CODE_INT;
147+
providedCountryIso = DEFAULT_COUNTRY_CODE;
148+
}
149+
150+
// National number shouldn't include '+', but just in case:
151+
providedNationalNumber = stripPlusSign(providedNationalNumber);
152+
153+
return new PhoneNumber(
154+
providedNationalNumber, providedCountryIso, String.valueOf(countryCode));
155+
}
156+
141157
private static String countryIsoForCountryCode(String countryCode) {
142158
final List<String> countries = CountryCodeToRegionCodeMap.get(Integer.valueOf(countryCode));
143159
if (countries != null) {
@@ -1337,6 +1353,10 @@ private static String stripCountryCode(String phoneNumber, String countryCode) {
13371353
return phoneNumber.replaceFirst("^\\+?" + countryCode, "");
13381354
}
13391355

1356+
private static String stripPlusSign(String phoneNumber) {
1357+
return phoneNumber.replaceFirst("^\\+?", "");
1358+
}
1359+
13401360
private static Locale getSimBasedLocale(@NonNull Context context) {
13411361
final TelephonyManager tm =
13421362
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

auth/src/main/java/com/firebase/ui/auth/ui/phone/PhoneVerificationActivity.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ private enum VerificationState {
7474
private PhoneAuthProvider.ForceResendingToken mForceResendingToken;
7575
private VerificationState mVerificationState;
7676

77-
public static Intent createIntent(Context context, FlowParameters flowParams, String phone) {
78-
return HelperActivityBase.createBaseIntent(context, PhoneVerificationActivity.class, flowParams)
79-
.putExtra(ExtraConstants.EXTRA_PHONE, phone);
77+
public static Intent createIntent(Context context, FlowParameters flowParams, Bundle params) {
78+
return HelperActivityBase.createBaseIntent(
79+
context, PhoneVerificationActivity.class, flowParams)
80+
.putExtra(ExtraConstants.EXTRA_PARAMS, params);
8081
}
8182

8283
@Override
@@ -88,15 +89,16 @@ protected void onCreate(final Bundle savedInstance) {
8889
mVerificationState = VerificationState.VERIFICATION_NOT_STARTED;
8990
if (savedInstance != null && !savedInstance.isEmpty()) {
9091
mPhoneNumber = savedInstance.getString(KEY_VERIFICATION_PHONE);
92+
9193
if (savedInstance.getSerializable(KEY_STATE) != null) {
9294
mVerificationState = (VerificationState) savedInstance.getSerializable(KEY_STATE);
9395
}
9496
return;
9597
}
9698

97-
String phone = getIntent().getExtras().getString(ExtraConstants.EXTRA_PHONE);
99+
Bundle params = getIntent().getExtras().getBundle(ExtraConstants.EXTRA_PARAMS);
98100
VerifyPhoneNumberFragment fragment = VerifyPhoneNumberFragment.newInstance
99-
(getFlowParams(), phone);
101+
(getFlowParams(), params);
100102
getSupportFragmentManager().beginTransaction()
101103
.replace(R.id.fragment_verify_phone, fragment, VerifyPhoneNumberFragment.TAG)
102104
.disallowAddToBackStack()
@@ -156,7 +158,18 @@ void verifyPhoneNumber(String phoneNumber, boolean forceResend) {
156158
}
157159
}
158160

159-
public void submitConfirmationCode(String confirmationCode) {
161+
public void submitConfirmationCode(@NonNull String confirmationCode) {
162+
if (TextUtils.isEmpty(mVerificationId) || TextUtils.isEmpty(confirmationCode)) {
163+
// This situation should never happen except in the case of an extreme race
164+
// condition, so we will just ignore the submission.
165+
// See: https://github.com/firebase/FirebaseUI-Android/issues/922
166+
Log.w(PHONE_VERIFICATION_LOG_TAG,
167+
String.format("submitConfirmationCode: mVerificationId is %s ; " +
168+
"confirmationCode is %s", TextUtils.isEmpty(mVerificationId) ? "empty" : "not empty",
169+
TextUtils.isEmpty(confirmationCode) ? "empty" : "not empty"));
170+
return;
171+
}
172+
160173
showLoadingDialog(getString(R.string.fui_verifying));
161174
signIn(PhoneAuthProvider.getCredential(mVerificationId, confirmationCode));
162175
}

0 commit comments

Comments
 (0)