Skip to content

Commit

Permalink
Remove ResultCodes in favor of Activity#RESULT_[OK/CANCELED] (#852)
Browse files Browse the repository at this point in the history
  • Loading branch information
SUPERCILEX authored and samtstern committed Aug 4, 2017
1 parent 2eb8050 commit fba3335
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import com.firebase.ui.auth.AuthUI.IdpConfig;
import com.firebase.ui.auth.ErrorCodes;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.ResultCodes;
import com.firebase.uidemo.R;
import com.google.android.gms.common.Scopes;
import com.google.firebase.auth.FirebaseAuth;
Expand Down Expand Up @@ -229,7 +228,7 @@ private void handleSignInResponse(int resultCode, Intent data) {
IdpResponse response = IdpResponse.fromResultIntent(data);

// Successfully signed in
if (resultCode == ResultCodes.OK) {
if (resultCode == RESULT_OK) {
startSignedInActivity(response);
finish();
return;
Expand Down
10 changes: 5 additions & 5 deletions auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ startActivityForResult(
##### Response codes

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

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

// Successfully signed in
if (resultCode == ResultCodes.OK) {
if (resultCode == RESULT_OK) {
startActivity(SignedInActivity.createIntent(this, response));
finish();
return;
Expand Down Expand Up @@ -316,7 +316,7 @@ Intent.
```java
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == ResultCodes.OK) {
if (resultCode == RESULT_OK) {
IdpResponse idpResponse = IdpResponse.fromResultIntent(data);
startActivity(new Intent(this, WelcomeBackActivity.class)
.putExtra("my_token", idpResponse.getIdpToken()));
Expand Down
3 changes: 2 additions & 1 deletion auth/src/main/java/com/firebase/ui/auth/IdpResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.firebase.ui.auth;

import android.app.Activity;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
Expand Down Expand Up @@ -189,7 +190,7 @@ public IdpResponse build() {
"Secret cannot be null when using the Twitter provider.");
}

return new IdpResponse(mUser, mToken, mSecret, ResultCodes.OK);
return new IdpResponse(mUser, mToken, mSecret, Activity.RESULT_OK);
}
}
}
8 changes: 4 additions & 4 deletions auth/src/main/java/com/firebase/ui/auth/KickoffActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected void onCreate(Bundle savedInstance) {
if (savedInstance == null || savedInstance.getBoolean(IS_WAITING_FOR_PLAY_SERVICES)) {
if (isOffline()) {
Log.d(TAG, "No network connection");
finish(ResultCodes.CANCELED,
finish(RESULT_CANCELED,
IdpResponse.getErrorCodeIntent(ErrorCodes.NO_NETWORK));
return;
}
Expand All @@ -44,7 +44,7 @@ protected void onCreate(Bundle savedInstance) {
new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
finish(ResultCodes.CANCELED,
finish(RESULT_CANCELED,
IdpResponse.getErrorCodeIntent(
ErrorCodes.UNKNOWN_ERROR));
}
Expand All @@ -70,10 +70,10 @@ public void onSaveInstanceState(Bundle outState) {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_PLAY_SERVICES) {
if (resultCode == ResultCodes.OK) {
if (resultCode == RESULT_OK) {
start();
} else {
finish(ResultCodes.CANCELED,
finish(RESULT_CANCELED,
IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions auth/src/main/java/com/firebase/ui/auth/ResultCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
/**
* Result codes returned when using {@link AuthUI.SignInIntentBuilder#build()} with {@code
* startActivityForResult}.
*
* @deprecated Check for {@link Activity#RESULT_OK} and {@link Activity#RESULT_CANCELED} instead.
*/
@Deprecated
public final class ResultCodes {
/**
* Sign in succeeded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.support.annotation.LayoutRes;

import com.firebase.ui.auth.R;
import com.firebase.ui.auth.ResultCodes;
import com.firebase.ui.auth.ui.FlowParameters;
import com.firebase.ui.auth.ui.email.RegisterEmailActivity;

Expand Down Expand Up @@ -41,8 +40,8 @@ public void startLogin(Activity activity) {

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RC_EMAIL_FLOW && resultCode == ResultCodes.OK) {
mActivity.setResult(ResultCodes.OK, data);
if (requestCode == RC_EMAIL_FLOW && resultCode == Activity.RESULT_OK) {
mActivity.setResult(Activity.RESULT_OK, data);
mActivity.finish();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.support.annotation.LayoutRes;

import com.firebase.ui.auth.R;
import com.firebase.ui.auth.ResultCodes;
import com.firebase.ui.auth.ui.FlowParameters;
import com.firebase.ui.auth.ui.phone.PhoneVerificationActivity;

Expand Down Expand Up @@ -42,8 +41,8 @@ public void startLogin(Activity activity) {

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RC_PHONE_FLOW && resultCode == ResultCodes.OK) {
mActivity.setResult(ResultCodes.OK, data);
if (requestCode == RC_PHONE_FLOW && resultCode == Activity.RESULT_OK) {
mActivity.setResult(Activity.RESULT_OK, data);
mActivity.finish();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.support.v7.app.AppCompatActivity;

import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.ResultCodes;
import com.firebase.ui.auth.util.AuthHelper;
import com.firebase.ui.auth.util.signincontainer.SaveSmartLock;
import com.google.firebase.auth.FirebaseUser;
Expand Down Expand Up @@ -84,7 +83,7 @@ public void saveCredentialsOrFinish(
IdpResponse response) {

if (saveSmartLock == null) {
finish(ResultCodes.OK, response.toIntent());
finish(Activity.RESULT_OK, response.toIntent());
} else {
saveSmartLock.saveCredentialsOrFinish(firebaseUser, password, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.firebase.ui.auth.ErrorCodes;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.R;
import com.firebase.ui.auth.ResultCodes;
import com.firebase.ui.auth.provider.FacebookProvider;
import com.firebase.ui.auth.provider.GoogleProvider;
import com.firebase.ui.auth.provider.IdpProvider;
Expand Down Expand Up @@ -99,7 +98,7 @@ protected void onCreate(Bundle savedInstanceState) {
break;
default:
Log.w(TAG, "Unknown provider: " + providerId);
finish(ResultCodes.CANCELED,
finish(RESULT_CANCELED,
IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
return;
}
Expand All @@ -110,7 +109,7 @@ protected void onCreate(Bundle savedInstanceState) {
Log.w(TAG, "Firebase login unsuccessful."
+ " Account linking failed due to provider not enabled by application: "
+ providerId);
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
finish(RESULT_CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
return;
}

Expand Down Expand Up @@ -146,7 +145,7 @@ public void onSuccess(final IdpResponse idpResponse) {
AuthCredential newCredential = ProviderUtils.getAuthCredential(idpResponse);
if (newCredential == null) {
Log.e(TAG, "No credential returned");
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
finish(RESULT_CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
return;
}

Expand All @@ -165,7 +164,7 @@ public void onSuccess(AuthResult result) {
idpResponse.getProviderType()))
.addOnCompleteListener(new FinishListener(idpResponse));
} else {
finish(ResultCodes.OK, idpResponse.toIntent());
finish(RESULT_OK, idpResponse.toIntent());
}
}
})
Expand Down Expand Up @@ -195,7 +194,7 @@ public void onFailure() {

private void finishWithError() {
Toast.makeText(this, R.string.fui_general_error, Toast.LENGTH_LONG).show();
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
finish(RESULT_CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
}

private class FinishListener implements OnCompleteListener<AuthResult> {
Expand All @@ -206,7 +205,7 @@ private class FinishListener implements OnCompleteListener<AuthResult> {
}

public void onComplete(@NonNull Task task) {
finish(ResultCodes.OK, mIdpResponse.toIntent());
finish(RESULT_OK, mIdpResponse.toIntent());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import com.firebase.ui.auth.ErrorCodes;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.R;
import com.firebase.ui.auth.ResultCodes;
import com.firebase.ui.auth.provider.ProviderUtils;
import com.firebase.ui.auth.ui.AppCompatBase;
import com.firebase.ui.auth.ui.ExtraConstants;
Expand Down Expand Up @@ -121,7 +120,7 @@ public void onClick(View view) {
this,
getFlowParams(),
mEmail));
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
finish(RESULT_CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.firebase.ui.auth.ui.email;

import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
Expand All @@ -11,7 +12,6 @@
import android.support.v7.app.AlertDialog;

import com.firebase.ui.auth.R;
import com.firebase.ui.auth.ResultCodes;
import com.firebase.ui.auth.ui.ExtraConstants;

@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
Expand All @@ -36,7 +36,7 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface anInterface) {
finish(ResultCodes.OK, new Intent());
finish(Activity.RESULT_OK, new Intent());
}
})
.setPositiveButton(android.R.string.ok, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.firebase.ui.auth.ui.idp;

import android.app.Activity;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
Expand All @@ -22,7 +23,6 @@

import com.firebase.ui.auth.ErrorCodes;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.ResultCodes;
import com.firebase.ui.auth.provider.ProviderUtils;
import com.firebase.ui.auth.ui.HelperActivityBase;
import com.firebase.ui.auth.User;
Expand Down Expand Up @@ -76,7 +76,7 @@ public void onComplete(@NonNull Task<AuthResult> task) {
@Override
public void onFailure(@NonNull Exception e) {
Intent intent = IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR);
mActivity.finish(ResultCodes.CANCELED, intent);
mActivity.finish(Activity.RESULT_CANCELED, intent);
}
});
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.firebase.ui.auth.FirebaseAuthError;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.R;
import com.firebase.ui.auth.ResultCodes;
import com.firebase.ui.auth.User;
import com.firebase.ui.auth.ui.AppCompatBase;
import com.firebase.ui.auth.ui.ExtraConstants;
Expand Down Expand Up @@ -293,7 +292,7 @@ private void finish(FirebaseUser user) {
.setPhoneNumber(user.getPhoneNumber())
.build())
.build();
setResult(ResultCodes.OK, response.toIntent());
setResult(RESULT_OK, response.toIntent());
finish();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.firebase.ui.auth.util.signincontainer;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
Expand All @@ -27,7 +28,6 @@
import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.ErrorCodes;
import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.ResultCodes;
import com.firebase.ui.auth.User;
import com.firebase.ui.auth.provider.FacebookProvider;
import com.firebase.ui.auth.provider.GoogleProvider;
Expand Down Expand Up @@ -111,7 +111,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {

if (providerConfig == null) {
// we don't have a provider to handle this
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
finish(Activity.RESULT_CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
return;
}

Expand Down Expand Up @@ -156,7 +156,7 @@ public void onSuccess(final IdpResponse response) {

@Override
public void onFailure() {
finish(ResultCodes.CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
finish(Activity.RESULT_CANCELED, IdpResponse.getErrorCodeIntent(ErrorCodes.UNKNOWN_ERROR));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.firebase.ui.auth.util.signincontainer;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
Expand All @@ -31,7 +32,6 @@

import com.firebase.ui.auth.IdpResponse;
import com.firebase.ui.auth.R;
import com.firebase.ui.auth.ResultCodes;
import com.firebase.ui.auth.ui.HelperActivityBase;
import com.firebase.ui.auth.util.GoogleApiHelper;
import com.firebase.ui.auth.util.PlayServicesHelper;
Expand Down Expand Up @@ -162,12 +162,12 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == RC_SAVE) {
if (resultCode != ResultCodes.OK) {
if (resultCode != Activity.RESULT_OK) {
Log.e(TAG, "SAVE: Canceled by user");
}
finish();
} else if (requestCode == RC_UPDATE_SERVICE) {
if (resultCode == ResultCodes.OK) {
if (resultCode == Activity.RESULT_OK) {
Credential credential = new Credential.Builder(mEmail).setPassword(mPassword)
.build();

Expand All @@ -182,12 +182,12 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}

private void finish() {
finish(ResultCodes.OK, mResponse.toIntent());
finish(Activity.RESULT_OK, mResponse.toIntent());
}

/**
* If SmartLock is enabled and Google Play Services is available, save the credentials.
* Otherwise, finish the calling Activity with {@link ResultCodes#OK RESULT_OK}.
* Otherwise, finish the calling Activity with {@link Activity#RESULT_OK}.
* <p>
* Note: saveCredentialsOrFinish cannot be called immediately after getInstance because onCreate
* has not yet been called.
Expand Down

0 comments on commit fba3335

Please sign in to comment.