Skip to content

Commit 3dffb40

Browse files
committed
feat: Add callback support
1 parent 9109c59 commit 3dffb40

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.content.pm.PackageInfo
66
import android.content.pm.PackageManager
77
import android.graphics.Typeface
88
import android.os.Build
9+
import com.mparticle.MParticle
910
import com.mparticle.commerce.CommerceEvent
1011
import com.mparticle.identity.MParticleUser
1112
import com.mparticle.internal.Logger
@@ -26,10 +27,7 @@ import java.math.BigDecimal
2627
*/
2728
class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListener, Rokt.RoktCallback {
2829
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
30+
private var mpEventCallback: MParticle.MpEventCallback? = null
3331
override fun getName(): String = NAME
3432

3533
override fun getInstance(): RoktKit = this
@@ -123,11 +121,8 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
123121
override fun execute(
124122
viewName: String,
125123
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>>?,
124+
mpEventCallback: MParticle.MpEventCallback,
125+
placeHolders: MutableMap<String, WeakReference<RoktEmbeddedView>>?,
131126
fontTypefaces: MutableMap<String, WeakReference<Typeface>>?,
132127
filterUser: FilteredMParticleUser?
133128
) {
@@ -138,10 +133,7 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
138133
entry.value.get()?.addView(widget)
139134
entry.key to WeakReference(widget)
140135
}?.toMap()
141-
onUnloadCallback = onUnload
142-
onLoadCallback = onLoad
143-
onShouldHideLoadingIndicatorCallback = onShouldHideLoadingIndicator
144-
onShouldShowLoadingIndicatorCallback = onShouldShowLoadingIndicator
136+
this.mpEventCallback = mpEventCallback
145137
val finalAttributes: HashMap<String, String> = HashMap<String, String>()
146138
filterUser?.userAttributes?.let { userAttrs ->
147139
for ((key, value) in userAttrs) {
@@ -187,19 +179,30 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
187179
}
188180

189181
override fun onLoad() : Unit{
190-
onLoadCallback?.run()
182+
mpEventCallback?.onLoad()
191183
}
192184

193185
override fun onShouldHideLoadingIndicator() : Unit {
194-
onShouldHideLoadingIndicatorCallback?.run()
186+
mpEventCallback?.onShouldHideLoadingIndicator()
195187
}
196188

197189
override fun onShouldShowLoadingIndicator() : Unit {
198-
onShouldShowLoadingIndicatorCallback?.run()
190+
mpEventCallback?.onShouldShowLoadingIndicator()
199191
}
200192

201193
override fun onUnload(reason: Rokt.UnloadReasons) : Unit {
202-
onUnloadCallback?.run()
194+
mpEventCallback?.onUnload(
195+
when (reason) {
196+
Rokt.UnloadReasons.NO_OFFERS -> MParticle.UnloadReasons.NO_OFFERS
197+
Rokt.UnloadReasons.FINISHED -> MParticle.UnloadReasons.FINISHED
198+
Rokt.UnloadReasons.TIMEOUT -> MParticle.UnloadReasons.TIMEOUT
199+
Rokt.UnloadReasons.NETWORK_ERROR -> MParticle.UnloadReasons.NETWORK_ERROR
200+
Rokt.UnloadReasons.NO_WIDGET -> MParticle.UnloadReasons.NO_WIDGET
201+
Rokt.UnloadReasons.INIT_FAILED -> MParticle.UnloadReasons.INIT_FAILED
202+
Rokt.UnloadReasons.UNKNOWN_PLACEHOLDER -> MParticle.UnloadReasons.UNKNOWN_PLACEHOLDER
203+
Rokt.UnloadReasons.UNKNOWN -> MParticle.UnloadReasons.UNKNOWN
204+
}
205+
)
203206
}
204207
}
205208

0 commit comments

Comments
 (0)