Skip to content

Commit

Permalink
PM-14333 Complete fix for crash caused by spannable text creation (#4479
Browse files Browse the repository at this point in the history
)
  • Loading branch information
dseverns-livefront authored Dec 20, 2024
1 parent f32eecc commit 1148e48
Show file tree
Hide file tree
Showing 15 changed files with 384 additions and 545 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ tasks {
maxHeapSize = "2g"
maxParallelForks = Runtime.getRuntime().availableProcessors()
jvmArgs = jvmArgs.orEmpty() + "-XX:+UseParallelGC"
android.sourceSets["main"].res.srcDirs("src/test/res")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.auth.feature.checkemail.handlers.rememberCheckEmailHandler
import com.x8bit.bitwarden.ui.platform.base.util.ClickableTextHighlight
import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect
import com.x8bit.bitwarden.ui.platform.base.util.createAnnotatedString
import com.x8bit.bitwarden.ui.platform.base.util.createClickableAnnotatedString
import com.x8bit.bitwarden.ui.platform.base.util.standardHorizontalMargin
import com.x8bit.bitwarden.ui.platform.base.util.toAnnotatedString
import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenTopAppBar
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenFilledButton
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenTextButton
Expand Down Expand Up @@ -152,18 +150,13 @@ private fun CheckEmailContent(
)
Spacer(modifier = Modifier.height(8.dp))

val descriptionAnnotatedString = createAnnotatedString(
mainString = stringResource(
id = R.string.we_sent_an_email_to,
email,
),
highlights = listOf(email),
highlightStyle = SpanStyle(
val descriptionAnnotatedString = R.string.we_sent_an_email_to.toAnnotatedString(
args = arrayOf(email),
emphasisHighlightStyle = SpanStyle(
color = BitwardenTheme.colorScheme.text.primary,
fontSize = BitwardenTheme.typography.bodyMedium.fontSize,
fontWeight = FontWeight.Bold,
),
tag = "EMAIL",
)
Text(
text = descriptionAnnotatedString,
Expand Down Expand Up @@ -241,18 +234,14 @@ private fun CheckEmailLegacyContent(
Spacer(modifier = Modifier.height(16.dp))

@Suppress("MaxLineLength")
val descriptionAnnotatedString = createAnnotatedString(
mainString = stringResource(
id = R.string.follow_the_instructions_in_the_email_sent_to_x_to_continue_creating_your_account,
val descriptionAnnotatedString =
R.string.follow_the_instructions_in_the_email_sent_to_x_to_continue_creating_your_account.toAnnotatedString(
email,
),
highlights = listOf(email),
highlightStyle = SpanStyle(
emphasisHighlightStyle = SpanStyle(
color = BitwardenTheme.colorScheme.text.primary,
fontSize = BitwardenTheme.typography.bodyMedium.fontSize,
fontWeight = FontWeight.Bold,
),
tag = "EMAIL",
)
Text(
text = descriptionAnnotatedString,
Expand All @@ -276,34 +265,17 @@ private fun CheckEmailLegacyContent(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
val goBackAnnotatedString = createClickableAnnotatedString(
mainString = stringResource(
id = R.string.no_email_go_back_to_edit_your_email_address,
),
highlights = listOf(
ClickableTextHighlight(
textToHighlight = stringResource(id = R.string.go_back),
onTextClick = onChangeEmailClick,
),
),
)
Text(
text = goBackAnnotatedString,
text = R.string.no_email_go_back_to_edit_your_email_address.toAnnotatedString {
onChangeEmailClick()
},
)
Spacer(modifier = Modifier.height(32.dp))
val logInAnnotatedString = createClickableAnnotatedString(
mainString = stringResource(
id = R.string.or_log_in_you_may_already_have_an_account,
),
highlights = listOf(
ClickableTextHighlight(
textToHighlight = stringResource(id = R.string.log_in_verb),
onTextClick = onLoginClick,
),
),
)
Text(
text = logInAnnotatedString,
text = R.string.or_log_in_you_may_already_have_an_account
.toAnnotatedString {
onLoginClick()
},
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect
import com.x8bit.bitwarden.ui.platform.base.util.bitwardenBoldSpanStyle
import com.x8bit.bitwarden.ui.platform.base.util.createAnnotatedString
import com.x8bit.bitwarden.ui.platform.base.util.standardHorizontalMargin
import com.x8bit.bitwarden.ui.platform.base.util.toAnnotatedString
import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenTopAppBar
Expand Down Expand Up @@ -130,6 +128,7 @@ private fun MasterPasswordGuidanceContent(
}
}

@Suppress("MaxLineLength")
@Composable
private fun MasterPasswordGuidanceContentBlocks(modifier: Modifier = Modifier) {
Column(modifier = modifier) {
Expand All @@ -138,46 +137,20 @@ private fun MasterPasswordGuidanceContentBlocks(modifier: Modifier = Modifier) {
ContentBlockData(
headerText = stringResource(R.string.choose_three_or_four_random_words)
.toAnnotatedString(),
subtitleText = createAnnotatedString(
mainString = stringResource(
R.string.pick_three_or_four_random_unrelated_words,
),
highlights = listOf(
stringResource(
R.string.pick_three_or_four_random_unrelated_words_highlight,
),
),
highlightStyle = bitwardenBoldSpanStyle,
),
subtitleText = R.string.pick_three_or_four_random_unrelated_words.toAnnotatedString(),
iconVectorResource = R.drawable.ic_number1,
),
ContentBlockData(
headerText = stringResource(R.string.combine_those_words_together)
.toAnnotatedString(),
subtitleText = createAnnotatedString(
mainString = stringResource(
R.string.put_the_words_together_in_any_order_to_form_your_passphrase,
),
highlights = listOf(
stringResource(
R.string.use_hyphens_spaces_or_leave_them_as_long_word_highlight,
),
),
highlightStyle = bitwardenBoldSpanStyle,
),
subtitleText = R.string.put_the_words_together_in_any_order_to_form_your_passphrase
.toAnnotatedString(),
iconVectorResource = R.drawable.ic_number2,
),
ContentBlockData(
headerText = stringResource(R.string.make_it_yours).toAnnotatedString(),
subtitleText = createAnnotatedString(
mainString = stringResource(
R.string.add_a_number_or_symbol_to_make_it_even_stronger,
),
highlights = listOf(
stringResource(R.string.add_a_number_or_symbol_highlight),
),
highlightStyle = bitwardenBoldSpanStyle,
),
subtitleText = R.string.add_a_number_or_symbol_to_make_it_even_stronger
.toAnnotatedString(),
iconVectorResource = R.drawable.ic_number3,
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import com.x8bit.bitwarden.ui.auth.feature.newdevicenotice.NewDeviceNoticeEmailA
import com.x8bit.bitwarden.ui.auth.feature.newdevicenotice.NewDeviceNoticeEmailAccessAction.EmailAccessToggle
import com.x8bit.bitwarden.ui.auth.feature.newdevicenotice.NewDeviceNoticeEmailAccessEvent.NavigateToTwoFactorOptions
import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect
import com.x8bit.bitwarden.ui.platform.base.util.createAnnotatedString
import com.x8bit.bitwarden.ui.platform.base.util.standardHorizontalMargin
import com.x8bit.bitwarden.ui.platform.base.util.toAnnotatedString
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenFilledButton
import com.x8bit.bitwarden.ui.platform.components.scaffold.BitwardenScaffold
import com.x8bit.bitwarden.ui.platform.components.toggle.BitwardenSwitch
Expand Down Expand Up @@ -146,18 +146,14 @@ private fun MainContent(
modifier = modifier,
) {
Text(
text = createAnnotatedString(
mainString = stringResource(
R.string.do_you_have_reliable_access_to_your_email,
email,
),
mainStringStyle = SpanStyle(
text = R.string.do_you_have_reliable_access_to_your_email.toAnnotatedString(
args = arrayOf(email),
style = SpanStyle(
color = BitwardenTheme.colorScheme.text.primary,
fontSize = BitwardenTheme.typography.bodyLarge.fontSize,
fontWeight = FontWeight.Normal,
),
highlights = listOf(email),
highlightStyle = SpanStyle(
emphasisHighlightStyle = SpanStyle(
color = BitwardenTheme.colorScheme.text.primary,
fontSize = BitwardenTheme.typography.bodyLarge.fontSize,
fontWeight = FontWeight.Bold,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationEv
import com.x8bit.bitwarden.ui.auth.feature.startregistration.StartRegistrationEvent.NavigateToTerms
import com.x8bit.bitwarden.ui.auth.feature.startregistration.handlers.StartRegistrationHandler
import com.x8bit.bitwarden.ui.auth.feature.startregistration.handlers.rememberStartRegistrationHandler
import com.x8bit.bitwarden.ui.platform.base.util.ClickableTextHighlight
import com.x8bit.bitwarden.ui.platform.base.util.EventsEffect
import com.x8bit.bitwarden.ui.platform.base.util.createClickableAnnotatedString
import com.x8bit.bitwarden.ui.platform.base.util.standardHorizontalMargin
import com.x8bit.bitwarden.ui.platform.base.util.toAnnotatedString
import com.x8bit.bitwarden.ui.platform.components.appbar.BitwardenTopAppBar
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenFilledButton
import com.x8bit.bitwarden.ui.platform.components.button.BitwardenStandardIconButton
Expand Down Expand Up @@ -288,7 +287,7 @@ private fun StartRegistrationContent(
}
}

@Suppress("LongMethod")
@Suppress("LongMethod", "MaxLineLength")
@Composable
private fun TermsAndPrivacyText(
onTermsClick: () -> Unit,
Expand All @@ -297,22 +296,13 @@ private fun TermsAndPrivacyText(
) {
val strTerms = stringResource(id = R.string.terms_of_service)
val strPrivacy = stringResource(id = R.string.privacy_policy)
val strTermsAndPrivacy = stringResource(
id = R.string.by_continuing_you_agree_to_the_terms_of_service_and_privacy_policy,
)
val annotatedLinkString: AnnotatedString = createClickableAnnotatedString(
mainString = strTermsAndPrivacy,
highlights = listOf(
ClickableTextHighlight(
textToHighlight = strTerms,
onTextClick = onTermsClick,
),
ClickableTextHighlight(
textToHighlight = strPrivacy,
onTextClick = onPrivacyPolicyClick,
),
),
)
val annotatedLinkString: AnnotatedString =
R.string.by_continuing_you_agree_to_the_terms_of_service_and_privacy_policy.toAnnotatedString {
when (it) {
"termsOfService" -> onTermsClick()
"privacyPolicy" -> onPrivacyPolicyClick()
}
}
Row(
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically,
Expand Down Expand Up @@ -356,19 +346,7 @@ private fun ReceiveMarketingEmailsSwitch(
modifier: Modifier = Modifier,
) {
val unsubscribeString = stringResource(id = R.string.unsubscribe)

@Suppress("MaxLineLength")
val annotatedLinkString = createClickableAnnotatedString(
mainString = stringResource(
id = R.string.get_emails_from_bitwarden_for_announcements_advices_and_research_opportunities_unsubscribe_any_time,
),
highlights = listOf(
ClickableTextHighlight(
textToHighlight = unsubscribeString,
onTextClick = onUnsubscribeClick,
),
),
)
BitwardenSwitch(
modifier = modifier
.semantics(mergeDescendants = true) {
Expand All @@ -382,7 +360,10 @@ private fun ReceiveMarketingEmailsSwitch(
),
)
},
label = annotatedLinkString,
label = R.string.get_emails_from_bitwarden_for_announcements_advices_and_research_opportunities_unsubscribe_any_time
.toAnnotatedString {
onUnsubscribeClick()
},
isChecked = isChecked,
onCheckedChange = onCheckedChange,
contentDescription = "ReceiveMarketingEmailsToggle",
Expand Down
Loading

0 comments on commit 1148e48

Please sign in to comment.