Improving performance of the UserNameDisplay by making variables immutable
This commit is contained in:
@@ -28,41 +28,55 @@ fun UsernameDisplay(baseUser: User, weight: Modifier = Modifier) {
|
|||||||
val userState by baseUser.live().metadata.observeAsState()
|
val userState by baseUser.live().metadata.observeAsState()
|
||||||
val user = userState?.user ?: return
|
val user = userState?.user ?: return
|
||||||
|
|
||||||
if (user.bestUsername() != null && user.bestDisplayName() != null) {
|
val bestUserName = user.bestUsername()
|
||||||
|
val bestDisplayName = user.bestDisplayName()
|
||||||
|
val npubDisplay = user.pubkeyDisplayHex()
|
||||||
|
|
||||||
|
UserNameDisplay(bestUserName, bestDisplayName, npubDisplay, weight)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun UserNameDisplay(
|
||||||
|
bestUserName: String?,
|
||||||
|
bestDisplayName: String?,
|
||||||
|
npubDisplay: String,
|
||||||
|
modifier: Modifier
|
||||||
|
) {
|
||||||
|
if (bestUserName != null && bestDisplayName != null) {
|
||||||
Text(
|
Text(
|
||||||
user.bestDisplayName() ?: "",
|
bestDisplayName,
|
||||||
fontWeight = FontWeight.Bold
|
fontWeight = FontWeight.Bold
|
||||||
)
|
)
|
||||||
Text(
|
Text(
|
||||||
"@${(user.bestUsername() ?: "")}",
|
"@$bestUserName",
|
||||||
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f),
|
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier = weight
|
modifier = modifier
|
||||||
)
|
)
|
||||||
} else if (user.bestDisplayName() != null) {
|
} else if (bestDisplayName != null) {
|
||||||
Text(
|
Text(
|
||||||
user.bestDisplayName() ?: "",
|
bestDisplayName,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier = weight
|
modifier = modifier
|
||||||
)
|
)
|
||||||
} else if (user.bestUsername() != null) {
|
} else if (bestUserName != null) {
|
||||||
Text(
|
Text(
|
||||||
"@${(user.bestUsername() ?: "")}",
|
"@$bestUserName",
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier = weight
|
modifier = modifier
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
Text(
|
Text(
|
||||||
user.pubkeyDisplayHex(),
|
npubDisplay,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier = weight
|
modifier = modifier
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user