Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions src/main/kotlin/com/mparticle/kits/RoktKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import android.content.pm.PackageInfo
import android.content.pm.PackageManager
import android.graphics.Typeface
import android.os.Build
import com.mparticle.MParticle
import com.mparticle.commerce.CommerceEvent
import com.mparticle.identity.MParticleUser
import com.mparticle.internal.Logger
import com.mparticle.kits.KitIntegration.CommerceListener
import com.mparticle.kits.KitIntegration.IdentityListener
import com.mparticle.kits.KitIntegration.RoktListener
import com.mparticle.rokt.RoktEmbeddedView
import com.rokt.roktsdk.Rokt
import com.rokt.roktsdk.Widget
import java.lang.ref.WeakReference
Expand All @@ -25,10 +27,7 @@ import java.math.BigDecimal
*/
class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListener, Rokt.RoktCallback {
private var applicationContext: Context? = null
private var onUnloadCallback: Runnable? = null
private var onLoadCallback: Runnable? = null
private var onShouldHideLoadingIndicatorCallback: Runnable? = null
private var onShouldShowLoadingIndicatorCallback: Runnable? = null
private var mpRoktEventCallback: MParticle.MpRoktEventCallback? = null
override fun getName(): String = NAME

override fun getInstance(): RoktKit = this
Expand Down Expand Up @@ -122,11 +121,8 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
override fun execute(
viewName: String,
attributes: Map<String, String>?,
onUnload: Runnable?,
onLoad: Runnable?,
onShouldHideLoadingIndicator: Runnable?,
onShouldShowLoadingIndicator: Runnable?,
placeHolders: MutableMap<String, WeakReference<com.mparticle.rokt.RoktEmbeddedView>>?,
mpRoktEventCallback: MParticle.MpRoktEventCallback,
placeHolders: MutableMap<String, WeakReference<RoktEmbeddedView>>?,
fontTypefaces: MutableMap<String, WeakReference<Typeface>>?,
filterUser: FilteredMParticleUser?
) {
Expand All @@ -136,10 +132,7 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
val widget = weakRef.get() as? Widget // Safe cast to Widget
widget?.let { entry.key to weakRef as WeakReference<Widget> } // Only include if it's a Widget
}?.toMap()
onUnloadCallback = onUnload
onLoadCallback = onLoad
onShouldHideLoadingIndicatorCallback = onShouldHideLoadingIndicator
onShouldShowLoadingIndicatorCallback = onShouldShowLoadingIndicator
this.mpRoktEventCallback = mpRoktEventCallback
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I guess in Android you can't just pass in the code blocks like I do here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about this on a call. Android seems to implement this callbacks in a protocol/delegate way while iOS passes around code blocks to achieve the same thing. Interesting difference on the Rokt side to note but we're doing things correctly for now.

val finalAttributes: HashMap<String, String> = HashMap<String, String>()
filterUser?.userAttributes?.let { userAttrs ->
for ((key, value) in userAttrs) {
Expand Down Expand Up @@ -185,19 +178,30 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
}

override fun onLoad() : Unit{
onLoadCallback?.run()
mpRoktEventCallback?.onLoad()
}

override fun onShouldHideLoadingIndicator() : Unit {
onShouldHideLoadingIndicatorCallback?.run()
mpRoktEventCallback?.onShouldHideLoadingIndicator()
}

override fun onShouldShowLoadingIndicator() : Unit {
onShouldShowLoadingIndicatorCallback?.run()
mpRoktEventCallback?.onShouldShowLoadingIndicator()
}

override fun onUnload(reason: Rokt.UnloadReasons) : Unit {
onUnloadCallback?.run()
mpRoktEventCallback?.onUnload(
when (reason) {
Rokt.UnloadReasons.NO_OFFERS -> MParticle.UnloadReasons.NO_OFFERS
Rokt.UnloadReasons.FINISHED -> MParticle.UnloadReasons.FINISHED
Rokt.UnloadReasons.TIMEOUT -> MParticle.UnloadReasons.TIMEOUT
Rokt.UnloadReasons.NETWORK_ERROR -> MParticle.UnloadReasons.NETWORK_ERROR
Rokt.UnloadReasons.NO_WIDGET -> MParticle.UnloadReasons.NO_WIDGET
Rokt.UnloadReasons.INIT_FAILED -> MParticle.UnloadReasons.INIT_FAILED
Rokt.UnloadReasons.UNKNOWN_PLACEHOLDER -> MParticle.UnloadReasons.UNKNOWN_PLACEHOLDER
Rokt.UnloadReasons.UNKNOWN -> MParticle.UnloadReasons.UNKNOWN
}
Comment on lines +193 to +203
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's missing from the iOS callback PR. Should we discuss? Looks like this code was added to android pr here, and I don't see an equivalent on iOS.

)
}
}

Expand Down
Loading