Make the profile mention match the profile color hashcode
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
package ac.cord.auxiliary.compose.ui.composable.widgets.content
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.NostrEvent
|
||||
import ac.cord.auxiliary.compose.database.model.Profile
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalMention
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalNostrEvent
|
||||
import ac.cord.auxiliary.compose.database.model.intermdiate.LocalQuotedNostrEvent
|
||||
import ac.cord.auxiliary.compose.ui.composable.widgets.content.Constants.INLINE_CONTENT_TAG
|
||||
import ac.cord.auxiliary.compose.ui.composable.widgets.profile.ProfileColor
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.text.InlineTextContent
|
||||
@@ -195,12 +197,13 @@ fun RichContent(
|
||||
Logger.withTag("RichContent").d("NostrProfileSegment: $seg")
|
||||
val pubkey = seg.pubkey
|
||||
val displayName = profileNames[seg.pubkey] ?: seg.pubkey.take(8)
|
||||
|
||||
withLink(
|
||||
LinkAnnotation.Clickable("profile") {
|
||||
onProfileClick?.invoke(pubkey)
|
||||
}
|
||||
) {
|
||||
withStyle(SpanStyle(color = effectiveLinkColor, textDecoration = linkDecoration)) {
|
||||
withStyle(SpanStyle(color = ProfileColor.fromPublicKey(seg.pubkey), textDecoration = linkDecoration)) {
|
||||
append("@${displayName.trimEnd()}")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,8 @@ fun ProfileAvatar(
|
||||
) {
|
||||
val modifier = Modifier.size(size).clip(shape = shape)
|
||||
|
||||
val tintColor = Color.hsl(
|
||||
hue = abs(
|
||||
publicKey.hashCode()
|
||||
).mod(360).toFloat(),
|
||||
saturation = 0.55f,
|
||||
lightness = 0.45f
|
||||
val tintColor = ProfileColor.fromPublicKey(
|
||||
publicKey
|
||||
)
|
||||
|
||||
if (profile?.picture == null) {
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package ac.cord.auxiliary.compose.ui.composable.widgets.profile
|
||||
|
||||
import ac.cord.auxiliary.compose.database.model.Profile
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import com.vitorpamplona.quartz.nip01Core.core.HexKey
|
||||
import kotlin.math.abs
|
||||
|
||||
object ProfileColor {
|
||||
fun fromPublicKey(publicKey: HexKey): Color {
|
||||
return Color.hsl(
|
||||
hue = abs(
|
||||
publicKey.hashCode()
|
||||
).mod(360).toFloat(),
|
||||
saturation = 0.55f,
|
||||
lightness = 0.45f
|
||||
)
|
||||
}
|
||||
|
||||
fun fromProfile(profile: Profile): Color {
|
||||
return fromPublicKey(
|
||||
profile.publicKey
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user