11package com.mparticle.kits
22
33import android.content.Context
4+ import com.mparticle.MPEvent
5+ import com.mparticle.MParticle.IdentityType
6+ import com.mparticle.commerce.CommerceEvent
7+ import com.mparticle.commerce.Product
8+ import com.mparticle.identity.MParticleUser
49import com.mparticle.kits.KitIntegration.AttributeListener
510import com.mparticle.kits.KitIntegration.CommerceListener
611import com.mparticle.kits.KitIntegration.IdentityListener
712import com.mparticle.kits.KitIntegration.SessionListener
8- import java.util.HashMap
913import com.taplytics.sdk.Taplytics
10- import org.json.JSONObject
1114import org.json.JSONException
12- import com.mparticle.MParticle.IdentityType
13- import com.mparticle.identity.MParticleUser
14- import com.mparticle.commerce.CommerceEvent
15- import com.mparticle.commerce.Product
16- import com.mparticle.MPEvent
15+ import org.json.JSONObject
1716import java.lang.Exception
1817import java.math.BigDecimal
18+ import java.util.HashMap
1919
20- open class TaplyticsKit : KitIntegration (), AttributeListener, KitIntegration.EventListener,
21- CommerceListener , IdentityListener , SessionListener {
20+ open class TaplyticsKit :
21+ KitIntegration (),
22+ AttributeListener ,
23+ KitIntegration .EventListener ,
24+ CommerceListener ,
25+ IdentityListener ,
26+ SessionListener {
2227 private fun mergeOptions (
2328 tlOptions : Map <String ?, Any ?>,
24- configuration : MutableMap <String , Any >?
29+ configuration : MutableMap <String , Any >? ,
2530 ): HashMap <String ?, Any ?> {
2631 var tlOptions: Map <String ?, Any ?>? = tlOptions
2732 var configuration = configuration
@@ -40,7 +45,7 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
4045
4146 public override fun onKitCreate (
4247 settings : Map <String , String >,
43- context : Context
48+ context : Context ,
4449 ): List <ReportingMessage > {
4550 if (! started && ! delayInitializationUntilSessionStart) {
4651 started = true
@@ -50,16 +55,20 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
5055 }
5156
5257 private fun createReportingMessages (message : String ): List <ReportingMessage > {
53- val reportingMessage = ReportingMessage (
54- this ,
55- message,
56- System .currentTimeMillis(),
57- null
58- )
58+ val reportingMessage =
59+ ReportingMessage (
60+ this ,
61+ message,
62+ System .currentTimeMillis(),
63+ null ,
64+ )
5965 return listOf (reportingMessage)
6066 }
6167
62- protected open fun startTaplytics (settings : Map <String , String >, context : Context ? ) {
68+ protected open fun startTaplytics (
69+ settings : Map <String , String >,
70+ context : Context ? ,
71+ ) {
6372 val apiKey = getAPIKey(settings)
6473 val options = mergeOptions(tlOptions, getOptionsFromConfiguration(settings))
6574 options[DELAYED_START ] = true
@@ -68,19 +77,19 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
6877
6978 private fun getAPIKey (settings : Map <String , String >): String? {
7079 val apiKey = settings[API_KEY ]
71- require(! KitUtils .isEmpty(apiKey)) { FAILED_TO_INITIALIZE_KIT_MESSAGE }
80+ require(! KitUtils .isEmpty(apiKey)) { FAILED_TO_INITIALIZE_KIT_MESSAGE }
7281 return apiKey
7382 }
7483
7584 private fun getOptionsFromConfiguration (settings : Map <String , String >): MutableMap <String , Any >? {
76- val options = HashMap <String , Any > ()
85+ val options = HashMap <String , Any >()
7786 addAggressiveOption(options, settings)
7887 return if (options.isEmpty()) null else options
7988 }
8089
8190 private fun addAggressiveOption (
8291 options : MutableMap <String , Any >,
83- settings : Map <String , String >
92+ settings : Map <String , String >,
8493 ) {
8594 val agg = settings[AGGRESSIVE ].toBoolean()
8695 options[TAPLYTICS_AGGRESSIVE ] = agg
@@ -91,7 +100,10 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
91100 /* *
92101 * AttributeListener Interface
93102 */
94- override fun setUserAttribute (attributeKey : String , attributeValue : String? ) {
103+ override fun setUserAttribute (
104+ attributeKey : String ,
105+ attributeValue : String? ,
106+ ) {
95107 try {
96108 val attr = JSONObject ()
97109 if (attributeValue != null ) {
@@ -108,14 +120,17 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
108120
109121 override fun setAllUserAttributes (
110122 attributes : Map <String , String >,
111- attributeLists : Map <String , List <String >>
123+ attributeLists : Map <String , List <String >>,
112124 ) {
113125 for ((key, value) in attributes) {
114126 setUserAttribute(key, value)
115127 }
116128 }
117129
118- override fun setUserIdentity (identityType : IdentityType , s : String? ) {
130+ override fun setUserIdentity (
131+ identityType : IdentityType ,
132+ s : String? ,
133+ ) {
119134 // no-op
120135 }
121136
@@ -129,7 +144,7 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
129144
130145 override fun onIdentifyCompleted (
131146 mParticleUser : MParticleUser ,
132- filteredIdentityApiRequest : FilteredIdentityApiRequest
147+ filteredIdentityApiRequest : FilteredIdentityApiRequest ,
133148 ) {
134149 setUserAttributeFromRequest(filteredIdentityApiRequest)
135150 }
@@ -152,13 +167,16 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
152167 }
153168 }
154169
155- override fun onLoginCompleted (user : MParticleUser , request : FilteredIdentityApiRequest ) {
170+ override fun onLoginCompleted (
171+ user : MParticleUser ,
172+ request : FilteredIdentityApiRequest ,
173+ ) {
156174 setUserAttributeFromRequest(request)
157175 }
158176
159177 override fun onLogoutCompleted (
160178 mParticleUser : MParticleUser ,
161- filteredIdentityApiRequest : FilteredIdentityApiRequest
179+ filteredIdentityApiRequest : FilteredIdentityApiRequest ,
162180 ) {
163181 Taplytics .resetAppUser {
164182 // no-op
@@ -167,7 +185,7 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
167185
168186 override fun onModifyCompleted (
169187 mParticleUser : MParticleUser ,
170- request : FilteredIdentityApiRequest
188+ request : FilteredIdentityApiRequest ,
171189 ) {
172190 setUserAttributeFromRequest(request)
173191 }
@@ -181,14 +199,17 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
181199 */
182200 override fun logout (): List <ReportingMessage > = emptyList()
183201
184- override fun setUserAttributeList (attribute : String , attributeValueList : List <String >) {}
202+ override fun setUserAttributeList (
203+ attribute : String ,
204+ attributeValueList : List <String >,
205+ ) {}
185206
186207 /* *
187208 * CommerceListener Interface
188209 */
189210 override fun logEvent (event : CommerceEvent ): List <ReportingMessage > {
190211 if (! KitUtils .isEmpty(event.productAction) &&
191- event.productAction.equals(Product .PURCHASE ,true )
212+ event.productAction.equals(Product .PURCHASE , true )
192213 ) {
193214 val transactionAttributes = event.transactionAttributes ? : return emptyList()
194215 val id = transactionAttributes.id
@@ -215,7 +236,7 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
215236
216237 override fun logScreen (
217238 screenName : String ,
218- screenAttributes : Map <String , String >
239+ screenAttributes : Map <String , String >,
219240 ): List <ReportingMessage > {
220241 Taplytics .logEvent(screenName)
221242 return createReportingMessages(ReportingMessage .MessageType .SCREEN_VIEW )
@@ -227,24 +248,22 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
227248 override fun logException (
228249 exception : Exception ,
229250 exceptionAttributes : Map <String , String >,
230- message : String
251+ message : String ,
231252 ): List <ReportingMessage > = emptyList()
232253
233-
234254 override fun logError (
235255 message : String ,
236- errorAttributes : Map <String , String >
256+ errorAttributes : Map <String , String >,
237257 ): List <ReportingMessage > = emptyList()
238258
239259 override fun leaveBreadcrumb (breadcrumb : String ): List <ReportingMessage > = emptyList()
240260
241-
242- // put all these together
261+ // put all these together
243262 override fun logLtvIncrease (
244263 valueIncreased : BigDecimal ,
245264 valueTotal : BigDecimal ,
246265 eventName : String ,
247- contextInfo : Map <String , String >
266+ contextInfo : Map <String , String >,
248267 ): List <ReportingMessage > = emptyList()
249268
250269 override fun setOptOut (optedOut : Boolean ): List <ReportingMessage > {
@@ -280,14 +299,16 @@ open class TaplyticsKit : KitIntegration(), AttributeListener, KitIntegration.Ev
280299 private const val DELAYED_START = " delayedStartTaplytics"
281300 private const val FAILED_TO_INITIALIZE_KIT_MESSAGE = " Failed to initialize Taplytics SDK - an API key is required"
282301 private const val KIT_NAME = " Taplytics"
302+
283303 @JvmField
284304 var delayInitializationUntilSessionStart = false
305+
285306 @JvmField
286307 var started = false
287308
288309 /* *
289310 * tlOptions get and set methods
290311 */
291- var tlOptions = HashMap <String ?, Any ?> ()
312+ var tlOptions = HashMap <String ?, Any ?>()
292313 }
293314}
0 commit comments