feat: display server official/verified badge

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2023-10-02 01:32:45 +02:00
parent 45009d180b
commit cec19dc501
5 changed files with 75 additions and 2 deletions

View File

@ -41,6 +41,16 @@ data class Server(
} }
} }
enum class ServerFlags(val value: Long) {
Official(1L shl 0),
Verified(1L shl 1),
}
infix fun Long?.has(flag: ServerFlags): Boolean {
if (this == null) return false
return this and flag.value == flag.value
}
@Serializable @Serializable
data class Category( data class Category(
val id: String? = null, val id: String? = null,

View File

@ -13,10 +13,13 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
@ -44,6 +47,7 @@ import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
@ -58,7 +62,9 @@ import chat.revolt.api.REVOLT_FILES
import chat.revolt.api.RevoltAPI import chat.revolt.api.RevoltAPI
import chat.revolt.api.internals.ChannelUtils import chat.revolt.api.internals.ChannelUtils
import chat.revolt.api.schemas.ChannelType import chat.revolt.api.schemas.ChannelType
import chat.revolt.api.schemas.ServerFlags
import chat.revolt.api.schemas.User import chat.revolt.api.schemas.User
import chat.revolt.api.schemas.has
import chat.revolt.components.generic.presenceFromStatus import chat.revolt.components.generic.presenceFromStatus
import chat.revolt.components.screens.chat.drawer.server.DrawerChannel import chat.revolt.components.screens.chat.drawer.server.DrawerChannel
import chat.revolt.sheets.ChannelContextSheet import chat.revolt.sheets.ChannelContextSheet
@ -345,6 +351,37 @@ fun RowScope.ChannelList(
Row( Row(
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
Spacer(Modifier.width(16.dp))
if (server?.flags has ServerFlags.Official) {
Icon(
painter = painterResource(id = R.drawable.ic_revolt_decagram_24dp),
contentDescription = stringResource(R.string.server_flag_official),
tint = if (server?.banner != null) {
bannerTextColour
} else {
LocalContentColor.current
},
modifier = Modifier
.padding(end = 8.dp)
.size(24.dp)
)
}
if (server?.flags has ServerFlags.Verified) {
Icon(
painter = painterResource(id = R.drawable.ic_check_decagram_24dp),
contentDescription = stringResource(R.string.server_flag_verified),
tint = if (server?.banner != null) {
bannerTextColour
} else {
LocalContentColor.current
},
modifier = Modifier
.padding(end = 8.dp)
.size(24.dp)
)
}
Text( Text(
text = (server?.name text = (server?.name
?: stringResource(R.string.unknown)), ?: stringResource(R.string.unknown)),
@ -358,10 +395,15 @@ fun RowScope.ChannelList(
modifier = Modifier modifier = Modifier
.then( .then(
if (server?.banner != null) { if (server?.banner != null) {
Modifier.padding(16.dp) Modifier.padding(
start = 0.dp,
end = 16.dp,
top = 16.dp,
bottom = 16.dp
)
} else { } else {
Modifier.padding( Modifier.padding(
start = 24.dp, start = 0.dp,
end = 24.dp, end = 24.dp,
top = 16.dp, top = 16.dp,
bottom = 16.dp bottom = 16.dp

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#ffffff"
android:pathData="M23,12L20.56,9.22L20.9,5.54L17.29,4.72L15.4,1.54L12,3L8.6,1.54L6.71,4.72L3.1,5.53L3.44,9.21L1,12L3.44,14.78L3.1,18.47L6.71,19.29L8.6,22.47L12,21L15.4,22.46L17.29,19.28L20.9,18.46L20.56,14.78L23,12M10,17L6,13L7.41,11.59L10,14.17L16.59,7.58L18,9L10,17Z" />
</vector>

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#ffffff"
android:pathData="M8.6,1.539L6.711,4.721L3.1,5.529L3.439,9.211L1,12L3.439,14.779L3.1,18.471L6.711,19.289L8.6,22.471L12,21L15.4,22.461L17.289,19.279L20.9,18.461L20.561,14.779L23,12L20.561,9.221L20.9,5.539L17.289,4.721L15.4,1.539L12,3L8.6,1.539zM7.965,7.66L12.789,7.66C14.919,7.66 15.982,8.884 15.982,10.393C15.995,10.968 15.812,11.53 15.461,11.986C15.11,12.443 14.613,12.766 14.053,12.902L16.059,16.34L13.668,16.34L11.859,13.064L11.352,13.064L11.352,16.34L9.234,16.34L9.234,9.42L7.965,7.66zM11.352,9.416L11.352,11.566L12.664,11.566C13.457,11.566 13.828,11.159 13.828,10.479C13.828,9.835 13.456,9.416 12.664,9.416L11.352,9.416z" />
</vector>

View File

@ -187,6 +187,9 @@
<string name="copy">Copy</string> <string name="copy">Copy</string>
<string name="copied">Copied to clipboard</string> <string name="copied">Copied to clipboard</string>
<string name="server_flag_official">Official Server</string>
<string name="server_flag_verified">Verified Server</string>
<string name="channel_link_invalid">You can\'t view this channel</string> <string name="channel_link_invalid">You can\'t view this channel</string>
<string name="channel_link_invalid_description">This channel may have been deleted or you may not have permission to view it.</string> <string name="channel_link_invalid_description">This channel may have been deleted or you may not have permission to view it.</string>