Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ interface SpConsentLib {
fun showView(view: View)
fun removeView(view: View)

fun dismissMessage()

@Deprecated(message = "This method is deprecated and has no effect.")
fun dispose()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andresilveirah why don't we remove it altogether?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's less intrusive if we simply trigger a dismiss action. The SDK will call onSPUIFinished and the app should already be prepared to remove the view on that callback. But if we get feedback it's better to remove the view all together, we can do that too.


@Deprecated(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,11 @@ class SpConsentLibMobileCore(
mainView?.removeView(view)
}

override fun dismissMessage() {
messageUI.dismiss()
}

@Deprecated(message = "This method is deprecated and has no effect.")
override fun dispose() {}

@Deprecated(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,6 +66,8 @@ interface SPMessageUI {
campaignType: CampaignType,
userData: SPUserData
)

fun dismiss()
}

/**
Expand Down Expand Up @@ -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 = ""
)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -295,6 +299,17 @@ class SPConsentWebView(
null
)

override fun dismiss() {
onAction(
view = this,
action = SPConsentAction(
actionType = MSG_CANCEL,
campaignType = campaignType,
messageId = ""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andresilveirah isn't the "" a typo?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a typo. We don't have that information easily available. Since the dismiss doesn't make any network request, it's okay to set it as empty string.

)
)
}

override fun loaded(view: View) = runOnMain {
evaluateJavascript("""window.spLegislation="${campaignType.name}"""", null)
if (!isPresenting) {
Expand Down