Updated on 2026-08-14
This commit is contained in:
parent
5987be96a7
commit
5968cf338f
2 changed files with 33 additions and 0 deletions
|
|
@ -98,6 +98,7 @@ dependencies {
|
|||
// Firebase
|
||||
implementation platform('com.google.firebase:firebase-bom:26.0.0')
|
||||
implementation 'com.google.firebase:firebase-crashlytics'
|
||||
implementation 'com.google.firebase:firebase-config-ktx'
|
||||
implementation 'com.google.firebase:firebase-analytics-ktx'
|
||||
|
||||
testImplementation 'junit:junit:4.13'
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package com.tangem.tap.domain.config
|
||||
|
||||
import android.content.Context
|
||||
import com.google.firebase.ktx.Firebase
|
||||
import com.google.firebase.remoteconfig.ktx.remoteConfig
|
||||
import com.squareup.moshi.JsonAdapter
|
||||
import com.tangem.wallet.BuildConfig
|
||||
import timber.log.Timber
|
||||
|
|
@ -65,4 +67,34 @@ class LocalLoader(
|
|||
private fun readAssetAsString(fileName: String): String {
|
||||
return context.assets.open("$fileName.json").bufferedReader().readText()
|
||||
}
|
||||
}
|
||||
|
||||
class RemoteLoader(
|
||||
private val nameResolver: NameResolver,
|
||||
private val adapter: JsonAdapter<ConfigModel>
|
||||
) : ConfigLoader {
|
||||
|
||||
override suspend fun loadConfig(onComplete: (Config) -> Unit) {
|
||||
val emptyConfig = Config.empty()
|
||||
val remoteConfig = Firebase.remoteConfig
|
||||
remoteConfig.fetchAndActivate().addOnCompleteListener {
|
||||
if (it.isSuccessful) {
|
||||
val config = remoteConfig.getValue(nameResolver.getFeaturesName())
|
||||
val jsonConfig = config.asString()
|
||||
if (jsonConfig.isEmpty()) {
|
||||
onComplete(emptyConfig)
|
||||
return@addOnCompleteListener
|
||||
}
|
||||
val configModel = adapter.fromJson(jsonConfig)
|
||||
val features = configModel?.toFeatures(ConfigType.Remote) ?: mutableMapOf()
|
||||
val configValues = configModel?.toConfigValues() ?: mutableMapOf()
|
||||
onComplete(Config(features, configValues))
|
||||
} else {
|
||||
onComplete(emptyConfig)
|
||||
}
|
||||
}.addOnFailureListener {
|
||||
Timber.e(it)
|
||||
onComplete(emptyConfig)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue