Coder Social home page Coder Social logo

edngulele / firextensions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from thatfiredev/firextensions

0.0 2.0 0.0 202 KB

Kotlin Extensions to simplify the way you use Firebase on Android.

Home Page: https://firebaseopensource.com/projects/rosariopfernandes/firextensions/

License: MIT License

Kotlin 95.49% Java 4.51%

firextensions's Introduction

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'
    }

Contributing

When contributing to this repository, please first discuss the change you wish to make, via issue, with the owners of this repository before making a change.

License

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

Acknowledgments

firextensions's People

Contributors

thatfiredev avatar

Watchers

James Cloos avatar Edilson Ngulele avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.