Skip to content

Commit 9a0c543

Browse files
committed
Add RoktEvent mapping and emission
1 parent 3eec545 commit 9a0c543

File tree

3 files changed

+324
-8
lines changed

3 files changed

+324
-8
lines changed

build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
21
buildscript {
3-
ext.kotlin_version = '1.7.22'
2+
ext.kotlin_version = '1.9.0'
43
if (!project.hasProperty('version') || project.version.equals('unspecified')) {
54
project.version = '+'
65
}
@@ -13,7 +12,7 @@ buildscript {
1312
dependencies {
1413
classpath 'com.android.tools.build:gradle:7.4.1'
1514
classpath 'com.mparticle:android-kit-plugin:' + project.version
16-
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.10'
15+
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0'
1716
}
1817
}
1918

@@ -58,9 +57,11 @@ repositories {
5857

5958
dependencies {
6059
implementation 'androidx.annotation:annotation:1.5.0'
60+
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
6161
api 'com.rokt:roktsdk:4.10.0'
6262

6363
testImplementation files('libs/java-json.jar')
6464
testImplementation 'com.squareup.assertj:assertj-android:1.2.0'
6565
testImplementation ("io.mockk:mockk:1.13.4")
66+
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4'
6667
}

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

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import android.content.pm.PackageManager
77
import android.graphics.Typeface
88
import android.os.Build
99
import com.mparticle.BuildConfig
10-
import com.mparticle.MParticle
1110
import com.mparticle.MParticle.IdentityType
1211
import com.mparticle.MpRoktEventCallback
1312
import com.mparticle.UnloadReasons
@@ -24,11 +23,15 @@ import com.mparticle.rokt.RoktEmbeddedView
2423
import com.rokt.roktsdk.CacheConfig
2524
import com.rokt.roktsdk.Rokt
2625
import com.rokt.roktsdk.Rokt.SdkFrameworkType.*
26+
import com.rokt.roktsdk.RoktEvent
2727
import com.rokt.roktsdk.RoktWidgetDimensionCallBack
2828
import com.rokt.roktsdk.Widget
2929
import java.lang.ref.WeakReference
3030
import java.math.BigDecimal
31-
31+
import kotlinx.coroutines.flow.Flow
32+
import kotlinx.coroutines.flow.filter
33+
import kotlinx.coroutines.flow.first
34+
import kotlinx.coroutines.flow.map
3235

3336
/**
3437
* MParticle embedded implementation of the Rokt Library.
@@ -203,6 +206,45 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
203206
)
204207
}
205208

209+
override fun events(identifier: String): Flow<com.mparticle.RoktEvent> {
210+
return Rokt.events(identifier)
211+
.map { event ->
212+
when (event) {
213+
is RoktEvent.HideLoadingIndicator -> com.mparticle.RoktEvent.HideLoadingIndicator
214+
is RoktEvent.ShowLoadingIndicator -> com.mparticle.RoktEvent.ShowLoadingIndicator
215+
is RoktEvent.FirstPositiveEngagement -> com.mparticle.RoktEvent.FirstPositiveEngagement(
216+
event.id
217+
)
218+
is RoktEvent.PositiveEngagement -> com.mparticle.RoktEvent.PositiveEngagement(
219+
event.id
220+
)
221+
is RoktEvent.OfferEngagement -> com.mparticle.RoktEvent.OfferEngagement(event.id)
222+
is RoktEvent.OpenUrl -> com.mparticle.RoktEvent.OpenUrl(event.id, event.url)
223+
is RoktEvent.PlacementClosed -> com.mparticle.RoktEvent.PlacementClosed(event.id)
224+
is RoktEvent.PlacementCompleted -> com.mparticle.RoktEvent.PlacementCompleted(
225+
event.id
226+
)
227+
is RoktEvent.PlacementFailure -> com.mparticle.RoktEvent.PlacementFailure(event.id)
228+
is RoktEvent.PlacementInteractive -> com.mparticle.RoktEvent.PlacementInteractive(
229+
event.id
230+
)
231+
is RoktEvent.PlacementReady -> com.mparticle.RoktEvent.PlacementReady(event.id)
232+
is RoktEvent.CartItemInstantPurchase -> com.mparticle.RoktEvent.CartItemInstantPurchase(
233+
placementId = event.placementId,
234+
cartItemId = event.cartItemId,
235+
catalogItemId = event.catalogItemId,
236+
currency = event.currency,
237+
description = event.description,
238+
linkedProductId = event.linkedProductId,
239+
totalPrice = event.totalPrice,
240+
quantity = event.quantity,
241+
unitPrice = event.unitPrice
242+
)
243+
is RoktEvent.InitComplete -> com.mparticle.RoktEvent.InitComplete(event.success)
244+
}
245+
}
246+
}
247+
206248
override fun setWrapperSdkVersion(wrapperSdkVersion: WrapperSdkVersion) {
207249
val sdkFrameworkType = when (wrapperSdkVersion.sdk) {
208250
WrapperSdk.WrapperFlutter -> Flutter
@@ -325,7 +367,6 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
325367
}
326368
}
327369

328-
329370
fun PackageManager.getPackageInfoForApp(packageName: String, flags: Int = 0): PackageInfo =
330371
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
331372
getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(flags.toLong()))

0 commit comments

Comments
 (0)