Skip to content

Commit e53cf1c

Browse files
fix: Kotlin lint error related to type casting for specific Kotlin version
1 parent 5fa0c10 commit e53cf1c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
118118
For more details, visit the official documentation:
119119
https://docs.rokt.com/developers/integration-guides/android/how-to/adding-a-placement/
120120
*/
121+
@Suppress("UNCHECKED_CAST", "CAST_NEVER_SUCCEEDS")
121122
override fun execute(
122123
viewName: String,
123124
attributes: Map<String, String>?,
@@ -131,17 +132,17 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
131132
) {
132133
// Converting the placeholders to a Map<String, WeakReference<Widget>> by filtering and casting each entry
133134
val placeholders: Map<String, WeakReference<Widget>>? = placeHolders?.mapNotNull { entry ->
134-
(entry.value as? WeakReference<Widget>)?.let {
135-
entry.key to it
136-
}
135+
val weakRef = entry.value
136+
val widget = weakRef.get() as? Widget // Safe cast to Widget
137+
widget?.let { entry.key to weakRef as WeakReference<Widget> } // Only include if it's a Widget
137138
}?.toMap()
138139
onUnloadCallback = onUnload
139140
onLoadCallback = onLoad
140141
onShouldHideLoadingIndicatorCallback = onShouldHideLoadingIndicator
141142
onShouldShowLoadingIndicatorCallback = onShouldShowLoadingIndicator
142143
val finalAttributes: HashMap<String, String> = HashMap<String, String>()
143-
filterUser?.userAttributes?.let { attributes ->
144-
for ((key, value) in attributes) {
144+
filterUser?.userAttributes?.let { userAttrs ->
145+
for ((key, value) in userAttrs) {
145146
finalAttributes[key] = value.toString()
146147
}
147148
}
@@ -183,19 +184,19 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
183184
const val NO_APP_VERSION_FOUND = "No App version found, can't initialize kit."
184185
}
185186

186-
override fun onLoad() {
187+
override fun onLoad() : Unit{
187188
onLoadCallback?.run()
188189
}
189190

190-
override fun onShouldHideLoadingIndicator() {
191+
override fun onShouldHideLoadingIndicator() : Unit {
191192
onShouldHideLoadingIndicatorCallback?.run()
192193
}
193194

194-
override fun onShouldShowLoadingIndicator() {
195+
override fun onShouldShowLoadingIndicator() : Unit {
195196
onShouldShowLoadingIndicatorCallback?.run()
196197
}
197198

198-
override fun onUnload(reason: Rokt.UnloadReasons) {
199+
override fun onUnload(reason: Rokt.UnloadReasons) : Unit {
199200
onUnloadCallback?.run()
200201
}
201202
}

0 commit comments

Comments
 (0)