Skip to content

Instantly share code, notes, and snippets.

@hi-manshu
Created February 23, 2022 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hi-manshu/e47cf324542cfeb920e1575bb5155f98 to your computer and use it in GitHub Desktop.
Save hi-manshu/e47cf324542cfeb920e1575bb5155f98 to your computer and use it in GitHub Desktop.
object RemoteConfigHelper {
private const val REMOTE_KEY_IN_APP_REVIEW_ENABLED =
BuildConfig.REMOTE_CONFIG_KEY_PREFIX + "in_app_review_enabled"
private const val REMOTE_KEY_APP_UPDATES = BuildConfig.REMOTE_CONFIG_KEY_PREFIX + "app_updates"
private const val REMOTE_KEY_WORDS_MANIFEST = BuildConfig.REMOTE_CONFIG_KEY_PREFIX + "words_manifest"
init {
val settings = remoteConfigSettings {
minimumFetchIntervalInSeconds = BuildConfig.REMOTE_CONFIG_MIN_FETCH_INTERVAL_SECONDS
}
Firebase.remoteConfig.apply {
setDefaultsAsync(R.xml.remote_config_defaults)
setConfigSettingsAsync(settings)
.addOnSuccessListener { fetchConfig(this) }
}
}
private fun fetchConfig(instance: FirebaseRemoteConfig) {
instance.fetchAndActivate()
.addOnSuccessListener { updated: Boolean ->
Log.d(logTag(), "Remote config updated: $updated")
}
.addOnFailureListener { e: Exception? ->
Log.w(logTag(), "Failed updating remote config.", e)
}
}
val isInAppReviewEnabled: Boolean
get() = Firebase.remoteConfig[REMOTE_KEY_IN_APP_REVIEW_ENABLED].asBoolean()
val appUpdatesData: String
get() = Firebase.remoteConfig[REMOTE_KEY_APP_UPDATES].asString()
val remoteWordsManifest: String
get() = Firebase.remoteConfig[REMOTE_KEY_WORDS_MANIFEST].asString()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment