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
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(){
/* if (!checkActivityStateI(activityState)) return
if (!isEnabledI()) return
if (!checkEventI(event)) return
if (!checkOrderIdI(event.orderId)) return
if (activityState!!.isGdprForgotten) return*/
val now = System.currentTimeMillis()
activityState!!.eventCount++
// updateActivityStateI(now)
val configBuilder =
PackageBuilder(wiseTrackConfig!!, deviceInfo!!, activityState, sessionParameters, now)
val configPackage = configBuilder.buildConfigPackage()
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)
/* val queueSize = packageQueue!!.size - 1
if (queueSize > 0) {
PackageBuilder.addLong(sendingParameters, "queue_size", queueSize.toLong())
}*/
return sendingParameters
}
override fun onResponseDataCallback(responseData: ResponseData) {
println("get response ${responseData.jsonResponse.toString()}")
if (callback != null){
callback.onResponseConfigDataCallback(responseData.jsonResponse.toString())
}
}
}