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 ;
49
+ import java .util .List ;
45
50
46
51
import butterknife .BindView ;
47
52
import butterknife .ButterKnife ;
48
53
import butterknife .OnClick ;
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,78 @@ 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 (int logo ,
245
+ int theme ,
246
+ List <IdpConfig > providerInfo ,
247
+ String tosUrl ,
248
+ boolean isSmartLockEnabled ) {
249
+ this .logo = logo ;
250
+ this .theme = theme ;
251
+ this .providerInfo = providerInfo ;
252
+ this .tosUrl = tosUrl ;
253
+ this .isSmartLockEnabled = isSmartLockEnabled ;
254
+ }
255
+
256
+ SignedInConfig (Parcel in ) {
257
+ logo = in .readInt ();
258
+ theme = in .readInt ();
259
+ providerInfo = new ArrayList <>();
260
+ in .readList (providerInfo , IdpConfig .class .getClassLoader ());
261
+ tosUrl = in .readString ();
262
+ isSmartLockEnabled = in .readInt () != 0 ;
263
+ }
264
+
265
+ public static final Creator <SignedInConfig > CREATOR = new Creator <SignedInConfig >() {
266
+ @ Override
267
+ public SignedInConfig createFromParcel (Parcel in ) {
268
+ return new SignedInConfig (in );
269
+ }
270
+
271
+ @ Override
272
+ public SignedInConfig [] newArray (int size ) {
273
+ return new SignedInConfig [size ];
274
+ }
275
+ };
276
+
277
+ @ Override
278
+ public int describeContents () {
279
+ return 0 ;
280
+ }
281
+
282
+ @ Override
283
+ public void writeToParcel (Parcel dest , int flags ) {
284
+ dest .writeInt (logo );
285
+ dest .writeInt (theme );
286
+ dest .writeList (providerInfo );
287
+ dest .writeString (tosUrl );
288
+ dest .writeInt (isSmartLockEnabled ? 1 : 0 );
289
+ }
290
+ }
291
+
292
+ public static Intent createIntent (
293
+ Context context ,
294
+ IdpResponse idpResponse ,
295
+ SignedInConfig signedInConfig ) {
207
296
Intent in = IdpResponse .getIntent (idpResponse );
208
297
in .setClass (context , SignedInActivity .class );
298
+ in .putExtra (EXTRA_SIGNED_IN_CONFIG , signedInConfig );
209
299
return in ;
210
300
}
301
+
302
+ @ Override
303
+ protected void onActivityResult (int requestCode , int resultCode , Intent data ) {
304
+ super .onActivityResult (requestCode , resultCode , data );
305
+ if (requestCode == RC_REAUTH ) {
306
+ mIdpResponse = IdpResponse .fromResultIntent (data );
307
+ populateIdpToken ();
308
+ populateProfile ();
309
+ }
310
+ }
211
311
}
0 commit comments