From 4b9fcbc1c9303395b53f907b95b3b0def96a10b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Fri, 18 Jul 2025 21:05:07 +0200 Subject: [PATCH 1/3] implement programmatically message dismiss --- .../sourcepoint/cmplibrary/SpConsentLib.kt | 2 ++ .../cmplibrary/SpConsentLibMobileCore.kt | 4 ++++ .../mobile_core/SPConsentWebView.kt | 23 +++++++++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt index 13aaff662..60c56eb21 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt @@ -86,6 +86,8 @@ interface SpConsentLib { fun showView(view: View) fun removeView(view: View) + fun dismissMessage() + fun dispose() @Deprecated( diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt index c57b762e6..242a8bc21 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt @@ -291,6 +291,10 @@ class SpConsentLibMobileCore( mainView?.removeView(view) } + override fun dismissMessage() { + messageUI.dismiss() + } + override fun dispose() {} @Deprecated( diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/mobile_core/SPConsentWebView.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/mobile_core/SPConsentWebView.kt index f7b69b532..7ffe09455 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/mobile_core/SPConsentWebView.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/mobile_core/SPConsentWebView.kt @@ -20,7 +20,9 @@ import com.sourcepoint.cmplibrary.exception.UnableToDownloadRenderingApp import com.sourcepoint.cmplibrary.exception.UnableToLoadRenderingApp import com.sourcepoint.cmplibrary.launch import com.sourcepoint.cmplibrary.model.ConsentAction -import com.sourcepoint.cmplibrary.model.exposed.ActionType +import com.sourcepoint.cmplibrary.model.exposed.ActionType.SHOW_OPTIONS +import com.sourcepoint.cmplibrary.model.exposed.ActionType.MSG_CANCEL +import com.sourcepoint.cmplibrary.model.exposed.ActionType.PM_DISMISS import com.sourcepoint.cmplibrary.model.exposed.MessageType import com.sourcepoint.cmplibrary.model.exposed.MessageType.LEGACY_OTT import com.sourcepoint.cmplibrary.model.exposed.MessageType.OTT @@ -64,6 +66,8 @@ interface SPMessageUI { campaignType: CampaignType, userData: SPUserData ) + + fun dismiss() } /** @@ -166,7 +170,7 @@ class SPConsentWebView( onAction( view = this, action = SPConsentAction( - actionType = if (isFirstLayer) ActionType.MSG_CANCEL else ActionType.PM_DISMISS, + actionType = if (isFirstLayer) MSG_CANCEL else PM_DISMISS, campaignType = campaignType, messageId = "" ) @@ -248,8 +252,8 @@ class SPConsentWebView( override fun onAction(view: View, action: ConsentAction) = runOnMain { messageUIClient.onAction(view, action) when (action.actionType) { - ActionType.SHOW_OPTIONS -> loadPrivacyManagerFrom(action) - ActionType.PM_DISMISS -> returnToFirstLayer() + SHOW_OPTIONS -> loadPrivacyManagerFrom(action) + PM_DISMISS -> returnToFirstLayer() else -> { finished(view) } @@ -295,6 +299,17 @@ class SPConsentWebView( null ) + override fun dismiss() { + onAction( + view = this, + action = SPConsentAction( + actionType = MSG_CANCEL, + campaignType = campaignType, + messageId = "" + ) + ) + } + override fun loaded(view: View) = runOnMain { evaluateJavascript("""window.spLegislation="${campaignType.name}"""", null) if (!isPresenting) { From 0a4a20024be960d5e16ab7142d8306224e580e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Fri, 18 Jul 2025 21:05:18 +0200 Subject: [PATCH 2/3] deprecate dispose method --- .../src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt | 1 + .../java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt | 1 + 2 files changed, 2 insertions(+) diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt index 60c56eb21..245e6d78e 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLib.kt @@ -88,6 +88,7 @@ interface SpConsentLib { fun dismissMessage() + @Deprecated(message = "This method is deprecated and has no effect.") fun dispose() @Deprecated( diff --git a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt index 242a8bc21..7f271648e 100644 --- a/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt +++ b/cmplibrary/src/main/java/com/sourcepoint/cmplibrary/SpConsentLibMobileCore.kt @@ -295,6 +295,7 @@ class SpConsentLibMobileCore( messageUI.dismiss() } + @Deprecated(message = "This method is deprecated and has no effect.") override fun dispose() {} @Deprecated( From f277628cd5ea23c9b03150f5ba1ee7f77c9ae1e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Fri, 18 Jul 2025 21:06:44 +0200 Subject: [PATCH 3/3] Update README.md --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index c0fee7fe0..405f491a1 100644 --- a/README.md +++ b/README.md @@ -843,6 +843,14 @@ It’s possible to programmatically issue a “reject all” action on behalf of spConsentLib.rejectAll(CampaignType.GDPR) ``` +## Programmatically dismissing a message + +You might have the use case in which you want to programmatically dismiss a message without relying on user input. The `dismissMessage()` method will try to dispatch a dismiss action on the message being currently displayed, just as if a user would have pressed the dismiss button on the UI. + +```kotlin +spConsentLib.dismissMessage() +``` + ## Adding or Removing custom consents It's possible to programmatically consent the current user to a list of vendors, categories and legitimate interest categories by using the following method from the consent lib: