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
24 changes: 24 additions & 0 deletions Documentation/style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ Feature toggles and interaction configuration.
| `behavior.privacyNotice.title` | string | `"Privacy Notice"` | Heading shown above the notice body. Blank hides only the heading. When omitted, the SDK uses its `concierge_privacy_notice_title` string resource, which apps can localize. |
| `behavior.privacyNotice.text` | string | `""` | Notice copy with optional `{Label}` placeholders; absent, empty, or whitespace-only text hides the notice. |
| `behavior.privacyNotice.links` | array | `[]` | Link objects use the same `{ "text": "...", "url": "..." }` shape as disclaimer links. The first exact label match is used. A link whose URL is blank or malformed renders as plain, unlinked text. |
| `behavior.privacyNotice.presentation` | string | `"inline"` | `"inline"` shows the full notice; `"collapsible"` starts collapsed and expands in place. |
| `behavior.privacyNotice.summary` | string | `""` | Optional approved summary for the collapsed notice; blank uses a line-limited preview. |
| `behavior.privacyNotice.collapsedMaxLines` | positive integer | `3` | Maximum preview lines when no summary is provided; short notices have no toggle. |
| `behavior.privacyNotice.readMoreLabel` | string | `"Read more"` | Expansion label; omitted uses the localizable `concierge_privacy_notice_read_more` resource. |
| `behavior.privacyNotice.showLessLabel` | string | `"Show less"` | Collapse label; omitted uses the localizable `concierge_privacy_notice_show_less` resource. |

The notice is informational and does not block submission or require acknowledgment.
It appears immediately before the first user-authored text message in a conversation,
Expand All @@ -380,6 +385,15 @@ runs first, then App Links, an in-app web view for `http`/`https`, or the system
for other schemes. `javascript`, `file`, `content`, `intent`, and `data` URLs are ignored.
Taps are tracked as link clicks with origin `privacyNotice`.

Use `"presentation": "collapsible"` to opt in without changing existing themes. Supply an
approved `summary` to keep essential information visible; summaries are not truncated.
Without a summary, the full text is previewed with an ellipsis only when it exceeds
`collapsedMaxLines`. Expansion pushes subsequent messages down; collapse restores the compact
card. There is no automatic animation or modal. Links become interactive in the full notice,
using the same routing and tracking as inline notices. Invalid presentation values and
nonpositive line limits fail decoding. Select **Demo Theme** in the test app to try sample copy;
replace it with approved legal copy before release.

> **Strict decoding:** unlike other `behavior` keys, a wrong type anywhere under
> `privacyNotice` (for example `"title": 42` or `"links": {}`) fails theme decoding, so the
> whole theme falls back to the defaults and an error is logged. This matches iOS. Missing
Expand Down Expand Up @@ -466,6 +480,11 @@ Before a vote, both thumbs use the concierge message text color. After a vote, t
"privacyNotice": {
"title": "Privacy Notice",
"text": "Your messages are processed by {Company}.",
"presentation": "inline",
"summary": "",
"collapsedMaxLines": 3,
"readMoreLabel": "Read more",
"showLessLabel": "Show less",
"links": [
{"text": "Company", "url": "https://example.com/privacy"}
]
Expand Down Expand Up @@ -1530,6 +1549,11 @@ This section documents which properties are fully implemented, partially impleme
| `behavior.privacyNotice.title` | ✅ | Optional heading; blank hides only the heading | `PrivacyNoticeView` |
| `behavior.privacyNotice.text` | ✅ | First user-message transcript notice; blank body hides the card | `MessageList` → `PrivacyNoticeView` |
| `behavior.privacyNotice.links` | ✅ | Brace placeholders share the disclaimer formatter; links use the shared chat link handling with origin `privacyNotice` | `PrivacyNoticeView` |
| `behavior.privacyNotice.presentation` | ✅ | Opt-in inline expansion | `PrivacyNoticeView` |
| `behavior.privacyNotice.summary` | ✅ | Authored collapsed summary | `PrivacyNoticeView` |
| `behavior.privacyNotice.collapsedMaxLines` | ✅ | Overflow-aware preview | `PrivacyNoticeView` |
| `behavior.privacyNotice.readMoreLabel` | ✅ | Localizable expansion label | `PrivacyNoticeView` |
| `behavior.privacyNotice.showLessLabel` | ✅ | Localizable collapse label | `PrivacyNoticeView` |

### Disclaimer

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@

package com.adobe.marketing.mobile.concierge.ui.components.messages

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Text
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.testTag
Expand All @@ -25,7 +31,10 @@ import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performSemanticsAction
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollToIndex
import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.test.junit4.StateRestorationTester
import androidx.compose.ui.test.click
import androidx.compose.ui.text.TextLayoutResult
import androidx.compose.ui.text.SpanStyle
Expand All @@ -36,8 +45,10 @@ import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeTheme
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeThemeData
import com.adobe.marketing.mobile.concierge.ui.theme.DisclaimerLink
import com.adobe.marketing.mobile.concierge.ui.theme.PrivacyNoticeConfig
import com.adobe.marketing.mobile.concierge.ui.theme.PrivacyNoticePresentation
import com.adobe.marketing.mobile.concierge.ui.theme.ThemeParser
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Rule
import org.junit.Test
Expand All @@ -47,6 +58,166 @@ class PrivacyNoticeViewTest {
@get:Rule
val composeTestRule = createComposeRule()

private val restorationNotice = PrivacyNoticeConfig(
text = "First privacy line.\nSecond privacy line.\nThird privacy line.\nFourth privacy line.\nFinal privacy line.",
presentation = PrivacyNoticePresentation.COLLAPSIBLE,
collapsedMaxLines = 3
)

@Test
fun notice_withoutSummaryKeepsCollapseControlAfterSavedStateRestoration() {
val restoration = StateRestorationTester(composeTestRule)
restoration.setContent {
ConciergeTheme {
PrivacyNoticeView(config = restorationNotice, handleLink = noOpLink)
}
}

assertRestorationNoticeLineCount(3)
composeTestRule.onNodeWithText("Read more").performClick()
assertRestorationNoticeLineCount(5)
composeTestRule.onNodeWithText("Show less").assertIsDisplayed()

restoration.emulateSavedInstanceStateRestore()

assertRestorationNoticeLineCount(5)
composeTestRule.onNodeWithText("Show less").assertIsDisplayed().performClick()
assertRestorationNoticeLineCount(3)
composeTestRule.onNodeWithText("Read more").assertIsDisplayed()
}

@Test
fun notice_withoutSummaryKeepsCollapseControlAfterLazyItemDisposal() {
var noticeInComposition = false
composeTestRule.setContent {
ConciergeTheme {
LazyColumn(Modifier.fillMaxSize().testTag("transcript")) {
item(key = "privacy-notice") {
DisposableEffect(Unit) {
noticeInComposition = true
onDispose { noticeInComposition = false }
}
PrivacyNoticeView(config = restorationNotice, handleLink = noOpLink)
}
items(100) { index ->
Text("Message $index", modifier = Modifier.height(72.dp))
}
}
}
}

assertRestorationNoticeLineCount(3)
composeTestRule.onNodeWithText("Read more").performClick()
assertRestorationNoticeLineCount(5)
composeTestRule.onNodeWithText("Show less").assertIsDisplayed()

composeTestRule.onNodeWithTag("transcript").performScrollToIndex(80)
composeTestRule.runOnIdle { assertFalse("Notice must actually leave composition", noticeInComposition) }
composeTestRule.onNodeWithTag("transcript").performScrollToIndex(0)
composeTestRule.runOnIdle { assertTrue(noticeInComposition) }

assertRestorationNoticeLineCount(5)
composeTestRule.onNodeWithText("Show less").assertIsDisplayed().performClick()
assertRestorationNoticeLineCount(3)
composeTestRule.onNodeWithText("Read more").assertIsDisplayed()
}

private fun assertRestorationNoticeLineCount(expected: Int) {
val layouts = mutableListOf<TextLayoutResult>()
composeTestRule.onNodeWithText(restorationNotice.text)
.performSemanticsAction(SemanticsActions.GetTextLayoutResult) { it(layouts) }
assertEquals(expected, layouts.single().lineCount)
}

@Test
fun notice_summaryExpandsAndCollapsesWithoutMovingFollowingContentAboveIt() {
composeTestRule.setContent {
ConciergeTheme {
Column {
PrivacyNoticeView(
config = PrivacyNoticeConfig(
text = "Full notice.\nAdditional details.\nRead {Privacy}.",
summary = "Short summary.",
presentation = PrivacyNoticePresentation.COLLAPSIBLE,
links = listOf(DisclaimerLink("Privacy", "https://example.com/privacy"))
),
handleLink = noOpLink
)
Text("Following message")
}
}
}

composeTestRule.onNodeWithText("Short summary.").assertIsDisplayed()
val collapsedTop = composeTestRule.onNodeWithText("Following message").getUnclippedBoundsInRoot().top
composeTestRule.onNodeWithText("Read more").performClick()
composeTestRule.onNodeWithText("Short summary.").assertDoesNotExist()
composeTestRule.onNodeWithText("Full notice.\nAdditional details.\nRead Privacy.").assertIsDisplayed()
.assert(SemanticsMatcher.keyIsDefined(SemanticsActions.CustomActions))
assertTrue(composeTestRule.onNodeWithText("Following message").getUnclippedBoundsInRoot().top > collapsedTop)
composeTestRule.onNodeWithText("Show less").performClick()
composeTestRule.onNodeWithText("Short summary.").assertIsDisplayed()
assertEquals(
collapsedTop.value,
composeTestRule.onNodeWithText("Following message").getUnclippedBoundsInRoot().top.value,
1f
)
}

@Test
fun notice_withoutSummaryOnlyOffersExpansionWhenPreviewOverflows() {
val longText = "First line.\nSecond line.\nThird line.\nFourth line."
composeTestRule.setContent {
ConciergeTheme {
Column {
PrivacyNoticeView(
config = PrivacyNoticeConfig(
title = "Short",
text = "Fits.",
presentation = PrivacyNoticePresentation.COLLAPSIBLE
),
handleLink = noOpLink
)
PrivacyNoticeView(
config = PrivacyNoticeConfig(
title = "Long",
text = longText,
collapsedMaxLines = 2,
presentation = PrivacyNoticePresentation.COLLAPSIBLE
),
handleLink = noOpLink
)
}
}
}
val layouts = mutableListOf<TextLayoutResult>()
composeTestRule.onNodeWithText(longText)
.performSemanticsAction(SemanticsActions.GetTextLayoutResult) { it(layouts) }
assertEquals(2, layouts.single().lineCount)
composeTestRule.onNodeWithText("Read more").performClick()
layouts.clear()
composeTestRule.onNodeWithText(longText)
.performSemanticsAction(SemanticsActions.GetTextLayoutResult) { it(layouts) }
assertEquals(4, layouts.single().lineCount)
composeTestRule.onNodeWithText("Show less").performClick()
composeTestRule.onNodeWithText("Read more").assertIsDisplayed()
}

@Test
fun notice_inlineRemainsFullyVisibleEvenWithSummary() {
composeTestRule.setContent {
ConciergeTheme {
PrivacyNoticeView(
config = PrivacyNoticeConfig(text = "Full notice.", summary = "Summary."),
handleLink = noOpLink
)
}
}
composeTestRule.onNodeWithText("Full notice.").assertIsDisplayed()
composeTestRule.onNodeWithText("Summary.").assertDoesNotExist()
composeTestRule.onNodeWithText("Read more").assertDoesNotExist()
}

@Test
fun notice_displaysHeadingAndBodyWithOuterTopSpacing() {
var expectedInset = 0.dp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,46 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ExpandLess
import androidx.compose.material.icons.filled.ExpandMore
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.CustomAccessibilityAction
import androidx.compose.ui.semantics.customActions
import androidx.compose.ui.semantics.heading
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.stateDescription
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import com.adobe.marketing.mobile.concierge.ConciergeConstants
import com.adobe.marketing.mobile.concierge.R
import com.adobe.marketing.mobile.concierge.ui.components.links.LinkedTextFormatter
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeStyles
import com.adobe.marketing.mobile.concierge.ui.theme.ConciergeTheme
import com.adobe.marketing.mobile.concierge.ui.theme.PrivacyNoticeConfig
import com.adobe.marketing.mobile.concierge.ui.theme.PrivacyNoticePresentation

/**
* Informational privacy notice shown before the first user query.
Expand Down Expand Up @@ -82,6 +96,23 @@ internal fun PrivacyNoticeView(
linkColor = linkColor
)
}
val collapsible = config.presentation == PrivacyNoticePresentation.COLLAPSIBLE
val hasSummary = config.summary.isNotBlank() && config.summary.trim() != config.text.trim()
var expanded by rememberSaveable(config.text, config.summary, config.presentation) { mutableStateOf(false) }
var truncated by remember(config.text, config.collapsedMaxLines) { mutableStateOf(false) }
val summaryText = remember(config, linkColor) {
LinkedTextFormatter.format(
text = config.summary,
links = config.links,
baseStyle = SpanStyle(),
linkColor = linkColor
).text
}
val readMore = config.readMoreLabel ?: stringResource(R.string.concierge_privacy_notice_read_more)
val showLess = config.showLessLabel ?: stringResource(R.string.concierge_privacy_notice_show_less)
val expandedState = stringResource(
if (expanded) R.string.concierge_privacy_notice_expanded else R.string.concierge_privacy_notice_collapsed
)
val linkActions = remember(annotatedText, openLinkFormat) {
annotatedText.getStringAnnotations("URL", 0, annotatedText.length)
.map { range ->
Expand Down Expand Up @@ -115,15 +146,44 @@ internal fun PrivacyNoticeView(
modifier = Modifier.semantics { heading() }
)
}
ClickableText(
text = annotatedText,
textStyle = bodyStyle,
textAlign = TextAlign.Start,
handleLink = openLink,
modifier = Modifier.semantics {
if (linkActions.isNotEmpty()) customActions = linkActions
}
)
if (collapsible && !expanded) {
Text(
text = if (hasSummary) summaryText else annotatedText.text,
style = bodyStyle,
color = bodyColor,
maxLines = if (hasSummary) Int.MAX_VALUE else config.collapsedMaxLines,
overflow = TextOverflow.Ellipsis,
onTextLayout = { if (!hasSummary) truncated = it.hasVisualOverflow }
)
} else {
ClickableText(
text = annotatedText,
textStyle = bodyStyle,
textAlign = TextAlign.Start,
handleLink = openLink,
modifier = Modifier.semantics {
if (linkActions.isNotEmpty()) customActions = linkActions
}
)
}
}
}
if (collapsible && (expanded || hasSummary || truncated)) {
TextButton(
onClick = { expanded = !expanded },
modifier = Modifier.heightIn(min = 48.dp).semantics { stateDescription = expandedState }
) {
Row(
horizontalArrangement = Arrangement.spacedBy(8.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(text = if (expanded) showLess else readMore, style = bodyStyle, color = linkColor)
Icon(
imageVector = if (expanded) Icons.Default.ExpandLess else Icons.Default.ExpandMore,
contentDescription = null,
tint = linkColor
)
}
}
}
}
Expand Down
Loading
Loading