Invites: simplify string building
This commit is contained in:
parent
0290d0a279
commit
9d52beb525
1 changed files with 17 additions and 17 deletions
|
|
@ -37,12 +37,12 @@ import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.AnnotatedString
|
||||||
import androidx.compose.ui.text.SpanStyle
|
import androidx.compose.ui.text.SpanStyle
|
||||||
import androidx.compose.ui.text.buildAnnotatedString
|
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextOverflow
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
import androidx.compose.ui.text.withStyle
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
@ -181,21 +181,21 @@ private fun SenderRow(sender: InviteSender) {
|
||||||
avatarData = sender.avatarData.copy(size = AvatarSize.Custom(16.dp)),
|
avatarData = sender.avatarData.copy(size = AvatarSize.Custom(16.dp)),
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
text = buildAnnotatedString {
|
text = stringResource(R.string.screen_invites_invited_you, sender.displayName, sender.userId.value).let { text ->
|
||||||
val placeholder = "$"
|
val senderNameStart = LocalContext.current.getString(R.string.screen_invites_invited_you).indexOf("%1\$s")
|
||||||
val text = stringResource(R.string.screen_invites_invited_you, placeholder, sender.userId.value)
|
AnnotatedString(
|
||||||
val nameIndex = text.indexOf(placeholder)
|
text = text,
|
||||||
|
spanStyles = listOf(
|
||||||
// Text before the placeholder
|
AnnotatedString.Range(
|
||||||
append(text.take(nameIndex))
|
SpanStyle(
|
||||||
|
fontWeight = FontWeight.Medium,
|
||||||
// Display name
|
color = MaterialTheme.colorScheme.primary
|
||||||
withStyle(SpanStyle(fontWeight = FontWeight.Medium, color = MaterialTheme.colorScheme.primary)) {
|
),
|
||||||
append(sender.displayName)
|
start = senderNameStart,
|
||||||
}
|
end = senderNameStart + sender.displayName.length
|
||||||
|
)
|
||||||
// Text after the placeholder
|
)
|
||||||
append(text.drop(nameIndex + placeholder.length))
|
)
|
||||||
},
|
},
|
||||||
style = noFontPadding,
|
style = noFontPadding,
|
||||||
color = MaterialTheme.colorScheme.secondary,
|
color = MaterialTheme.colorScheme.secondary,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue