Skip to content

Refactor SaveCredentialsActivity #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Oct 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
05ce3b5
temporary: saving to work on another computer
SUPERCILEX Oct 7, 2016
2391efb
Merge remote-tracking branch 'firebase/master' into refactor-zombie-a…
SUPERCILEX Oct 8, 2016
05a476a
Merge remote-tracking branch 'firebase/master' into refactor-zombie-a…
SUPERCILEX Oct 14, 2016
2c0eaf5
Code compiles
SUPERCILEX Oct 14, 2016
8adeee1
Cleanup
SUPERCILEX Oct 14, 2016
11f3c2b
Cleanup
SUPERCILEX Oct 14, 2016
cb826f4
Cleanup
SUPERCILEX Oct 14, 2016
3b788f5
Update SmartLock.java with new fragment logic
SUPERCILEX Oct 14, 2016
9eaa4cd
Fix bug in SmartLock.java
SUPERCILEX Oct 14, 2016
3b76ac6
Cleanup
SUPERCILEX Oct 14, 2016
86d58a9
Cleanup
SUPERCILEX Oct 14, 2016
6ad0021
Fix broken tests
SUPERCILEX Oct 14, 2016
550acc9
Cleanup
SUPERCILEX Oct 14, 2016
b9d3ca5
Cleanup
SUPERCILEX Oct 15, 2016
a8b5cf5
Cleanup
SUPERCILEX Oct 15, 2016
9a4921e
Bug fix
SUPERCILEX Oct 16, 2016
db96c91
Cleanup
SUPERCILEX Oct 18, 2016
19bde41
Add interface to SmartLock
SUPERCILEX Oct 18, 2016
96027d0
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into refact…
SUPERCILEX Oct 18, 2016
9511a6d
Merge dev
SUPERCILEX Oct 18, 2016
cbe0cfb
working on tests
SUPERCILEX Oct 19, 2016
a81bf5a
working on tests
SUPERCILEX Oct 19, 2016
db05831
Revert interface, working on fixing tests
SUPERCILEX Oct 19, 2016
8c96216
Fix tests
SUPERCILEX Oct 19, 2016
d333302
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into refact…
SUPERCILEX Oct 19, 2016
cb6efad
Merge dev
SUPERCILEX Oct 19, 2016
af644be
Fix merge mistakes
SUPERCILEX Oct 19, 2016
4152c23
Cleanup
SUPERCILEX Oct 19, 2016
2cc8adf
Final cleanup and fix tests
SUPERCILEX Oct 19, 2016
c138a51
Fix test
SUPERCILEX Oct 19, 2016
f88aab3
Fix test
SUPERCILEX Oct 19, 2016
ad115f0
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into refact…
SUPERCILEX Oct 19, 2016
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
4 changes: 0 additions & 4 deletions auth/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
android:name="com.firebase.ui.auth.ui.email.SignInActivity"
android:label="@string/title_sign_in_activity"
android:theme="@style/FirebaseUI" />
<activity
android:name="com.firebase.ui.auth.ui.account_link.SaveCredentialsActivity"
android:label="@string/default_toolbar_title"
android:theme="@style/FirebaseUI.Translucent" />
<activity
android:name="com.firebase.ui.auth.ui.account_link.WelcomeBackIdpPrompt"
android:label="@string/title_welcome_back_idp_prompt"
Expand Down
4 changes: 2 additions & 2 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.firebase.ui.auth.util.CredentialsApiHelper;
import com.firebase.ui.auth.util.GoogleApiClientTaskHelper;
import com.firebase.ui.auth.util.Preconditions;
import com.firebase.ui.auth.util.SmartlockUtil;
import com.firebase.ui.auth.util.SmartLockUtil;
import com.google.android.gms.auth.api.Auth;
import com.google.android.gms.auth.api.credentials.Credential;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
Expand Down Expand Up @@ -343,7 +343,7 @@ public Task<Void> delete(@NonNull Activity activity) {
CredentialsApiHelper credentialHelper = CredentialsApiHelper.getInstance(gacHelper);

// Get all SmartLock credentials associated with the user
List<Credential> credentials = SmartlockUtil.credentialsFromFirebaseUser(firebaseUser);
List<Credential> credentials = SmartLockUtil.credentialsFromFirebaseUser(firebaseUser);

// For each Credential in the list, create a task to delete it.
List<Task<?>> credentialTasks = new ArrayList<>();
Expand Down
4 changes: 2 additions & 2 deletions auth/src/main/java/com/firebase/ui/auth/ui/AppCompatBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

public class AppCompatBase extends android.support.v7.app.AppCompatActivity {
public class AppCompatBase extends AppCompatActivity {
protected ActivityHelper mActivityHelper;

@Override
Expand All @@ -36,5 +37,4 @@ protected void onDestroy() {
public void finish(int resultCode, Intent intent) {
mActivityHelper.finish(resultCode, intent);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ private boolean hasNetworkConnection() {
public void onCredentialsApiConnected(
CredentialsAPI credentialsApi,
ActivityHelper activityHelper) {

String email = credentialsApi.getEmailFromCredential();
String password = credentialsApi.getPasswordFromCredential();
String accountType = credentialsApi.getAccountTypeFromCredential();
Expand Down Expand Up @@ -249,7 +248,6 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
finish(resultCode, new Intent());
}
break;

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import com.firebase.ui.auth.ui.TaskFailureLogger;
import com.firebase.ui.auth.ui.email.PasswordToggler;
import com.firebase.ui.auth.ui.email.RecoverPasswordActivity;
import com.firebase.ui.auth.util.SmartlockUtil;
import com.firebase.ui.auth.util.SmartLock;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.AuthCredential;
Expand All @@ -50,8 +50,6 @@
* the password before initiating a link.
*/
public class WelcomeBackPasswordPrompt extends AppCompatBase implements View.OnClickListener {

private static final int RC_CREDENTIAL_SAVE = 3;
private static final String TAG = "WelcomeBackPassword";
private static final StyleSpan BOLD = new StyleSpan(Typeface.BOLD);

Expand Down Expand Up @@ -107,14 +105,6 @@ public void onClick(View view) {
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_CREDENTIAL_SAVE) {
finish(RESULT_OK, new Intent());
}
}

private void next(String email, final String password) {
final FirebaseAuth firebaseAuth = mActivityHelper.getFirebaseAuth();

Expand Down Expand Up @@ -148,14 +138,15 @@ public void onSuccess(AuthResult authResult) {
new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
mActivityHelper.dismissDialog();
SmartlockUtil.saveCredentialOrFinish(
WelcomeBackPasswordPrompt.this,
RC_CREDENTIAL_SAVE,
mActivityHelper.getFlowParams(),
authResult.getUser(),
password,
null /* provider */);
SmartLock
.getInstance(WelcomeBackPasswordPrompt.this,
TAG)
.saveCredentialsOrFinish(
WelcomeBackPasswordPrompt.this,
mActivityHelper,
authResult.getUser(),
password,
null /* provider */);
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just noticed this, why are we removing the calls to dismissDialog()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to get rid of them because when you close the activity, they get closed with it. Leaving them open means the loading dialog stays open during the credential save.

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.firebase.ui.auth.ui.email.field_validators.EmailFieldValidator;
import com.firebase.ui.auth.ui.email.field_validators.PasswordFieldValidator;
import com.firebase.ui.auth.ui.email.field_validators.RequiredFieldValidator;
import com.firebase.ui.auth.util.SmartlockUtil;
import com.firebase.ui.auth.util.SmartLock;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
Expand All @@ -56,8 +56,6 @@
* Activity displaying a form to create a new email/password account.
*/
public class RegisterEmailActivity extends AppCompatBase implements View.OnClickListener {

private static final int RC_SAVE_CREDENTIAL = 3;
private static final String TAG = "RegisterEmailActivity";

private EditText mEmailEditText;
Expand Down Expand Up @@ -97,10 +95,8 @@ protected void onCreate(Bundle savedInstanceState) {
mPasswordFieldValidator = new PasswordFieldValidator((TextInputLayout)
findViewById(R.id.password_layout),
getResources().getInteger(R.integer.min_password_length));
mNameValidator = new RequiredFieldValidator((TextInputLayout)
findViewById(R.id.name_layout));
mEmailFieldValidator = new EmailFieldValidator((TextInputLayout) findViewById(R.id
.email_layout));
mNameValidator = new RequiredFieldValidator((TextInputLayout) findViewById(R.id.name_layout));
mEmailFieldValidator = new EmailFieldValidator((TextInputLayout) findViewById(R.id.email_layout));

if (email != null) {
mEmailEditText.setText(email);
Expand Down Expand Up @@ -155,18 +151,15 @@ public void onSuccess(AuthResult authResult) {
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
mActivityHelper.dismissDialog();

// This executes even if the name change fails, since
// the account creation succeeded and we want to save
// the credential to SmartLock (if enabled).
SmartlockUtil.saveCredentialOrFinish(
RegisterEmailActivity.this,
RC_SAVE_CREDENTIAL,
mActivityHelper.getFlowParams(),
firebaseUser,
password,
null /* provider */);
SmartLock.getInstance(RegisterEmailActivity.this, TAG)
.saveCredentialsOrFinish(RegisterEmailActivity.this,
mActivityHelper,
firebaseUser,
password,
null /* provider */);
}
});
}
Expand Down Expand Up @@ -199,14 +192,6 @@ public void onFailure(@NonNull Exception e) {
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SAVE_CREDENTIAL) {
finish(RESULT_OK, new Intent());
}
}

@Override
public void onClick(View view) {
if (view.getId() == R.id.button_create) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import com.firebase.ui.auth.ui.TaskFailureLogger;
import com.firebase.ui.auth.ui.email.field_validators.EmailFieldValidator;
import com.firebase.ui.auth.ui.email.field_validators.RequiredFieldValidator;
import com.firebase.ui.auth.util.SmartlockUtil;
import com.firebase.ui.auth.util.SmartLock;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.auth.AuthResult;
Expand All @@ -44,7 +44,6 @@
*/
public class SignInActivity extends AppCompatBase implements View.OnClickListener {
private static final String TAG = "SignInActivity";
private static final int RC_CREDENTIAL_SAVE = 101;

private EditText mEmailEditText;
private EditText mPasswordEditText;
Expand All @@ -67,7 +66,8 @@ protected void onCreate(Bundle savedInstanceState) {
getResources().getValue(R.dimen.slightly_visible_icon, slightlyVisibleIcon, true);

mPasswordEditText = (EditText) findViewById(R.id.password);
((TextInputLayout) findViewById(R.id.password_layout)).setPasswordVisibilityToggleEnabled(false);
((TextInputLayout) findViewById(R.id.password_layout)).setPasswordVisibilityToggleEnabled(
false);
ImageView togglePasswordImage = (ImageView) findViewById(R.id.toggle_visibility);

mPasswordEditText.setOnFocusChangeListener(new ImageFocusTransparencyChanger(
Expand All @@ -77,24 +77,16 @@ protected void onCreate(Bundle savedInstanceState) {

togglePasswordImage.setOnClickListener(new PasswordToggler(mPasswordEditText));

mEmailValidator = new EmailFieldValidator((TextInputLayout) findViewById(R.id
.email_layout));
mPasswordValidator = new RequiredFieldValidator((TextInputLayout) findViewById(R.id
.password_layout));
mEmailValidator = new EmailFieldValidator((TextInputLayout) findViewById(R.id.email_layout));
mPasswordValidator = new RequiredFieldValidator((TextInputLayout) findViewById(R.id.password_layout));
Button signInButton = (Button) findViewById(R.id.button_done);
TextView recoveryButton = (TextView) findViewById(R.id.trouble_signing_in);
TextView recoveryButton = (TextView) findViewById(R.id.trouble_signing_in);

if (email != null) {
mEmailEditText.setText(email);
}
signInButton.setOnClickListener(this);
recoveryButton.setOnClickListener(this);

}

@Override
public void onBackPressed () {
super.onBackPressed();
}

private void signIn(String email, final String password) {
Expand All @@ -105,16 +97,13 @@ private void signIn(String email, final String password) {
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override
public void onSuccess(AuthResult authResult) {
mActivityHelper.dismissDialog();

// Save credential in SmartLock (if enabled)
SmartlockUtil.saveCredentialOrFinish(
SignInActivity.this,
RC_CREDENTIAL_SAVE,
mActivityHelper.getFlowParams(),
authResult.getUser(),
password,
null /* provider */);
SmartLock.getInstance(SignInActivity.this, TAG)
.saveCredentialsOrFinish(SignInActivity.this,
mActivityHelper,
authResult.getUser(),
password,
null /* provider */);
}
})
.addOnFailureListener(new OnFailureListener() {
Expand All @@ -131,32 +120,20 @@ public void onFailure(@NonNull Exception e) {
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_CREDENTIAL_SAVE) {
finish(RESULT_OK, new Intent());
}
}

@Override
public void onClick(View view) {
if (view.getId() == R.id.button_done) {
boolean emailValid = mEmailValidator.validate(mEmailEditText.getText());
boolean passwordValid = mPasswordValidator.validate(mPasswordEditText.getText());
if (!emailValid || !passwordValid) {
return;
} else {
if (emailValid && passwordValid) {
mActivityHelper.showLoadingDialog(R.string.progress_dialog_signing_in);
signIn(mEmailEditText.getText().toString(), mPasswordEditText.getText().toString());
return;
}
} else if (view.getId() == R.id.trouble_signing_in) {
startActivity(RecoverPasswordActivity.createIntent(
this,
mActivityHelper.getFlowParams(),
mEmailEditText.getText().toString()));
return;
}
}

Expand Down
Loading