feat: use brush for user colour
to support gradient role colours Signed-off-by: Infi <wingit@geist.ga>
This commit is contained in:
parent
166512fb4f
commit
5a365e8bd2
|
|
@ -4,32 +4,41 @@ import android.util.Log
|
||||||
import androidx.compose.material3.LocalContentColor
|
import androidx.compose.material3.LocalContentColor
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
|
// color is spelled american because Color from compose is spelled american
|
||||||
|
fun Brush.Companion.solidColor(colour: Color) = linearGradient(
|
||||||
|
colorStops = arrayOf(
|
||||||
|
0f to colour,
|
||||||
|
1f to colour
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
object WebCompat {
|
object WebCompat {
|
||||||
@Composable
|
@Composable
|
||||||
fun parseColour(colour: String): Color {
|
fun parseColour(colour: String): Brush {
|
||||||
if (colour.startsWith("var(")) {
|
if (colour.startsWith("var(")) {
|
||||||
Log.d(
|
Log.d(
|
||||||
"WebCompat",
|
"WebCompat",
|
||||||
"Parsing colour $colour. ${colour.substringAfter("var(").substringBefore(")")}"
|
"Parsing colour $colour. ${colour.substringAfter("var(").substringBefore(")")}"
|
||||||
)
|
)
|
||||||
return when (colour.substringAfter("var(").substringBefore(")")) {
|
return when (colour.substringAfter("var(").substringBefore(")")) {
|
||||||
"--accent" -> MaterialTheme.colorScheme.primary
|
"--accent" -> Brush.solidColor(MaterialTheme.colorScheme.primary)
|
||||||
"--foreground" -> MaterialTheme.colorScheme.onBackground
|
"--foreground" -> Brush.solidColor(MaterialTheme.colorScheme.onBackground)
|
||||||
"--background" -> MaterialTheme.colorScheme.background
|
"--background" -> Brush.solidColor(MaterialTheme.colorScheme.background)
|
||||||
"--error" -> MaterialTheme.colorScheme.error
|
"--error" -> Brush.solidColor(MaterialTheme.colorScheme.error)
|
||||||
else -> LocalContentColor.current
|
else -> Brush.solidColor(LocalContentColor.current)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
return Color(android.graphics.Color.parseColor(colour))
|
return Brush.solidColor(Color(android.graphics.Color.parseColor(colour)))
|
||||||
} catch (e: IllegalArgumentException) {
|
} catch (e: IllegalArgumentException) {
|
||||||
Log.d(
|
Log.d(
|
||||||
"WebCompat",
|
"WebCompat",
|
||||||
"Failed to parse colour $colour, falling back to LocalContentColor.current"
|
"Failed to parse colour $colour, falling back to LocalContentColor.current"
|
||||||
)
|
)
|
||||||
return LocalContentColor.current
|
return Brush.solidColor(LocalContentColor.current)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,11 +20,13 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
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.Brush
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import chat.revolt.api.routes.microservices.january.asJanuaryProxyUrl
|
|
||||||
import chat.revolt.api.internals.WebCompat
|
import chat.revolt.api.internals.WebCompat
|
||||||
|
import chat.revolt.api.internals.solidColor
|
||||||
|
import chat.revolt.api.routes.microservices.january.asJanuaryProxyUrl
|
||||||
import chat.revolt.api.schemas.Embed
|
import chat.revolt.api.schemas.Embed
|
||||||
import chat.revolt.components.generic.RemoteImage
|
import chat.revolt.components.generic.RemoteImage
|
||||||
import chat.revolt.components.generic.UIMarkdown
|
import chat.revolt.components.generic.UIMarkdown
|
||||||
|
|
@ -50,7 +52,7 @@ fun RegularEmbed(
|
||||||
.fillMaxHeight()
|
.fillMaxHeight()
|
||||||
.background(
|
.background(
|
||||||
embed.colour?.let { WebCompat.parseColour(it) }
|
embed.colour?.let { WebCompat.parseColour(it) }
|
||||||
?: MaterialTheme.colorScheme.primary
|
?: Brush.solidColor(MaterialTheme.colorScheme.primary)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,12 @@ import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
import androidx.compose.material3.LocalContentColor
|
import androidx.compose.material3.LocalContentColor
|
||||||
|
import androidx.compose.material3.LocalTextStyle
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.font.FontFamily
|
import androidx.compose.ui.text.font.FontFamily
|
||||||
import androidx.compose.ui.text.font.FontStyle
|
import androidx.compose.ui.text.font.FontStyle
|
||||||
|
|
@ -22,6 +24,7 @@ import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import chat.revolt.R
|
import chat.revolt.R
|
||||||
import chat.revolt.api.RevoltAPI
|
import chat.revolt.api.RevoltAPI
|
||||||
|
import chat.revolt.api.internals.solidColor
|
||||||
import chat.revolt.api.routes.microservices.january.asJanuaryProxyUrl
|
import chat.revolt.api.routes.microservices.january.asJanuaryProxyUrl
|
||||||
import chat.revolt.api.schemas.User
|
import chat.revolt.api.schemas.User
|
||||||
import chat.revolt.components.generic.UserAvatar
|
import chat.revolt.components.generic.UserAvatar
|
||||||
|
|
@ -41,7 +44,7 @@ fun InReplyTo(
|
||||||
?: stringResource(id = R.string.unknown)
|
?: stringResource(id = R.string.unknown)
|
||||||
|
|
||||||
val contentColor = LocalContentColor.current
|
val contentColor = LocalContentColor.current
|
||||||
val usernameColor = message?.let { authorColour(it) } ?: contentColor
|
val usernameColor = message?.let { authorColour(it) } ?: Brush.solidColor(contentColor)
|
||||||
|
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
|
|
@ -73,9 +76,11 @@ fun InReplyTo(
|
||||||
} else {
|
} else {
|
||||||
stringResource(id = R.string.unknown)
|
stringResource(id = R.string.unknown)
|
||||||
},
|
},
|
||||||
fontWeight = FontWeight.Bold,
|
style = LocalTextStyle.current.copy(
|
||||||
fontSize = 12.sp,
|
fontWeight = FontWeight.Bold,
|
||||||
color = usernameColor,
|
fontSize = 12.sp,
|
||||||
|
brush = usernameColor
|
||||||
|
),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis,
|
overflow = TextOverflow.Ellipsis,
|
||||||
modifier = Modifier.padding(horizontal = 4.dp)
|
modifier = Modifier.padding(horizontal = 4.dp)
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,13 @@ import androidx.compose.material.icons.filled.Edit
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.LocalContentColor
|
import androidx.compose.material3.LocalContentColor
|
||||||
|
import androidx.compose.material3.LocalTextStyle
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
|
@ -50,6 +52,7 @@ import chat.revolt.api.REVOLT_FILES
|
||||||
import chat.revolt.api.RevoltAPI
|
import chat.revolt.api.RevoltAPI
|
||||||
import chat.revolt.api.internals.ULID
|
import chat.revolt.api.internals.ULID
|
||||||
import chat.revolt.api.internals.WebCompat
|
import chat.revolt.api.internals.WebCompat
|
||||||
|
import chat.revolt.api.internals.solidColor
|
||||||
import chat.revolt.api.routes.microservices.january.asJanuaryProxyUrl
|
import chat.revolt.api.routes.microservices.january.asJanuaryProxyUrl
|
||||||
import chat.revolt.api.schemas.AutumnResource
|
import chat.revolt.api.schemas.AutumnResource
|
||||||
import chat.revolt.api.schemas.User
|
import chat.revolt.api.schemas.User
|
||||||
|
|
@ -58,11 +61,11 @@ import chat.revolt.components.generic.UserAvatarWidthPlaceholder
|
||||||
import chat.revolt.api.schemas.Message as MessageSchema
|
import chat.revolt.api.schemas.Message as MessageSchema
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun authorColour(message: MessageSchema): Color {
|
fun authorColour(message: MessageSchema): Brush {
|
||||||
return if (message.masquerade?.colour != null) {
|
return if (message.masquerade?.colour != null) {
|
||||||
WebCompat.parseColour(message.masquerade.colour)
|
WebCompat.parseColour(message.masquerade.colour)
|
||||||
} else {
|
} else {
|
||||||
LocalContentColor.current
|
Brush.solidColor(LocalContentColor.current)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,8 +215,15 @@ fun Message(
|
||||||
Row(verticalAlignment = Alignment.CenterVertically) {
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
Text(
|
Text(
|
||||||
text = authorName(message),
|
text = authorName(message),
|
||||||
fontWeight = FontWeight.Bold,
|
style = LocalTextStyle.current.copy(
|
||||||
color = authorColour(message),
|
fontWeight = FontWeight.Bold,
|
||||||
|
brush = if (message.author == RevoltAPI.selfId) Brush.horizontalGradient(
|
||||||
|
listOf(
|
||||||
|
Color.Magenta,
|
||||||
|
Color.Cyan,
|
||||||
|
),
|
||||||
|
) else authorColour(message),
|
||||||
|
),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis
|
overflow = TextOverflow.Ellipsis
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Close
|
import androidx.compose.material.icons.filled.Close
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.LocalTextStyle
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.surfaceColorAtElevation
|
import androidx.compose.material3.surfaceColorAtElevation
|
||||||
|
|
@ -88,14 +89,16 @@ fun ManageableReply(
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
text = authorName(message = replyMessage),
|
text = authorName(message = replyMessage),
|
||||||
fontSize = 12.sp,
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.clickable {
|
.clickable {
|
||||||
onToggleMention()
|
onToggleMention()
|
||||||
}
|
}
|
||||||
.padding(4.dp),
|
.padding(4.dp),
|
||||||
color = authorColour(message = replyMessage),
|
style = LocalTextStyle.current.copy(
|
||||||
fontWeight = FontWeight.Bold,
|
brush = authorColour(message = replyMessage),
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
Text(
|
Text(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue