Skip to content

Commit a934f3b

Browse files
committed
Updates README and fixes Google error
1 parent 418fe5e commit a934f3b

File tree

5 files changed

+82
-46
lines changed

5 files changed

+82
-46
lines changed

README.md

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,29 @@ FirebaseUI has a built-in dialog that you can use pop up to allow your users to
4040

4141
To use FirebaseUI to authenticate users we need to do a few things:
4242

43-
1. Add our Facebook/Twitter/Google keys to strings.xml
44-
2. Add our activities to our AndroidManifest.xml
45-
3. Inherit from FirebaseLoginBaseActivity
46-
4. Enable authentication providers
47-
5. Call showFirebaseLoginDialog();
43+
1. Add SDK dependencies
44+
2. Add Facebook/Twitter/Google keys to strings.xml
45+
3. Change our AndroidManifest.xml
46+
4. Inherit from FirebaseLoginBaseActivity
47+
5. Enable authentication providers
48+
6. Call showFirebaseLoginDialog();
4849

4950
We'll go into each of these steps below.
5051

51-
### Add our Facebook/Twitter/Google keys to strings.xml
52+
### Add SDK dependencies
53+
54+
Since FirebaseUI depends on the SDKs of various providers, we'll need to include those in our depedencies as well.
55+
56+
```
57+
dependencies {
58+
...
59+
compile 'com.facebook.android:facebook-android-sdk:4.6.0'
60+
compile 'com.google.android.gms:play-services-auth:8.3.0'
61+
compile 'org.twitter4j:twitter4j-core:4.0.2'
62+
}
63+
```
64+
65+
### Add Facebook/Twitter/Google keys to strings.xml
5266

5367
Open your `res/values/strings.xml` file and add the following lines, replacing `[VALUE]` with your key.
5468

@@ -63,10 +77,16 @@ Keep in mind, these are all optional. You only have to provide values for the pr
6377
<string name="google_client_id">[VALUE]</string>
6478
```
6579

66-
### Add our activities to our AndroidManifest.xml
80+
### Change our AndroidManifest.xml
6781

6882
Open your `manifests/AndroidManifest.xml` file. This will allow Android to recognize the various activities that FirebaseUI exposes.
6983

84+
First though, double check that you've requested the `INTERNET` permission in your `<manifest>` tag.
85+
86+
```xml
87+
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
88+
```
89+
7090
If you're using Twitter authentication, add the following to your `<application>` tag.
7191

7292
```xml
@@ -96,15 +116,15 @@ If you're using Facebook authentication, add the following to your `<application
96116

97117
If you're using Google authentication, add the following to your `<application>` tag.
98118

99-
```
119+
```xml
100120
<!-- Google Configuration -->
101121
<meta-data
102122
android:name="com.firebase.ui.GoogleClientId"
103123
android:value="@string/google_client_id" />
104124
```
105125

106-
If you're using Google Sign-in you'll also need to ensure that your `google-services.json` file is created
107-
and placed in your app folder.
126+
**Note:** If you're using Google Sign-in you'll also need to ensure that your `google-services.json` file is created
127+
and placed in your app folder.
108128

109129
### Inherit from FirebaseLoginBaseActivity
110130

@@ -127,12 +147,12 @@ public class MainActivity extends FirebaseLoginBaseActivity {
127147
}
128148

129149
@Override
130-
public void onFirebaseLoginSuccess(AuthData authData) {
150+
public void onFirebaseLoggedIn(AuthData authData) {
131151
// TODO: Handle successful login
132152
}
133153

134154
@Override
135-
public void onFirebaseLogout() {
155+
public void onFirebaseLoggedOut() {
136156
// TODO: Handle logout
137157
}
138158

library/src/main/java/com/firebase/ui/auth/core/FirebaseLoginBaseActivity.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Intent;
44
import android.support.v7.app.AppCompatActivity;
5+
import android.util.Log;
56

67
import com.firebase.client.AuthData;
78
import com.firebase.client.Firebase;
@@ -72,6 +73,10 @@ public void resetFirebaseLoginDialog() {
7273
mDialog.reset();
7374
}
7475

76+
public void setEnabledAuthProvider(SocialProvider provider) {
77+
mDialog.setEnabledProvider(provider);
78+
}
79+
7580
@Override
7681
protected void onStart() {
7782
super.onStart();
@@ -113,12 +118,21 @@ public void onAuthStateChanged(AuthData authData) {
113118
getFirebaseRef().addAuthStateListener(mAuthStateListener);
114119
}
115120

116-
public void setEnabledAuthProvider(SocialProvider provider) {
117-
mDialog.setEnabledProvider(provider);
118-
}
119-
120121
protected void onStop() {
121122
super.onStop();
122123
getFirebaseRef().removeAuthStateListener(mAuthStateListener);
124+
mDialog.cleanUp();
125+
}
126+
127+
@Override
128+
protected void onPause() {
129+
super.onPause();
130+
mDialog.cleanUp();
131+
}
132+
133+
@Override
134+
protected void onDestroy() {
135+
super.onDestroy();
136+
mDialog.cleanUp();
123137
}
124138
}

library/src/main/java/com/firebase/ui/auth/core/FirebaseLoginDialog.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,41 @@ public class FirebaseLoginDialog extends DialogFragment {
3131
Context mContext;
3232
View mView;
3333

34-
public void onStart() {
35-
super.onStart();
36-
if (mGoogleAuthProvider != null) mGoogleAuthProvider.onStart();
37-
}
38-
39-
4034
/*
4135
We need to be extra aggressive about building / destroying mGoogleauthProviders so we don't
4236
end up with two clients connected at the same time.
4337
*/
4438

4539
public void onStop() {
4640
super.onStop();
47-
if (mGoogleAuthProvider != null) mGoogleAuthProvider.onStop();
41+
cleanUp();
4842
}
4943

5044
public void onDestroy() {
5145
super.onDestroy();
52-
if (mGoogleAuthProvider != null) mGoogleAuthProvider.onStop();
46+
cleanUp();
47+
}
48+
49+
@Override
50+
public void onPause() {
51+
super.onPause();
52+
cleanUp();
53+
}
54+
55+
public void cleanUp() {
56+
if (mGoogleAuthProvider != null) mGoogleAuthProvider.cleanUp();
5357
}
5458

5559
public void onActivityResult(int requestCode, int resultCode, Intent data) {
56-
if (mFacebookAuthProvider != null && mActiveProvider == SocialProvider.facebook) {
60+
if (mFacebookAuthProvider != null) {
5761
mFacebookAuthProvider.mCallbackManager.onActivityResult(requestCode, resultCode, data);
5862
}
5963

60-
if (mTwitterAuthProvider != null && mActiveProvider == SocialProvider.twitter) {
64+
if (mTwitterAuthProvider != null) {
6165
mTwitterAuthProvider.onActivityResult(requestCode, resultCode, data);
6266
}
6367

64-
if (mGoogleAuthProvider != null && mActiveProvider == SocialProvider.google) {
68+
if (mGoogleAuthProvider != null) {
6569
mGoogleAuthProvider.onActivityResult(requestCode, resultCode, data);
6670
}
6771
}
@@ -120,12 +124,10 @@ public void logout() {
120124
}
121125

122126
public FirebaseLoginDialog setHandler(final TokenAuthHandler handler) {
123-
//TODO: Make this idiomatic?
124-
final DialogFragment self = this;
125127
mHandler = new TokenAuthHandler() {
126128
@Override
127129
public void onSuccess(AuthData auth) {
128-
self.dismiss();
130+
dismiss();
129131
handler.onSuccess(auth);
130132
}
131133

library/src/main/java/com/firebase/ui/auth/google/GoogleAuthProvider.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public GoogleAuthProvider(Context context, Firebase ref, TokenAuthHandler handle
7878
.enableAutoManage((FragmentActivity) mActivity, this)
7979
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
8080
.build();
81+
82+
mGoogleApiClient.connect();
83+
8184
}
8285

8386
public String getProviderName() { return PROVIDER_NAME; }
@@ -137,6 +140,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
137140
}
138141

139142
if (requestCode == GoogleActions.SIGN_IN && resultCode == 0) {
143+
Log.d(TAG, data.getExtras().keySet().toString());
140144
mHandler.onUserError(new FirebaseLoginError(FirebaseResponse.LOGIN_CANCELLED, "User closed login dialog."));
141145
}
142146
}
@@ -164,13 +168,8 @@ public void onOAuthFailure(FirebaseLoginError firebaseError) {
164168
mHandler.onProviderError(firebaseError);
165169
}
166170

167-
public void onStart() {
168-
if (mGoogleApiClient != null)
169-
mGoogleApiClient.connect();
170-
}
171-
172-
public void onStop() {
173-
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
171+
public void cleanUp() {
172+
if (mGoogleApiClient != null) {
174173
mGoogleApiClient.disconnect();
175174
mGoogleApiClient.stopAutoManage((FragmentActivity) mActivity);
176175
}

library/src/main/res/layout/fragment_firebase_login.xml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@
9797
android:background="@drawable/facebook_button"
9898
android:textColor="#ffffff"
9999
android:typeface="normal"
100-
android:textAlignment="center"
100+
android:textAlignment="gravity"
101101
android:drawableLeft="@drawable/ic_facebook"
102102
android:drawablePadding="10dp"
103-
android:gravity="left|center"
104103
android:textStyle="bold"
105104
android:paddingLeft="12dp"
106-
android:layout_marginBottom="10dp" />
105+
android:layout_marginBottom="10dp"
106+
android:layout_gravity="left"
107+
android:gravity="left|center_vertical" />
107108

108109
<Button
109110
android:layout_width="match_parent"
@@ -113,13 +114,13 @@
113114
android:background="@drawable/google_button"
114115
android:textColor="#ffffff"
115116
android:typeface="normal"
116-
android:textAlignment="center"
117+
android:textAlignment="gravity"
117118
android:drawableLeft="@drawable/ic_google"
118119
android:drawablePadding="10dp"
119-
android:gravity="left|center"
120120
android:textStyle="bold"
121121
android:paddingLeft="12dp"
122-
android:layout_marginBottom="10dp" />
122+
android:layout_marginBottom="10dp"
123+
android:gravity="left|center_vertical" />
123124

124125
<Button
125126
android:layout_width="match_parent"
@@ -129,13 +130,13 @@
129130
android:background="@drawable/twitter_button"
130131
android:textColor="#ffffff"
131132
android:typeface="normal"
132-
android:textAlignment="center"
133+
android:textAlignment="gravity"
133134
android:drawableLeft="@drawable/ic_twitter"
134135
android:drawablePadding="10dp"
135-
android:gravity="left|center"
136136
android:textStyle="bold"
137137
android:paddingLeft="12dp"
138-
android:layout_marginBottom="10dp" />
138+
android:layout_marginBottom="10dp"
139+
android:gravity="left|center_vertical" />
139140

140141
</LinearLayout>
141142
</LinearLayout>

0 commit comments

Comments
 (0)