-
Notifications
You must be signed in to change notification settings - Fork 4
/
RemoteConfigWrapper.kt
37 lines (29 loc) · 1.22 KB
/
RemoteConfigWrapper.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.canerture.firebaseexamples.data.wrapper
import com.canerture.firebaseexamples.common.showLogDebug
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings
import kotlin.time.Duration.Companion.hours
import kotlin.time.DurationUnit
class RemoteConfigWrapper(private val firebaseRemoteConfig: FirebaseRemoteConfig) {
fun initRemoteConfig() {
val configSettings = FirebaseRemoteConfigSettings.Builder()
.setMinimumFetchIntervalInSeconds(12.hours.toLong(DurationUnit.SECONDS))
.build()
firebaseRemoteConfig.setConfigSettingsAsync(configSettings)
firebaseRemoteConfig.setDefaultsAsync(
mapOf(
"interstitialAdShowState" to true
)
)
}
fun fetchInterstitialAdShowState(nativeAdsShowState: (Boolean) -> Unit) {
firebaseRemoteConfig.fetchAndActivate().addOnCompleteListener {
nativeAdsShowState(firebaseRemoteConfig.getBoolean("interstitialAdShowState"))
}.addOnFailureListener {
showLogDebug(TAG, it.message.orEmpty())
}
}
companion object {
private const val TAG = "RemoteConfigWrapper"
}
}