Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,15 @@ public class AuthUiActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.auth_ui_layout);
ButterKnife.bind(this);

FirebaseAuth auth = FirebaseAuth.getInstance();
if (auth.getCurrentUser() != null) {
startActivity(SignedInActivity.createIntent(this, null));
startSignedInActivity(null);
finish();
}

setContentView(R.layout.auth_ui_layout);
ButterKnife.bind(this);

if (!isGoogleConfigured()) {
mUseGoogleProvider.setChecked(false);
mUseGoogleProvider.setEnabled(false);
Expand Down Expand Up @@ -208,7 +207,7 @@ private void handleSignInResponse(int resultCode, Intent data) {

// Successfully signed in
if (resultCode == ResultCodes.OK) {
startActivity(SignedInActivity.createIntent(this, response));
startSignedInActivity(response);
finish();
return;
} else {
Expand All @@ -233,6 +232,19 @@ private void handleSignInResponse(int resultCode, Intent data) {
showSnackbar(R.string.unknown_sign_in_response);
}

private void startSignedInActivity(IdpResponse response) {
startActivity(
SignedInActivity.createIntent(
this,
response,
new SignedInActivity.SignedInConfig(
getSelectedLogo(),
getSelectedTheme(),
getSelectedProviders(),
getSelectedTosUrl(),
mEnableSmartLock.isChecked())));
}

@MainThread
private void setGoogleScopesEnabled(boolean enabled) {
mGoogleScopesLabel.setEnabled(enabled);
Expand Down
107 changes: 104 additions & 3 deletions app/src/main/java/com/firebase/uidemo/auth/SignedInActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.MainThread;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
Expand All @@ -31,6 +33,7 @@

import com.bumptech.glide.Glide;
import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.AuthUI.IdpConfig;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.uidemo.R;
import com.google.android.gms.tasks.OnCompleteListener;
Expand All @@ -41,13 +44,19 @@
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;

import java.util.ArrayList;
import java.util.Iterator;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import java.util.List;

public class SignedInActivity extends AppCompatActivity {
private static final String EXTRA_SIGNED_IN_CONFIG = "extra_signed_in_config";

private static final int RC_REAUTH = 100;

@BindView(android.R.id.content)
View mRootView;

Expand All @@ -65,6 +74,8 @@ public class SignedInActivity extends AppCompatActivity {

private IdpResponse mIdpResponse;

private SignedInConfig mSignedInConfig;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -77,6 +88,7 @@ public void onCreate(Bundle savedInstanceState) {
}

mIdpResponse = IdpResponse.fromResultIntent(getIntent());
mSignedInConfig = getIntent().getParcelableExtra(EXTRA_SIGNED_IN_CONFIG);

setContentView(R.layout.signed_in_layout);
ButterKnife.bind(this);
Expand All @@ -101,6 +113,21 @@ public void onComplete(@NonNull Task<Void> task) {
});
}

@OnClick(R.id.reauthenticate)
public void reauthenticate() {
Intent reauthIntent = AuthUI.getInstance()
.createReauthIntentBuilder()
.setProviders(mSignedInConfig.providerInfo)
.setIsSmartLockEnabled(mSignedInConfig.isSmartLockEnabled)
.setLogo(mSignedInConfig.logo)
.setTheme(mSignedInConfig.theme)
.setTosUrl(mSignedInConfig.tosUrl)
.setReauthReason(getString(R.string.reauthentication_reason))
.build();

startActivityForResult(reauthIntent, RC_REAUTH);
}

@OnClick(R.id.delete_account)
public void deleteAccountClicked() {

Expand Down Expand Up @@ -185,14 +212,18 @@ private void populateIdpToken() {
token = mIdpResponse.getIdpToken();
secret = mIdpResponse.getIdpSecret();
}
View idpTokenLayout = findViewById(R.id.idp_token_layout);
if (token == null) {
findViewById(R.id.idp_token_layout).setVisibility(View.GONE);
idpTokenLayout.setVisibility(View.GONE);
} else {
idpTokenLayout.setVisibility(View.VISIBLE);
((TextView) findViewById(R.id.idp_token)).setText(token);
}
View idpSecretLayout = findViewById(R.id.idp_secret_layout);
if (secret == null) {
findViewById(R.id.idp_secret_layout).setVisibility(View.GONE);
idpSecretLayout.setVisibility(View.GONE);
} else {
idpSecretLayout.setVisibility(View.VISIBLE);
((TextView) findViewById(R.id.idp_secret)).setText(secret);
}
}
Expand All @@ -203,9 +234,79 @@ private void showSnackbar(@StringRes int errorMessageRes) {
.show();
}

public static Intent createIntent(Context context, IdpResponse idpResponse) {
static final class SignedInConfig implements Parcelable {
int logo;
int theme;
List<IdpConfig> providerInfo;
String tosUrl;
boolean isSmartLockEnabled;

SignedInConfig(
int logo,
int theme,
List<IdpConfig> providerInfo,
String tosUrl,
boolean isSmartLockEnabled) {
this.logo = logo;
this.theme = theme;
this.providerInfo = providerInfo;
this.tosUrl = tosUrl;
this.isSmartLockEnabled = isSmartLockEnabled;
}

SignedInConfig(Parcel in) {
logo = in.readInt();
theme = in.readInt();
providerInfo = new ArrayList<>();
in.readList(providerInfo, IdpConfig.class.getClassLoader());
tosUrl = in.readString();
isSmartLockEnabled = in.readInt() != 0;
}

public static final Creator<SignedInConfig> CREATOR = new Creator<SignedInConfig>() {
@Override
public SignedInConfig createFromParcel(Parcel in) {
return new SignedInConfig(in);
}

@Override
public SignedInConfig[] newArray(int size) {
return new SignedInConfig[size];
}
};

@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(logo);
dest.writeInt(theme);
dest.writeList(providerInfo);
dest.writeString(tosUrl);
dest.writeInt(isSmartLockEnabled ? 1 : 0);
}
}

public static Intent createIntent(
Context context,
IdpResponse idpResponse,
SignedInConfig signedInConfig) {
Intent in = IdpResponse.getIntent(idpResponse);
in.setClass(context, SignedInActivity.class);
in.putExtra(EXTRA_SIGNED_IN_CONFIG, signedInConfig);
return in;
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_REAUTH) {
mIdpResponse = IdpResponse.fromResultIntent(data);
populateIdpToken();
populateProfile();
}
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/layout/signed_in_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@
android:layout_margin="16dp"
android:text="@string/sign_out"/>

<Button
android:id="@+id/reauthenticate"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="16dp"
android:text="@string/reauthenticate"/>

<Button
android:id="@+id/delete_account"
android:layout_width="wrap_content"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
<string name="accessibility_downloaded_image">Downloaded image</string>
<string name="drive_file">Drive File</string>
<string name="allow_new_email_acccount">Allow account creation if email does not exist.</string>
<string name="reauthenticate">Reauth</string>
<string name="reauthentication_reason">Reauth was requested from the test app. Please login to continue.</string>

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