@@ -51,7 +51,7 @@ We'll go into each of these steps below.
51
51
52
52
### Add SDK dependencies
53
53
54
- Since FirebaseUI depends on the SDKs of various providers, we'll need to include those in our depedencies as well.
54
+ Since FirebaseUI depends on the SDKs of various providers, we'll need to include those in our dependencies as well.
55
55
56
56
```
57
57
dependencies {
@@ -62,9 +62,9 @@ dependencies {
62
62
}
63
63
```
64
64
65
- ### Add Facebook/Twitter/Google keys to strings.xml
65
+ ### Add Facebook/Twitter/Google keys
66
66
67
- Open your ` res/values/strings.xml ` file and add the following lines, replacing ` [VALUE] ` with your key.
67
+ Open your application's ` res/values/strings.xml ` file and add the following lines, replacing ` [VALUE] ` with your key.
68
68
69
69
Keep in mind, these are all optional. You only have to provide values for the providers you plan to use.
70
70
@@ -74,9 +74,10 @@ Keep in mind, these are all optional. You only have to provide values for the pr
74
74
<string name =" facebook_app_id" >[VALUE]</string >
75
75
<string name =" twitter_app_key" >[VALUE]</string >
76
76
<string name =" twitter_app_secret" >[VALUE]</string >
77
- <string name =" google_client_id" >[VALUE]</string >
78
77
```
79
78
79
+ If you're using Google authentication, place your ` google-services.json ` in the app folder.
80
+
80
81
### Change our AndroidManifest.xml
81
82
82
83
Open your ` manifests/AndroidManifest.xml ` file. This will allow Android to recognize the various activities that FirebaseUI exposes.
@@ -114,18 +115,6 @@ If you're using Facebook authentication, add the following to your `<application
114
115
android : value =" @string/facebook_app_id" />
115
116
```
116
117
117
- If you're using Google authentication, add the following to your ` <application> ` tag.
118
-
119
- ``` xml
120
- <!-- Google Configuration -->
121
- <meta-data
122
- android : name =" com.firebase.ui.GoogleClientId"
123
- android : value =" @string/google_client_id" />
124
- ```
125
-
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.
128
-
129
118
### Inherit from FirebaseLoginBaseActivity
130
119
131
120
Now we get to the juicy bits. Open your ` MainActivity ` and change your activity to extend ` FirebaseLoginBaseActivity `
@@ -147,27 +136,34 @@ public class MainActivity extends FirebaseLoginBaseActivity {
147
136
}
148
137
149
138
@Override
150
- public void onFirebaseLoggedIn ( AuthData authData ) {
151
- // TODO: Handle successful login
139
+ public void onFirebaseLoginProviderError ( FirebaseLoginError firebaseError ) {
140
+ // TODO: Handle an error from the authentication provider
152
141
}
153
142
154
143
@Override
155
- public void onFirebaseLoggedOut ( ) {
156
- // TODO: Handle logout
144
+ public void onFirebaseLoginUserError ( FirebaseLoginError firebaseError ) {
145
+ // TODO: Handle an error from the user
157
146
}
147
+ }
148
+ ```
149
+
150
+ In addition you can override these methods to customize what happens when a user logs in or out:
158
151
152
+ ```
159
153
@Override
160
- public void onFirebaseLoginProviderError ( FirebaseLoginError firebaseError ) {
161
- // TODO: Handle an error from the authentication provider
154
+ public void onFirebaseLoggedIn(AuthData authData ) {
155
+ // TODO: Handle successful login
162
156
}
163
157
164
158
@Override
165
- public void onFirebaseLoginUserError ( FirebaseLoginError firebaseError ) {
166
- // TODO: Handle an error from the user
159
+ public void onFirebaseLoggedOut( ) {
160
+ // TODO: Handle logout
167
161
}
168
- }
162
+
169
163
```
170
164
165
+ If you want to know the current ` AuthData ` at any point, you can call ` getAuth() ` . This will return the ` AuthData ` for the currently authenticated user, or ` null ` if no user is authenticated.
166
+
171
167
### Enable Authentication Providers
172
168
173
169
Now that our activity is set up, we can enable authentication providers. The FirebaseUI login prompt will only display providers you enable here, so don't worry if you don't want to use them all!
@@ -179,15 +175,15 @@ public class MainActivity extends FirebaseLoginBaseActivity {
179
175
protected void onStart () {
180
176
super . onStart();
181
177
// All providers are optional! Remove any you don't want.
182
- setEnabledAuthProvider(SocialProvider . facebook );
183
- setEnabledAuthProvider(SocialProvider . twitter );
184
- setEnabledAuthProvider(SocialProvider . google );
185
- setEnabledAuthProvider(SocialProvider . password );
178
+ setEnabledAuthProvider(AuthProviderType . FACEBOOK );
179
+ setEnabledAuthProvider(AuthProviderType . TWITTER );
180
+ setEnabledAuthProvider(AuthProviderType . GOOGLE );
181
+ setEnabledAuthProvider(AuthProviderType . PASSWORD );
186
182
}
187
183
```
188
184
189
185
190
- ### Call showFirebaseLoginDialog ();
186
+ ### Call showFirebaseLoginPrompt ();
191
187
192
188
You ' re now ready to display the login dialog!
193
189
@@ -331,7 +327,7 @@ protected void onCreate(Bundle savedInstanceState) {
331
327
332
328
mAdapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, ref) {
333
329
@Override
334
- protected void populateView(View view, ChatMessage chatMessage) {
330
+ protected void populateView(View view, ChatMessage chatMessage, int position ) {
335
331
((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
336
332
((TextView)view.findViewById(android.R.id.text2)).setText(chatMessage.getMessage());
337
333
@@ -385,7 +381,7 @@ protected void onCreate(Bundle savedInstanceState) {
385
381
386
382
mAdapter = new FirebaseListAdapter<ChatMessage > (this , ChatMessage . class, android. R . layout. two_line_list_item, ref) {
387
383
@Override
388
- protected void populateView (View view , ChatMessage chatMessage ) {
384
+ protected void populateView (View view , ChatMessage chatMessage , int position ) {
389
385
((TextView )view. findViewById(android. R . id. text1)). setText(chatMessage. getName());
390
386
((TextView )view. findViewById(android. R . id. text2)). setText(chatMessage. getMessage());
391
387
}
@@ -428,7 +424,7 @@ If we use the same layout as before (`android.R.layout.two_line_list_item`), the
428
424
We can wrap that in a ViewHolder with:
429
425
430
426
```java
431
- private static class ChatMessageViewHolder extends RecyclerView .ViewHolder {
427
+ public static class ChatMessageViewHolder extends RecyclerView .ViewHolder {
432
428
TextView messageText;
433
429
TextView nameText;
434
430
@@ -442,18 +438,18 @@ private static class ChatMessageViewHolder extends RecyclerView.ViewHolder {
442
438
443
439
There ' s nothing magical going on here; we' re just mapping numeric IDs and casts into a nice, type- safe contract.
444
440
445
- ### Create a custom FirebaseListAdapter
441
+ ### Create a custom FirebaseRecyclerAdapter
446
442
447
- Just like we did for FirebaseListAdapter , we' ll create an anonymous subclass for our ChatMessages:
443
+ Just like we did for ` FirebaseListAdapter ` , we' ll create an anonymous subclass for our ChatMessages, but this time we ' ll use ` FirebaseRecyclerAdapter ` :
448
444
449
445
```java
450
446
RecyclerView recycler = (RecyclerView ) findViewById(R . id. messages_recycler);
451
447
recycler.setHasFixedSize (true );
452
448
recycler.setLayoutManager (new LinearLayoutManager (this ));
453
449
454
- mAdapter = new FirebaseRecyclerViewAdapter <ChatMessage, ChatMessageViewHolder>(ChatMessage.class, android.R.layout.two_line_list_item, ChatMessageViewHolder.class, mRef) {
450
+ mAdapter = new FirebaseRecyclerAdapter <ChatMessage , ChatMessageViewHolder > (ChatMessage . class, android. R . layout. two_line_list_item, ChatMessageViewHolder . class, mRef) {
455
451
@Override
456
- public void populateViewHolder(ChatMessageViewHolder chatMessageViewHolder, ChatMessage chatMessage) {
452
+ public void populateViewHolder (ChatMessageViewHolder chatMessageViewHolder , ChatMessage chatMessage , int position ) {
457
453
chatMessageViewHolder. nameText. setText(chatMessage. getName());
458
454
chatMessageViewHolder. messageText. setText(chatMessage. getMessage());
459
455
}
0 commit comments