Skip to content

Puf 0.2.0 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 65 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ We can now use that in our activity to allow sending a message:
Firebase.setAndroidContext(this);
Firebase ref = new Firebase("https://nanochat.firebaseio.com");

mAdapter = new FirebaseListAdapter<ChatMessage>(ChatMessage.class, android.R.layout.two_line_list_item, this, ref) {
mAdapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, ref) {
@Override
protected void populateView(View view, ChatMessage chatMessage) {
((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
Expand All @@ -218,6 +218,54 @@ We can now use that in our activity to allow sending a message:

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

## Using a RecyclerView

RecyclerView is the new preferred way to handle potentially long lists of items. Since Firebase collections
can contain many items, there is an `FirebaseRecyclerViewAdapter` too. Here's how you use it:

1. Create a custom ViewHolder class
2. Create a custom subclass FirebaseListAdapter

The rest of the steps is the same as for the `FirebaseListAdapter` above, so be sure to read that first.

### Create a custom ViewHolder

A ViewHolder is similar to container of a ViewGroup that allows simple lookup of the sub-views of the group.
If we use the same layout as before (`android.R.layout.two_line_list_item`), there are two `TextView`s in there.
We can wrap that in a ViewHolder with:

private static class ChatMessageViewHolder extends RecyclerView.ViewHolder {
TextView messageText;
TextView nameText;

public ChatMessageViewHolder(View itemView) {
super(itemView);
nameText = (TextView)itemView.findViewById(android.R.id.text1);
messageText = (TextView) itemView.findViewById(android.R.id.text2);
}
}

There's nothing magical going on here; we're just mapping numeric IDs and casts into a nice, type-safe contract.

### Create a custom FirebaseListAdapter

Just like we did for FirebaseListAdapter, we'll create an anonymous subclass for our ChatMessages:

RecyclerView recycler = (RecyclerView) findViewById(R.id.messages_recycler);
recycler.setHasFixedSize(true);
recycler.setLayoutManager(new LinearLayoutManager(this));

mAdapter = new FirebaseRecyclerViewAdapter<ChatMessage, ChatMessageViewHolder>(ChatMessage.class, android.R.layout.two_line_list_item, ChatMessageViewHolder.class, mRef) {
@Override
public void populateViewHolder(ChatMessageViewHolder chatMessageViewHolder, ChatMessage chatMessage) {
chatMessageViewHolder.nameText.setText(chatMessage.getName());
chatMessageViewHolder.messageText.setText(chatMessage.getMessage());
}
};
recycler.setAdapter(mAdapter);

Like before, we get a custom RecyclerView populated with data from Firebase by setting the properties to the correct fields.

## Installing locally

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

## Deployment

### To get the build server ready to build/deploy FirebaseUI-Android
### To get the build server ready to build FirebaseUI-Android

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

### to build a release

* build the project in Android Studio or with Gradle
* this generates the main binary: `library/build/outputs/aar/library-debug.aar`
* open the Gradle projects tab, by clicking the tiny gradle tab on the right (or View > Tool Windows > Gradle)
* select :library > Tasks > other > bundleReleaseJavadoc
* this generates the javadoc: `library/build/outputs/library-javadoc.jar`


### to tag a release on Github

* ensure that all your changes are on master and that your local build is on master
* ensure that the correct version number is in both `library/build.gradle` and `library/pom.xml`


### to build/deploy
### to deploy a release to Maven Central

* log onto the build box
* checkout and update the master branch
Expand Down
86 changes: 15 additions & 71 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,90 +8,34 @@ android {
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "0.1.0"
versionName "0.2.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
//android.libraryVariants.all { variant ->
// task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
// description "Generates Javadoc for $variant.name."
// source = variant.javaCompile.source
// ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
// classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
// options.links("http://docs.oracle.com/javase/7/docs/api/");
// options.links("http://d.android.com/reference/");
// }
//}

apply plugin: 'maven'
apply plugin: 'signing'

version = "0.1.0"
group = "com.firebase"

configurations {
archives {
extendsFrom configurations.default
android.libraryVariants.all { variant ->
task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {
description "Generates Javadoc for $variant.name."
source = variant.javaCompile.source
ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar)
options.links("http://docs.oracle.com/javase/7/docs/api/");
options.links("http://d.android.com/reference/");
}
}

signing {
required { has("release") && gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}

uploadArchives {
configuration = configurations.archives
repositories.mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

repository(url: sonatypeRepo) {
authentication(userName: sonatypeUsername,
password: sonatypePassword)
}

pom.project {
name 'FirebaseUI'
packaging 'aar'
description 'FirebaseUI library for Android applications'
url 'https://github.com/firebase/FirebaseUI-Android'

scm {
url 'scm:[email protected]/firebase/FirebaseUI-Android'
connection 'scm:git:[email protected]:firebase/FirebaseUI-Android.git'
developerConnection 'scm:git:[email protected]:firebase/FirebaseUI-Android.git'
}

organization {
name 'Firebase'
url 'https://www.firebase.com/'
}

licenses {
license {
name 'MIT'
url 'http://firebase.mit-license.org'
}
}

developers {
developer {
id 'puf'
name 'Frank van Puffelen'
email '[email protected]'
}
}
}
task("bundle${variant.name.capitalize()}Javadoc", type: Jar) {
description "Bundles Javadoc into zip for $variant.name."
classifier = "javadoc"
destinationDir = file("build/outputs")
from tasks["generate${variant.name.capitalize()}Javadoc"]
}
}

Expand Down
4 changes: 2 additions & 2 deletions library/library.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -65,6 +65,7 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand All @@ -86,7 +87,6 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
Expand Down
17 changes: 16 additions & 1 deletion library/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<name>FirebaseUI-Android</name>
<description>FirebaseUI library for Android applications</description>
<url>https://github.com/firebase/FirebaseUI-Android</url>
<version>0.1.0</version>
<version>0.2.0</version>
<packaging>aar</packaging>
<scm>
<url>scm:[email protected]/firebase/FirebaseUI-Android</url>
Expand All @@ -26,4 +26,19 @@
<email>[email protected]</email>
</developer>
</developers>
<build>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.1.0</version>
<extensions>true</extensions>
<configuration>
<sign>
<debug>false</debug>
</sign>
</configuration>
</plugin>
</plugins>
</build>
</project>
15 changes: 15 additions & 0 deletions library/src/main/java/com/firebase/ui/FirebaseListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@
* instance of your list item mLayout and an instance your class that holds your data. Simply populate the view however
* you like and this class will handle updating the list as the data changes.
*
* <blockquote><pre>
* {@code
* Firebase ref = new Firebase("https://<yourapp>.firebaseio.com");
* ListAdapter adapter = new FirebaseListAdapter<ChatMessage>(this, ChatMessage.class, android.R.layout.two_line_list_item, mRef)
* {
* protected void populateView(View view, ChatMessage chatMessage)
* {
* ((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
* ((TextView)view.findViewById(android.R.id.text2)).setText(chatMessage.getMessage());
* }
* };
* listView.setListAdapter(adapter);
* }
* </pre></blockquote>
*
* @param <T> The class type to use as a model for the data contained in the children of the given Firebase location
*/
public abstract class FirebaseListAdapter<T> extends BaseAdapter {
Expand Down
Loading