Remote Config
Remote Config can help to define variables to used for the app, the value can be vary based on condition defined. For example, Remote Config can set a greeting based on user's device language used, or imageUrl based on date, and etc. DevBase include RemoteConfigHandler
to implement Remote Config, initialize it like this:
// defaultValues is XML files that defines default values for remote config, more about that here:
// https://firebase.google.com/docs/remote-config/get-started?platform=android#set-in-app-default-parameter-values
// millis defines interval in seconds between fetching
val remoteConfig by lazy { MobileService.getRemoteConfig(defaultValues = R.xml.default_values, millis = 3600) }
Fetch and Activate¶
For fetching new data, call this method:
remoteConfig.fetchAndActivate {
// Action to do when the values fetched
}
After calling this method, all the values met condition will be stored and can be called later.
Get value¶
For getting values from Remote Config, call getValue
method like this:
val stringValue = if (remoteConfig is FirebaseRemoteConfiguration)
(remoteConfig.get("greeting_splash") as RemoteConfigValue.FirebaseValue).value.asString()
else if (remoteConfig is AGConnectValue)
(remoteConfig.get("greeting_splash") as RemoteConfigValue.AgConnectValue).value.toString()