18
18
import android .content .DialogInterface ;
19
19
import android .content .Intent ;
20
20
import android .os .Bundle ;
21
+ import android .os .Parcel ;
22
+ import android .os .Parcelable ;
21
23
import android .support .annotation .MainThread ;
22
24
import android .support .annotation .NonNull ;
23
25
import android .support .annotation .StringRes ;
31
33
32
34
import com .bumptech .glide .Glide ;
33
35
import com .firebase .ui .auth .AuthUI ;
36
+ import com .firebase .ui .auth .AuthUI .IdpConfig ;
34
37
import com .firebase .ui .auth .IdpResponse ;
35
38
import com .firebase .uidemo .R ;
36
39
import com .google .android .gms .tasks .OnCompleteListener ;
41
44
import com .google .firebase .auth .FirebaseUser ;
42
45
import com .google .firebase .auth .GoogleAuthProvider ;
43
46
47
+ import java .util .ArrayList ;
44
48
import java .util .Iterator ;
45
49
46
50
import butterknife .BindView ;
47
51
import butterknife .ButterKnife ;
48
52
import butterknife .OnClick ;
53
+ import java .util .List ;
49
54
50
55
public class SignedInActivity extends AppCompatActivity {
56
+ private static final String EXTRA_SIGNED_IN_CONFIG = "extra_signed_in_config" ;
57
+
58
+ private static final int RC_REAUTH = 100 ;
59
+
51
60
@ BindView (android .R .id .content )
52
61
View mRootView ;
53
62
@@ -65,6 +74,8 @@ public class SignedInActivity extends AppCompatActivity {
65
74
66
75
private IdpResponse mIdpResponse ;
67
76
77
+ private SignedInConfig mSignedInConfig ;
78
+
68
79
@ Override
69
80
public void onCreate (Bundle savedInstanceState ) {
70
81
super .onCreate (savedInstanceState );
@@ -77,6 +88,7 @@ public void onCreate(Bundle savedInstanceState) {
77
88
}
78
89
79
90
mIdpResponse = IdpResponse .fromResultIntent (getIntent ());
91
+ mSignedInConfig = getIntent ().getParcelableExtra (EXTRA_SIGNED_IN_CONFIG );
80
92
81
93
setContentView (R .layout .signed_in_layout );
82
94
ButterKnife .bind (this );
@@ -101,6 +113,21 @@ public void onComplete(@NonNull Task<Void> task) {
101
113
});
102
114
}
103
115
116
+ @ OnClick (R .id .reauthenticate )
117
+ public void reauthenticate () {
118
+ Intent reauthIntent = AuthUI .getInstance ()
119
+ .createReauthIntentBuilder ()
120
+ .setProviders (mSignedInConfig .providerInfo )
121
+ .setIsSmartLockEnabled (mSignedInConfig .isSmartLockEnabled )
122
+ .setLogo (mSignedInConfig .logo )
123
+ .setTheme (mSignedInConfig .theme )
124
+ .setTosUrl (mSignedInConfig .tosUrl )
125
+ .setReauthReason (getString (R .string .reauthentication_reason ))
126
+ .build ();
127
+
128
+ startActivityForResult (reauthIntent , RC_REAUTH );
129
+ }
130
+
104
131
@ OnClick (R .id .delete_account )
105
132
public void deleteAccountClicked () {
106
133
@@ -185,14 +212,18 @@ private void populateIdpToken() {
185
212
token = mIdpResponse .getIdpToken ();
186
213
secret = mIdpResponse .getIdpSecret ();
187
214
}
215
+ View idpTokenLayout = findViewById (R .id .idp_token_layout );
188
216
if (token == null ) {
189
- findViewById ( R . id . idp_token_layout ) .setVisibility (View .GONE );
217
+ idpTokenLayout .setVisibility (View .GONE );
190
218
} else {
219
+ idpTokenLayout .setVisibility (View .VISIBLE );
191
220
((TextView ) findViewById (R .id .idp_token )).setText (token );
192
221
}
222
+ View idpSecretLayout = findViewById (R .id .idp_secret_layout );
193
223
if (secret == null ) {
194
- findViewById ( R . id . idp_secret_layout ) .setVisibility (View .GONE );
224
+ idpSecretLayout .setVisibility (View .GONE );
195
225
} else {
226
+ idpSecretLayout .setVisibility (View .VISIBLE );
196
227
((TextView ) findViewById (R .id .idp_secret )).setText (secret );
197
228
}
198
229
}
@@ -203,9 +234,79 @@ private void showSnackbar(@StringRes int errorMessageRes) {
203
234
.show ();
204
235
}
205
236
206
- public static Intent createIntent (Context context , IdpResponse idpResponse ) {
237
+ static final class SignedInConfig implements Parcelable {
238
+ int logo ;
239
+ int theme ;
240
+ List <IdpConfig > providerInfo ;
241
+ String tosUrl ;
242
+ boolean isSmartLockEnabled ;
243
+
244
+ SignedInConfig (
245
+ int logo ,
246
+ int theme ,
247
+ List <IdpConfig > providerInfo ,
248
+ String tosUrl ,
249
+ boolean isSmartLockEnabled ) {
250
+ this .logo = logo ;
251
+ this .theme = theme ;
252
+ this .providerInfo = providerInfo ;
253
+ this .tosUrl = tosUrl ;
254
+ this .isSmartLockEnabled = isSmartLockEnabled ;
255
+ }
256
+
257
+ SignedInConfig (Parcel in ) {
258
+ logo = in .readInt ();
259
+ theme = in .readInt ();
260
+ providerInfo = new ArrayList <>();
261
+ in .readList (providerInfo , IdpConfig .class .getClassLoader ());
262
+ tosUrl = in .readString ();
263
+ isSmartLockEnabled = in .readInt () != 0 ;
264
+ }
265
+
266
+ public static final Creator <SignedInConfig > CREATOR = new Creator <SignedInConfig >() {
267
+ @ Override
268
+ public SignedInConfig createFromParcel (Parcel in ) {
269
+ return new SignedInConfig (in );
270
+ }
271
+
272
+ @ Override
273
+ public SignedInConfig [] newArray (int size ) {
274
+ return new SignedInConfig [size ];
275
+ }
276
+ };
277
+
278
+ @ Override
279
+ public int describeContents () {
280
+ return 0 ;
281
+ }
282
+
283
+ @ Override
284
+ public void writeToParcel (Parcel dest , int flags ) {
285
+ dest .writeInt (logo );
286
+ dest .writeInt (theme );
287
+ dest .writeList (providerInfo );
288
+ dest .writeString (tosUrl );
289
+ dest .writeInt (isSmartLockEnabled ? 1 : 0 );
290
+ }
291
+ }
292
+
293
+ public static Intent createIntent (
294
+ Context context ,
295
+ IdpResponse idpResponse ,
296
+ SignedInConfig signedInConfig ) {
207
297
Intent in = IdpResponse .getIntent (idpResponse );
208
298
in .setClass (context , SignedInActivity .class );
299
+ in .putExtra (EXTRA_SIGNED_IN_CONFIG , signedInConfig );
209
300
return in ;
210
301
}
302
+
303
+ @ Override
304
+ protected void onActivityResult (int requestCode , int resultCode , Intent data ) {
305
+ super .onActivityResult (requestCode , resultCode , data );
306
+ if (requestCode == RC_REAUTH ) {
307
+ mIdpResponse = IdpResponse .fromResultIntent (data );
308
+ populateIdpToken ();
309
+ populateProfile ();
310
+ }
311
+ }
211
312
}
0 commit comments