1818import android .content .DialogInterface ;
1919import android .content .Intent ;
2020import android .os .Bundle ;
21+ import android .os .Parcel ;
22+ import android .os .Parcelable ;
2123import android .support .annotation .MainThread ;
2224import android .support .annotation .NonNull ;
2325import android .support .annotation .StringRes ;
3133
3234import com .bumptech .glide .Glide ;
3335import com .firebase .ui .auth .AuthUI ;
36+ import com .firebase .ui .auth .AuthUI .IdpConfig ;
3437import com .firebase .ui .auth .IdpResponse ;
3538import com .firebase .uidemo .R ;
3639import com .google .android .gms .tasks .OnCompleteListener ;
4144import com .google .firebase .auth .FirebaseUser ;
4245import com .google .firebase .auth .GoogleAuthProvider ;
4346
47+ import java .util .ArrayList ;
4448import java .util .Iterator ;
49+ import java .util .List ;
4550
4651import butterknife .BindView ;
4752import butterknife .ButterKnife ;
4853import butterknife .OnClick ;
4954
5055public 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+
5160 @ BindView (android .R .id .content )
5261 View mRootView ;
5362
@@ -65,6 +74,8 @@ public class SignedInActivity extends AppCompatActivity {
6574
6675 private IdpResponse mIdpResponse ;
6776
77+ private SignedInConfig mSignedInConfig ;
78+
6879 @ Override
6980 public void onCreate (Bundle savedInstanceState ) {
7081 super .onCreate (savedInstanceState );
@@ -77,6 +88,7 @@ public void onCreate(Bundle savedInstanceState) {
7788 }
7889
7990 mIdpResponse = IdpResponse .fromResultIntent (getIntent ());
91+ mSignedInConfig = getIntent ().getParcelableExtra (EXTRA_SIGNED_IN_CONFIG );
8092
8193 setContentView (R .layout .signed_in_layout );
8294 ButterKnife .bind (this );
@@ -101,6 +113,21 @@ public void onComplete(@NonNull Task<Void> task) {
101113 });
102114 }
103115
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+
104131 @ OnClick (R .id .delete_account )
105132 public void deleteAccountClicked () {
106133
@@ -185,14 +212,18 @@ private void populateIdpToken() {
185212 token = mIdpResponse .getIdpToken ();
186213 secret = mIdpResponse .getIdpSecret ();
187214 }
215+ View idpTokenLayout = findViewById (R .id .idp_token_layout );
188216 if (token == null ) {
189- findViewById ( R . id . idp_token_layout ) .setVisibility (View .GONE );
217+ idpTokenLayout .setVisibility (View .GONE );
190218 } else {
219+ idpTokenLayout .setVisibility (View .VISIBLE );
191220 ((TextView ) findViewById (R .id .idp_token )).setText (token );
192221 }
222+ View idpSecretLayout = findViewById (R .id .idp_secret_layout );
193223 if (secret == null ) {
194- findViewById ( R . id . idp_secret_layout ) .setVisibility (View .GONE );
224+ idpSecretLayout .setVisibility (View .GONE );
195225 } else {
226+ idpSecretLayout .setVisibility (View .VISIBLE );
196227 ((TextView ) findViewById (R .id .idp_secret )).setText (secret );
197228 }
198229 }
@@ -203,9 +234,78 @@ private void showSnackbar(@StringRes int errorMessageRes) {
203234 .show ();
204235 }
205236
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 ) {
207296 Intent in = IdpResponse .getIntent (idpResponse );
208297 in .setClass (context , SignedInActivity .class );
298+ in .putExtra (EXTRA_SIGNED_IN_CONFIG , signedInConfig );
209299 return in ;
210300 }
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+ }
211311}
0 commit comments