@@ -7,13 +7,18 @@ import android.content.pm.PackageManager
7
7
import android.graphics.Typeface
8
8
import android.os.Build
9
9
import com.mparticle.BuildConfig
10
+ import com.mparticle.MParticle
11
+ import com.mparticle.MParticle.IdentityType
10
12
import com.mparticle.commerce.CommerceEvent
11
13
import com.mparticle.identity.MParticleUser
14
+ import com.mparticle.internal.Constants
12
15
import com.mparticle.internal.Logger
13
16
import com.mparticle.kits.KitIntegration.CommerceListener
14
17
import com.mparticle.kits.KitIntegration.IdentityListener
15
18
import com.mparticle.kits.KitIntegration.RoktListener
19
+ import com.mparticle.rokt.RoktEmbeddedView
16
20
import com.rokt.roktsdk.Rokt
21
+ import com.rokt.roktsdk.RoktWidgetDimensionCallBack
17
22
import com.rokt.roktsdk.Widget
18
23
import java.lang.ref.WeakReference
19
24
import java.math.BigDecimal
@@ -26,10 +31,7 @@ import java.math.BigDecimal
26
31
*/
27
32
class RoktKit : KitIntegration (), CommerceListener, IdentityListener, RoktListener, Rokt.RoktCallback {
28
33
private var applicationContext: Context ? = null
29
- private var onUnloadCallback: Runnable ? = null
30
- private var onLoadCallback: Runnable ? = null
31
- private var onShouldHideLoadingIndicatorCallback: Runnable ? = null
32
- private var onShouldShowLoadingIndicatorCallback: Runnable ? = null
34
+ private var mpRoktEventCallback: MParticle .MpRoktEventCallback ? = null
33
35
override fun getName (): String = NAME
34
36
35
37
override fun getInstance (): RoktKit = this
@@ -134,38 +136,54 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
134
136
@Suppress(" UNCHECKED_CAST" , " CAST_NEVER_SUCCEEDS" )
135
137
override fun execute (
136
138
viewName : String ,
137
- attributes : Map <String , String >? ,
138
- onUnload : Runnable ? ,
139
- onLoad : Runnable ? ,
140
- onShouldHideLoadingIndicator : Runnable ? ,
141
- onShouldShowLoadingIndicator : Runnable ? ,
142
- placeHolders : MutableMap <String , WeakReference <com.mparticle.rokt.RoktEmbeddedView >>? ,
139
+ attributes : Map <String , String >,
140
+ mpRoktEventCallback : MParticle .MpRoktEventCallback ? ,
141
+ placeHolders : MutableMap <String , WeakReference <RoktEmbeddedView >>? ,
143
142
fontTypefaces : MutableMap <String , WeakReference <Typeface >>? ,
144
143
filterUser : FilteredMParticleUser ?
145
144
) {
146
- // Converting the placeholders to a Map<String, WeakReference<Widget>> by filtering and casting each entry
147
145
val placeholders: Map <String , WeakReference <Widget >>? = placeHolders?.mapNotNull { entry ->
148
- val weakRef = entry.value
149
- val widget = weakRef.get() as ? Widget // Safe cast to Widget
150
- widget?.let { entry.key to weakRef as WeakReference <Widget > } // Only include if it's a Widget
146
+ val widget = Widget (entry.value.get()?.context as Context )
147
+ entry.value.get()?.removeAllViews()
148
+ entry.value.get()?.addView(widget)
149
+ entry.value.get()?.dimensionCallBack?.let {
150
+ widget.registerDimensionListener(object : RoktWidgetDimensionCallBack {
151
+ override fun onHeightChanged (height : Int ) {
152
+ it.onHeightChanged(height)
153
+ }
154
+
155
+ override fun onMarginChanged (
156
+ start : Int ,
157
+ top : Int ,
158
+ end : Int ,
159
+ bottom : Int
160
+ ) {
161
+ it.onMarginChanged(start, top, end, bottom)
162
+ }
163
+
164
+ })
165
+ }
166
+ entry.key to WeakReference (widget)
151
167
}?.toMap()
152
- onUnloadCallback = onUnload
153
- onLoadCallback = onLoad
154
- onShouldHideLoadingIndicatorCallback = onShouldHideLoadingIndicator
155
- onShouldShowLoadingIndicatorCallback = onShouldShowLoadingIndicator
168
+
169
+ this .mpRoktEventCallback = mpRoktEventCallback
156
170
val finalAttributes: HashMap <String , String > = HashMap <String , String >()
157
171
filterUser?.userAttributes?.let { userAttrs ->
158
172
for ((key, value) in userAttrs) {
159
173
finalAttributes[key] = value.toString()
160
174
}
161
175
}
162
- filterAttributes(finalAttributes, configuration).let {
163
- finalAttributes.putAll(it)
164
- }
165
- filterUser?.id?.let { mpid ->
166
- finalAttributes.put(MPID , mpid.toString())
167
- } ? : run {
168
- Logger .warning(" RoktKit: No user ID available for placement" )
176
+
177
+ filterUser?.id?.toString()?.let { mpid ->
178
+ finalAttributes[MPID ] = mpid
179
+ } ? : Logger .warning(" RoktKit: No user ID available for placement" )
180
+
181
+ addIdentityAttributes(finalAttributes, filterUser)
182
+
183
+
184
+ val SANDBOX_MODE_ROKT : String = " sandbox"
185
+ attributes?.get(SANDBOX_MODE_ROKT )?.let { value ->
186
+ finalAttributes.put(SANDBOX_MODE_ROKT , value)
169
187
}
170
188
171
189
Rokt .execute(
@@ -178,15 +196,49 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
178
196
)
179
197
}
180
198
181
- private fun filterAttributes (attributes : Map <String , String >, kitConfiguration : KitConfiguration ): Map <String , String > {
182
- val userAttributes: MutableMap <String , String > = HashMap <String , String >()
183
- for ((key, value) in attributes) {
184
- val hashKey = KitUtils .hashForFiltering(key)
185
- if (! kitConfiguration.mAttributeFilters.get(hashKey)) {
186
- userAttributes[key] = value
199
+
200
+ private fun addIdentityAttributes (attributes : MutableMap <String , String >? , filterUser : FilteredMParticleUser ? ): MutableMap <String , String > {
201
+ val identityAttributes = mutableMapOf<String , String >()
202
+ if (filterUser != null ) {
203
+ for ((identityNumberKey, identityValue) in filterUser.userIdentities) {
204
+ val identityType = getStringForIdentity(identityNumberKey)
205
+ identityAttributes[identityType] = identityValue
187
206
}
188
207
}
189
- return userAttributes
208
+ if (attributes != null ) {
209
+ attributes.putAll(identityAttributes)
210
+ return attributes
211
+ } else {
212
+ return identityAttributes
213
+ }
214
+ }
215
+
216
+ private fun getStringForIdentity (identityType : IdentityType ): String {
217
+ return when (identityType) {
218
+ IdentityType .Other -> " other"
219
+ IdentityType .CustomerId -> " customerid"
220
+ IdentityType .Facebook -> " facebook"
221
+ IdentityType .Twitter -> " twitter"
222
+ IdentityType .Google -> " google"
223
+ IdentityType .Microsoft -> " microsoft"
224
+ IdentityType .Yahoo -> " yahoo"
225
+ IdentityType .Email -> " email"
226
+ IdentityType .Alias -> " alias"
227
+ IdentityType .FacebookCustomAudienceId -> " facebookcustomaudienceid"
228
+ IdentityType .Other2 -> " other2"
229
+ IdentityType .Other3 -> " other3"
230
+ IdentityType .Other4 -> " other4"
231
+ IdentityType .Other5 -> " other5"
232
+ IdentityType .Other6 -> " other6"
233
+ IdentityType .Other7 -> " other7"
234
+ IdentityType .Other8 -> " other8"
235
+ IdentityType .Other9 -> " other9"
236
+ IdentityType .Other10 -> " other10"
237
+ IdentityType .MobileNumber -> " mobilenumber"
238
+ IdentityType .PhoneNumber2 -> " phonenumber2"
239
+ IdentityType .PhoneNumber3 -> " phonenumber3"
240
+ else -> " "
241
+ }
190
242
}
191
243
192
244
companion object {
@@ -197,20 +249,32 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
197
249
const val NO_APP_VERSION_FOUND = " No App version found, can't initialize kit."
198
250
}
199
251
252
+
200
253
override fun onLoad () : Unit {
201
- onLoadCallback?. run ()
254
+ mpRoktEventCallback?.onLoad ()
202
255
}
203
256
204
257
override fun onShouldHideLoadingIndicator () : Unit {
205
- onShouldHideLoadingIndicatorCallback?. run ()
258
+ mpRoktEventCallback?.onShouldHideLoadingIndicator ()
206
259
}
207
260
208
261
override fun onShouldShowLoadingIndicator () : Unit {
209
- onShouldShowLoadingIndicatorCallback?. run ()
262
+ mpRoktEventCallback?.onShouldShowLoadingIndicator ()
210
263
}
211
264
212
265
override fun onUnload (reason : Rokt .UnloadReasons ) : Unit {
213
- onUnloadCallback?.run ()
266
+ mpRoktEventCallback?.onUnload(
267
+ when (reason) {
268
+ Rokt .UnloadReasons .NO_OFFERS -> MParticle .UnloadReasons .NO_OFFERS
269
+ Rokt .UnloadReasons .FINISHED -> MParticle .UnloadReasons .FINISHED
270
+ Rokt .UnloadReasons .TIMEOUT -> MParticle .UnloadReasons .TIMEOUT
271
+ Rokt .UnloadReasons .NETWORK_ERROR -> MParticle .UnloadReasons .NETWORK_ERROR
272
+ Rokt .UnloadReasons .NO_WIDGET -> MParticle .UnloadReasons .NO_WIDGET
273
+ Rokt .UnloadReasons .INIT_FAILED -> MParticle .UnloadReasons .INIT_FAILED
274
+ Rokt .UnloadReasons .UNKNOWN_PLACEHOLDER -> MParticle .UnloadReasons .UNKNOWN_PLACEHOLDER
275
+ Rokt .UnloadReasons .UNKNOWN -> MParticle .UnloadReasons .UNKNOWN
276
+ }
277
+ )
214
278
}
215
279
}
216
280
0 commit comments