Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,20 @@ fun ChannelHeader(
}

channel.channelType?.let {
ChannelIcon(
channelType = it,
modifier = Modifier.alpha(0.6f)
)
when (it) {
ChannelType.TextChannel, ChannelType.VoiceChannel -> {
ChannelIcon(
channel = channel,
modifier = Modifier.alpha(0.6f)
)
}
else -> {
ChannelIcon(
channelType = it,
modifier = Modifier.alpha(0.6f)
)
}
}
}

Spacer(modifier = Modifier.width(8.dp))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package chat.revolt.composables.screens.chat

import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import chat.revolt.R
import chat.revolt.api.REVOLT_FILES
import chat.revolt.api.schemas.Channel
import chat.revolt.api.schemas.ChannelType
import chat.revolt.composables.generic.RemoteImage

@Composable
fun ChannelIcon(channelType: ChannelType, modifier: Modifier = Modifier) {
Expand Down Expand Up @@ -56,6 +62,29 @@ fun ChannelIcon(channelType: ChannelType, modifier: Modifier = Modifier) {
}
}

@Composable
fun ChannelIcon(
channel: Channel,
modifier: Modifier = Modifier,
size: androidx.compose.ui.unit.Dp = 24.dp
) {
val channelType = channel.channelType ?: ChannelType.TextChannel

if (channel.icon?.id != null) {
RemoteImage(
url = "$REVOLT_FILES/icons/${channel.icon.id}",
description = channel.name ?: stringResource(R.string.unknown),
contentScale = ContentScale.Crop,
height = size.value.toInt(),
width = size.value.toInt(),
allowAnimation = false,
modifier = modifier.size(size)
)
} else {
ChannelIcon(channelType = channelType, modifier = modifier)
}
}

class ChannelTypeProvider : PreviewParameterProvider<ChannelType> {
override val values: Sequence<ChannelType>
get() = sequenceOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ fun ChannelItem(
)
}

else -> ChannelIcon(iconType.type)
else -> ChannelIcon(channel = channel, size = 24.dp)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,14 @@ fun ChannelScreen(
)
}

ChannelType.TextChannel, ChannelType.VoiceChannel -> {
ChannelIcon(
channel = it,
size = 24.dp,
modifier = Modifier.alpha(0.8f)
)
}

else -> {
ChannelIcon(
channelType = it.channelType ?: ChannelType.TextChannel,
Expand Down