@@ -191,7 +191,7 @@ We can now use that in our activity to allow sending a message:
191
191
Firebase.setAndroidContext(this);
192
192
Firebase ref = new Firebase("https://nanochat.firebaseio.com");
193
193
194
- mAdapter = new FirebaseListAdapter<ChatMessage>(ChatMessage.class, android.R.layout.two_line_list_item, this , ref) {
194
+ mAdapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, ref) {
195
195
@Override
196
196
protected void populateView(View view, ChatMessage chatMessage) {
197
197
((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
@@ -218,6 +218,54 @@ We can now use that in our activity to allow sending a message:
218
218
219
219
Et voila: a minimal, yet fully functional, chat app in about 30 lines of code. Not bad, right?
220
220
221
+ ## Using a RecyclerView
222
+
223
+ RecyclerView is the new preferred way to handle potentially long lists of items. Since Firebase collections
224
+ can contain many items, there is an ` FirebaseRecyclerViewAdapter ` too. Here's how you use it:
225
+
226
+ 1 . Create a custom ViewHolder class
227
+ 2 . Create a custom subclass FirebaseListAdapter
228
+
229
+ The rest of the steps is the same as for the ` FirebaseListAdapter ` above, so be sure to read that first.
230
+
231
+ ### Create a custom ViewHolder
232
+
233
+ A ViewHolder is similar to container of a ViewGroup that allows simple lookup of the sub-views of the group.
234
+ If we use the same layout as before (` android.R.layout.two_line_list_item ` ), there are two ` TextView ` s in there.
235
+ We can wrap that in a ViewHolder with:
236
+
237
+ private static class ChatMessageViewHolder extends RecyclerView.ViewHolder {
238
+ TextView messageText;
239
+ TextView nameText;
240
+
241
+ public ChatMessageViewHolder(View itemView) {
242
+ super(itemView);
243
+ nameText = (TextView)itemView.findViewById(android.R.id.text1);
244
+ messageText = (TextView) itemView.findViewById(android.R.id.text2);
245
+ }
246
+ }
247
+
248
+ There's nothing magical going on here; we're just mapping numeric IDs and casts into a nice, type-safe contract.
249
+
250
+ ### Create a custom FirebaseListAdapter
251
+
252
+ Just like we did for FirebaseListAdapter, we'll create an anonymous subclass for our ChatMessages:
253
+
254
+ RecyclerView recycler = (RecyclerView) findViewById(R.id.messages_recycler);
255
+ recycler.setHasFixedSize(true);
256
+ recycler.setLayoutManager(new LinearLayoutManager(this));
257
+
258
+ mAdapter = new FirebaseRecyclerViewAdapter<ChatMessage, ChatMessageViewHolder>(ChatMessage.class, android.R.layout.two_line_list_item, ChatMessageViewHolder.class, mRef) {
259
+ @Override
260
+ public void populateViewHolder(ChatMessageViewHolder chatMessageViewHolder, ChatMessage chatMessage) {
261
+ chatMessageViewHolder.nameText.setText(chatMessage.getName());
262
+ chatMessageViewHolder.messageText.setText(chatMessage.getMessage());
263
+ }
264
+ };
265
+ recycler.setAdapter(mAdapter);
266
+
267
+ Like before, we get a custom RecyclerView populated with data from Firebase by setting the properties to the correct fields.
268
+
221
269
## Installing locally
222
270
223
271
We are still working on deploying FirebaseUI to Maven Central. In the meantime, you can download the
@@ -229,7 +277,7 @@ with:
229
277
230
278
## Deployment
231
279
232
- ### To get the build server ready to build/deploy FirebaseUI-Android
280
+ ### To get the build server ready to build FirebaseUI-Android
233
281
234
282
* Install a JDK (if it's not installed yet):
235
283
* ` sudo apt-get install default-jdk `
@@ -262,8 +310,22 @@ with:
262
310
sonatypeUsername=YourSonatypeJiraUsername
263
311
sonatypePassword=YourSonatypeJiraPassword
264
312
313
+ ### to build a release
314
+
315
+ * build the project in Android Studio or with Gradle
316
+ * this generates the main binary: ` library/build/outputs/aar/library-debug.aar `
317
+ * open the Gradle projects tab, by clicking the tiny gradle tab on the right (or View > Tool Windows > Gradle)
318
+ * select : library > Tasks > other > bundleReleaseJavadoc
319
+ * this generates the javadoc: ` library/build/outputs/library-javadoc.jar `
320
+
321
+
322
+ ### to tag a release on Github
323
+
324
+ * ensure that all your changes are on master and that your local build is on master
325
+ * ensure that the correct version number is in both ` library/build.gradle ` and ` library/pom.xml `
326
+
265
327
266
- ### to build/ deploy
328
+ ### to deploy a release to Maven Central
267
329
268
330
* log onto the build box
269
331
* checkout and update the master branch
0 commit comments