Coder Social home page Coder Social logo

shanbit200 / kotfirebase Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raipankaj/kotfirebase

0.0 0.0 0.0 200 KB

A wrapper over existing firebase APIs to reduce the developer effort while using them

License: Apache License 2.0

Kotlin 100.00%

kotfirebase's Introduction

kotfirebase

A wrapper over existing firebase APIs to reduce the developer effort in using them, currently it supports APIs for cloud firestore, cloud storage and firebase analytics

The objective of this library is to bring down APIs to a single line of code by using the kotlin features, under the hood everything remains same it's just a matter of fact that developer need not have to worry about them.

Following are the steps to add kotfirebase to your android project

  1. Add it in your root build.gradle at the end of repositories
allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}
  1. Add the dependency
dependencies {
	implementation 'com.github.raipankaj:kotfirebase:1.0.0'
}

Cloud Firestore

Here are the ways to use cloud firestore APIs
//Get single time result
val documentsLiveData: LiveData<DocumentResult> =
Firestore.getFromDocument("collectionId/documentId")
        //or
//Get realtime result
val documentsRealtimeLiveData: LiveData<DocumentResult> =
Firestore.getFromDocument("collectionId/documentId", true)

//Get the document data to the model class
val modelFormedLiveData: LiveData<Any> = Firestore.getDocumentResultsIn<Any>("collectionId/documentId")
        //or
//Get the document data to the model class in realtime
val modelFormedRealtimeLiveData: LiveData<Any> = Firestore.getDocumentResultsIn<Any>("collectionId/documentId", true)

//Get the documents in collection
val collectionLiveData: LiveData<CollectionResult> = Firestore.getFromCollection("collectionId")
        //or
//Get the collection with realtime listener attached to it
val collectionRealtimeLiveData: LiveData<CollectionResult> = Firestore.getFromCollection("collectionId", true)

//Write data to collection
val addToCollection: LiveData<CollectionWrite> = Firestore.addToCollection("collectionId", mapOf("one" to 1, "two" to 2))

//Write data to document
val addToDocument: LiveData<DocumentWrite> = Firestore.addToDocument("collectionId/documentId", mapOf("one" to 1, "two" to 2))

//Using kotlin extension on string for single time result
val documentsKtxLiveData: LiveData<DocumentResult> = "collectionId/documentId".getFirebaseDocuments()

//Using kotlin extension on string for realtime result
val documentsKtxRealtimeLiveData: LiveData<DocumentResult> = "collectionId/documentId".getFirebaseDocuments(true)
        //or
//Get the document data to the model class
val modelFormedKtxLiveData: LiveData<Any> = "collectionId/documentId".getFirebaseDocumentsIn<Any>()

//Get the document data to the model class in realtime
val modelFormedKtxRealtimeLiveData: LiveData<Any> = "collectionId/documentId".getFirebaseDocumentsIn<Any>(true)

//Get documents in the collection using ktx
val collectionKtxLiveData: LiveData<CollectionResult> = "collectionId".getFirebaseCollection()
        //or
//Listen for the realtime update
val collectionRealtimeKtxLiveData: LiveData<CollectionResult> = "collectionId".getFirebaseCollection(true)
 

Cloud Storage

Here are the ways to use cloud storage APIs
//Upload file by providing file name, storage path and file path
val uploadFileLiveData: LiveData<StorageResult> = Storage.uploadFile("myimage.jpg","storagePath", "filePath")

//Upload file stream by providing file name, storage path and file path
val uploadFileStreamLiveData: LiveData<StorageResult> = Storage.uploadFileStream("myimage.jpg","storagePath", "filePath")

//Upload bitmap by providing file name, storage path and bitmap
val uploadBitmapLiveData: LiveData<StorageResult> = Storage.uploadBitmap("myimage.jpg","storagePath", bitmap)

//Get the download url for the multimedia
val getDownloadUrlLiveData: LiveData<StorageDownloadResult> = Storage.getDownloadUrl("myimage.jpg", "storagePath")

//Download into another file
val downloadFileLiveData: LiveData<StorageDownloadResult> = Storage.downloadFile("myimage.jpg", "storagePath", file)

//Download file into local memory
val ONE_MEGABYTE: Long = 1024 * 1024
val downloadTempStorageLiveData: LiveData<StorageDownloadResult> = Storage.downloadInMemory("myimage.jpg", "storagePath", ONE_MEGABYTE)

Firebase Analytics

Here are the ways to add events
//Log event to firebase by providing bundle
logBundledEvent("eventName") {
	putString("name", "xyz")
	putString("info", "test")
	}

//log event to firebase without bundle
logEvent("eventName")

Remote Config

Update app behaviour without updating app on playstore using the remote config
//Initiate the remote config to provide the default value and to change other params
RemoteConfig.initRemoteConfig(R.xml.remote_config_defaults)

//Fetch and activate to update the remote config values in realtime
val isFetchedLiveData: LiveData<RemoteConfigResult> = RemoteConfig.fetchAndShow()

//Just fetch but do not update the remote config values
RemoteConfig.justFetch()

//Activate the fetched result so as to get latest remote config values
val isFetchedResultActivated: LiveData<RemoteConfigResult> = RemoteConfig.activateFetchedResults()

//Get the value from remote config using these predefined methods
RemoteConfig.getRemoteBoolean("is_update_available")
RemoteConfig.getRemoteDouble("current_version")
RemoteConfig.getRemoteLong("last_updated_timestamp")
RemoteConfig.getRemoteString("app_theme_name")

kotfirebase's People

Contributors

raipankaj 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.