Skip to content

Commit c5185f7

Browse files
authored
Handle dynamic list of identity providers (#1800)
1 parent c7b5036 commit c5185f7

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

auth/src/main/java/com/firebase/ui/auth/ui/idp/AuthMethodPickerActivity.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import com.google.firebase.auth.EmailAuthProvider;
5252
import com.google.firebase.auth.FacebookAuthProvider;
5353
import com.google.firebase.auth.FirebaseAuth;
54-
import com.google.firebase.auth.GithubAuthProvider;
5554
import com.google.firebase.auth.GoogleAuthProvider;
5655
import com.google.firebase.auth.PhoneAuthProvider;
5756

@@ -229,14 +228,36 @@ private void populateIdpListCustomLayout(List<IdpConfig> providerConfigs) {
229228
for (IdpConfig idpConfig : providerConfigs) {
230229
final String providerId = providerOrEmailLinkProvider(idpConfig.getProviderId());
231230

232-
if (!providerButtonIds.containsKey(providerId)) {
231+
Integer buttonResId = providerButtonIds.get(providerId);
232+
if (buttonResId == null) {
233233
throw new IllegalStateException("No button found for auth provider: " + idpConfig.getProviderId());
234234
}
235235

236-
@IdRes int buttonId = providerButtonIds.get(providerId);
236+
@IdRes int buttonId = buttonResId;
237237
View loginButton = findViewById(buttonId);
238238
handleSignInOperation(idpConfig, loginButton);
239239
}
240+
//hide custom layout buttons that don't have their identity provider set
241+
for (String providerBtnId : providerButtonIds.keySet()) {
242+
if (providerBtnId == null) {
243+
continue;
244+
}
245+
boolean hasProvider = false;
246+
for (IdpConfig idpConfig : providerConfigs) {
247+
if (providerBtnId.equals(idpConfig.getProviderId())) {
248+
hasProvider = true;
249+
break;
250+
}
251+
}
252+
if (!hasProvider) {
253+
Integer resId = providerButtonIds.get(providerBtnId);
254+
if (resId == null) {
255+
continue;
256+
}
257+
@IdRes int buttonId = resId;
258+
findViewById(buttonId).setVisibility(View.GONE);
259+
}
260+
}
240261
}
241262

242263
@NonNull

0 commit comments

Comments
 (0)