SlideShare a Scribd company logo
1 of 34
Firebase Remote
Config + Kotlin =
EasyFRC
Android utility for handle Firebase Remote
Config
Omar Miatello
Personal profile
google.com/+OmarMiatello
Google+ Community: Kotlin for Android
goo.gl/mUKF1w
Slide on Google Presentation
goo.gl/1S1Z1E
Organizer
Android Developer
Firebase Remote Config
Firebase Remote Config | What is it?
Change the behavior and appearance of your app without publishing an app
update.
Feature:
● It’s a cloud service
● A simple key-value store
● Customize your app for segments of your user base (ex: A/B tests)
Docs: https://firebase.google.com/docs/remote-config/ (+ 3min video)
Firebase Remote Config | How it works?
● Open Firebase console https://console.firebase.google.com
● Choose or create a new project
● Select “Remote Config”
● Add/change/remove parameter
● Publish!
Firebase Remote Config | API architecture
● Singleton exposed to your app
● Default Config bundled with your
app
● Active Config for keep
consistency
● Fetched Config synced with FRC
console values
Let’s code!
Java version
Firebase Remote Config | Configure project | 1/3
1) Add Firebase to your app
Add the dependency for Remote Config to your app-level build.gradle file as part of this step:
compile 'com.google.firebase:firebase-config:11.4.0'
2) Get the Remote Config singleton object
mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance()
3) Set in-app default parameter values
using a Map object or an XML resource file stored in your app's res/xml folder
mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults);
Firebase Remote Config | Configure project | 2/3
Example of Default Config XML
<?xml version="1.0" encoding="utf-8"?>
<defaultsMap>
<entry>
<key>loading_phrase</key>
<value>Fetching config…</value>
</entry>
<entry>
<key>secretFeature1_enabled</key>
<value>false</value>
</entry>
</defaultsMap>
Firebase Remote Config | Configure project | 3/3
4) Get parameter values to use in your app
getBoolean(key) , getByteArray(key), getDouble(key), getLong(key), getString(key)
mFirebaseRemoteConfig.getBoolean("secretFeature1_enabled");
5) Fetch and activate values from the service (as needed)
● To fetch parameter values from the Remote Config service, call the fetch() method. Any values that you set in the
Remote Config service are fetched and cached in the Remote Config object.
● To make fetched parameter values available to your app, call the activateFetched() method.
Make it easy…
with Kotlin!
Kotlin: Properties
Declaring Properties
val secretFeature1_enabled: Boolean = false
Properties: Getters and Setters
val secretFeature1_enabled: Boolean
get() = FirebaseRemoteConfig.getInstance().getBoolean("secretFeature1_enabled")
From code
if (secretFeature1_enabled) {
// do something …
}
Kotlin: Delegated Properties | 1/3
There are certain common kinds of properties, that, though we can implement
them manually every time we need them, would be very nice to implement once
and for all, and put into a library.
class Example {
val myProperty: String by MyDelegate()
}
Kotlin: Delegated Properties | 2/3
Define getValue() in your MyDelegate class.
class Example {
val myProperty: String by MyDelegate()
}
class MyDelegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): String {
return "$thisRef, thank you for delegating '${property.name}' to me!"
}
}
Kotlin: Delegated Properties | 3/3
Providing a delegate (since Koltin 1.1)
class Example {
val myProperty: String by MyDelegate()
}
class MyDelegate {
operator fun provideDelegate(thisRef: Any?, property: KProperty<*>): ReadOnlyProperty<Any?, T> {
// init: check and create delegate
}
operator fun getValue(thisRef: Any?, property: KProperty<*>): String {
return "$thisRef, thank you for delegating '${property.name}' to me!"
}
}
The Goal
The Goal
Define a class with only properties and defaults
object FRC {
val signup_useHint by boolean(true)
val secretFeature1_enabled by boolean(false)
val logMaxLines by int(10)
}
The Goal | Singleton
Define a class with only properties and defaults
object FRC { // it’s a singleton!
val signup_useHint by boolean(true)
val secretFeature1_enabled by boolean(false)
val logMaxLines by int(10)
}
The Goal | Declare config name once
Define a class with only properties and defaults
object FRC {
val signup_useHint by boolean(true) // no need to declare string name!
val secretFeature1_enabled by boolean(false)
val logMaxLines by int(10)
}
The Goal | Static type-safe
Define a class with only properties and defaults
object FRC {
val signup_useHint by boolean(true) // it’s a type-safe!
val secretFeature1_enabled by boolean(false)
val logMaxLines by int(10)
}
The Goal | Declare default
Define a class with only properties and defaults
object FRC {
val signup_useHint by boolean(true) // has default!
val secretFeature1_enabled by boolean(false)
val logMaxLines by int(10)
}
The Goal | Easy to use
Define a class with only properties and defaults
object FRC {
val signup_useHint by boolean(true)
val secretFeature1_enabled by boolean(false)
val logMaxLines by int(10)
}
Easy to use in our code (with static type-safe)
if (FRC.secretFeature1_enabled) {
// do something ...
}
Build EasyFRC
Build EasyFRC | Defaults for initialization
abstract class EasyFRC {
val _defaults = HashMap<String, Any?>()
}
Build EasyFRC | Auto setup for Firebase Remote Config
abstract class EasyFRC {
val _defaults = HashMap<String, Any?>()
val frc by lazy {
FirebaseRemoteConfig.getInstance().apply {
setDefaults(_defaults)
activateFetched()
fetch()
}
}
}
Build EasyFRC | Our Delegate Class
abstract class EasyFRC {
val _defaults = HashMap<String, Any?>()
val frc by lazy {
FirebaseRemoteConfig.getInstance().apply {
setDefaults(_defaults)
activateFetched()
fetch()
}
}
class FRCDelegate<T>(val defaultValue: T, val getMethod: (String) -> T) {
override fun getValue(thisRef: EasyFRC, property: KProperty<*>) = getMethod(property.name)
}
}
Build EasyFRC | Method for build Delegates | 1/2
abstract class EasyFRC {
val _defaults = HashMap<String, Any?>()
val frc by lazy {
FirebaseRemoteConfig.getInstance().apply {
setDefaults(_defaults)
activateFetched()
fetch()
}
}
fun string(defaultValue: String? = null) = FRCDelegate(defaultValue) { frc.getString(it) }
class FRCDelegate<T>(val defaultValue: T, val getMethod: (String) -> T) {
override fun getValue(thisRef: EasyFRC, property: KProperty<*>) = getMethod(property.name)
}
}
Build EasyFRC | Method for build Delegates | 2/2
abstract class EasyFRC {
// ...
fun string(defaultValue: String? = null) = FRCDelegate(defaultValue) { frc.getString(it) }
fun boolean(defaultValue: Boolean = false) = FRCDelegate(defaultValue) { frc.getBoolean(it) }
// ...
class FRCDelegate<T>(val defaultValue: T, val getMethod: (String) -> T) {
override fun getValue(thisRef: EasyFRC, property: KProperty<*>) = getMethod(property.name)
}
}
Build EasyFRC | provideDelegate() with Kotlin 1.1
abstract class EasyFRC {
// ...
fun string(defaultValue: String? = null) = FRCDelegate(defaultValue) { frc.getString(it) }
fun boolean(defaultValue: Boolean = false) = FRCDelegate(defaultValue) { frc.getBoolean(it) }
// ...
class FRCDelegate<T>(val defaultValue: T, val getMethod: (String) -> T) {
override fun getValue(thisRef: EasyFRC, property: KProperty<*>) = getMethod(property.name)
operator fun provideDelegate(thisRef: EasyFRC, property: KProperty<*>): FRCDelegate<T> {
thisRef._defaults.put(property.name, defaultValue)
return this
}
}
}
Build EasyFRC | The result!
object FRC : EasyFRC() {
// Basic example
val myBoolean by boolean(false)
val myInt by int(1337)
val myLong by long(134567890123456789)
val myDouble by double(0.0)
val myString by string("Ciao")
val myByteArray by byteArray(ByteArray(0))
// Real world examples
val signup_useHint by boolean(true)
val secretFeature1_enabled by boolean(false)
val secretFeature2_enabled by boolean(true)
val cache_expireMax by long(TimeUnit.DAYS.toSeconds(7))
val logMaxLines by int(10)
val logLevel by int(Log.INFO)
}
Mission complete!
More complex example ...
Added support for: devMode, custom keys, fetch() and fetchAndActivate()
Full example: https://github.com/jacklt/jutils
Import as dependency (with JitPack)!
Gradle (v4 or later):
implementation 'com.github.jacklt.jutils:easyfrc:1.0.1'
or Gradle (before v4):
compile 'com.github.jacklt.jutils:easyfrc:1.0.1'
Questions?
Let’s try it!
https://github.com/jacklt/jutils
Thanks!

More Related Content

What's hot

Everything you need to know about GraalVM Native Image
Everything you need to know about GraalVM Native ImageEverything you need to know about GraalVM Native Image
Everything you need to know about GraalVM Native ImageAlina Yurenko
 
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid RahimianAPI Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid RahimianVahid Rahimian
 
Kubermatic CNCF Webinar - start.kubermatic.pdf
Kubermatic CNCF Webinar - start.kubermatic.pdfKubermatic CNCF Webinar - start.kubermatic.pdf
Kubermatic CNCF Webinar - start.kubermatic.pdfLibbySchulze
 
CI with Gitlab & Docker
CI with Gitlab & DockerCI with Gitlab & Docker
CI with Gitlab & DockerJoerg Henning
 
API Automation Testing Using RestAssured+Cucumber
API Automation Testing Using RestAssured+CucumberAPI Automation Testing Using RestAssured+Cucumber
API Automation Testing Using RestAssured+CucumberKnoldus Inc.
 
Using GitLab CI
Using GitLab CIUsing GitLab CI
Using GitLab CIColCh
 
TAKING SIMPLE PHONE MESSAGES.ppt
TAKING SIMPLE PHONE MESSAGES.pptTAKING SIMPLE PHONE MESSAGES.ppt
TAKING SIMPLE PHONE MESSAGES.pptrimasusanti7
 
GitOps on Kubernetes with Carvel
GitOps on Kubernetes with CarvelGitOps on Kubernetes with Carvel
GitOps on Kubernetes with CarvelAlexandre Roman
 
Android application penetration testing
Android application penetration testingAndroid application penetration testing
Android application penetration testingRoshan Kumar Gami
 
Devops Porto - CI/CD at Gitlab
Devops Porto - CI/CD at GitlabDevops Porto - CI/CD at Gitlab
Devops Porto - CI/CD at GitlabFilipa Lacerda
 
Introduction to GitHub Actions
Introduction to GitHub ActionsIntroduction to GitHub Actions
Introduction to GitHub ActionsKnoldus Inc.
 
Default GitLab CI Pipeline - Auto DevOps
Default GitLab CI Pipeline - Auto DevOpsDefault GitLab CI Pipeline - Auto DevOps
Default GitLab CI Pipeline - Auto DevOpsRajith Bhanuka Mahanama
 
Kubernetes presentation
Kubernetes presentationKubernetes presentation
Kubernetes presentationGauranG Bajpai
 
Managing dependencies with gradle
Managing dependencies with gradleManaging dependencies with gradle
Managing dependencies with gradleLiviu Tudor
 
Introduction to GraphQL using Nautobot and Arista cEOS
Introduction to GraphQL using Nautobot and Arista cEOSIntroduction to GraphQL using Nautobot and Arista cEOS
Introduction to GraphQL using Nautobot and Arista cEOSJoel W. King
 
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git민태 김
 

What's hot (20)

Everything you need to know about GraalVM Native Image
Everything you need to know about GraalVM Native ImageEverything you need to know about GraalVM Native Image
Everything you need to know about GraalVM Native Image
 
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid RahimianAPI Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
API Design, A Quick Guide to REST, SOAP, gRPC, and GraphQL, By Vahid Rahimian
 
harun pdf tanpa 01
harun pdf tanpa 01harun pdf tanpa 01
harun pdf tanpa 01
 
cmake.pdf
cmake.pdfcmake.pdf
cmake.pdf
 
Github in Action
Github in ActionGithub in Action
Github in Action
 
Kubermatic CNCF Webinar - start.kubermatic.pdf
Kubermatic CNCF Webinar - start.kubermatic.pdfKubermatic CNCF Webinar - start.kubermatic.pdf
Kubermatic CNCF Webinar - start.kubermatic.pdf
 
CI with Gitlab & Docker
CI with Gitlab & DockerCI with Gitlab & Docker
CI with Gitlab & Docker
 
API Automation Testing Using RestAssured+Cucumber
API Automation Testing Using RestAssured+CucumberAPI Automation Testing Using RestAssured+Cucumber
API Automation Testing Using RestAssured+Cucumber
 
Using GitLab CI
Using GitLab CIUsing GitLab CI
Using GitLab CI
 
TAKING SIMPLE PHONE MESSAGES.ppt
TAKING SIMPLE PHONE MESSAGES.pptTAKING SIMPLE PHONE MESSAGES.ppt
TAKING SIMPLE PHONE MESSAGES.ppt
 
GitOps on Kubernetes with Carvel
GitOps on Kubernetes with CarvelGitOps on Kubernetes with Carvel
GitOps on Kubernetes with Carvel
 
Android application penetration testing
Android application penetration testingAndroid application penetration testing
Android application penetration testing
 
Devops Porto - CI/CD at Gitlab
Devops Porto - CI/CD at GitlabDevops Porto - CI/CD at Gitlab
Devops Porto - CI/CD at Gitlab
 
Introduction to GitHub Actions
Introduction to GitHub ActionsIntroduction to GitHub Actions
Introduction to GitHub Actions
 
Default GitLab CI Pipeline - Auto DevOps
Default GitLab CI Pipeline - Auto DevOpsDefault GitLab CI Pipeline - Auto DevOps
Default GitLab CI Pipeline - Auto DevOps
 
Kubernetes presentation
Kubernetes presentationKubernetes presentation
Kubernetes presentation
 
Managing dependencies with gradle
Managing dependencies with gradleManaging dependencies with gradle
Managing dependencies with gradle
 
Introduction to GraphQL using Nautobot and Arista cEOS
Introduction to GraphQL using Nautobot and Arista cEOSIntroduction to GraphQL using Nautobot and Arista cEOS
Introduction to GraphQL using Nautobot and Arista cEOS
 
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
버전관리를 들어본적 없는 사람들을 위한 DVCS - Git
 
Test studio
Test studioTest studio
Test studio
 

Similar to Firebase Remote Config + Kotlin = EasyFRC

From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modelingCodemotion
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modelingMario Fusco
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android developmentAdit Lal
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyMobileAcademy
 
Practical tips for building apps with kotlin
Practical tips for building apps with kotlinPractical tips for building apps with kotlin
Practical tips for building apps with kotlinAdit Lal
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchainedEduard Tomàs
 
Swift - One step forward from Obj-C
Swift -  One step forward from Obj-CSwift -  One step forward from Obj-C
Swift - One step forward from Obj-CNissan Tsafrir
 
Annotation Processing
Annotation ProcessingAnnotation Processing
Annotation ProcessingJintin Lin
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftOleksandr Stepanov
 
Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationUsing Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationIvan Dolgushin
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 
Kotlin Advanced - language reference for Android developers
Kotlin Advanced - language reference for Android developers Kotlin Advanced - language reference for Android developers
Kotlin Advanced - language reference for Android developers STX Next
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScriptkvangork
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascriptkvangork
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design PatternsStefano Fago
 
Porting legacy apps to Griffon
Porting legacy apps to GriffonPorting legacy apps to Griffon
Porting legacy apps to GriffonJames Williams
 
RDSDataSource: Мастер-класс по Dip
RDSDataSource: Мастер-класс по DipRDSDataSource: Мастер-класс по Dip
RDSDataSource: Мастер-класс по DipRAMBLER&Co
 

Similar to Firebase Remote Config + Kotlin = EasyFRC (20)

From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
Save time with kotlin in android development
Save time with kotlin in android developmentSave time with kotlin in android development
Save time with kotlin in android development
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRready
 
Practical tips for building apps with kotlin
Practical tips for building apps with kotlinPractical tips for building apps with kotlin
Practical tips for building apps with kotlin
 
6976.ppt
6976.ppt6976.ppt
6976.ppt
 
EcmaScript unchained
EcmaScript unchainedEcmaScript unchained
EcmaScript unchained
 
Swift - One step forward from Obj-C
Swift -  One step forward from Obj-CSwift -  One step forward from Obj-C
Swift - One step forward from Obj-C
 
Annotation Processing
Annotation ProcessingAnnotation Processing
Annotation Processing
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
 
Using Reflections and Automatic Code Generation
Using Reflections and Automatic Code GenerationUsing Reflections and Automatic Code Generation
Using Reflections and Automatic Code Generation
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
Kotlin Advanced - language reference for Android developers
Kotlin Advanced - language reference for Android developers Kotlin Advanced - language reference for Android developers
Kotlin Advanced - language reference for Android developers
 
Object-Oriented JavaScript
Object-Oriented JavaScriptObject-Oriented JavaScript
Object-Oriented JavaScript
 
Object-Oriented Javascript
Object-Oriented JavascriptObject-Oriented Javascript
Object-Oriented Javascript
 
Java vs kotlin
Java vs kotlinJava vs kotlin
Java vs kotlin
 
Uncommon Design Patterns
Uncommon Design PatternsUncommon Design Patterns
Uncommon Design Patterns
 
Porting legacy apps to Griffon
Porting legacy apps to GriffonPorting legacy apps to Griffon
Porting legacy apps to Griffon
 
Byte code field report
Byte code field reportByte code field report
Byte code field report
 
RDSDataSource: Мастер-класс по Dip
RDSDataSource: Мастер-класс по DipRDSDataSource: Мастер-класс по Dip
RDSDataSource: Мастер-класс по Dip
 

More from Omar Miatello

Google Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScriptGoogle Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScriptOmar Miatello
 
Kotlin: lo Swift di Android (2015)
Kotlin: lo Swift di Android (2015)Kotlin: lo Swift di Android (2015)
Kotlin: lo Swift di Android (2015)Omar Miatello
 
AARRR, Pirate Metrics with Firebase for Android (now in real time!) (2016)
AARRR, Pirate Metrics with Firebase for Android (now in real time!) (2016)AARRR, Pirate Metrics with Firebase for Android (now in real time!) (2016)
AARRR, Pirate Metrics with Firebase for Android (now in real time!) (2016)Omar Miatello
 
Android & Kotlin - The code awakens #03
Android & Kotlin - The code awakens #03Android & Kotlin - The code awakens #03
Android & Kotlin - The code awakens #03Omar Miatello
 
Android & Kotlin - The code awakens #02
Android & Kotlin - The code awakens #02Android & Kotlin - The code awakens #02
Android & Kotlin - The code awakens #02Omar Miatello
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Omar Miatello
 
Kotlin - lo Swift di Android
Kotlin - lo Swift di AndroidKotlin - lo Swift di Android
Kotlin - lo Swift di AndroidOmar Miatello
 

More from Omar Miatello (8)

Google Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScriptGoogle Cloud Functions: try { Kotlin } instead of JavaScript
Google Cloud Functions: try { Kotlin } instead of JavaScript
 
Kotlin: lo Swift di Android (2015)
Kotlin: lo Swift di Android (2015)Kotlin: lo Swift di Android (2015)
Kotlin: lo Swift di Android (2015)
 
AARRR, Pirate Metrics with Firebase for Android (now in real time!) (2016)
AARRR, Pirate Metrics with Firebase for Android (now in real time!) (2016)AARRR, Pirate Metrics with Firebase for Android (now in real time!) (2016)
AARRR, Pirate Metrics with Firebase for Android (now in real time!) (2016)
 
Google Wave (2010)
Google Wave (2010)Google Wave (2010)
Google Wave (2010)
 
Android & Kotlin - The code awakens #03
Android & Kotlin - The code awakens #03Android & Kotlin - The code awakens #03
Android & Kotlin - The code awakens #03
 
Android & Kotlin - The code awakens #02
Android & Kotlin - The code awakens #02Android & Kotlin - The code awakens #02
Android & Kotlin - The code awakens #02
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01
 
Kotlin - lo Swift di Android
Kotlin - lo Swift di AndroidKotlin - lo Swift di Android
Kotlin - lo Swift di Android
 

Recently uploaded

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Firebase Remote Config + Kotlin = EasyFRC

  • 1. Firebase Remote Config + Kotlin = EasyFRC Android utility for handle Firebase Remote Config
  • 2. Omar Miatello Personal profile google.com/+OmarMiatello Google+ Community: Kotlin for Android goo.gl/mUKF1w Slide on Google Presentation goo.gl/1S1Z1E Organizer Android Developer
  • 4. Firebase Remote Config | What is it? Change the behavior and appearance of your app without publishing an app update. Feature: ● It’s a cloud service ● A simple key-value store ● Customize your app for segments of your user base (ex: A/B tests) Docs: https://firebase.google.com/docs/remote-config/ (+ 3min video)
  • 5. Firebase Remote Config | How it works? ● Open Firebase console https://console.firebase.google.com ● Choose or create a new project ● Select “Remote Config” ● Add/change/remove parameter ● Publish!
  • 6. Firebase Remote Config | API architecture ● Singleton exposed to your app ● Default Config bundled with your app ● Active Config for keep consistency ● Fetched Config synced with FRC console values
  • 8. Firebase Remote Config | Configure project | 1/3 1) Add Firebase to your app Add the dependency for Remote Config to your app-level build.gradle file as part of this step: compile 'com.google.firebase:firebase-config:11.4.0' 2) Get the Remote Config singleton object mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance() 3) Set in-app default parameter values using a Map object or an XML resource file stored in your app's res/xml folder mFirebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults);
  • 9. Firebase Remote Config | Configure project | 2/3 Example of Default Config XML <?xml version="1.0" encoding="utf-8"?> <defaultsMap> <entry> <key>loading_phrase</key> <value>Fetching config…</value> </entry> <entry> <key>secretFeature1_enabled</key> <value>false</value> </entry> </defaultsMap>
  • 10. Firebase Remote Config | Configure project | 3/3 4) Get parameter values to use in your app getBoolean(key) , getByteArray(key), getDouble(key), getLong(key), getString(key) mFirebaseRemoteConfig.getBoolean("secretFeature1_enabled"); 5) Fetch and activate values from the service (as needed) ● To fetch parameter values from the Remote Config service, call the fetch() method. Any values that you set in the Remote Config service are fetched and cached in the Remote Config object. ● To make fetched parameter values available to your app, call the activateFetched() method.
  • 12. Kotlin: Properties Declaring Properties val secretFeature1_enabled: Boolean = false Properties: Getters and Setters val secretFeature1_enabled: Boolean get() = FirebaseRemoteConfig.getInstance().getBoolean("secretFeature1_enabled") From code if (secretFeature1_enabled) { // do something … }
  • 13. Kotlin: Delegated Properties | 1/3 There are certain common kinds of properties, that, though we can implement them manually every time we need them, would be very nice to implement once and for all, and put into a library. class Example { val myProperty: String by MyDelegate() }
  • 14. Kotlin: Delegated Properties | 2/3 Define getValue() in your MyDelegate class. class Example { val myProperty: String by MyDelegate() } class MyDelegate { operator fun getValue(thisRef: Any?, property: KProperty<*>): String { return "$thisRef, thank you for delegating '${property.name}' to me!" } }
  • 15. Kotlin: Delegated Properties | 3/3 Providing a delegate (since Koltin 1.1) class Example { val myProperty: String by MyDelegate() } class MyDelegate { operator fun provideDelegate(thisRef: Any?, property: KProperty<*>): ReadOnlyProperty<Any?, T> { // init: check and create delegate } operator fun getValue(thisRef: Any?, property: KProperty<*>): String { return "$thisRef, thank you for delegating '${property.name}' to me!" } }
  • 17. The Goal Define a class with only properties and defaults object FRC { val signup_useHint by boolean(true) val secretFeature1_enabled by boolean(false) val logMaxLines by int(10) }
  • 18. The Goal | Singleton Define a class with only properties and defaults object FRC { // it’s a singleton! val signup_useHint by boolean(true) val secretFeature1_enabled by boolean(false) val logMaxLines by int(10) }
  • 19. The Goal | Declare config name once Define a class with only properties and defaults object FRC { val signup_useHint by boolean(true) // no need to declare string name! val secretFeature1_enabled by boolean(false) val logMaxLines by int(10) }
  • 20. The Goal | Static type-safe Define a class with only properties and defaults object FRC { val signup_useHint by boolean(true) // it’s a type-safe! val secretFeature1_enabled by boolean(false) val logMaxLines by int(10) }
  • 21. The Goal | Declare default Define a class with only properties and defaults object FRC { val signup_useHint by boolean(true) // has default! val secretFeature1_enabled by boolean(false) val logMaxLines by int(10) }
  • 22. The Goal | Easy to use Define a class with only properties and defaults object FRC { val signup_useHint by boolean(true) val secretFeature1_enabled by boolean(false) val logMaxLines by int(10) } Easy to use in our code (with static type-safe) if (FRC.secretFeature1_enabled) { // do something ... }
  • 24. Build EasyFRC | Defaults for initialization abstract class EasyFRC { val _defaults = HashMap<String, Any?>() }
  • 25. Build EasyFRC | Auto setup for Firebase Remote Config abstract class EasyFRC { val _defaults = HashMap<String, Any?>() val frc by lazy { FirebaseRemoteConfig.getInstance().apply { setDefaults(_defaults) activateFetched() fetch() } } }
  • 26. Build EasyFRC | Our Delegate Class abstract class EasyFRC { val _defaults = HashMap<String, Any?>() val frc by lazy { FirebaseRemoteConfig.getInstance().apply { setDefaults(_defaults) activateFetched() fetch() } } class FRCDelegate<T>(val defaultValue: T, val getMethod: (String) -> T) { override fun getValue(thisRef: EasyFRC, property: KProperty<*>) = getMethod(property.name) } }
  • 27. Build EasyFRC | Method for build Delegates | 1/2 abstract class EasyFRC { val _defaults = HashMap<String, Any?>() val frc by lazy { FirebaseRemoteConfig.getInstance().apply { setDefaults(_defaults) activateFetched() fetch() } } fun string(defaultValue: String? = null) = FRCDelegate(defaultValue) { frc.getString(it) } class FRCDelegate<T>(val defaultValue: T, val getMethod: (String) -> T) { override fun getValue(thisRef: EasyFRC, property: KProperty<*>) = getMethod(property.name) } }
  • 28. Build EasyFRC | Method for build Delegates | 2/2 abstract class EasyFRC { // ... fun string(defaultValue: String? = null) = FRCDelegate(defaultValue) { frc.getString(it) } fun boolean(defaultValue: Boolean = false) = FRCDelegate(defaultValue) { frc.getBoolean(it) } // ... class FRCDelegate<T>(val defaultValue: T, val getMethod: (String) -> T) { override fun getValue(thisRef: EasyFRC, property: KProperty<*>) = getMethod(property.name) } }
  • 29. Build EasyFRC | provideDelegate() with Kotlin 1.1 abstract class EasyFRC { // ... fun string(defaultValue: String? = null) = FRCDelegate(defaultValue) { frc.getString(it) } fun boolean(defaultValue: Boolean = false) = FRCDelegate(defaultValue) { frc.getBoolean(it) } // ... class FRCDelegate<T>(val defaultValue: T, val getMethod: (String) -> T) { override fun getValue(thisRef: EasyFRC, property: KProperty<*>) = getMethod(property.name) operator fun provideDelegate(thisRef: EasyFRC, property: KProperty<*>): FRCDelegate<T> { thisRef._defaults.put(property.name, defaultValue) return this } } }
  • 30. Build EasyFRC | The result! object FRC : EasyFRC() { // Basic example val myBoolean by boolean(false) val myInt by int(1337) val myLong by long(134567890123456789) val myDouble by double(0.0) val myString by string("Ciao") val myByteArray by byteArray(ByteArray(0)) // Real world examples val signup_useHint by boolean(true) val secretFeature1_enabled by boolean(false) val secretFeature2_enabled by boolean(true) val cache_expireMax by long(TimeUnit.DAYS.toSeconds(7)) val logMaxLines by int(10) val logLevel by int(Log.INFO) }
  • 32. More complex example ... Added support for: devMode, custom keys, fetch() and fetchAndActivate() Full example: https://github.com/jacklt/jutils Import as dependency (with JitPack)! Gradle (v4 or later): implementation 'com.github.jacklt.jutils:easyfrc:1.0.1' or Gradle (before v4): compile 'com.github.jacklt.jutils:easyfrc:1.0.1'