diff --git a/src/main/kotlin/com/mparticle/kits/RoktKit.kt b/src/main/kotlin/com/mparticle/kits/RoktKit.kt index 89136d5..8116cca 100644 --- a/src/main/kotlin/com/mparticle/kits/RoktKit.kt +++ b/src/main/kotlin/com/mparticle/kits/RoktKit.kt @@ -118,6 +118,7 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen For more details, visit the official documentation: https://docs.rokt.com/developers/integration-guides/android/how-to/adding-a-placement/ */ + @Suppress("UNCHECKED_CAST", "CAST_NEVER_SUCCEEDS") override fun execute( viewName: String, attributes: Map?, @@ -131,17 +132,17 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen ) { // Converting the placeholders to a Map> by filtering and casting each entry val placeholders: Map>? = placeHolders?.mapNotNull { entry -> - (entry.value as? WeakReference)?.let { - entry.key to it - } + val weakRef = entry.value + val widget = weakRef.get() as? Widget // Safe cast to Widget + widget?.let { entry.key to weakRef as WeakReference } // Only include if it's a Widget }?.toMap() onUnloadCallback = onUnload onLoadCallback = onLoad onShouldHideLoadingIndicatorCallback = onShouldHideLoadingIndicator onShouldShowLoadingIndicatorCallback = onShouldShowLoadingIndicator val finalAttributes: HashMap = HashMap() - filterUser?.userAttributes?.let { attributes -> - for ((key, value) in attributes) { + filterUser?.userAttributes?.let { userAttrs -> + for ((key, value) in userAttrs) { finalAttributes[key] = value.toString() } } @@ -183,19 +184,19 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen const val NO_APP_VERSION_FOUND = "No App version found, can't initialize kit." } - override fun onLoad() { + override fun onLoad(): Unit { onLoadCallback?.run() } - override fun onShouldHideLoadingIndicator() { + override fun onShouldHideLoadingIndicator(): Unit { onShouldHideLoadingIndicatorCallback?.run() } - override fun onShouldShowLoadingIndicator() { + override fun onShouldShowLoadingIndicator(): Unit { onShouldShowLoadingIndicatorCallback?.run() } - override fun onUnload(reason: Rokt.UnloadReasons) { + override fun onUnload(reason: Rokt.UnloadReasons): Unit { onUnloadCallback?.run() } }