Skip to content

Commit 195f7fb

Browse files
committed
Merge pull request #4 from firebase/puf-0.2.0
Puf 0.2.0
2 parents 7c58f2a + c6cf930 commit 195f7fb

File tree

7 files changed

+205
-105
lines changed

7 files changed

+205
-105
lines changed

README.md

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ We can now use that in our activity to allow sending a message:
191191
Firebase.setAndroidContext(this);
192192
Firebase ref = new Firebase("https://nanochat.firebaseio.com");
193193

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) {
195195
@Override
196196
protected void populateView(View view, ChatMessage chatMessage) {
197197
((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:
218218

219219
Et voila: a minimal, yet fully functional, chat app in about 30 lines of code. Not bad, right?
220220

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+
221269
## Installing locally
222270

223271
We are still working on deploying FirebaseUI to Maven Central. In the meantime, you can download the
@@ -229,7 +277,7 @@ with:
229277

230278
## Deployment
231279

232-
### To get the build server ready to build/deploy FirebaseUI-Android
280+
### To get the build server ready to build FirebaseUI-Android
233281

234282
* Install a JDK (if it's not installed yet):
235283
* `sudo apt-get install default-jdk`
@@ -262,8 +310,22 @@ with:
262310
sonatypeUsername=YourSonatypeJiraUsername
263311
sonatypePassword=YourSonatypeJiraPassword
264312

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+
265327

266-
### to build/deploy
328+
### to deploy a release to Maven Central
267329

268330
* log onto the build box
269331
* checkout and update the master branch

library/build.gradle

Lines changed: 15 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -8,90 +8,34 @@ android {
88
minSdkVersion 10
99
targetSdkVersion 22
1010
versionCode 1
11-
versionName "0.1.0"
11+
versionName "0.2.0"
1212
}
1313
buildTypes {
1414
release {
1515
minifyEnabled false
1616
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17-
}
17+
}
1818
}
1919
packagingOptions {
2020
exclude 'META-INF/LICENSE'
2121
exclude 'META-INF/LICENSE-FIREBASE.txt'
2222
exclude 'META-INF/NOTICE'
2323
}
2424
}
25-
//android.libraryVariants.all { variant ->
26-
// task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
27-
// description "Generates Javadoc for $variant.name."
28-
// source = variant.javaCompile.source
29-
// ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
30-
// classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
31-
// options.links("http://docs.oracle.com/javase/7/docs/api/");
32-
// options.links("http://d.android.com/reference/");
33-
// }
34-
//}
35-
36-
apply plugin: 'maven'
37-
apply plugin: 'signing'
38-
39-
version = "0.1.0"
40-
group = "com.firebase"
41-
42-
configurations {
43-
archives {
44-
extendsFrom configurations.default
25+
android.libraryVariants.all { variant ->
26+
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
27+
description "Generates Javadoc for $variant.name."
28+
source = variant.javaCompile.source
29+
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
30+
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
31+
options.links("http://docs.oracle.com/javase/7/docs/api/");
32+
options.links("http://d.android.com/reference/");
4533
}
46-
}
47-
48-
signing {
49-
required { has("release") && gradle.taskGraph.hasTask("uploadArchives") }
50-
sign configurations.archives
51-
}
52-
53-
uploadArchives {
54-
configuration = configurations.archives
55-
repositories.mavenDeployer {
56-
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
57-
58-
repository(url: sonatypeRepo) {
59-
authentication(userName: sonatypeUsername,
60-
password: sonatypePassword)
61-
}
62-
63-
pom.project {
64-
name 'FirebaseUI'
65-
packaging 'aar'
66-
description 'FirebaseUI library for Android applications'
67-
url 'https://github.com/firebase/FirebaseUI-Android'
68-
69-
scm {
70-
url 'scm:git@github.com/firebase/FirebaseUI-Android'
71-
connection 'scm:git:git@github.com:firebase/FirebaseUI-Android.git'
72-
developerConnection 'scm:git:git@github.com:firebase/FirebaseUI-Android.git'
73-
}
74-
75-
organization {
76-
name 'Firebase'
77-
url 'https://www.firebase.com/'
78-
}
79-
80-
licenses {
81-
license {
82-
name 'MIT'
83-
url 'http://firebase.mit-license.org'
84-
}
85-
}
86-
87-
developers {
88-
developer {
89-
id 'puf'
90-
name 'Frank van Puffelen'
91-
email 'puf@google.com'
92-
}
93-
}
94-
}
34+
task("bundle${variant.name.capitalize()}Javadoc", type: Jar) {
35+
description "Bundles Javadoc into zip for $variant.name."
36+
classifier = "javadoc"
37+
destinationDir = file("build/outputs")
38+
from tasks["generate${variant.name.capitalize()}Javadoc"]
9539
}
9640
}
9741

library/library.iml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="com.firebase" external.system.module.version="0.1.0" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":library" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="FirebaseUI-Android" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -65,6 +65,7 @@
6565
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
6666
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
6767
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
68+
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
6869
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
6970
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
7071
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
@@ -86,7 +87,6 @@
8687
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
8788
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
8889
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
89-
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
9090
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
9191
</content>
9292
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />

library/pom.xml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<name>FirebaseUI-Android</name>
77
<description>FirebaseUI library for Android applications</description>
88
<url>https://github.com/firebase/FirebaseUI-Android</url>
9-
<version>0.1.0</version>
9+
<version>0.2.0</version>
1010
<packaging>aar</packaging>
1111
<scm>
1212
<url>scm:git@github.com/firebase/FirebaseUI-Android</url>
@@ -26,4 +26,19 @@
2626
<email>puf@google.com</email>
2727
</developer>
2828
</developers>
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<groupId>com.simpligility.maven.plugins</groupId>
33+
<artifactId>android-maven-plugin</artifactId>
34+
<version>4.1.0</version>
35+
<extensions>true</extensions>
36+
<configuration>
37+
<sign>
38+
<debug>false</debug>
39+
</sign>
40+
</configuration>
41+
</plugin>
42+
</plugins>
43+
</build>
2944
</project>

library/src/main/java/com/firebase/ui/FirebaseListAdapter.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@
4343
* instance of your list item mLayout and an instance your class that holds your data. Simply populate the view however
4444
* you like and this class will handle updating the list as the data changes.
4545
*
46+
* <blockquote><pre>
47+
* {@code
48+
* Firebase ref = new Firebase("https://<yourapp>.firebaseio.com");
49+
* ListAdapter adapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, mRef)
50+
* {
51+
* protected void populateView(View view, ChatMessage chatMessage)
52+
* {
53+
* ((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
54+
* ((TextView)view.findViewById(android.R.id.text2)).setText(chatMessage.getMessage());
55+
* }
56+
* };
57+
* listView.setListAdapter(adapter);
58+
* }
59+
* </pre></blockquote>
60+
*
4661
* @param <T> The class type to use as a model for the data contained in the children of the given Firebase location
4762
*/
4863
public abstract class FirebaseListAdapter<T> extends BaseAdapter {

0 commit comments

Comments
 (0)