main.com.wisetrack.sdk.SDKConfig.kt Maven / Gradle / Ivy
package com.wisetrack.sdk
import com.wisetrack.sdk.network.ActivityPackageSender
import com.wisetrack.sdk.network.IActivityPackageSender
import com.wisetrack.sdk.network.parser.JsonObjectDecoder
class SDKConfig constructor(private var wiseTrackConfig: WiseTrackConfig) :
IActivityPackageSender.ResponseDataCallbackSubscriber {
private var deviceInfo: DeviceInfo? = null
private var activityState: ActivityState? = null
private var sessionParameters: SessionParameters? = null
private var activityPackageSender: IActivityPackageSender? = null
lateinit var callback: IActivityPackageSender.ResponseConfigDataCallbackSubscriber
init {
deviceInfo = DeviceInfo(wiseTrackConfig!!)
activityState = ActivityState()
sessionParameters = SessionParameters()
val packageHandlerActivitySender: IActivityPackageSender = ActivityPackageSender(
wiseTrackConfig!!.getUrlStrategy(),
wiseTrackConfig!!.basePath,
wiseTrackConfig!!.gdprPath,
wiseTrackConfig!!.subscriptionPath,
deviceInfo!!.clientSdk
)
activityPackageSender = packageHandlerActivitySender
}
fun start() {
val now = System.currentTimeMillis()
activityState!!.eventCount++
val configBuilder =
PackageBuilder(wiseTrackConfig!!, deviceInfo!!, activityState, sessionParameters, now)
val configPackage = configBuilder.buildConfigPackage()
val sendingParameters = generateSendingParametersI()
activityPackageSender!!.sendActivityPackage(
configPackage,
sendingParameters,
this
)
}
fun initSessionInterval() {
val now = System.currentTimeMillis()
activityState!!.eventCount++
val configBuilder =
PackageBuilder(wiseTrackConfig!!, deviceInfo!!, activityState, sessionParameters, now)
val configPackage = configBuilder.buildAppSettingsPackage()
val sendingParameters = generateSendingParametersI()
activityPackageSender!!.sendActivityPackage(
configPackage,
sendingParameters,
this
)
}
private fun generateSendingParametersI(): HashMap {
val sendingParameters = HashMap()
val now = System.currentTimeMillis()
val dateString = Util.dateFormatter.format(now)
PackageBuilder.addString(sendingParameters, "sent_at", dateString)
return sendingParameters
}
override fun onResponseDataCallback(responseData: ResponseData) {
if (Util.isStageOrDebug())
println("config response: " + responseData.toString())
if (responseData.activityKind!!.name.equals("APP_SETTINGS")) {
val parseJson = JsonObjectDecoder(responseData.jsonResponse.toString())
val configResponse = parseJson.getConfigModel()
if (configResponse.session_interval != null) {
Constants.CONFIG_SESSION_INTERVAL =
configResponse.session_interval!!.toLong()
}
return
}
if (callback != null) {
callback.onResponseConfigDataCallback(responseData.jsonResponse.toString())
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy