Skip to content

Instantly share code, notes, and snippets.

@PetkevichPavel
Last active August 28, 2019 15:45
Show Gist options
  • Save PetkevichPavel/a73810141f7e6bd08339b93c0125a91a to your computer and use it in GitHub Desktop.
Save PetkevichPavel/a73810141f7e6bd08339b93c0125a91a to your computer and use it in GitHub Desktop.
AN_Cloud Function: Code example.
fun Context.setDefaultRCFromFile() : Boolean =
File(filesDir, LOCAL_RC_JSON).takeIf { it.exists() }?.let {file->
val defaultRC = mutableMapOf<String, Any>()
gson.fromJson(file.inputStream().convertLocalJsonToString(), RCModel::class.java)?.let { rcModel ->
defaultRC[RemoteConfigConstants.RC_JSON_PARAM_NAME] = file.inputStream().convertLocalJsonToString()
remoteConfigManager.updateRc(rcModel)
remoteConfigManager.updateFetchState(true, currentDateTimestamp)
}
app?.firebaseRemoteConfig?.setDefaults(defaultRC)
file.inputStream().close()
true
}?: false
fun setDefaultRC() {
if (remoteConfigManager.lastFetchedTime == null && !context.setDefaultRCFromFile()) {
//the body will be the same as in the old function!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment