forked from github/wulkanowy-mirror
Use user agent template from firebase remote config (#2139)
* Use user agent template from firebase remote config * Improve base class usage, activation refactor
This commit is contained in:
parent
a495fcbc5f
commit
5331bf90cd
@ -246,6 +246,7 @@ dependencies {
|
|||||||
playImplementation 'com.google.firebase:firebase-analytics-ktx'
|
playImplementation 'com.google.firebase:firebase-analytics-ktx'
|
||||||
playImplementation 'com.google.firebase:firebase-messaging:'
|
playImplementation 'com.google.firebase:firebase-messaging:'
|
||||||
playImplementation 'com.google.firebase:firebase-crashlytics:'
|
playImplementation 'com.google.firebase:firebase-crashlytics:'
|
||||||
|
playImplementation 'com.google.firebase:firebase-config-ktx'
|
||||||
playImplementation 'com.google.android.play:core:1.10.3'
|
playImplementation 'com.google.android.play:core:1.10.3'
|
||||||
playImplementation 'com.google.android.play:core-ktx:1.8.1'
|
playImplementation 'com.google.android.play:core-ktx:1.8.1'
|
||||||
playImplementation 'com.google.android.gms:play-services-ads:21.4.0'
|
playImplementation 'com.google.android.gms:play-services-ads:21.4.0'
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
package io.github.wulkanowy.utils
|
||||||
|
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class RemoteConfigHelper @Inject constructor() : BaseRemoteConfigHelper()
|
@ -0,0 +1,7 @@
|
|||||||
|
package io.github.wulkanowy.utils
|
||||||
|
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class RemoteConfigHelper @Inject constructor() : BaseRemoteConfigHelper()
|
@ -34,11 +34,15 @@ class WulkanowyApp : Application(), Configuration.Provider {
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var adsHelper: AdsHelper
|
lateinit var adsHelper: AdsHelper
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
lateinit var remoteConfigHelper: RemoteConfigHelper
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
initializeAppLanguage()
|
initializeAppLanguage()
|
||||||
themeManager.applyDefaultTheme()
|
themeManager.applyDefaultTheme()
|
||||||
adsHelper.initialize()
|
adsHelper.initialize()
|
||||||
|
remoteConfigHelper.initialize()
|
||||||
initLogging()
|
initLogging()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import io.github.wulkanowy.data.db.SharedPrefProvider
|
|||||||
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
||||||
import io.github.wulkanowy.sdk.Sdk
|
import io.github.wulkanowy.sdk.Sdk
|
||||||
import io.github.wulkanowy.utils.AppInfo
|
import io.github.wulkanowy.utils.AppInfo
|
||||||
|
import io.github.wulkanowy.utils.RemoteConfigHelper
|
||||||
import kotlinx.serialization.ExperimentalSerializationApi
|
import kotlinx.serialization.ExperimentalSerializationApi
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import okhttp3.MediaType.Companion.toMediaType
|
import okhttp3.MediaType.Companion.toMediaType
|
||||||
@ -36,10 +37,11 @@ internal class DataModule {
|
|||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@Provides
|
@Provides
|
||||||
fun provideSdk(chuckerInterceptor: ChuckerInterceptor) =
|
fun provideSdk(chuckerInterceptor: ChuckerInterceptor, remoteConfig: RemoteConfigHelper) =
|
||||||
Sdk().apply {
|
Sdk().apply {
|
||||||
androidVersion = android.os.Build.VERSION.RELEASE
|
androidVersion = android.os.Build.VERSION.RELEASE
|
||||||
buildTag = android.os.Build.MODEL
|
buildTag = android.os.Build.MODEL
|
||||||
|
userAgentTemplate = remoteConfig.userAgentTemplate
|
||||||
setSimpleHttpLogger { Timber.d(it) }
|
setSimpleHttpLogger { Timber.d(it) }
|
||||||
|
|
||||||
// for debug only
|
// for debug only
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package io.github.wulkanowy.utils
|
||||||
|
|
||||||
|
abstract class BaseRemoteConfigHelper {
|
||||||
|
|
||||||
|
open fun initialize() = Unit
|
||||||
|
|
||||||
|
open val userAgentTemplate: String
|
||||||
|
get() = RemoteConfigDefaults.USER_AGENT_TEMPLATE.value as String
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package io.github.wulkanowy.utils
|
||||||
|
|
||||||
|
enum class RemoteConfigDefaults(val value: Any) {
|
||||||
|
USER_AGENT_TEMPLATE(""),
|
||||||
|
;
|
||||||
|
|
||||||
|
val key get() = name.lowercase()
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package io.github.wulkanowy.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import com.google.firebase.FirebaseApp
|
||||||
|
import com.google.firebase.ktx.Firebase
|
||||||
|
import com.google.firebase.remoteconfig.ktx.remoteConfig
|
||||||
|
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings
|
||||||
|
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Singleton
|
||||||
|
|
||||||
|
@Singleton
|
||||||
|
class RemoteConfigHelper @Inject constructor(
|
||||||
|
@ApplicationContext private val context: Context,
|
||||||
|
private val appInfo: AppInfo,
|
||||||
|
) : BaseRemoteConfigHelper() {
|
||||||
|
|
||||||
|
fun initialize() {
|
||||||
|
FirebaseApp.initializeApp(context)
|
||||||
|
|
||||||
|
Firebase.remoteConfig.setConfigSettingsAsync(remoteConfigSettings {
|
||||||
|
fetchTimeoutInSeconds = 3
|
||||||
|
if (appInfo.isDebug) {
|
||||||
|
minimumFetchIntervalInSeconds = 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
Firebase.remoteConfig.setDefaultsAsync(RemoteConfigDefaults.values().associate {
|
||||||
|
it.key to it.value
|
||||||
|
})
|
||||||
|
Firebase.remoteConfig.fetchAndActivate()
|
||||||
|
}
|
||||||
|
|
||||||
|
override val userAgentTemplate: String
|
||||||
|
get() = Firebase.remoteConfig.getString(RemoteConfigDefaults.USER_AGENT_TEMPLATE.key)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user