Skip to content

Commit 7842c48

Browse files
committed
Refactor progress hiding and delegateSignIn()
1 parent 20413ee commit 7842c48

File tree

1 file changed

+19
-39
lines changed

1 file changed

+19
-39
lines changed

auth/src/main/java/com/firebase/ui/auth/util/smartlock/SignInDelegate.java

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ public class SignInDelegate extends SmartLock<CredentialRequestResult> {
6565
private AuthUI.AuthUIResult mAuthUIResult;
6666
private FlowParameters mFlowParams;
6767
private ProgressDialog mProgressDialog;
68-
6968
private GoogleApiClient mGoogleApiClient;
70-
private CredentialRequestResult mCredentialRequestResult;
7169
private Credential mCredential;
7270

7371
@Override
@@ -82,7 +80,8 @@ public void onCreate(Bundle savedInstance) {
8280
new DialogInterface.OnCancelListener() {
8381
@Override
8482
public void onCancel(DialogInterface dialogInterface) {
85-
Log.w(TAG, "playServices:dialog.onCancel()");
83+
Log.w(TAG,
84+
"playServices:dialog.onCancel()");
8685
finish(RESULT_CANCELED, new Intent());
8786
}
8887
});
@@ -113,36 +112,36 @@ public void onCancel(DialogInterface dialogInterface) {
113112

114113
@Override
115114
public void onResult(@NonNull CredentialRequestResult result) {
116-
mCredentialRequestResult = result;
117115
Status status = result.getStatus();
118116

119117
if (status.isSuccess()) {
120118
// Auto sign-in success
121119
handleCredential(result.getCredential());
122-
delegateSignIn(true);
123-
} else if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
124-
delegateSignIn(false);
125-
}
126-
}
127-
128-
private void delegateSignIn(boolean isAutoSignInAvailable) {
129-
String email = getEmailFromCredential();
130-
String password = getPasswordFromCredential();
120+
String email = getEmailFromCredential();
121+
String password = getPasswordFromCredential();
131122

132-
// Attempt auto-sign in using SmartLock
133-
if (isAutoSignInAvailable) {
134123
if (TextUtils.isEmpty(password)) {
135124
// log in with id/provider
136125
redirectToIdpSignIn(email, getAccountTypeFromCredential());
137126
} else {
138127
// Sign in with the email/password retrieved from SmartLock
139128
signInWithEmailAndPassword(email, password);
140129
}
141-
} else {
142-
// resolve credential
143-
resolveSavedEmails();
130+
} else if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
131+
hideProgress();
132+
// resolve saved emails
133+
try {
134+
startIntentSenderForResult(status.getResolution().getIntentSender(),
135+
RC_CREDENTIALS_READ,
136+
null,
137+
0,
138+
0,
139+
0,
140+
null);
141+
} catch (IntentSender.SendIntentException e) {
142+
Log.e(TAG, "Failed to send Credentials intent.", e);
143+
}
144144
}
145-
hideProgress();
146145
}
147146

148147
@Override
@@ -252,26 +251,6 @@ private void initGoogleApiClient(String accountName) {
252251
mGoogleApiClient.connect();
253252
}
254253

255-
private void resolveSavedEmails() {
256-
if (mCredentialRequestResult == null || mCredentialRequestResult.getStatus() == null) {
257-
return;
258-
}
259-
Status status = mCredentialRequestResult.getStatus();
260-
if (status.getStatusCode() == CommonStatusCodes.RESOLUTION_REQUIRED) {
261-
try {
262-
startIntentSenderForResult(status.getResolution().getIntentSender(),
263-
RC_CREDENTIALS_READ,
264-
null,
265-
0,
266-
0,
267-
0,
268-
null);
269-
} catch (IntentSender.SendIntentException e) {
270-
Log.e(TAG, "Failed to send Credentials intent.", e);
271-
}
272-
}
273-
}
274-
275254
private void startAuthMethodChoice() {
276255
List<IDPProviderParcel> providers = mFlowParams.providerInfo;
277256

@@ -394,6 +373,7 @@ private void finish(int resultCode, Intent data) {
394373
if (mGoogleApiClient != null) {
395374
mGoogleApiClient.disconnect();
396375
}
376+
hideProgress();
397377
mAuthUIResult.onResult(resultCode, data);
398378
getActivity().getSupportFragmentManager().beginTransaction().remove(this).commit();
399379
}

0 commit comments

Comments
 (0)