@@ -51,7 +51,7 @@ We'll go into each of these steps below.
5151
5252### Add SDK dependencies
5353
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.
5555
5656```
5757dependencies {
@@ -62,9 +62,9 @@ dependencies {
6262}
6363```
6464
65- ### Add Facebook/Twitter/Google keys to strings.xml
65+ ### Add Facebook/Twitter/Google keys
6666
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.
6868
6969Keep in mind, these are all optional. You only have to provide values for the providers you plan to use.
7070
@@ -74,9 +74,10 @@ Keep in mind, these are all optional. You only have to provide values for the pr
7474<string name =" facebook_app_id" >[VALUE]</string >
7575<string name =" twitter_app_key" >[VALUE]</string >
7676<string name =" twitter_app_secret" >[VALUE]</string >
77- <string name =" google_client_id" >[VALUE]</string >
7877```
7978
79+ If you're using Google authentication, place your ` google-services.json ` in the app folder.
80+
8081### Change our AndroidManifest.xml
8182
8283Open 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
114115 android : value =" @string/facebook_app_id" />
115116```
116117
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-
129118### Inherit from FirebaseLoginBaseActivity
130119
131120Now 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 {
147136 }
148137
149138 @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
152141 }
153142
154143 @Override
155- public void onFirebaseLoggedOut ( ) {
156- // TODO: Handle logout
144+ public void onFirebaseLoginUserError ( FirebaseLoginError firebaseError ) {
145+ // TODO: Handle an error from the user
157146 }
147+ }
148+ ```
149+
150+ In addition you can override these methods to customize what happens when a user logs in or out:
158151
152+ ```
159153 @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
162156 }
163157
164158 @Override
165- public void onFirebaseLoginUserError ( FirebaseLoginError firebaseError ) {
166- // TODO: Handle an error from the user
159+ public void onFirebaseLoggedOut( ) {
160+ // TODO: Handle logout
167161 }
168- }
162+
169163```
170164
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+
171167### Enable Authentication Providers
172168
173169Now 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 {
179175 protected void onStart () {
180176 super . onStart();
181177 // 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 );
186182 }
187183```
188184
189185
190- ### Call showFirebaseLoginDialog ();
186+ ### Call showFirebaseLoginPrompt ();
191187
192188You ' re now ready to display the login dialog!
193189
@@ -331,7 +327,7 @@ protected void onCreate(Bundle savedInstanceState) {
331327
332328 mAdapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, ref) {
333329 @Override
334- protected void populateView(View view, ChatMessage chatMessage) {
330+ protected void populateView(View view, ChatMessage chatMessage, int position ) {
335331 ((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
336332 ((TextView)view.findViewById(android.R.id.text2)).setText(chatMessage.getMessage());
337333
@@ -385,7 +381,7 @@ protected void onCreate(Bundle savedInstanceState) {
385381
386382 mAdapter = new FirebaseListAdapter<ChatMessage > (this , ChatMessage . class, android. R . layout. two_line_list_item, ref) {
387383 @Override
388- protected void populateView (View view , ChatMessage chatMessage ) {
384+ protected void populateView (View view , ChatMessage chatMessage , int position ) {
389385 ((TextView )view. findViewById(android. R . id. text1)). setText(chatMessage. getName());
390386 ((TextView )view. findViewById(android. R . id. text2)). setText(chatMessage. getMessage());
391387 }
@@ -428,7 +424,7 @@ If we use the same layout as before (`android.R.layout.two_line_list_item`), the
428424We can wrap that in a ViewHolder with:
429425
430426```java
431- private static class ChatMessageViewHolder extends RecyclerView .ViewHolder {
427+ public static class ChatMessageViewHolder extends RecyclerView .ViewHolder {
432428 TextView messageText;
433429 TextView nameText;
434430
@@ -442,18 +438,18 @@ private static class ChatMessageViewHolder extends RecyclerView.ViewHolder {
442438
443439There ' s nothing magical going on here; we' re just mapping numeric IDs and casts into a nice, type- safe contract.
444440
445- ### Create a custom FirebaseListAdapter
441+ ### Create a custom FirebaseRecyclerAdapter
446442
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 ` :
448444
449445```java
450446RecyclerView recycler = (RecyclerView ) findViewById(R . id. messages_recycler);
451447recycler.setHasFixedSize (true );
452448recycler.setLayoutManager (new LinearLayoutManager (this ));
453449
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) {
455451 @Override
456- public void populateViewHolder(ChatMessageViewHolder chatMessageViewHolder, ChatMessage chatMessage) {
452+ public void populateViewHolder (ChatMessageViewHolder chatMessageViewHolder , ChatMessage chatMessage , int position ) {
457453 chatMessageViewHolder. nameText. setText(chatMessage. getName());
458454 chatMessageViewHolder. messageText. setText(chatMessage. getMessage());
459455 }
0 commit comments