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
36 changes: 33 additions & 3 deletions src/main/kotlin/com/mparticle/kits/RoktKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ 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.RoktConfig
import com.mparticle.rokt.RoktEmbeddedView
import com.rokt.roktsdk.CacheConfig
import com.rokt.roktsdk.Rokt
import com.rokt.roktsdk.RoktWidgetDimensionCallBack
import com.rokt.roktsdk.Widget
Expand Down Expand Up @@ -139,7 +141,8 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
mpRoktEventCallback: MParticle.MpRoktEventCallback?,
placeHolders: MutableMap<String, WeakReference<RoktEmbeddedView>>?,
fontTypefaces: MutableMap<String, WeakReference<Typeface>>?,
filterUser: FilteredMParticleUser?
filterUser: FilteredMParticleUser?,
mpRoktConfig: RoktConfig?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
mpRoktConfig: RoktConfig?
mpRoktConfig: RoktConfig?,

Lint rules to add these automatically would be nice

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

KtLint currently isn't working in the repo from what I can tell. Bumping to version 12.3.0 of the plugin used fixes the issue but there are around 50 issues flagged

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I made this ticket to update KTKLint. We can prioritize it in the future for someone. It may make sense for right after or before the release once the purchaseFinalized API gets in bc I think that's the last one we need for release.

) {
val placeholders: Map<String, WeakReference<Widget>>? = placeHolders?.mapNotNull { entry ->
val widget = Widget(entry.value.get()?.context as Context)
Expand Down Expand Up @@ -184,17 +187,44 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
attributes?.get(SANDBOX_MODE_ROKT)?.let { value ->
finalAttributes.put(SANDBOX_MODE_ROKT, value)
}

val roktConfig = mpRoktConfig?.let { mapToRoktConfig(it) }
Rokt.execute(
viewName,
finalAttributes,
this,
// Pass placeholders and fontTypefaces only if they are not empty or null
placeholders.takeIf { it?.isNotEmpty() == true },
fontTypefaces.takeIf { it?.isNotEmpty() == true }
fontTypefaces.takeIf { it?.isNotEmpty() == true },
roktConfig
)
}

public fun mapToRoktConfig(config: RoktConfig): com.rokt.roktsdk.RoktConfig {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Mansi-mParticle I know it's merged already but wondering if this really should be public?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't be public. I just made it public for testing and will change it back.

val colorMode = when (config.colorMode) {
RoktConfig.ColorMode.LIGHT -> com.rokt.roktsdk.RoktConfig.ColorMode.LIGHT
RoktConfig.ColorMode.DARK -> com.rokt.roktsdk.RoktConfig.ColorMode.DARK
RoktConfig.ColorMode.SYSTEM -> com.rokt.roktsdk.RoktConfig.ColorMode.SYSTEM
else -> com.rokt.roktsdk.RoktConfig.ColorMode.SYSTEM
}

val cacheConfig = config.cacheConfig?.cacheDurationInSeconds?.let {
CacheConfig(
cacheDurationInSeconds = it,
cacheAttributes = config.cacheConfig?.cacheAttributes
)
}

val edgeToEdgeDisplay = config.edgeToEdgeDisplay

val builder = com.rokt.roktsdk.RoktConfig.Builder()
.colorMode(colorMode)
.edgeToEdgeDisplay(edgeToEdgeDisplay)

cacheConfig?.let {
builder.cacheConfig(it)
}
return builder.build()
}

private fun addIdentityAttributes(attributes: MutableMap<String, String>?, filterUser: FilteredMParticleUser?): MutableMap<String, String> {
val identityAttributes = mutableMapOf<String, String>()
Expand Down
Loading