Skip to content

Commit fba3335

Browse files
SUPERCILEXsamtstern
authored andcommitted
Remove ResultCodes in favor of Activity#RESULT_[OK/CANCELED] (#852)
1 parent 2eb8050 commit fba3335

16 files changed

+44
-47
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.firebase.ui.auth.AuthUI.IdpConfig;
3636
import com.firebase.ui.auth.ErrorCodes;
3737
import com.firebase.ui.auth.IdpResponse;
38-
import com.firebase.ui.auth.ResultCodes;
3938
import com.firebase.uidemo.R;
4039
import com.google.android.gms.common.Scopes;
4140
import com.google.firebase.auth.FirebaseAuth;
@@ -229,7 +228,7 @@ private void handleSignInResponse(int resultCode, Intent data) {
229228
IdpResponse response = IdpResponse.fromResultIntent(data);
230229

231230
// Successfully signed in
232-
if (resultCode == ResultCodes.OK) {
231+
if (resultCode == RESULT_OK) {
233232
startSignedInActivity(response);
234233
finish();
235234
return;

auth/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ startActivityForResult(
262262
##### Response codes
263263

264264
The authentication flow provides several response codes of which the most common are as follows:
265-
`ResultCodes.OK` if a user is signed in, `ResultCodes.CANCELLED` if the user manually canceled the sign in,
266-
`ResultCodes.NO_NETWORK` if sign in failed due to a lack of network connectivity,
267-
and `ResultCodes.UNKNOWN_ERROR` for all other errors.
265+
`Activity.RESULT_OK` if a user is signed in, `Activity.RESULT_CANCELED` if the user manually canceled the sign in,
266+
`ErrorCodes.NO_NETWORK` if sign in failed due to a lack of network connectivity,
267+
and `ErrorCodes.UNKNOWN_ERROR` for all other errors.
268268
Typically, the only recourse for most apps if sign in fails is to ask
269269
the user to sign in again later, or proceed with anonymous sign-in if supported.
270270

@@ -276,7 +276,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
276276
IdpResponse response = IdpResponse.fromResultIntent(data);
277277

278278
// Successfully signed in
279-
if (resultCode == ResultCodes.OK) {
279+
if (resultCode == RESULT_OK) {
280280
startActivity(SignedInActivity.createIntent(this, response));
281281
finish();
282282
return;
@@ -316,7 +316,7 @@ Intent.
316316
```java
317317
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
318318
super.onActivityResult(requestCode, resultCode, data);
319-
if (resultCode == ResultCodes.OK) {
319+
if (resultCode == RESULT_OK) {
320320
IdpResponse idpResponse = IdpResponse.fromResultIntent(data);
321321
startActivity(new Intent(this, WelcomeBackActivity.class)
322322
.putExtra("my_token", idpResponse.getIdpToken()));

auth/src/main/java/com/firebase/ui/auth/IdpResponse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.firebase.ui.auth;
1616

17+
import android.app.Activity;
1718
import android.content.Intent;
1819
import android.os.Parcel;
1920
import android.os.Parcelable;
@@ -189,7 +190,7 @@ public IdpResponse build() {
189190
"Secret cannot be null when using the Twitter provider.");
190191
}
191192

192-
return new IdpResponse(mUser, mToken, mSecret, ResultCodes.OK);
193+
return new IdpResponse(mUser, mToken, mSecret, Activity.RESULT_OK);
193194
}
194195
}
195196
}

auth/src/main/java/com/firebase/ui/auth/KickoffActivity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected void onCreate(Bundle savedInstance) {
3333
if (savedInstance == null || savedInstance.getBoolean(IS_WAITING_FOR_PLAY_SERVICES)) {
3434
if (isOffline()) {
3535
Log.d(TAG, "No network connection");
36-
finish(ResultCodes.CANCELED,
36+
finish(RESULT_CANCELED,
3737
IdpResponse.getErrorCodeIntent(ErrorCodes.NO_NETWORK));
3838
return;
3939
}
@@ -44,7 +44,7 @@ protected void onCreate(Bundle savedInstance) {
4444
new DialogInterface.OnCancelListener() {
4545
@Override
4646
public void onCancel(DialogInterface dialog) {
47-
finish(ResultCodes.CANCELED,
47+
finish(RESULT_CANCELED,
4848
IdpResponse.getErrorCodeIntent(
4949
ErrorCodes.UNKNOWN_ERROR));
5050
}
@@ -70,10 +70,10 @@ public void onSaveInstanceState(Bundle outState) {
7070
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
7171
super.onActivityResult(requestCode, resultCode, data);
7272
if (requestCode == RC_PLAY_SERVICES) {
73-
if (resultCode == ResultCodes.OK) {
73+
if (resultCode == RESULT_OK) {
7474
start();
7575
} else {
76-
finish(ResultCodes.CANCELED,
76+
finish(RESULT_CANCELED,
7777
IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
7878
}
7979
} else {

auth/src/main/java/com/firebase/ui/auth/ResultCodes.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
/**
66
* Result codes returned when using {@link AuthUI.SignInIntentBuilder#build()} with {@code
77
* startActivityForResult}.
8+
*
9+
* @deprecated Check for {@link Activity#RESULT_OK} and {@link Activity#RESULT_CANCELED} instead.
810
*/
11+
@Deprecated
912
public final class ResultCodes {
1013
/**
1114
* Sign in succeeded

auth/src/main/java/com/firebase/ui/auth/provider/EmailProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import android.support.annotation.LayoutRes;
77

88
import com.firebase.ui.auth.R;
9-
import com.firebase.ui.auth.ResultCodes;
109
import com.firebase.ui.auth.ui.FlowParameters;
1110
import com.firebase.ui.auth.ui.email.RegisterEmailActivity;
1211

@@ -41,8 +40,8 @@ public void startLogin(Activity activity) {
4140

4241
@Override
4342
public void onActivityResult(int requestCode, int resultCode, Intent data) {
44-
if (requestCode == RC_EMAIL_FLOW && resultCode == ResultCodes.OK) {
45-
mActivity.setResult(ResultCodes.OK, data);
43+
if (requestCode == RC_EMAIL_FLOW && resultCode == Activity.RESULT_OK) {
44+
mActivity.setResult(Activity.RESULT_OK, data);
4645
mActivity.finish();
4746
}
4847
}

auth/src/main/java/com/firebase/ui/auth/provider/PhoneProvider.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import android.support.annotation.LayoutRes;
77

88
import com.firebase.ui.auth.R;
9-
import com.firebase.ui.auth.ResultCodes;
109
import com.firebase.ui.auth.ui.FlowParameters;
1110
import com.firebase.ui.auth.ui.phone.PhoneVerificationActivity;
1211

@@ -42,8 +41,8 @@ public void startLogin(Activity activity) {
4241

4342
@Override
4443
public void onActivityResult(int requestCode, int resultCode, Intent data) {
45-
if (requestCode == RC_PHONE_FLOW && resultCode == ResultCodes.OK) {
46-
mActivity.setResult(ResultCodes.OK, data);
44+
if (requestCode == RC_PHONE_FLOW && resultCode == Activity.RESULT_OK) {
45+
mActivity.setResult(Activity.RESULT_OK, data);
4746
mActivity.finish();
4847
}
4948
}

auth/src/main/java/com/firebase/ui/auth/ui/HelperActivityBase.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import android.support.v7.app.AppCompatActivity;
1111

1212
import com.firebase.ui.auth.IdpResponse;
13-
import com.firebase.ui.auth.ResultCodes;
1413
import com.firebase.ui.auth.util.AuthHelper;
1514
import com.firebase.ui.auth.util.signincontainer.SaveSmartLock;
1615
import com.google.firebase.auth.FirebaseUser;
@@ -84,7 +83,7 @@ public void saveCredentialsOrFinish(
8483
IdpResponse response) {
8584

8685
if (saveSmartLock == null) {
87-
finish(ResultCodes.OK, response.toIntent());
86+
finish(Activity.RESULT_OK, response.toIntent());
8887
} else {
8988
saveSmartLock.saveCredentialsOrFinish(firebaseUser, password, response);
9089
}

auth/src/main/java/com/firebase/ui/auth/ui/accountlink/WelcomeBackIdpPrompt.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import com.firebase.ui.auth.ErrorCodes;
3131
import com.firebase.ui.auth.IdpResponse;
3232
import com.firebase.ui.auth.R;
33-
import com.firebase.ui.auth.ResultCodes;
3433
import com.firebase.ui.auth.provider.FacebookProvider;
3534
import com.firebase.ui.auth.provider.GoogleProvider;
3635
import com.firebase.ui.auth.provider.IdpProvider;
@@ -99,7 +98,7 @@ protected void onCreate(Bundle savedInstanceState) {
9998
break;
10099
default:
101100
Log.w(TAG, "Unknown provider: " + providerId);
102-
finish(ResultCodes.CANCELED,
101+
finish(RESULT_CANCELED,
103102
IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
104103
return;
105104
}
@@ -110,7 +109,7 @@ protected void onCreate(Bundle savedInstanceState) {
110109
Log.w(TAG, "Firebase login unsuccessful."
111110
+ " Account linking failed due to provider not enabled by application: "
112111
+ providerId);
113-
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
112+
finish(RESULT_CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
114113
return;
115114
}
116115

@@ -146,7 +145,7 @@ public void onSuccess(final IdpResponse idpResponse) {
146145
AuthCredential newCredential = ProviderUtils.getAuthCredential(idpResponse);
147146
if (newCredential == null) {
148147
Log.e(TAG, "No credential returned");
149-
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
148+
finish(RESULT_CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
150149
return;
151150
}
152151

@@ -165,7 +164,7 @@ public void onSuccess(AuthResult result) {
165164
idpResponse.getProviderType()))
166165
.addOnCompleteListener(new FinishListener(idpResponse));
167166
} else {
168-
finish(ResultCodes.OK, idpResponse.toIntent());
167+
finish(RESULT_OK, idpResponse.toIntent());
169168
}
170169
}
171170
})
@@ -195,7 +194,7 @@ public void onFailure() {
195194

196195
private void finishWithError() {
197196
Toast.makeText(this, R.string.fui_general_error, Toast.LENGTH_LONG).show();
198-
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
197+
finish(RESULT_CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
199198
}
200199

201200
private class FinishListener implements OnCompleteListener<AuthResult> {
@@ -206,7 +205,7 @@ private class FinishListener implements OnCompleteListener<AuthResult> {
206205
}
207206

208207
public void onComplete(@NonNull Task task) {
209-
finish(ResultCodes.OK, mIdpResponse.toIntent());
208+
finish(RESULT_OK, mIdpResponse.toIntent());
210209
}
211210
}
212211
}

auth/src/main/java/com/firebase/ui/auth/ui/accountlink/WelcomeBackPasswordPrompt.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import com.firebase.ui.auth.ErrorCodes;
3535
import com.firebase.ui.auth.IdpResponse;
3636
import com.firebase.ui.auth.R;
37-
import com.firebase.ui.auth.ResultCodes;
3837
import com.firebase.ui.auth.provider.ProviderUtils;
3938
import com.firebase.ui.auth.ui.AppCompatBase;
4039
import com.firebase.ui.auth.ui.ExtraConstants;
@@ -121,7 +120,7 @@ public void onClick(View view) {
121120
this,
122121
getFlowParams(),
123122
mEmail));
124-
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
123+
finish(RESULT_CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
125124
}
126125
}
127126

0 commit comments

Comments
 (0)