SlideShare ist ein Scribd-Unternehmen logo
1 von 43
Downloaden Sie, um offline zu lesen
Android architecture
components with cloud firestore
Pankaj Rai
@raipankaj7
Agenda ● Android architecture components
● Firebase services
● Cloud firestore
● What’s new in firebase
What is AAC?
Android Jetpack
Accelerate app development
Eliminate boilerplate code
Build high quality apps
Android
Architecture
Component
● Design robust, testable and
maintainable apps
● Handle data persistence
● Reduce app development time
● Improve app quality
ViewModel ● Designed to store and manage UI-related
data with lifecycle awareness
● Live through the configuration changes
● Caution: ViewModel does not replace
onSaveInstanceState()
ViewModel
(cont)
LiveData ● Observable data holder class
● Respect lifecycle of app components, such
as activities, fragments or services
● Only notifies active observers about updates
● Inactive observers registered to watch
LiveData objects aren't notified about
changes
Crash due to stopped activity
Why
LiveData?
● No memory leaks
● No crashes due to stopped activities
● No more manual lifecycle handling
● Always up to date data
LiveData which publicly exposes setValue(T) and postValue(T) method
MutableLiveData<Boolean> userIdLiveData = new MutableLiveData()
userIdLiveData.setValue(true)
MutableLiveData
LiveData subclass which may observe other LiveData objects and react on
OnChanged events from them
LiveData liveData1 = ...;
LiveData liveData2 = ...;
MediatorLiveData liveDataMerger = new MediatorLiveData<>();
liveDataMerger.addSource(liveData1,value ->liveDataMerger.setValue(value));
liveDataMerger.addSource(liveData2,value ->liveDataMerger.setValue(value));
MediatorLiveData
Applies the given function on the main thread to each value emitted by
source LiveData and returns LiveData, which emits resulting values
LiveData userLiveData = ...
LiveData userName = Transformations.map(userLiveData, user -> {
return user.firstName + " " + user.lastName; // Returns String
}
)
Transformations.map
Reacts on changes of trigger LiveData, applies the given function to new
value of trigger LiveData and sets resulting LiveData as a "backing"
LiveData
MutableLiveData userIdLiveData = ...
LiveData userLiveData = Transformations.switchMap(userIdLiveData, id ->
repository.getUserById(id) // Returns LiveData
)
void setUserId(String userId) { this.userIdLiveData.setValue(userId) }
Transformations.switchMap
Firebase
A comprehensive app development platform
Why
Firebase?
● Available for Android, iOS and Web
● Reduce time for app development
● All in one platform to build app or website
● Helps to grow your business
● Auto scale your app to support billions of users
2M28 days active apps
Cloud Firestore
● It’s NoSQL document database for mobile and web
app development
● Cloud Firestore also offers seamless integration
with other Firebase and Google Cloud Platform
products, including Cloud Functions
● It keeps your data in sync across client apps
through real-time listeners and offers offline support
for mobile and web
Why cloud
firestore?
● Documents and collections structure with powerful
querying capability
● Automatic multi-region data replication with strong
consistency
● Real-time data synchronization
● Android, iOS and Web SDKs with offline data
access
Key
capabilities
Collections are like a container which itself do not
store any data but contains document which in
turn stores data
Collection
It’s the smallest unit to store data in the database
more set of data type are now supported with
document
Document
Write to database
// Create a new user with a first and last name
val user = HashMap<String, Any>()
user["first"] = "Ada"
user["last"] = "Lovelace"
user["born"] = 1815
// Add a new document with a generated ID
db.collection("users")
.add(user)
.addOnSuccessListener { documentReference ->
Log.d(TAG, "DocumentSnapshot added with ID: ${documentReference.id}")
}
.addOnFailureListener { e ->
Log.w(TAG, "Error adding document", e)
}
val city = HashMap<String, Any>()
city["name"] = "Los Angeles"
city["state"] = "CA"
city["country"] = "USA"
db.collection("cities").document("LA")
.set(city) or set(data, SetOptions.merge())
.addOnSuccessListener { Log.d(TAG, "DocumentSnapshot
successfully written!") }
.addOnFailureListener { e -> Log.w(TAG, "Error writing document", e) }
Read from database
db.collection("users")
.get()
.addOnSuccessListener { result ->
for (document in result) {
Log.d(TAG, "${document.id} => ${document.data}")
}
}
.addOnFailureListener { exception ->
Log.w(TAG, "Error getting documents.", exception)
}
db.collection("cities")
.whereEqualTo("capital", true)
.get()
.addOnSuccessListener { documents ->
for (document in documents) {
Log.d(TAG, "${document.id} => ${document.data}")
}
}
.addOnFailureListener { exception ->
Log.w(TAG, "Error getting documents: ", exception)
}
FirebaseFirestore.getInstance().collection("sd").whereEqualTo("state","ca").addSnapshotListener(this) { snapshot,
e ->
if (e != null) {
Log.w(TAG, "listen:error", e)
return@EventListener
}
for (dc in snapshots.documentChanges) {
when (dc.type) {
DocumentChange.Type.ADDED -> Log.d(TAG, "New city: ${dc.document.data}")
DocumentChange.Type.MODIFIED -> Log.d(TAG, "Modified city: ${dc.document.data}")
DocumentChange.Type.REMOVED -> Log.d(TAG, "Removed city: ${dc.document.data}")
}
}
}
Combined with AAC
object NetworkRepository {
fun registerAttendee(map: Map<String, Any?>): LiveData<Boolean> {
val mutableLiveData = MutableLiveData<Boolean>()
FirebaseFirestore.getInstance().collection(AppConstant.ATTENDEES)
.document(map.getValue(AppConstant.ATTENDEE_EMAIL).toString())
.set(map)
.addOnCompleteListener{
mutableLiveData.value = it.isSuccessful
}
return mutableLiveData
}
}
class AttendeesViewModel: ViewModel() {
private val _registerAttendee = MutableLiveData<Map<String, Any?>>()
val registerAttendee = _registerAttendee.switchMap {
NetworkRepository.registerAttendee(it)
}
fun setRegAttendeeInfo(map: Map<String, Any?>) {
_registerAttendee.value = map
}
}
val attendeesDetails = mapOf(
AppConstant.ATTENDEE_EMAIL to mAttendeeEmail,
AppConstant.TIMESTAMP to FieldValue.serverTimestamp()
)
//Send the attendees details to firestore
mAttendeesViewModel.setRegAttendeeInfo(attendeesDetails)
//Observe the result from firestore
mAttendeesViewModel.registerAttendee.observe(this, Observer {
...
...
})
What’s new in Firebase?
● Analytics for web
● FCM for web
● Remote config for web
● Firebase Extensions
● Firebase App Distributions
Firebase
Extensions
Firebase
App
Distribution
● It makes distributing your apps to trusted testers
easy
● Get stability metrics for all your builds
● Distribute builds using the Firebase console, the
Firebase Command Line Interface (CLI) tool or
Gradle (Android)
How to
distribute
app?
● Upload the APK or IPA to App Distribution using the
Firebase console, Gradle, or the CLI tools
● Add the testers you want to try your app. Testers will
receive an email that walks them through the
onboarding process
● When new build is ready for testing, just upload it to
App Distribution. Your testers will be notified that a
new build is available to try out
Thank You
Pankaj Rai
https://twitter.com/raipankaj7

Weitere ähnliche Inhalte

Was ist angesagt?

SF big Analytics : Stream all things by Gwen Shapira @ Lyft 2018
SF big Analytics : Stream all things by Gwen Shapira @ Lyft 2018SF big Analytics : Stream all things by Gwen Shapira @ Lyft 2018
SF big Analytics : Stream all things by Gwen Shapira @ Lyft 2018
Chester Chen
 
Kliq planflyer
Kliq planflyerKliq planflyer
Kliq planflyer
CL0905
 

Was ist angesagt? (20)

A practical approach for naming elements in Adobe Launch
A practical approach for naming elements in Adobe LaunchA practical approach for naming elements in Adobe Launch
A practical approach for naming elements in Adobe Launch
 
CData Power BI Connectors
CData Power BI ConnectorsCData Power BI Connectors
CData Power BI Connectors
 
Azure Data Factory Data Flow
Azure Data Factory Data FlowAzure Data Factory Data Flow
Azure Data Factory Data Flow
 
Data Modeling and Relational to NoSQL
Data Modeling and Relational to NoSQLData Modeling and Relational to NoSQL
Data Modeling and Relational to NoSQL
 
Feature store Overview St. Louis Big Data IDEA Meetup aug 2020
Feature store Overview   St. Louis Big Data IDEA Meetup aug 2020Feature store Overview   St. Louis Big Data IDEA Meetup aug 2020
Feature store Overview St. Louis Big Data IDEA Meetup aug 2020
 
AIC x PyLadies TW Python Data Vis - 3: Dashboard
AIC x PyLadies TW Python Data Vis - 3: DashboardAIC x PyLadies TW Python Data Vis - 3: Dashboard
AIC x PyLadies TW Python Data Vis - 3: Dashboard
 
ASP.Net 3.5 SP1 Dynamic Data
ASP.Net 3.5 SP1 Dynamic DataASP.Net 3.5 SP1 Dynamic Data
ASP.Net 3.5 SP1 Dynamic Data
 
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)Performant APIs with GraphQL and PHP (Dutch PHP 2019)
Performant APIs with GraphQL and PHP (Dutch PHP 2019)
 
SF big Analytics : Stream all things by Gwen Shapira @ Lyft 2018
SF big Analytics : Stream all things by Gwen Shapira @ Lyft 2018SF big Analytics : Stream all things by Gwen Shapira @ Lyft 2018
SF big Analytics : Stream all things by Gwen Shapira @ Lyft 2018
 
Grokking Engineering - Data Analytics Infrastructure at Viki - Huy Nguyen
Grokking Engineering - Data Analytics Infrastructure at Viki - Huy NguyenGrokking Engineering - Data Analytics Infrastructure at Viki - Huy Nguyen
Grokking Engineering - Data Analytics Infrastructure at Viki - Huy Nguyen
 
CCT Check and Calculate Transfer
CCT Check and Calculate TransferCCT Check and Calculate Transfer
CCT Check and Calculate Transfer
 
Kliq planflyer
Kliq planflyerKliq planflyer
Kliq planflyer
 
Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019Integrating React.js Into a PHP Application: Dutch PHP 2019
Integrating React.js Into a PHP Application: Dutch PHP 2019
 
How to write your database: the story about Event Store
How to write your database: the story about Event StoreHow to write your database: the story about Event Store
How to write your database: the story about Event Store
 
WSO2 Stream Processor: Graphical Editor, HTTP & Message Trace Analytics and m...
WSO2 Stream Processor: Graphical Editor, HTTP & Message Trace Analytics and m...WSO2 Stream Processor: Graphical Editor, HTTP & Message Trace Analytics and m...
WSO2 Stream Processor: Graphical Editor, HTTP & Message Trace Analytics and m...
 
Big Data processing with Spark, Scala or Java?
Big Data processing with Spark, Scala or Java?Big Data processing with Spark, Scala or Java?
Big Data processing with Spark, Scala or Java?
 
BigQuery ML - Machine learning at scale using SQL
BigQuery ML - Machine learning at scale using SQLBigQuery ML - Machine learning at scale using SQL
BigQuery ML - Machine learning at scale using SQL
 
C* Summit 2013: Optimizing the Public Cloud for Cost and Scalability with Cas...
C* Summit 2013: Optimizing the Public Cloud for Cost and Scalability with Cas...C* Summit 2013: Optimizing the Public Cloud for Cost and Scalability with Cas...
C* Summit 2013: Optimizing the Public Cloud for Cost and Scalability with Cas...
 
Jean-René Roy : The Modern DBA
Jean-René Roy : The Modern DBAJean-René Roy : The Modern DBA
Jean-René Roy : The Modern DBA
 
CloudStack Metering – Working with the Usage Data
CloudStack Metering – Working with the Usage DataCloudStack Metering – Working with the Usage Data
CloudStack Metering – Working with the Usage Data
 

Ähnlich wie Android architecture components with cloud firestore

Azure data analytics platform - A reference architecture
Azure data analytics platform - A reference architecture Azure data analytics platform - A reference architecture
Azure data analytics platform - A reference architecture
Rajesh Kumar
 

Ähnlich wie Android architecture components with cloud firestore (20)

Android Jetpack - Google IO Extended Singapore 2018
Android Jetpack - Google IO Extended Singapore 2018Android Jetpack - Google IO Extended Singapore 2018
Android Jetpack - Google IO Extended Singapore 2018
 
Firestore MENA digital days : GDG Abu dhabi
Firestore MENA digital days : GDG Abu dhabiFirestore MENA digital days : GDG Abu dhabi
Firestore MENA digital days : GDG Abu dhabi
 
Firebase
Firebase Firebase
Firebase
 
The Best Way to Become an Android Developer Expert with Android Jetpack
The Best Way to Become an Android Developer Expert  with Android JetpackThe Best Way to Become an Android Developer Expert  with Android Jetpack
The Best Way to Become an Android Developer Expert with Android Jetpack
 
Giga Spaces Data Grid / Data Caching Overview
Giga Spaces Data Grid / Data Caching OverviewGiga Spaces Data Grid / Data Caching Overview
Giga Spaces Data Grid / Data Caching Overview
 
Building event-driven Serverless Apps with Azure Functions and Azure Cosmos DB
Building event-driven Serverless Apps with Azure Functions and Azure Cosmos DBBuilding event-driven Serverless Apps with Azure Functions and Azure Cosmos DB
Building event-driven Serverless Apps with Azure Functions and Azure Cosmos DB
 
Why and How SmartNews uses SaaS?
Why and How SmartNews uses SaaS?Why and How SmartNews uses SaaS?
Why and How SmartNews uses SaaS?
 
Google Firebase presentation - English
Google Firebase presentation - EnglishGoogle Firebase presentation - English
Google Firebase presentation - English
 
Firebase overview
Firebase overviewFirebase overview
Firebase overview
 
Decomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservicesDecomposing the Monolith using modern-day .NET and a touch of microservices
Decomposing the Monolith using modern-day .NET and a touch of microservices
 
Web App Prototypes with Google App Engine
Web App Prototypes with Google App EngineWeb App Prototypes with Google App Engine
Web App Prototypes with Google App Engine
 
Windows Azure and a little SQL Data Services
Windows Azure and a little SQL Data ServicesWindows Azure and a little SQL Data Services
Windows Azure and a little SQL Data Services
 
Azure data analytics platform - A reference architecture
Azure data analytics platform - A reference architecture Azure data analytics platform - A reference architecture
Azure data analytics platform - A reference architecture
 
Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...
Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...
Sebastian Schmidt, Rachel Myers - How To Go Serverless And Not Violate The GD...
 
About The Event-Driven Data Layer & Adobe Analytics
About The Event-Driven Data Layer & Adobe AnalyticsAbout The Event-Driven Data Layer & Adobe Analytics
About The Event-Driven Data Layer & Adobe Analytics
 
CodeCamp Iasi - Creating serverless data analytics system on GCP using BigQuery
CodeCamp Iasi - Creating serverless data analytics system on GCP using BigQueryCodeCamp Iasi - Creating serverless data analytics system on GCP using BigQuery
CodeCamp Iasi - Creating serverless data analytics system on GCP using BigQuery
 
Stmik bandung
Stmik bandungStmik bandung
Stmik bandung
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
Implementing Real-Time IoT Stream Processing in Azure
Implementing Real-Time IoT Stream Processing in Azure Implementing Real-Time IoT Stream Processing in Azure
Implementing Real-Time IoT Stream Processing in Azure
 
Building workflow solution with Microsoft Azure and Cloud | Integration Monday
Building workflow solution with Microsoft Azure and Cloud | Integration MondayBuilding workflow solution with Microsoft Azure and Cloud | Integration Monday
Building workflow solution with Microsoft Azure and Cloud | Integration Monday
 

Kürzlich hochgeladen

Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
amilabibi1
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
ZurliaSoop
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Hung Le
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
David Celestin
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
Kayode Fayemi
 

Kürzlich hochgeladen (17)

Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
Zone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptxZone Chairperson Role and Responsibilities New updated.pptx
Zone Chairperson Role and Responsibilities New updated.pptx
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
Jual obat aborsi Jakarta 085657271886 Cytote pil telat bulan penggugur kandun...
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven CuriosityUnlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
Unlocking Exploration: Self-Motivated Agents Thrive on Memory-Driven Curiosity
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait Cityin kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
in kuwait௹+918133066128....) @abortion pills for sale in Kuwait City
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
Introduction to Artificial intelligence.
Introduction to Artificial intelligence.Introduction to Artificial intelligence.
Introduction to Artificial intelligence.
 

Android architecture components with cloud firestore

  • 1. Android architecture components with cloud firestore Pankaj Rai @raipankaj7
  • 2. Agenda ● Android architecture components ● Firebase services ● Cloud firestore ● What’s new in firebase
  • 4. Android Jetpack Accelerate app development Eliminate boilerplate code Build high quality apps
  • 5. Android Architecture Component ● Design robust, testable and maintainable apps ● Handle data persistence ● Reduce app development time ● Improve app quality
  • 6. ViewModel ● Designed to store and manage UI-related data with lifecycle awareness ● Live through the configuration changes ● Caution: ViewModel does not replace onSaveInstanceState()
  • 8. LiveData ● Observable data holder class ● Respect lifecycle of app components, such as activities, fragments or services ● Only notifies active observers about updates ● Inactive observers registered to watch LiveData objects aren't notified about changes
  • 9. Crash due to stopped activity
  • 10. Why LiveData? ● No memory leaks ● No crashes due to stopped activities ● No more manual lifecycle handling ● Always up to date data
  • 11. LiveData which publicly exposes setValue(T) and postValue(T) method MutableLiveData<Boolean> userIdLiveData = new MutableLiveData() userIdLiveData.setValue(true) MutableLiveData
  • 12. LiveData subclass which may observe other LiveData objects and react on OnChanged events from them LiveData liveData1 = ...; LiveData liveData2 = ...; MediatorLiveData liveDataMerger = new MediatorLiveData<>(); liveDataMerger.addSource(liveData1,value ->liveDataMerger.setValue(value)); liveDataMerger.addSource(liveData2,value ->liveDataMerger.setValue(value)); MediatorLiveData
  • 13. Applies the given function on the main thread to each value emitted by source LiveData and returns LiveData, which emits resulting values LiveData userLiveData = ... LiveData userName = Transformations.map(userLiveData, user -> { return user.firstName + " " + user.lastName; // Returns String } ) Transformations.map
  • 14. Reacts on changes of trigger LiveData, applies the given function to new value of trigger LiveData and sets resulting LiveData as a "backing" LiveData MutableLiveData userIdLiveData = ... LiveData userLiveData = Transformations.switchMap(userIdLiveData, id -> repository.getUserById(id) // Returns LiveData ) void setUserId(String userId) { this.userIdLiveData.setValue(userId) } Transformations.switchMap
  • 15. Firebase A comprehensive app development platform
  • 16. Why Firebase? ● Available for Android, iOS and Web ● Reduce time for app development ● All in one platform to build app or website ● Helps to grow your business ● Auto scale your app to support billions of users
  • 17.
  • 20. ● It’s NoSQL document database for mobile and web app development ● Cloud Firestore also offers seamless integration with other Firebase and Google Cloud Platform products, including Cloud Functions ● It keeps your data in sync across client apps through real-time listeners and offers offline support for mobile and web Why cloud firestore?
  • 21. ● Documents and collections structure with powerful querying capability ● Automatic multi-region data replication with strong consistency ● Real-time data synchronization ● Android, iOS and Web SDKs with offline data access Key capabilities
  • 22.
  • 23. Collections are like a container which itself do not store any data but contains document which in turn stores data Collection
  • 24. It’s the smallest unit to store data in the database more set of data type are now supported with document Document
  • 26. // Create a new user with a first and last name val user = HashMap<String, Any>() user["first"] = "Ada" user["last"] = "Lovelace" user["born"] = 1815 // Add a new document with a generated ID db.collection("users") .add(user) .addOnSuccessListener { documentReference -> Log.d(TAG, "DocumentSnapshot added with ID: ${documentReference.id}") } .addOnFailureListener { e -> Log.w(TAG, "Error adding document", e) }
  • 27. val city = HashMap<String, Any>() city["name"] = "Los Angeles" city["state"] = "CA" city["country"] = "USA" db.collection("cities").document("LA") .set(city) or set(data, SetOptions.merge()) .addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully written!") } .addOnFailureListener { e -> Log.w(TAG, "Error writing document", e) }
  • 29. db.collection("users") .get() .addOnSuccessListener { result -> for (document in result) { Log.d(TAG, "${document.id} => ${document.data}") } } .addOnFailureListener { exception -> Log.w(TAG, "Error getting documents.", exception) }
  • 30. db.collection("cities") .whereEqualTo("capital", true) .get() .addOnSuccessListener { documents -> for (document in documents) { Log.d(TAG, "${document.id} => ${document.data}") } } .addOnFailureListener { exception -> Log.w(TAG, "Error getting documents: ", exception) }
  • 31. FirebaseFirestore.getInstance().collection("sd").whereEqualTo("state","ca").addSnapshotListener(this) { snapshot, e -> if (e != null) { Log.w(TAG, "listen:error", e) return@EventListener } for (dc in snapshots.documentChanges) { when (dc.type) { DocumentChange.Type.ADDED -> Log.d(TAG, "New city: ${dc.document.data}") DocumentChange.Type.MODIFIED -> Log.d(TAG, "Modified city: ${dc.document.data}") DocumentChange.Type.REMOVED -> Log.d(TAG, "Removed city: ${dc.document.data}") } } }
  • 33. object NetworkRepository { fun registerAttendee(map: Map<String, Any?>): LiveData<Boolean> { val mutableLiveData = MutableLiveData<Boolean>() FirebaseFirestore.getInstance().collection(AppConstant.ATTENDEES) .document(map.getValue(AppConstant.ATTENDEE_EMAIL).toString()) .set(map) .addOnCompleteListener{ mutableLiveData.value = it.isSuccessful } return mutableLiveData } }
  • 34. class AttendeesViewModel: ViewModel() { private val _registerAttendee = MutableLiveData<Map<String, Any?>>() val registerAttendee = _registerAttendee.switchMap { NetworkRepository.registerAttendee(it) } fun setRegAttendeeInfo(map: Map<String, Any?>) { _registerAttendee.value = map } }
  • 35. val attendeesDetails = mapOf( AppConstant.ATTENDEE_EMAIL to mAttendeeEmail, AppConstant.TIMESTAMP to FieldValue.serverTimestamp() ) //Send the attendees details to firestore mAttendeesViewModel.setRegAttendeeInfo(attendeesDetails) //Observe the result from firestore mAttendeesViewModel.registerAttendee.observe(this, Observer { ... ... })
  • 36. What’s new in Firebase?
  • 37. ● Analytics for web ● FCM for web ● Remote config for web ● Firebase Extensions ● Firebase App Distributions
  • 39. Firebase App Distribution ● It makes distributing your apps to trusted testers easy ● Get stability metrics for all your builds ● Distribute builds using the Firebase console, the Firebase Command Line Interface (CLI) tool or Gradle (Android)
  • 40. How to distribute app? ● Upload the APK or IPA to App Distribution using the Firebase console, Gradle, or the CLI tools ● Add the testers you want to try your app. Testers will receive an email that walks them through the onboarding process ● When new build is ready for testing, just upload it to App Distribution. Your testers will be notified that a new build is available to try out
  • 41.
  • 42.