33
33
34
34
import com .firebase .ui .auth .AuthUI ;
35
35
import com .firebase .ui .auth .AuthUI .IdpConfig ;
36
+ import com .firebase .ui .auth .ErrorCodes ;
36
37
import com .firebase .ui .auth .IdpResponse ;
37
- import com .firebase .ui .auth .ui . ResultCodes ;
38
+ import com .firebase .ui .auth .ResultCodes ;
38
39
import com .firebase .uidemo .R ;
39
40
import com .google .android .gms .common .Scopes ;
40
41
import com .google .firebase .auth .FirebaseAuth ;
50
51
public class AuthUiActivity extends AppCompatActivity {
51
52
private static final String UNCHANGED_CONFIG_VALUE = "CHANGE-ME" ;
52
53
private static final String GOOGLE_TOS_URL = "https://www.google.com/policies/terms/" ;
53
- private static final String FIREBASE_TOS_URL = "https://www. firebase.com/terms/terms-of-service.html " ;
54
+ private static final String FIREBASE_TOS_URL = "https://firebase.google. com/terms/" ;
54
55
private static final int RC_SIGN_IN = 100 ;
55
56
56
57
@ BindView (R .id .default_theme )
@@ -86,7 +87,7 @@ public class AuthUiActivity extends AppCompatActivity {
86
87
@ BindView (R .id .sign_in )
87
88
Button mSignIn ;
88
89
89
- @ BindView (android . R .id .content )
90
+ @ BindView (R .id .root )
90
91
View mRootView ;
91
92
92
93
@ BindView (R .id .firebase_logo )
@@ -199,20 +200,30 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
199
200
200
201
@ MainThread
201
202
private void handleSignInResponse (int resultCode , Intent data ) {
202
- if (resultCode == RESULT_OK ) {
203
- startActivity (SignedInActivity .createIntent (this , IdpResponse .fromResultIntent (data )));
204
- finish ();
205
- return ;
206
- }
207
-
208
- if (resultCode == RESULT_CANCELED ) {
209
- showSnackbar (R .string .sign_in_cancelled );
210
- return ;
211
- }
203
+ IdpResponse response = IdpResponse .fromResultIntent (data );
212
204
213
- if (resultCode == ResultCodes .RESULT_NO_NETWORK ) {
214
- showSnackbar (R .string .no_internet_connection );
205
+ // Successfully signed in
206
+ if (resultCode == ResultCodes .OK ) {
207
+ startActivity (SignedInActivity .createIntent (this , response ));
208
+ finish ();
215
209
return ;
210
+ } else {
211
+ // Sign in failed
212
+ if (response == null ) {
213
+ // User pressed back button
214
+ showSnackbar (R .string .sign_in_cancelled );
215
+ return ;
216
+ }
217
+
218
+ if (response .getErrorCode () == ErrorCodes .NO_NETWORK ) {
219
+ showSnackbar (R .string .no_internet_connection );
220
+ return ;
221
+ }
222
+
223
+ if (response .getErrorCode () == ErrorCodes .UNKNOWN_ERROR ) {
224
+ showSnackbar (R .string .unknown_error );
225
+ return ;
226
+ }
216
227
}
217
228
218
229
showSnackbar (R .string .unknown_sign_in_response );
@@ -269,6 +280,10 @@ private List<IdpConfig> getSelectedProviders() {
269
280
selectedProviders .add (new IdpConfig .Builder (AuthUI .EMAIL_PROVIDER ).build ());
270
281
}
271
282
283
+ if (mUseTwitterProvider .isChecked ()) {
284
+ selectedProviders .add (new IdpConfig .Builder (AuthUI .TWITTER_PROVIDER ).build ());
285
+ }
286
+
272
287
if (mUseFacebookProvider .isChecked ()) {
273
288
selectedProviders .add (
274
289
new IdpConfig .Builder (AuthUI .FACEBOOK_PROVIDER )
@@ -283,10 +298,6 @@ private List<IdpConfig> getSelectedProviders() {
283
298
.build ());
284
299
}
285
300
286
- if (mUseTwitterProvider .isChecked ()) {
287
- selectedProviders .add (new IdpConfig .Builder (AuthUI .TWITTER_PROVIDER ).build ());
288
- }
289
-
290
301
return selectedProviders ;
291
302
}
292
303
@@ -302,20 +313,20 @@ private String getSelectedTosUrl() {
302
313
@ MainThread
303
314
private boolean isGoogleConfigured () {
304
315
return !UNCHANGED_CONFIG_VALUE .equals (
305
- getResources (). getString (R .string .default_web_client_id ));
316
+ getString (R .string .default_web_client_id ));
306
317
}
307
318
308
319
@ MainThread
309
320
private boolean isFacebookConfigured () {
310
321
return !UNCHANGED_CONFIG_VALUE .equals (
311
- getResources (). getString (R .string .facebook_application_id ));
322
+ getString (R .string .facebook_application_id ));
312
323
}
313
324
314
325
@ MainThread
315
326
private boolean isTwitterConfigured () {
316
327
List <String > twitterConfigs = Arrays .asList (
317
- getResources (). getString (R .string .twitter_consumer_key ),
318
- getResources (). getString (R .string .twitter_consumer_secret )
328
+ getString (R .string .twitter_consumer_key ),
329
+ getString (R .string .twitter_consumer_secret )
319
330
);
320
331
321
332
return !twitterConfigs .contains (UNCHANGED_CONFIG_VALUE );
0 commit comments