-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from horaciocome1/docs
formatting
- Loading branch information
Showing
1 changed file
with
41 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,67 @@ | ||
# fireflow | ||
[![](https://jitpack.io/v/horaciocome1/fireflow.svg)](https://jitpack.io/#horaciocome1/fireflow) [![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![API](https://img.shields.io/badge/API-19%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=19) | ||
[![](https://jitpack.io/v/horaciocome1/fireflow.svg)](https://jitpack.io/#horaciocome1/fireflow) . [![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![API](https://img.shields.io/badge/API-19%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=19) | ||
|
||
## Getting Started | ||
Android library that aims to hide Firebase Firestore listener implementation and expose only a Kotlin Flow of specified type. ;) | ||
Android library that aims to hide Firebase Firestore listener implementation and expose only a Kotlin Flow of specified type. ;) | ||
Works for ColletionReferences, Queries, and DocumentReferences. | ||
|
||
## Pre-requisites | ||
Check the pre-requisites for Firebase Firestore and for Kotlin Flow on respective documentation. | ||
Be familiar with Kotlin Coroutines. | ||
Check the pre-requisites for Firebase Firestore and for Kotlin Flow on respective documentation. | ||
Be familiar with Kotlin Coroutines. | ||
Based on versions **23.0.1** and **1.4.1** of _firebase-firestore-ktx_ and _kotlinx-coroutines-play-services_ respectively | ||
|
||
## Adding to your project | ||
Lets start by adding a corresponding repository in your _root_ `build.gradle` file. | ||
```gradle | ||
allprojects { | ||
repositories { | ||
... | ||
maven { url 'https://jitpack.io' } | ||
} | ||
allprojects { | ||
repositories { | ||
... | ||
maven { url 'https://jitpack.io' } | ||
} | ||
} | ||
``` | ||
The next task is to add the dependency to your _app_ `build.gradle` file. | ||
```gradle | ||
dependencies { | ||
... | ||
implementation 'com.github.horaciocome1:fireflow:0.0.1' | ||
} | ||
dependencies { | ||
... | ||
implementation 'com.github.horaciocome1:fireflow:0.0.1' | ||
} | ||
``` | ||
Now you ready to go. You might want to _**sync your project**_ first. ;) | ||
Now you ready to go. | ||
You might want to _**sync your project**_ first. ;) | ||
|
||
## How to use | ||
### without fireflow | ||
```kotlin | ||
val db = FirebaseFirestore.getInstance() | ||
val ref = db.collection("posts") | ||
ref.addSnapshotListener { snapshot, error -> | ||
if (error != null) { | ||
// handle | ||
} else if (snapshot != null) { | ||
val posts = snapshot.toObjects(Post::class.java) | ||
// set posts to UI | ||
} | ||
val db = FirebaseFirestore.getInstance() | ||
val ref = db.collection("posts") | ||
ref.addSnapshotListener { snapshot, error -> | ||
if (error != null) { | ||
// handle | ||
} else if (snapshot != null) { | ||
val posts = snapshot.toObjects(Post::class.java) | ||
// set posts to UI | ||
} | ||
} | ||
``` | ||
### with fireflow | ||
```kotlin | ||
val db = FirebaseFirestore.getInstance() | ||
db.collection("posts").getAsFlow<Post>().collect { posts -> | ||
// set posts to UI | ||
} | ||
val db = FirebaseFirestore.getInstance() | ||
db.collection("posts").getAsFlow<Post>().collect { posts -> | ||
// set posts to UI | ||
} | ||
``` | ||
You can also read documents as flows | ||
```kotlin | ||
val db = FirebaseFirestore.getInstance() | ||
db.collection("posts").document("1") | ||
.getAsFlow<Post>().collect { post -> | ||
// set post to UI | ||
} | ||
val db = FirebaseFirestore.getInstance() | ||
db.collection("posts").document("1") | ||
.getAsFlow<Post>().collect { post -> | ||
// set post to UI | ||
} | ||
``` | ||
|
||
## Troubleshooting | ||
There is no Java support. | ||
There is no Java support. | ||
For other things please open an Issue or reach me via [[email protected]](mailto:[email protected]) | ||
|
||
## Licenses | ||
|
@@ -78,14 +79,15 @@ For other things please open an Issue or reach me via [[email protected]](mailto:hcome | |
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
### Not maintained by us | ||
Firebase Firestore is a product of Google. | ||
Kotlin is a product of Jetbrains. | ||
[Firebase Firestore](https://firebase.google.com/docs/firestore/) is a product from Google. | ||
[Kotlin](https://kotlinlang.org/) is a product from Jetbrains. | ||
|
||
## How to contribute | ||
We open to suggestions of any kind. | ||
Email me, open pull requests, etc. | ||
|
||
## Less Boilerplate Utils | ||
If you want to see another utility please check my work on Recyclerview. | ||
[Simple RecyclerView Listener](https://github.com/horaciocome1/simple-recyclerview-listener) | ||
[Simple RecyclerView Adapter](https://github.com/horaciocome1/simple-recyclerview-adapter) | ||
## More | ||
Hope you development experience gets smootherrrrr. | ||
If you want to see another utility please check my work on Recyclerview. | ||
[Simple RecyclerView Listener](https://github.com/horaciocome1/simple-recyclerview-listener) | ||
[Simple RecyclerView Adapter](https://github.com/horaciocome1/simple-recyclerview-adapter) |