Skip to content
This repository has been archived by the owner. It is now read-only.
[DEPRECATED] Unofficial Kotlin Extensions for the Firebase Android SDK.
Kotlin
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.idea docs: add links to reference docs Oct 10, 2018
.opensource docs: add links to reference docs Oct 10, 2018
app chore: update dependencies Aug 30, 2018
database
docs docs: update docs/README.md Oct 9, 2018
firestore feat: create the reference docs Oct 8, 2018
gradle/wrapper Initial commit Jul 10, 2018
tutorials
.gitignore Initial commit Jul 10, 2018
CONTRIBUTING.md docs: Create Contributing Guidelines Sep 6, 2018
LICENSE.md
README.md style: fix README bold styling Sep 6, 2019
build.gradle
gradle.properties chore: Add Android X and Jetifier support Jul 11, 2018
gradlew Initial commit Jul 10, 2018
gradlew.bat
settings.gradle docs: update README Aug 30, 2018

README.md

FirebaseOpensource.com

fireXtensions [DEPRECATED]

THIS LIBRARY IS NOW DEPRECATED IN FAVOR OF THE OFFICIAL FIREBASE KTX LIBRARIES.

PLEASE NOTE THAT NOT ALL THE FIREXTENSIONS ARE PRESENT IN THE OFFICIAL KTX, THAT'S BECAUSE SOME FIREXTENSIONS WOULD CAUSE MEMORY LEAKS WHILE OTHER SIMPLY DID NOT ADD MUCH VALUE TO THE SDK. IF YOU FIND A FIREXTENSION WITH NO CORRESPONDING KTX, YOU'LL HAVE TO STICK TO THE OFFICIAL KOTLIN USAGE. APOLOGIES FOR THAT.

THANKS FOR EVERYONE WHO CONTRIBUTED, SUPPORTED OR USED FIREXTENSIONS!

Introduction

fireXtensions are a set of Kotlin extension functions that aim to simplify the way you use the Firebase SDK for Android.

Realtime Database

See all examples on the Tutorial.

Kotlin

ref.addValueEventListener(object: ValueEventListener {
    override fun onDataChange(dataSnapshot: DataSnapshot) {
        val data = dataSnapshot.getValue(String::class.java)
        //Update the UI with received data
    }

    override fun onCancelled(error: DatabaseError) {
        //print error.message
    }
})

fireXtensions

ref.observe<DataSnapshot> { dataSnapshot, _ ->
    dataSnapshot?.let {
        val data = dataSnapshot.getValue(String::class.java)
        //Update the UI with received data
    }
}

Kotlin

ref.addValueEventListener(object: ValueEventListener {
    override fun onDataChange(dataSnapshot: DataSnapshot) {
        val todo = dataSnapshot.getValue(Todo::class.java)
        //Update the UI with received data
    }

    override fun onCancelled(error: DatabaseError) {
        //print error.message
    }
})

fireXtensions

ref.observe<Todo> { todo, _ ->
    todo?.let {
        //Update the UI with received data
    }
}

Kotlin

ref.addValueEventListener(object: ValueEventListener {
    override fun onDataChange(dataSnapshot: DataSnapshot) {
        val todos = ArrayList<Todo>()
        for (snapshot in dataSnapshot.children) {
            val todo = dataSnapshot.getValue(Todo::class.java)
            todos.add(todo!!)
        }
        //Update the UI with received list
    }

    override fun onCancelled(error: DatabaseError) {
        //print error.message
    }
})

fireXtensions

ref.observeChildren<Todo> { todos, error ->
    todos?.let {
        //Update the UI with received list
    }
    error.let {
        //print error.message
    }
}

More can be found on the Tutorial.


Cloud Firestore

See all examples on the Tutorial.

Kotlin

val docRef = db.collection("cities").document("SF")
// Source can be CACHE, SERVER or DEFAULT
docRef.get(Source.CACHE).addOnCompleteListener { task ->
    if (task.isSuccessful()) {
        val document = task.result
        if (document.exists()) {
            Log.d(TAG, "DocumentSnapshot data: " + document.data)
        } else {
            Log.d(TAG, "No such document")
        }
    } else {
        Log.d(TAG, "get failed with ", task.exception)
    }
}

fireXtensions

// Source can be CACHE, SERVER or DEFAULT
docRef.getDocument<DocumentSnapshot>(Source.CACHE) { document, exception ->
    document?.let {
        Log.d(TAG, "DocumentSnapshot data: " + document.data)
    }
    exception?.let {
        Log.d(TAG, "get failed with ", exception)
    }
}

Kotlin

val docRef = db.collection("cities").document("BJ")
docRef.get().addOnCompleteListener { task ->
    if (task.isSuccessful()) {
        val city = task.result.toObject(City::class.java)
        //Update UI with city
    }
}

fireXtensions

docRef.getDocument<City>() { city, _ ->
    city?.let {
        //update UI with city
    }
}

More can be found on the Tutorial.

Getting Started

Step 1 - Add the jitpack maven in your root build.gradle at the end of repositories:

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

Step 2 - Add one of the dependencies to your app's build.gradle:

    dependencies {
        // You can either import the whole library
        implementation 'com.github.rosariopfernandes:fireXtensions:0.3.4'

        // or import database extensions only
        implementation 'com.github.rosariopfernandes.fireXtensions:database:0.3.4'

        // or import firestore extensions only
        implementation 'com.github.rosariopfernandes.fireXtensions:firestore:0.3.4'
    }

Reference Docs: rosariopfernandes.me/fireXtensions

Contributing

Anyone and everyone is welcome to contribute. Please take a moment to review the contributing guidelines.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

You can’t perform that action at this time.