Skip to content

Refactor container activities #374

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

Closed
wants to merge 90 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 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
83e13d8
Refactor SaveSmartLock.java
SUPERCILEX Oct 15, 2016
c529171
Initial refactor
SUPERCILEX Oct 16, 2016
5142dec
Cleanup
SUPERCILEX Oct 16, 2016
361d308
Cleanup
SUPERCILEX Oct 16, 2016
9a4921e
Bug fix
SUPERCILEX Oct 16, 2016
6af7674
Cleanup
SUPERCILEX Oct 16, 2016
35d94bb
Cleanup
SUPERCILEX Oct 16, 2016
64728b2
Cleanup and bug fixes
SUPERCILEX Oct 16, 2016
dde4160
Cleanup
SUPERCILEX Oct 16, 2016
2d5dfdc
Cleanup
SUPERCILEX Oct 16, 2016
f3bd0f1
Fix intellij messing up documentation.
SUPERCILEX Oct 16, 2016
f06845b
Cleanup
SUPERCILEX Oct 16, 2016
9782793
Cleanup
SUPERCILEX Oct 16, 2016
7d1d1c6
Remove unused strings
SUPERCILEX Oct 16, 2016
20413ee
Cleanup
SUPERCILEX Oct 16, 2016
7842c48
Refactor progress hiding and delegateSignIn()
SUPERCILEX Oct 16, 2016
135d2c5
Cleanup sample
SUPERCILEX Oct 16, 2016
23ae513
Fix null pointer for low memory devices
SUPERCILEX Oct 17, 2016
25eb137
Fix for #171
SUPERCILEX Oct 17, 2016
be7e0c3
Fix for #152
SUPERCILEX Oct 17, 2016
07beeb3
Force activity to implement onResult
SUPERCILEX Oct 17, 2016
13122c3
Fix smart lock failed flow
SUPERCILEX Oct 17, 2016
862b884
make it compile
SUPERCILEX Oct 17, 2016
a7b3336
Relaxed activity requirements to FragmentActivity
SUPERCILEX Oct 18, 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
0a161d7
Merge remote-tracking branch 'origin/refactor-zombie-activities' into…
SUPERCILEX Oct 21, 2016
8813c8c
Fix merge mistakes
SUPERCILEX Oct 21, 2016
6f0f4da
Make git show ChooseAccountActivity renamed to SignInDelegate.java
SUPERCILEX Oct 21, 2016
099ef6d
Now shows rename
SUPERCILEX Oct 21, 2016
517f4ce
Working on fixing merge mistakes and preventing regressions
SUPERCILEX Oct 21, 2016
24ef137
Merge stuff from ChooseAccountActivity into SignInDelegate.java
SUPERCILEX Oct 21, 2016
9b568ec
Merge remote-tracking branch 'firebase/version-1.0.0-dev' into refact…
SUPERCILEX Oct 21, 2016
4a449d5
test
SUPERCILEX Oct 21, 2016
a6553d5
Remove references to enableAutoManage
SUPERCILEX Oct 22, 2016
00126d1
It compiles!
SUPERCILEX Oct 22, 2016
a9c895e
Rename public API to AuthUISignInResult and onSignInResult
SUPERCILEX Oct 22, 2016
8566118
Update public api
SUPERCILEX Oct 22, 2016
f5738b1
Cleanup
SUPERCILEX Oct 22, 2016
1fb5c08
Working on tests
SUPERCILEX Oct 22, 2016
1793dbd
working on tests
SUPERCILEX Oct 22, 2016
ca10f6c
Removed unnecessary tests
SUPERCILEX Oct 22, 2016
a0355b5
Fix bug in SaveSmartLock.java not connecting
SUPERCILEX Oct 22, 2016
e60bb5e
More refactoring!
SUPERCILEX Oct 22, 2016
704a5ce
Refactoring part 1
SUPERCILEX Oct 22, 2016
7fcf057
It compiles!
SUPERCILEX Oct 22, 2016
121919a
Fix tests
SUPERCILEX Oct 22, 2016
a78480e
Fix nullPointerException
SUPERCILEX Oct 22, 2016
76b1292
Merge branch 'refactor-ChooseAccountActivity' into containers
SUPERCILEX Oct 22, 2016
a94aedc
Simplify public api
SUPERCILEX Oct 22, 2016
b629cf9
Update dependencies and revert
SUPERCILEX Oct 22, 2016
cda7bfd
Bug fixes and prettification
SUPERCILEX Oct 22, 2016
617628e
Merge branch 'refactor-ChooseAccountActivity' into containers
SUPERCILEX Oct 22, 2016
9a620d7
Rename for nice diff
SUPERCILEX Oct 22, 2016
b36a401
tmp
SUPERCILEX Oct 22, 2016
8af7342
EmailHintContainer.java refactor
SUPERCILEX Oct 23, 2016
83a0551
Fix null pointer
SUPERCILEX Oct 23, 2016
67cf311
Merge branch 'refactor-ChooseAccountActivity' into containers
SUPERCILEX Oct 23, 2016
ecefc69
Fix merge mistakes
SUPERCILEX Oct 23, 2016
4613154
Really fix null pointer
SUPERCILEX Oct 23, 2016
5a2151c
Merge branch 'refactor-ChooseAccountActivity' into containers
SUPERCILEX Oct 23, 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
56 changes: 18 additions & 38 deletions app/src/main/java/com/firebase/uidemo/auth/AuthUiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;

import android.widget.TextView;

import com.firebase.ui.auth.AuthUI;
import com.firebase.ui.auth.AuthUI.IdpConfig;
import com.firebase.ui.auth.IdpResponse;
Expand All @@ -47,18 +47,10 @@
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AuthUiActivity extends AppCompatActivity {

private static final String TAG = "AuthUIActivity";

public class AuthUiActivity extends AppCompatActivity implements AuthUI.SignInResult {
private static final String UNCHANGED_CONFIG_VALUE = "CHANGE-ME";

private static final String GOOGLE_TOS_URL =
"https://www.google.com/policies/terms/";
private static final String FIREBASE_TOS_URL =
"https://www.firebase.com/terms/terms-of-service.html";

private static final int RC_SIGN_IN = 100;
private static final String GOOGLE_TOS_URL = "https://www.google.com/policies/terms/";
private static final String FIREBASE_TOS_URL = "https://www.firebase.com/terms/terms-of-service.html";

@BindView(R.id.default_theme)
RadioButton mUseDefaultTheme;
Expand Down Expand Up @@ -183,26 +175,13 @@ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {

@OnClick(R.id.sign_in)
public void signIn(View view) {
startActivityForResult(
AuthUI.getInstance().createSignInIntentBuilder()
.setTheme(getSelectedTheme())
.setLogo(getSelectedLogo())
.setProviders(getSelectedProviders())
.setTosUrl(getSelectedTosUrl())
.setIsSmartLockEnabled(mEnableSmartLock.isChecked())
.build(),
RC_SIGN_IN);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
handleSignInResponse(resultCode, data);
return;
}

showSnackbar(R.string.unknown_response);
AuthUI.getInstance().createSignInIntentBuilder()
.setTheme(getSelectedTheme())
.setLogo(getSelectedLogo())
.setProviders(getSelectedProviders())
.setTosUrl(getSelectedTosUrl())
.setIsSmartLockEnabled(mEnableSmartLock.isChecked())
.build(this);
}


Expand All @@ -221,13 +200,14 @@ private void setFacebookScopesEnabled(boolean enabled) {
}

@MainThread
private void handleSignInResponse(int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
startActivity(SignedInActivity.createIntent(this, IdpResponse.fromResultIntent(data)));
finish();
return;
}
@Override
public void onSignInSuccessful(Intent data) {
startActivity(SignedInActivity.createIntent(this, IdpResponse.fromResultIntent(data)));
finish();
}

@Override
public void onSignInFailed(int resultCode) {
if (resultCode == RESULT_CANCELED) {
showSnackbar(R.string.sign_in_cancelled);
return;
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/fabric.properties

This file was deleted.

2 changes: 0 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
<string name="google_tos_label">Google TOS</string>
<string name="firebase_tos_label">Firebase TOS</string>
<string name="tos_header">Terms of Service URL:</string>
<string name="unknown_response">Unexpected onActivityResult response code</string>
<string name="ok_label">OK</string>
<string name="unknown_sign_in_response">Unknown response from AuthUI sign-in</string>
<string name="sign_in_cancelled">Sign in cancelled</string>
<string name="no_internet_connection">No internet connection</string>
Expand Down
6 changes: 3 additions & 3 deletions auth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ dependencies {
// See https://github.com/robolectric/robolectric/issues/1932#issuecomment-219796474
testCompile 'org.khronos:opengl-api:gl1.1-android-2.1_r1'

compile 'com.facebook.android:facebook-android-sdk:4.14.1'
compile("com.twitter.sdk.android:twitter:2.0.0@aar") {
transitive = true;
compile 'com.facebook.android:facebook-android-sdk:4.16.1'
compile("com.twitter.sdk.android:twitter:2.1.1@aar") {
transitive = true
}
compile "com.android.support:design:${project.ext.support_library_version}"

Expand Down
13 changes: 2 additions & 11 deletions auth/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
android:name="com.firebase.ui.auth.ui.email.ConfirmRecoverPasswordActivity"
android:label="@string/title_confirm_recover_password_activity"
android:theme="@style/FirebaseUI.Dialog" />
<activity
android:name="com.firebase.ui.auth.ui.email.EmailHintContainerActivity"
android:label="@string/default_toolbar_title"
android:theme="@style/FirebaseUI.Translucent" />
<activity
android:name="com.firebase.ui.auth.ui.email.RecoverPasswordActivity"
android:label="@string/title_recover_password_activity"
Expand Down Expand Up @@ -49,17 +45,12 @@
<activity
android:name="com.firebase.ui.auth.ui.idp.IdpSignInContainerActivity"
android:label="@string/default_toolbar_title"
android:theme="@style/FirebaseUI.Translucent" />
<activity
android:name=".ui.ChooseAccountActivity"
android:label="@string/default_toolbar_title"
android:theme="@style/FirebaseUI.Translucent" />

android:theme="@style/FirebaseUI.FacebookTranslucent" />
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name"
android:theme="@style/FirebaseUI.Translucent"
android:theme="@style/FirebaseUI.FacebookTranslucent"
tools:replace="android:theme" />

<activity
Expand Down
58 changes: 32 additions & 26 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
package com.firebase.ui.auth;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.annotation.VisibleForTesting;
import android.support.v4.app.FragmentActivity;

import com.facebook.FacebookSdk;
import com.facebook.login.LoginManager;
import com.firebase.ui.auth.ui.ChooseAccountActivity;
import com.firebase.ui.auth.ui.FlowParameters;
import com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity;
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.smartlock.SignInDelegate;
import com.firebase.ui.auth.util.smartlock.SmartLock;
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 All @@ -48,6 +48,7 @@
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.GoogleAuthProvider;
import com.google.firebase.auth.TwitterAuthProvider;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -226,6 +227,11 @@
* </ul>
*/
public class AuthUI {
public interface SignInResult {
void onSignInSuccessful(Intent data);

void onSignInFailed(int resultCode);
}

/**
* Provider identifier for email and password credentials, for use with
Expand Down Expand Up @@ -325,6 +331,7 @@ public Void then(@NonNull Task<GoogleApiClient> task) throws Exception {
* API. Returns a {@code Task} that succeeds if the Firebase Auth user deletion succeeds and
* fails if the Firebase Auth deletion fails. Credentials deletion failures are handled
* silently.
*
* @param activity the calling {@link Activity}.
*/
public Task<Void> delete(@NonNull Activity activity) {
Expand All @@ -343,7 +350,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 = SmartLock.credentialsFromFirebaseUser(firebaseUser);

// For each Credential in the list, create a task to delete it.
List<Task<?>> credentialTasks = new ArrayList<>();
Expand Down Expand Up @@ -381,6 +388,7 @@ public SignInIntentBuilder createSignInIntentBuilder() {
/**
* Retrieves the {@link AuthUI} instance associated with the default app, as returned by
* {@code FirebaseApp.getInstance()}.
*
* @throws IllegalStateException if the default app is not initialized.
*/
public static AuthUI getInstance() {
Expand All @@ -406,7 +414,8 @@ public static AuthUI getInstance(FirebaseApp app) {
* Default theme used by {@link SignInIntentBuilder#setTheme(int)} if no theme
* customization is required.
*/
public static @StyleRes int getDefaultTheme() {
@StyleRes
public static int getDefaultTheme() {
// TODO(iainmgin): figure out why this works as a static method but not as a static
// final variable.
return R.style.FirebaseUI;
Expand Down Expand Up @@ -471,6 +480,7 @@ public static class Builder {

/**
* Builds the configuration parameters for an identity provider.
*
* @param providerId An ID of one of the supported identity providers. e.g.
* {@link AuthUI#GOOGLE_PROVIDER}. See {@link AuthUI#SUPPORTED_PROVIDERS} for the
* complete list of supported Identity providers
Expand Down Expand Up @@ -568,7 +578,8 @@ public SignInIntentBuilder setProviders(@NonNull List<IdpConfig> idpConfigs) {
for (IdpConfig idpConfig : idpConfigs) {
if (configuredProviders.contains(idpConfig.getProviderId())) {
throw new IllegalArgumentException("Each provider can only be set once. "
+ idpConfig.getProviderId() + " was set twice.");
+ idpConfig.getProviderId()
+ " was set twice.");
}
configuredProviders.add(idpConfig.getProviderId());
mProviders.add(idpConfig);
Expand Down Expand Up @@ -602,32 +613,14 @@ public SignInIntentBuilder setProviders(@NonNull String... providers) {

/**
* Enables or disables the use of Smart Lock for Passwords in the sign in flow.
*
*
* <p>SmartLock is enabled by default
*/
public SignInIntentBuilder setIsSmartLockEnabled(boolean enabled) {
mIsSmartLockEnabled = enabled;
return this;
}

public Intent build() {
Context context = mApp.getApplicationContext();
return build(context);
}

@VisibleForTesting
public Intent build(Context context) {
return ChooseAccountActivity.createIntent(
context,
new FlowParameters(
mApp.getName(),
new ArrayList<>(mProviders),
mTheme,
mLogo,
mTosUrl,
mIsSmartLockEnabled));
}

private boolean isIdpAlreadyConfigured(@NonNull String providerId) {
for (IdpConfig config : mProviders) {
if (config.getProviderId().equals(providerId)) {
Expand All @@ -636,5 +629,18 @@ private boolean isIdpAlreadyConfigured(@NonNull String providerId) {
}
return false;
}

public void build(@NonNull FragmentActivity activity) {
SignInDelegate.delegateSignIn(activity, getFlowParams());
}

public FlowParameters getFlowParams() {
return new FlowParameters(mApp.getName(),
new ArrayList<>(mProviders),
mTheme,
mLogo,
mTosUrl,
mIsSmartLockEnabled);
}
}
}
22 changes: 22 additions & 0 deletions auth/src/main/java/com/firebase/ui/auth/IdpResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;

import com.firebase.ui.auth.provider.FacebookProvider;
import com.firebase.ui.auth.provider.GoogleProvider;
import com.firebase.ui.auth.provider.TwitterProvider;
import com.firebase.ui.auth.ui.ExtraConstants;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.FacebookAuthProvider;
import com.google.firebase.auth.GoogleAuthProvider;
import com.google.firebase.auth.TwitterAuthProvider;

/**
* A container that encapsulates the result of authenticating with an Identity Provider.
Expand Down Expand Up @@ -120,4 +128,18 @@ public void writeToParcel(Parcel dest, int flags) {
public static IdpResponse fromResultIntent(Intent resultIntent) {
return resultIntent.getParcelableExtra(ExtraConstants.EXTRA_IDP_RESPONSE);
}

public static AuthCredential createCredential(IdpResponse idpSignInResponse) {
if (idpSignInResponse.getProviderType().equalsIgnoreCase(FacebookAuthProvider.PROVIDER_ID)) {
return FacebookProvider.createAuthCredential(idpSignInResponse);
} else if (idpSignInResponse.getProviderType().equalsIgnoreCase(GoogleAuthProvider
.PROVIDER_ID)) {
return GoogleProvider.createAuthCredential(idpSignInResponse);
} else if (idpSignInResponse
.getProviderType()
.equalsIgnoreCase(TwitterAuthProvider.PROVIDER_ID)) {
return TwitterProvider.createAuthCredential(idpSignInResponse);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
Expand All @@ -34,11 +35,13 @@
import com.firebase.ui.auth.R;
import com.google.firebase.auth.AuthCredential;
import com.google.firebase.auth.FacebookAuthProvider;
import java.util.ArrayList;
import java.util.List;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class FacebookProvider implements IdpProvider, FacebookCallback<LoginResult> {
protected static final String ERROR = "err";
protected static final String ERROR_MSG = "err_msg";
Expand Down
Loading