Skip to content

Commit 0fe76da

Browse files
committed
Will migrate old Firebase to Google Firebase library
We migrated the codebase to new Firebase and re-think the design Issue: #5
1 parent 120c513 commit 0fe76da

32 files changed

+862
-529
lines changed

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ Contents
1717

1818
Usage
1919
-----
20+
#### Use the project with your own Firebase instance
21+
22+
1. Clone this repository.
23+
- Create a new project in the [Firebase console](https://console.firebase.google.com/).
24+
- Click *Add Firebase to your Android app*
25+
* provide a **unique package name**
26+
* use the same package name for the **applicationId** in your `build.gradle`
27+
* insert SHA-1 fingerprint of your debug certificate, otherwise you won't be able to log in
28+
- Copy the generated *google-services.json* to the `app` folder of your project which will replace the mock google services json file.
29+
- You should be able to successfully sync the project now.
30+
- Copy contents of the `./server/database.rules.json` into your *Firebase -> Database -> Rules* and publish them.
31+
- Import data `./server/sample-data.json` into your *Firebase -> Database*
32+
- Change the *Firebase URL path* in this [file](https://github.com/ezhome/Android-RxFirebase/blob/master/app/src/main/java/com/ezhome/rxfirebasedemo/PostsFragment.java#L30)
33+
- Build and run the app.
34+
35+
#### Example
2036

2137
```java
2238
final Firebase firebaseRef = new Firebase("https://docs-examples.firebaseio.com/web/saving-data/fireblog/posts");
@@ -49,7 +65,7 @@ Download
4965
The project is available on jCenter. In your app build.gradle (or explicit module) you must add this:
5066
```
5167
dependencies {
52-
compile 'com.ezhome:rxfirebase:1.0.0'
68+
compile 'com.ezhome:rxfirebase:2.0.0'
5369
}
5470
```
5571

app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ dependencies {
3232
//rxfirebase
3333
testCompile 'junit:junit:4.12'
3434
}
35+
apply plugin: 'com.google.gms.google-services'

app/google-services.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"project_info": {
3+
"project_id": "mockproject-1234",
4+
"project_number": "123456789000",
5+
"name": "FirebaseQuickstarts",
6+
"firebase_url": "https://mockproject-1234.firebaseio.com"
7+
},
8+
"client": [
9+
{
10+
"client_info": {
11+
"mobilesdk_app_id": "1:123456789000:android:f1bf012572b04063",
12+
"client_id": "android:com.ezhome.rxfirebasedemo",
13+
"client_type": 1,
14+
"android_client_info": {
15+
"package_name": "com.ezhome.rxfirebasedemo",
16+
"certificate_hash": []
17+
}
18+
},
19+
"api_key": [
20+
{
21+
"current_key": ""
22+
}
23+
]
24+
}
25+
],
26+
"client_info": [],
27+
"ARTIFACT_VERSION": "1"
28+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.ezhome.rxfirebasedemo;
22

33
import android.app.Application;
4-
import com.firebase.client.Firebase;
4+
import com.google.firebase.database.FirebaseDatabase;
55

66
/**
77
* Base application
@@ -10,6 +10,6 @@ public class BaseApplication extends Application {
1010

1111
@Override public void onCreate() {
1212
super.onCreate();
13-
Firebase.setAndroidContext(this);
13+
FirebaseDatabase.getInstance().setPersistenceEnabled(true);
1414
}
1515
}

app/src/main/java/com/ezhome/rxfirebasedemo/PostsFragment.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
import android.widget.Toast;
1313
import butterknife.BindView;
1414
import butterknife.ButterKnife;
15-
import com.ezhome.rxfirebase.RxFirebase;
15+
import com.ezhome.rxfirebase2.database.RxFirebaseDatabase;
1616
import com.ezhome.rxfirebasedemo.model.BlogPostEntity;
17-
import com.firebase.client.DataSnapshot;
18-
import com.firebase.client.Firebase;
17+
import com.google.firebase.database.DataSnapshot;
18+
import com.google.firebase.database.DatabaseReference;
19+
import com.google.firebase.database.FirebaseDatabase;
1920
import java.util.ArrayList;
2021
import java.util.Collections;
2122
import java.util.List;
@@ -27,8 +28,8 @@
2728
public class PostsFragment extends Fragment {
2829

2930
//For example purposes
30-
private final Firebase firebaseRef =
31-
new Firebase("https://docs-examples.firebaseio.com/web/saving-data/fireblog/posts");
31+
private final DatabaseReference firebaseRef = FirebaseDatabase.getInstance()
32+
.getReferenceFromUrl("https://<yourdomainname>.firebaseio.com/fireblog");
3233

3334
//Adapter
3435
private BlogPostsAdapter blogPostsAdapter;
@@ -66,7 +67,7 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
6667
*/
6768
private void loadPosts() {
6869
PostsFragment.this.showProgress(true);
69-
RxFirebase.getInstance().observeValueEvent(firebaseRef).subscribe(new GetPostsSubscriber());
70+
RxFirebaseDatabase.getInstance().observeValueEvent(firebaseRef).subscribe(new GetPostsSubscriber());
7071
}
7172

7273
/**
@@ -100,7 +101,7 @@ private void showError(String message) {
100101
}
101102

102103
/**
103-
* Subscriber for {@link com.ezhome.rxfirebase.RxFirebase} query
104+
* Subscriber for {@link RxFirebaseDatabase} query
104105
*/
105106
private final class GetPostsSubscriber extends Subscriber<DataSnapshot> {
106107
@Override public void onCompleted() {

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ buildscript {
55
dependencies {
66
classpath 'com.android.tools.build:gradle:2.1.2'
77
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
8+
classpath 'com.google.gms:google-services:3.0.0'
89

910
// NOTE: Do not place your application dependencies here; they belong
1011
// in the individual module build.gradle files

rxfirebase/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ dependencies {
5858
def libraryTestDependencies = project.ext.libraryTestDependencies
5959

6060
//Data
61-
compile libraryDependencies.firebase
61+
compile libraryDependencies.firebaseDatabase
62+
compile libraryDependencies.firebaseAuth
6263

6364
//Rx
6465
compile libraryDependencies.rxJava

rxfirebase/buildsystem/dependencies.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ ext {
66
androidBuildToolsVersion = '23.0.3'
77

88
//Firebase
9-
firebaseVersion = '2.5.2+'
9+
firebaseVersion = '9.4.0'
1010

1111
//RxJava
12-
rxJavaVersion = '1.1.7'
12+
rxJavaVersion = '1.1.9'
1313

1414
//Test
1515
jUnitVersion = '4.12'
@@ -18,7 +18,8 @@ ext {
1818
mockitoVersion = '1.9.5'
1919

2020
libraryDependencies = [
21-
firebase: "com.firebase:firebase-client-android:${firebaseVersion}",
21+
firebaseDatabase: "com.google.firebase:firebase-database:${firebaseVersion}",
22+
firebaseAuth: "com.google.firebase:firebase-auth:${firebaseVersion}",
2223
rxJava: "io.reactivex:rxjava:${rxJavaVersion}",
2324
]
2425

rxfirebase/src/androidTest/java/com/ezhome/rxfirebase/ApplicationTest.java renamed to rxfirebase/src/androidTest/java/com/ezhome/rxfirebase2/ApplicationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.ezhome.rxfirebase;
1+
package com.ezhome.rxfirebase2;
22

33
import android.app.Application;
44
import android.test.ApplicationTestCase;

0 commit comments

Comments
 (0)