From c2a396c4c7f68264d1c305569b0577afb003a6bf Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 6 Oct 2025 12:31:22 +0200 Subject: [PATCH 1/4] reinit `messageUI` on new pending actions --- .../cmplibrary/SpConsentLibMobileCore.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt index f61001b2a..5649198d6 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt @@ -71,19 +71,29 @@ class SpConsentLibMobileCore( override var cleanUserDataOnError: Boolean = false ) : SpConsentLib, SPMessageUIClient { private var pendingActions: Int = 0 + set(value) { + if(field==0 && value>0) { + messageUI = SPConsentWebView.create( + context = context, + messageUIClient = this@SpConsentLibMobileCore, + propertyId = propertyId, + onBackPressed = dismissMessageOnBackPress + ) + } + field = value + } private var messagesToDisplay: ArrayDeque = ArrayDeque(emptyList()) private val mainView: ViewGroup? get() = activity?.get()?.findViewById(content) private val userData: SPUserData get() = coordinator.userData private val spConsents: SPConsents get() = SPConsents(userData) - private val messageUI: SPMessageUI by lazy { + private var messageUI: SPMessageUI = SPConsentWebView.create( context = context, messageUIClient = this@SpConsentLibMobileCore, propertyId = propertyId, onBackPressed = dismissMessageOnBackPress ) - } override fun loadMessage() = loadMessage(authId = null, pubData = null, cmpViewId = null) From da17357dedf93fffd7fccef6df511cf67f433116 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 6 Oct 2025 15:22:00 +0200 Subject: [PATCH 2/4] lateinit `messageUI` --- .../com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt index 5649198d6..9bfa57d3f 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt @@ -87,13 +87,7 @@ class SpConsentLibMobileCore( private val userData: SPUserData get() = coordinator.userData private val spConsents: SPConsents get() = SPConsents(userData) - private var messageUI: SPMessageUI = - SPConsentWebView.create( - context = context, - messageUIClient = this@SpConsentLibMobileCore, - propertyId = propertyId, - onBackPressed = dismissMessageOnBackPress - ) + private lateinit var messageUI: SPMessageUI override fun loadMessage() = loadMessage(authId = null, pubData = null, cmpViewId = null) From ff2f1bad82faa2c1ba2fe1bafab8db0592c8247f Mon Sep 17 00:00:00 2001 From: Dmytro Date: Mon, 6 Oct 2025 16:57:47 +0200 Subject: [PATCH 3/4] review fix --- .../cmplibrary/SpConsentLibMobileCore.kt | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt index 9bfa57d3f..e45cab1be 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt @@ -71,23 +71,22 @@ class SpConsentLibMobileCore( override var cleanUserDataOnError: Boolean = false ) : SpConsentLib, SPMessageUIClient { private var pendingActions: Int = 0 - set(value) { - if(field==0 && value>0) { - messageUI = SPConsentWebView.create( - context = context, - messageUIClient = this@SpConsentLibMobileCore, - propertyId = propertyId, - onBackPressed = dismissMessageOnBackPress - ) - } - field = value - } private var messagesToDisplay: ArrayDeque = ArrayDeque(emptyList()) private val mainView: ViewGroup? get() = activity?.get()?.findViewById(content) private val userData: SPUserData get() = coordinator.userData private val spConsents: SPConsents get() = SPConsents(userData) - private lateinit var messageUI: SPMessageUI + private var messageUI: SPMessageUI? = null + get() { + field = field ?: SPConsentWebView.create( + context = context, + messageUIClient = this@SpConsentLibMobileCore, + propertyId = propertyId, + onBackPressed = dismissMessageOnBackPress + ) + return field!! + } + set(value) { field = value} override fun loadMessage() = loadMessage(authId = null, pubData = null, cmpViewId = null) @@ -129,10 +128,11 @@ class SpConsentLibMobileCore( private fun renderNextMessageIfAny() = if (pendingActions == 0 && messagesToDisplay.isEmpty()) { + messageUI = null spClient.onSpFinished(spConsents) } else if (messagesToDisplay.isNotEmpty()) { val messageToRender = messagesToDisplay.removeFirst() - messageUI.load( + messageUI!!.load( message = messageToRender.message, messageType = MessageType.fromMessageSubCategory(messageToRender.metaData.subCategoryId), url = messageToRender.url, @@ -267,7 +267,7 @@ class SpConsentLibMobileCore( } pendingActions++ - messageUI.load( + messageUI!!.load( messageType = messageType, url = buildPMUrl( campaignType = campaignType, @@ -297,7 +297,7 @@ class SpConsentLibMobileCore( } override fun dismissMessage() { - messageUI.dismiss() + messageUI!!.dismiss() } @Deprecated(message = "This method is deprecated and has no effect.") @@ -339,6 +339,7 @@ class SpConsentLibMobileCore( spClient.onConsentReady(SPConsents(userData)) pendingActions-- if (pendingActions == 0) { + messageUI = null spClient.onSpFinished(spConsents) } }.onFailure { @@ -352,7 +353,7 @@ class SpConsentLibMobileCore( finished(view) } ActionType.PM_DISMISS -> { - if (messageUI.isFirstLayer) { + if (messageUI!!.isFirstLayer) { pendingActions-- finished(view) } @@ -390,7 +391,7 @@ class SpConsentLibMobileCore( } override fun finished(view: View) { - messageUI.isPresenting = false + messageUI!!.isPresenting = false runOnMain { spClient.onUIFinished(view) } renderNextMessageIfAny() } From a458504f0a326728dc1b4fdef194885a01c529eb Mon Sep 17 00:00:00 2001 From: Dmytro Date: Tue, 7 Oct 2025 11:24:48 +0200 Subject: [PATCH 4/4] review fix --- .../cmplibrary/SpConsentLibMobileCore.kt | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt index e45cab1be..d135e8d1f 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt @@ -77,16 +77,15 @@ class SpConsentLibMobileCore( private val spConsents: SPConsents get() = SPConsents(userData) private var messageUI: SPMessageUI? = null - get() { - field = field ?: SPConsentWebView.create( - context = context, - messageUIClient = this@SpConsentLibMobileCore, - propertyId = propertyId, - onBackPressed = dismissMessageOnBackPress - ) - return field!! - } - set(value) { field = value} + fun getOrCreateMessageUI(): SPMessageUI { + messageUI = messageUI ?: SPConsentWebView.create( + context = context, + messageUIClient = this@SpConsentLibMobileCore, + propertyId = propertyId, + onBackPressed = dismissMessageOnBackPress + ) + return messageUI!! + } override fun loadMessage() = loadMessage(authId = null, pubData = null, cmpViewId = null) @@ -132,7 +131,7 @@ class SpConsentLibMobileCore( spClient.onSpFinished(spConsents) } else if (messagesToDisplay.isNotEmpty()) { val messageToRender = messagesToDisplay.removeFirst() - messageUI!!.load( + getOrCreateMessageUI().load( message = messageToRender.message, messageType = MessageType.fromMessageSubCategory(messageToRender.metaData.subCategoryId), url = messageToRender.url, @@ -267,7 +266,7 @@ class SpConsentLibMobileCore( } pendingActions++ - messageUI!!.load( + getOrCreateMessageUI().load( messageType = messageType, url = buildPMUrl( campaignType = campaignType, @@ -297,7 +296,7 @@ class SpConsentLibMobileCore( } override fun dismissMessage() { - messageUI!!.dismiss() + getOrCreateMessageUI().dismiss() } @Deprecated(message = "This method is deprecated and has no effect.") @@ -353,7 +352,7 @@ class SpConsentLibMobileCore( finished(view) } ActionType.PM_DISMISS -> { - if (messageUI!!.isFirstLayer) { + if (getOrCreateMessageUI().isFirstLayer) { pendingActions-- finished(view) } @@ -391,7 +390,7 @@ class SpConsentLibMobileCore( } override fun finished(view: View) { - messageUI!!.isPresenting = false + getOrCreateMessageUI().isPresenting = false runOnMain { spClient.onUIFinished(view) } renderNextMessageIfAny() }