Fix shrinking of public channel names

This commit is contained in:
Oleg Koretsky
2023-03-08 20:50:42 +02:00
parent 13e488e1e2
commit f2b1fa9101

View File

@@ -31,10 +31,13 @@ import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.graphics.painter.Painter import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDirection import androidx.compose.ui.text.style.TextDirection
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.text.withStyle
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.navigation.NavController import androidx.navigation.NavController
@@ -49,7 +52,11 @@ import com.vitorpamplona.amethyst.ui.components.ResizeImage
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
@Composable @Composable
fun ChatroomCompose(baseNote: Note, accountViewModel: AccountViewModel, navController: NavController) { fun ChatroomCompose(
baseNote: Note,
accountViewModel: AccountViewModel,
navController: NavController
) {
val noteState by baseNote.live().metadata.observeAsState() val noteState by baseNote.live().metadata.observeAsState()
val note = noteState?.note val note = noteState?.note
@@ -84,24 +91,43 @@ fun ChatroomCompose(baseNote: Note, accountViewModel: AccountViewModel, navContr
LaunchedEffect(key1 = notificationCache, key2 = note) { LaunchedEffect(key1 = notificationCache, key2 = note) {
note.createdAt()?.let { note.createdAt()?.let {
hasNewMessages = it > notificationCache.cache.load("Channel/${channel.idHex}", context) hasNewMessages =
it > notificationCache.cache.load("Channel/${channel.idHex}", context)
} }
} }
ChannelName( ChannelName(
channelPicture = channel.profilePicture(), channelPicture = channel.profilePicture(),
channelPicturePlaceholder = BitmapPainter(RoboHashCache.get(context, channel.idHex)), channelPicturePlaceholder = BitmapPainter(
RoboHashCache.get(
context,
channel.idHex
)
),
channelTitle = { channelTitle = {
Text( Text(
"${channel.info.name}", text = buildAnnotatedString {
withStyle(
SpanStyle(
fontWeight = FontWeight.Bold
)
) {
append(channel.info.name)
}
withStyle(
SpanStyle(
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f),
fontWeight = FontWeight.Normal
)
) {
append(" ${stringResource(id = R.string.public_chat)}")
}
},
fontWeight = FontWeight.Bold, fontWeight = FontWeight.Bold,
modifier = it, modifier = it,
style = LocalTextStyle.current.copy(textDirection = TextDirection.Content) style = LocalTextStyle.current.copy(textDirection = TextDirection.Content)
) )
Text(
" ${stringResource(R.string.public_chat)}",
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
)
}, },
channelLastTime = note.createdAt(), channelLastTime = note.createdAt(),
channelLastContent = "${author?.toBestDisplayName()}: " + description, channelLastContent = "${author?.toBestDisplayName()}: " + description,
@@ -127,12 +153,21 @@ fun ChatroomCompose(baseNote: Note, accountViewModel: AccountViewModel, navContr
LaunchedEffect(key1 = notificationCache, key2 = note) { LaunchedEffect(key1 = notificationCache, key2 = note) {
noteEvent?.let { noteEvent?.let {
hasNewMessages = it.createdAt() > notificationCache.cache.load("Room/${userToComposeOn.pubkeyHex}", context) hasNewMessages = it.createdAt() > notificationCache.cache.load(
"Room/${userToComposeOn.pubkeyHex}",
context
)
} }
} }
ChannelName( ChannelName(
channelPicture = { UserPicture(userToComposeOn, account.userProfile(), size = 55.dp) }, channelPicture = {
UserPicture(
userToComposeOn,
account.userProfile(),
size = 55.dp
)
},
channelTitle = { UsernameDisplay(userToComposeOn, it) }, channelTitle = { UsernameDisplay(userToComposeOn, it) },
channelLastTime = note.createdAt(), channelLastTime = note.createdAt(),
channelLastContent = accountViewModel.decrypt(note), channelLastContent = accountViewModel.decrypt(note),
@@ -209,7 +244,10 @@ fun ChannelName(
} }
} }
Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) { Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
if (channelLastContent != null) { if (channelLastContent != null) {
Text( Text(
channelLastContent, channelLastContent,