Skip to content

Commit ae83d83

Browse files
committed
Merge remote-tracking branch 'firebase/version-2.0.0-dev' into db-callback
2 parents 64bfb37 + 7c2f436 commit ae83d83

File tree

15 files changed

+417
-91
lines changed

15 files changed

+417
-91
lines changed

app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,15 @@ public class AuthUiActivity extends AppCompatActivity {
126126
@Override
127127
public void onCreate(Bundle savedInstanceState) {
128128
super.onCreate(savedInstanceState);
129+
setContentView(R.layout.auth_ui_layout);
130+
ButterKnife.bind(this);
129131

130132
FirebaseAuth auth = FirebaseAuth.getInstance();
131133
if (auth.getCurrentUser() != null) {
132-
startActivity(SignedInActivity.createIntent(this, null));
134+
startSignedInActivity(null);
133135
finish();
134136
}
135137

136-
setContentView(R.layout.auth_ui_layout);
137-
ButterKnife.bind(this);
138-
139138
if (!isGoogleConfigured()) {
140139
mUseGoogleProvider.setChecked(false);
141140
mUseGoogleProvider.setEnabled(false);
@@ -208,7 +207,7 @@ private void handleSignInResponse(int resultCode, Intent data) {
208207

209208
// Successfully signed in
210209
if (resultCode == ResultCodes.OK) {
211-
startActivity(SignedInActivity.createIntent(this, response));
210+
startSignedInActivity(response);
212211
finish();
213212
return;
214213
} else {
@@ -233,6 +232,19 @@ private void handleSignInResponse(int resultCode, Intent data) {
233232
showSnackbar(R.string.unknown_sign_in_response);
234233
}
235234

235+
private void startSignedInActivity(IdpResponse response) {
236+
startActivity(
237+
SignedInActivity.createIntent(
238+
this,
239+
response,
240+
new SignedInActivity.SignedInConfig(
241+
getSelectedLogo(),
242+
getSelectedTheme(),
243+
getSelectedProviders(),
244+
getSelectedTosUrl(),
245+
mEnableSmartLock.isChecked())));
246+
}
247+
236248
@MainThread
237249
private void setGoogleScopesEnabled(boolean enabled) {
238250
mGoogleScopesLabel.setEnabled(enabled);

app/src/main/java/com/firebase/uidemo/auth/SignedInActivity.java

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import android.content.DialogInterface;
1919
import android.content.Intent;
2020
import android.os.Bundle;
21+
import android.os.Parcel;
22+
import android.os.Parcelable;
2123
import android.support.annotation.MainThread;
2224
import android.support.annotation.NonNull;
2325
import android.support.annotation.StringRes;
@@ -31,6 +33,7 @@
3133

3234
import com.bumptech.glide.Glide;
3335
import com.firebase.ui.auth.AuthUI;
36+
import com.firebase.ui.auth.AuthUI.IdpConfig;
3437
import com.firebase.ui.auth.IdpResponse;
3538
import com.firebase.uidemo.R;
3639
import com.google.android.gms.tasks.OnCompleteListener;
@@ -41,13 +44,19 @@
4144
import com.google.firebase.auth.FirebaseUser;
4245
import com.google.firebase.auth.GoogleAuthProvider;
4346

47+
import java.util.ArrayList;
4448
import java.util.Iterator;
49+
import java.util.List;
4550

4651
import butterknife.BindView;
4752
import butterknife.ButterKnife;
4853
import butterknife.OnClick;
4954

5055
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+
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
}

app/src/main/res/layout/signed_in_layout.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
android:layout_margin="16dp"
4141
android:text="@string/sign_out"/>
4242

43+
<Button
44+
android:id="@+id/reauthenticate"
45+
style="@style/Widget.AppCompat.Button.Colored"
46+
android:layout_width="wrap_content"
47+
android:layout_height="wrap_content"
48+
android:layout_gravity="center"
49+
android:layout_margin="16dp"
50+
android:text="@string/reauthenticate"/>
51+
4352
<Button
4453
android:id="@+id/delete_account"
4554
android:layout_width="wrap_content"

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
<string name="accessibility_downloaded_image">Downloaded image</string>
6565
<string name="drive_file">Drive File</string>
6666
<string name="allow_new_email_acccount">Allow account creation if email does not exist.</string>
67+
<string name="reauthenticate">Reauth</string>
68+
<string name="reauthentication_reason">Reauth was requested from the test app. Please login to continue.</string>
6769

6870
<!-- strings for database demo activities -->
6971
<string name="start_chatting">No messages. Start chatting at the bottom!</string>

0 commit comments

Comments
 (0)