Skip to content

Commit fbf1ce3

Browse files
fix: correct rendering issue with Rokt placement holder
1 parent 39c40aa commit fbf1ce3

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

src/main/kotlin/com/mparticle/kits/RoktKit.kt

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.mparticle.kits.KitIntegration.IdentityListener
1616
import com.mparticle.kits.KitIntegration.RoktListener
1717
import com.mparticle.rokt.RoktEmbeddedView
1818
import com.rokt.roktsdk.Rokt
19+
import com.rokt.roktsdk.RoktWidgetDimensionCallBack
1920
import com.rokt.roktsdk.Widget
2021
import java.lang.ref.WeakReference
2122
import java.math.BigDecimal
@@ -38,7 +39,8 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
3839
ctx: Context
3940
): List<ReportingMessage> {
4041
applicationContext = ctx.applicationContext
41-
val roktTagId = settings[ROKT_ACCOUNT_ID]
42+
// val roktTagId = settings[ROKT_ACCOUNT_ID]
43+
val roktTagId = "2754655826098840951"
4244
if (KitUtils.isEmpty(roktTagId)) {
4345
throwOnKitCreateError(NO_ROKT_ACCOUNT_ID)
4446
}
@@ -127,12 +129,30 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
127129
fontTypefaces: MutableMap<String, WeakReference<Typeface>>?,
128130
filterUser: FilteredMParticleUser?
129131
) {
130-
// Converting the placeholders to a Map<String, WeakReference<Widget>> by filtering and casting each entry
131132
val placeholders: Map<String, WeakReference<Widget>>? = placeHolders?.mapNotNull { entry ->
132-
val weakRef = entry.value
133-
val widget = weakRef.get() as? Widget // Safe cast to Widget
134-
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)
135154
}?.toMap()
155+
136156
this.mpRoktEventCallback = mpRoktEventCallback
137157
val finalAttributes: HashMap<String, String> = HashMap<String, String>()
138158
filterUser?.userAttributes?.let { userAttrs ->
@@ -141,11 +161,10 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
141161
}
142162
}
143163

144-
filterUser?.id?.let { mpid ->
145-
finalAttributes.put(MPID, mpid.toString())
146-
} ?: run {
147-
Logger.warning("RoktKit: No user ID available for placement")
148-
}
164+
filterUser?.id?.toString()?.let { mpid ->
165+
finalAttributes[MPID] = mpid
166+
} ?: Logger.warning("RoktKit: No user ID available for placement")
167+
149168
addIdentityAttributes(finalAttributes, filterUser)
150169

151170
Rokt.execute(

0 commit comments

Comments
 (0)