-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add callback support #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Mansi-mParticle
merged 2 commits into
development
from
feat/Rokt_Callback_Support-cherry-pick
May 12, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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? | ||
) { | ||
|
@@ -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 | ||
val finalAttributes: HashMap<String, String> = HashMap<String, String>() | ||
filterUser?.userAttributes?.let { userAttrs -> | ||
for ((key, value) in userAttrs) { | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
) | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.