All Downloads are FREE. Search and download functionalities are using the official Maven repository.

main.com.wisetrack.sdk.SDKConfig.kt Maven / Gradle / Ivy

There is a newer version: 1.5.3
Show newest version
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())
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy