Skip to content

Commit f041fea

Browse files
authored
Merge pull request #681 from SUPERCILEX/provider-order
Fix displayed provider order being the inverse of the order in which they were supplied
2 parents 78149cb + 393f900 commit f041fea

21 files changed

+230
-180
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public void signIn(View view) {
182182
AuthUI.getInstance().createSignInIntentBuilder()
183183
.setTheme(getSelectedTheme())
184184
.setLogo(getSelectedLogo())
185-
.setProviders(getSelectedProviders())
185+
.setAvailableProviders(getSelectedProviders())
186186
.setTosUrl(getSelectedTosUrl())
187187
.setIsSmartLockEnabled(mEnableSmartLock.isChecked())
188188
.setAllowNewEmailAccounts(mAllowNewEmailAccounts.isChecked())
@@ -292,12 +292,11 @@ private int getSelectedLogo() {
292292
private List<IdpConfig> getSelectedProviders() {
293293
List<IdpConfig> selectedProviders = new ArrayList<>();
294294

295-
if (mUseEmailProvider.isChecked()) {
296-
selectedProviders.add(new IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build());
297-
}
298-
299-
if (mUseTwitterProvider.isChecked()) {
300-
selectedProviders.add(new IdpConfig.Builder(AuthUI.TWITTER_PROVIDER).build());
295+
if (mUseGoogleProvider.isChecked()) {
296+
selectedProviders.add(
297+
new IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER)
298+
.setPermissions(getGooglePermissions())
299+
.build());
301300
}
302301

303302
if (mUseFacebookProvider.isChecked()) {
@@ -307,11 +306,12 @@ private List<IdpConfig> getSelectedProviders() {
307306
.build());
308307
}
309308

310-
if (mUseGoogleProvider.isChecked()) {
311-
selectedProviders.add(
312-
new IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER)
313-
.setPermissions(getGooglePermissions())
314-
.build());
309+
if (mUseTwitterProvider.isChecked()) {
310+
selectedProviders.add(new IdpConfig.Builder(AuthUI.TWITTER_PROVIDER).build());
311+
}
312+
313+
if (mUseEmailProvider.isChecked()) {
314+
selectedProviders.add(new IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build());
315315
}
316316

317317
return selectedProviders;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void onComplete(@NonNull Task<Void> task) {
117117
public void reauthenticate() {
118118
Intent reauthIntent = AuthUI.getInstance()
119119
.createReauthIntentBuilder()
120-
.setProviders(mSignedInConfig.providerInfo)
120+
.setAvailableProviders(mSignedInConfig.providerInfo)
121121
.setIsSmartLockEnabled(mSignedInConfig.isSmartLockEnabled)
122122
.setLogo(mSignedInConfig.logo)
123123
.setTheme(mSignedInConfig.theme)

auth/README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,17 @@ is returned to your app in onActivityResult(...). See the [response codes](#resp
161161
details on receiving the results of the sign in flow.
162162

163163
You can enable sign-in providers like Google Sign-In or Facebook Log In by calling the
164-
`setProviders` method:
164+
`setAvailableProviders` method:
165165

166166
```java
167167
startActivityForResult(
168168
AuthUI.getInstance()
169169
.createSignInIntentBuilder()
170-
.setProviders(Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
171-
new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build(),
172-
new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build(),
173-
new AuthUI.IdpConfig.Builder(AuthUI.TWITTER_PROVIDER).build()))
170+
.setAvailableProviders(
171+
Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
172+
new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build(),
173+
new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build(),
174+
new AuthUI.IdpConfig.Builder(AuthUI.TWITTER_PROVIDER).build()))
174175
.build(),
175176
RC_SIGN_IN);
176177
```
@@ -181,7 +182,7 @@ If a terms of service URL and a custom theme are required:
181182
startActivityForResult(
182183
AuthUI.getInstance()
183184
.createSignInIntentBuilder()
184-
.setProviders(...)
185+
.setAvailableProviders(...)
185186
.setTosUrl("https://superapp.example.com/terms-of-service.html")
186187
.setTheme(R.style.SuperAppTheme)
187188
.build(),
@@ -426,9 +427,9 @@ AuthUI.IdpConfig googleIdp = new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER
426427
startActivityForResult(
427428
AuthUI.getInstance()
428429
.createSignInIntentBuilder()
429-
.setProviders(Arrays.asList(new IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
430-
googleIdp,
431-
new IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build()))
430+
.setAvailableProviders(Arrays.asList(new IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
431+
googleIdp,
432+
new IdpConfig.Builder(AuthUI.FACEBOOK_PROVIDER).build()))
432433
.build(),
433434
RC_SIGN_IN);
434435
```
@@ -452,8 +453,8 @@ AuthUI.IdpConfig facebookIdp = new AuthUI.IdpConfig.Builder(AuthUI.FACEBOOK_PROV
452453
startActivityForResult(
453454
AuthUI.getInstance()
454455
.createSignInIntentBuilder()
455-
.setProviders(Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
456-
facebookIdp))
456+
.setAvailableProviders(Arrays.asList(new AuthUI.IdpConfig.Builder(AuthUI.EMAIL_PROVIDER).build(),
457+
facebookIdp))
457458
.build(),
458459
RC_SIGN_IN);
459460
```

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

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,22 @@ public class AuthUI {
7676

7777
/**
7878
* Provider identifier for email and password credentials, for use with
79-
* {@link SignInIntentBuilder#setProviders}.
79+
* {@link SignInIntentBuilder#setAvailableProviders(List)}.
8080
*/
8181
public static final String EMAIL_PROVIDER = EmailAuthProvider.PROVIDER_ID;
8282

8383
/**
84-
* Provider identifier for Google, for use with {@link SignInIntentBuilder#setProviders}.
84+
* Provider identifier for Google, for use with {@link SignInIntentBuilder#setAvailableProviders(List)}.
8585
*/
8686
public static final String GOOGLE_PROVIDER = GoogleAuthProvider.PROVIDER_ID;
8787

8888
/**
89-
* Provider identifier for Facebook, for use with {@link SignInIntentBuilder#setProviders}.
89+
* Provider identifier for Facebook, for use with {@link SignInIntentBuilder#setAvailableProviders(List)}.
9090
*/
9191
public static final String FACEBOOK_PROVIDER = FacebookAuthProvider.PROVIDER_ID;
9292

9393
/**
94-
* Provider identifier for Twitter, for use with {@link SignInIntentBuilder#setProviders}.
94+
* Provider identifier for Twitter, for use with {@link SignInIntentBuilder#setAvailableProviders(List)}.
9595
*/
9696
public static final String TWITTER_PROVIDER = TwitterAuthProvider.PROVIDER_ID;
9797

@@ -494,8 +494,9 @@ public T setTosUrl(@Nullable String tosUrl) {
494494
* configuration parameters for the IDP.
495495
* @see IdpConfig
496496
*/
497-
public T setProviders(@NonNull List<IdpConfig> idpConfigs) {
497+
public T setAvailableProviders(@NonNull List<IdpConfig> idpConfigs) {
498498
mProviders.clear();
499+
499500
for (IdpConfig config : idpConfigs) {
500501
if (mProviders.contains(config)) {
501502
throw new IllegalArgumentException("Each provider can only be set once. "
@@ -505,6 +506,35 @@ public T setProviders(@NonNull List<IdpConfig> idpConfigs) {
505506
mProviders.add(config);
506507
}
507508
}
509+
510+
return (T) this;
511+
}
512+
513+
/**
514+
* Specified the set of supported authentication providers. At least one provider must
515+
* be specified. There may only be one instance of each provider.
516+
* <p>
517+
* <p>If no providers are explicitly specified by calling this method, then the email
518+
* provider is the default supported provider.
519+
*
520+
* @param idpConfigs a list of {@link IdpConfig}s, where each {@link IdpConfig} contains the
521+
* configuration parameters for the IDP.
522+
* @see IdpConfig
523+
* @deprecated because the order in which providers were displayed was the inverse of the
524+
* order in which they were supplied. Use {@link #setAvailableProviders(List)} to display
525+
* the providers in the order in which they were supplied.
526+
*/
527+
@Deprecated
528+
public T setProviders(@NonNull List<IdpConfig> idpConfigs) {
529+
setAvailableProviders(idpConfigs);
530+
531+
// Ensure email provider is at the bottom to keep backwards compatibility
532+
int emailProviderIndex = mProviders.indexOf(new IdpConfig.Builder(EMAIL_PROVIDER).build());
533+
if (emailProviderIndex != -1) {
534+
mProviders.add(0, mProviders.remove(emailProviderIndex));
535+
}
536+
Collections.reverse(mProviders);
537+
508538
return (T) this;
509539
}
510540

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.firebase.ui.auth.provider;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.support.annotation.LayoutRes;
7+
8+
import com.firebase.ui.auth.R;
9+
import com.firebase.ui.auth.ResultCodes;
10+
import com.firebase.ui.auth.ui.BaseHelper;
11+
import com.firebase.ui.auth.ui.email.RegisterEmailActivity;
12+
import com.google.firebase.auth.EmailAuthProvider;
13+
14+
public class EmailProvider implements Provider {
15+
private static final int RC_EMAIL_FLOW = 2;
16+
17+
private Activity mActivity;
18+
private BaseHelper mHelper;
19+
20+
public EmailProvider(Activity activity, BaseHelper helper) {
21+
mActivity = activity;
22+
mHelper = helper;
23+
}
24+
25+
@Override
26+
public String getName(Context context) {
27+
return context.getString(R.string.provider_name_email);
28+
}
29+
30+
@Override
31+
public String getProviderId() {
32+
return EmailAuthProvider.PROVIDER_ID;
33+
}
34+
35+
@Override
36+
@LayoutRes
37+
public int getButtonLayout() {
38+
return R.layout.provider_button_email;
39+
}
40+
41+
@Override
42+
public void startLogin(Activity activity) {
43+
activity.startActivityForResult(
44+
RegisterEmailActivity.createIntent(activity, mHelper.getFlowParams()),
45+
RC_EMAIL_FLOW);
46+
}
47+
48+
@Override
49+
public void onActivityResult(int requestCode, int resultCode, Intent data) {
50+
if (resultCode == ResultCodes.OK) {
51+
mHelper.finishActivity(mActivity, ResultCodes.OK, data);
52+
}
53+
}
54+
}

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.content.Context;
1919
import android.content.Intent;
2020
import android.os.Bundle;
21+
import android.support.annotation.LayoutRes;
2122
import android.support.annotation.StyleRes;
2223
import android.util.Log;
2324

@@ -83,14 +84,20 @@ public static AuthCredential createAuthCredential(IdpResponse response) {
8384

8485
@Override
8586
public String getName(Context context) {
86-
return context.getResources().getString(R.string.idp_name_facebook);
87+
return context.getString(R.string.idp_name_facebook);
8788
}
8889

8990
@Override
9091
public String getProviderId() {
9192
return FacebookAuthProvider.PROVIDER_ID;
9293
}
9394

95+
@Override
96+
@LayoutRes
97+
public int getButtonLayout() {
98+
return R.layout.idp_button_facebook;
99+
}
100+
94101
@Override
95102
public void startLogin(Activity activity) {
96103
sCallbackManager = CallbackManager.Factory.create();

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.content.Context;
1919
import android.content.Intent;
2020
import android.os.Bundle;
21+
import android.support.annotation.LayoutRes;
2122
import android.support.annotation.NonNull;
2223
import android.support.annotation.Nullable;
2324
import android.support.v4.app.FragmentActivity;
@@ -97,15 +98,22 @@ private GoogleSignInOptions getSignInOptions(@Nullable String email) {
9798
return builder.build();
9899
}
99100

101+
@Override
100102
public String getName(Context context) {
101-
return context.getResources().getString(R.string.idp_name_google);
103+
return context.getString(R.string.idp_name_google);
102104
}
103105

104106
@Override
105107
public String getProviderId() {
106108
return GoogleAuthProvider.PROVIDER_ID;
107109
}
108110

111+
@Override
112+
@LayoutRes
113+
public int getButtonLayout() {
114+
return R.layout.idp_button_google;
115+
}
116+
109117
@Override
110118
public void setAuthenticationCallback(IdpCallback callback) {
111119
mIdpCallback = callback;

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

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,13 @@
1414

1515
package com.firebase.ui.auth.provider;
1616

17-
import android.app.Activity;
18-
import android.content.Context;
19-
import android.content.Intent;
2017
import android.os.Bundle;
2118

2219
import com.firebase.ui.auth.IdpResponse;
2320

24-
public interface IdpProvider {
25-
26-
/**
27-
* Retrieves the name of the IDP, for display on-screen.
28-
*/
29-
String getName(Context context);
30-
31-
String getProviderId();
32-
21+
public interface IdpProvider extends Provider {
3322
void setAuthenticationCallback(IdpCallback callback);
3423

35-
void onActivityResult(int requestCode, int resultCode, Intent data);
36-
37-
void startLogin(Activity activity);
38-
3924
interface IdpCallback {
4025
void onSuccess(IdpResponse idpResponse);
4126

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.firebase.ui.auth.provider;
2+
3+
import android.app.Activity;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.support.annotation.LayoutRes;
7+
8+
import com.google.firebase.auth.GoogleAuthProvider;
9+
10+
public interface Provider {
11+
/** Retrieves the name of the IDP, for display on-screen. */
12+
String getName(Context context);
13+
14+
/** Retrieves the id of the IDP, e.g. {@link GoogleAuthProvider#PROVIDER_ID}. */
15+
String getProviderId();
16+
17+
/** Retrieves the layout id of the button to inflate and/or set a click listener. */
18+
@LayoutRes
19+
int getButtonLayout();
20+
21+
/** Start the login process for the IDP, e.g. show the Google sign-in activity. */
22+
void startLogin(Activity activity);
23+
24+
/**
25+
* Handle the sign result by either finishing the calling activity or sending an {@link
26+
* IdpProvider.IdpCallback} response.
27+
*/
28+
void onActivityResult(int requestCode, int resultCode, Intent data);
29+
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Context;
55
import android.content.Intent;
66
import android.os.Bundle;
7+
import android.support.annotation.LayoutRes;
78
import android.util.Log;
89

910
import com.firebase.ui.auth.IdpResponse;
@@ -57,6 +58,12 @@ public String getProviderId() {
5758
return TwitterAuthProvider.PROVIDER_ID;
5859
}
5960

61+
@Override
62+
@LayoutRes
63+
public int getButtonLayout() {
64+
return R.layout.idp_button_twitter;
65+
}
66+
6067
@Override
6168
public void setAuthenticationCallback(IdpCallback callback) {
6269
mCallbackObject = callback;

0 commit comments

Comments
 (0)