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