|
|
|
@ -16,26 +16,24 @@
@@ -16,26 +16,24 @@
|
|
|
|
|
|
|
|
|
|
package io.element.android.features.analytics.api.preferences |
|
|
|
|
|
|
|
|
|
import androidx.annotation.StringRes |
|
|
|
|
import androidx.compose.foundation.text.ClickableText |
|
|
|
|
import androidx.compose.runtime.Composable |
|
|
|
|
import androidx.compose.ui.Modifier |
|
|
|
|
import androidx.compose.ui.graphics.Color |
|
|
|
|
import androidx.compose.ui.res.stringResource |
|
|
|
|
import androidx.compose.ui.text.SpanStyle |
|
|
|
|
import androidx.compose.ui.text.buildAnnotatedString |
|
|
|
|
import androidx.compose.ui.text.style.TextDecoration |
|
|
|
|
import androidx.compose.ui.tooling.preview.Preview |
|
|
|
|
import androidx.compose.ui.tooling.preview.PreviewParameter |
|
|
|
|
import io.element.android.features.analytics.api.AnalyticsOptInEvents |
|
|
|
|
import io.element.android.libraries.designsystem.components.list.ListItemContent |
|
|
|
|
import io.element.android.libraries.designsystem.preview.ElementPreviewDark |
|
|
|
|
import io.element.android.libraries.designsystem.preview.ElementPreviewLight |
|
|
|
|
import io.element.android.libraries.designsystem.text.buildAnnotatedStringWithStyledPart |
|
|
|
|
import io.element.android.libraries.designsystem.theme.components.ListItem |
|
|
|
|
import io.element.android.libraries.designsystem.theme.components.Text |
|
|
|
|
import io.element.android.libraries.theme.LinkColor |
|
|
|
|
import io.element.android.libraries.ui.strings.CommonStrings |
|
|
|
|
|
|
|
|
|
private const val LINK_TAG = "link" |
|
|
|
|
|
|
|
|
|
@Composable |
|
|
|
|
fun AnalyticsPreferencesView( |
|
|
|
|
state: AnalyticsPreferencesState, |
|
|
|
@ -47,10 +45,10 @@ fun AnalyticsPreferencesView(
@@ -47,10 +45,10 @@ fun AnalyticsPreferencesView(
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val firstPart = stringResource(id = CommonStrings.screen_analytics_settings_help_us_improve, state.applicationName) |
|
|
|
|
val secondPart = buildAnnotatedStringWithColoredPart( |
|
|
|
|
val secondPart = buildAnnotatedStringWithStyledPart( |
|
|
|
|
CommonStrings.screen_analytics_settings_read_terms, |
|
|
|
|
CommonStrings.screen_analytics_settings_read_terms_content_link, |
|
|
|
|
link = state.policyUrl, |
|
|
|
|
tagAndLink = LINK_TAG to state.policyUrl, |
|
|
|
|
) |
|
|
|
|
val subtitle = buildAnnotatedString { |
|
|
|
|
append(firstPart) |
|
|
|
@ -67,7 +65,7 @@ fun AnalyticsPreferencesView(
@@ -67,7 +65,7 @@ fun AnalyticsPreferencesView(
|
|
|
|
|
text = subtitle, |
|
|
|
|
onClick = { |
|
|
|
|
subtitle |
|
|
|
|
.getStringAnnotations("link", it, it) |
|
|
|
|
.getStringAnnotations(LINK_TAG, it, it) |
|
|
|
|
.firstOrNull()?.let { stringAnnotation -> |
|
|
|
|
onOpenAnalyticsPolicy(stringAnnotation.item) |
|
|
|
|
} |
|
|
|
@ -81,37 +79,6 @@ fun AnalyticsPreferencesView(
@@ -81,37 +79,6 @@ fun AnalyticsPreferencesView(
|
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// TODO Use buildAnnotatedStringWithStyledPart. |
|
|
|
|
@Composable |
|
|
|
|
fun buildAnnotatedStringWithColoredPart( |
|
|
|
|
@StringRes fullTextRes: Int, |
|
|
|
|
@StringRes coloredTextRes: Int, |
|
|
|
|
color: Color = LinkColor, |
|
|
|
|
underline: Boolean = true, |
|
|
|
|
link: String? = null, |
|
|
|
|
) = buildAnnotatedString { |
|
|
|
|
val coloredPart = stringResource(coloredTextRes) |
|
|
|
|
val fullText = stringResource(fullTextRes, coloredPart) |
|
|
|
|
val startIndex = fullText.indexOf(coloredPart) |
|
|
|
|
append(fullText) |
|
|
|
|
addStyle( |
|
|
|
|
style = SpanStyle( |
|
|
|
|
color = color, |
|
|
|
|
textDecoration = if (underline) TextDecoration.Underline else null |
|
|
|
|
), |
|
|
|
|
start = startIndex, |
|
|
|
|
end = startIndex + coloredPart.length, |
|
|
|
|
) |
|
|
|
|
if (link != null) { |
|
|
|
|
addStringAnnotation( |
|
|
|
|
tag = "link", |
|
|
|
|
annotation = link, |
|
|
|
|
start = startIndex, |
|
|
|
|
end = startIndex + coloredPart.length |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Preview |
|
|
|
|
@Composable |
|
|
|
|
internal fun AnalyticsPreferencesViewLightPreview(@PreviewParameter(AnalyticsPreferencesStateProvider::class) state: AnalyticsPreferencesState) = |
|
|
|
|