mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-04-09 04:18:11 +02:00
improving speed of chatlist rendering
This commit is contained in:
parent
b0c33808e6
commit
6df2c3a0cf
@ -28,21 +28,21 @@ import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.RowScope
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.ListItem
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.ui.note.NewItemsBubble
|
||||
import com.vitorpamplona.amethyst.ui.note.elements.TimeAgo
|
||||
import com.vitorpamplona.amethyst.ui.stringRes
|
||||
import com.vitorpamplona.amethyst.ui.theme.ChatHeadlineBorders
|
||||
import com.vitorpamplona.amethyst.ui.theme.DividerThickness
|
||||
import com.vitorpamplona.amethyst.ui.theme.DoubleHorzSpacer
|
||||
import com.vitorpamplona.amethyst.ui.theme.Height4dpModifier
|
||||
@ -108,31 +108,29 @@ fun ChatHeaderLayout(
|
||||
secondRow: @Composable RowScope.() -> Unit,
|
||||
onClick: () -> Unit,
|
||||
) {
|
||||
Column(modifier = remember { Modifier.clickable(onClick = onClick) }) {
|
||||
Row(
|
||||
modifier = ChatHeadlineBorders,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
Row(
|
||||
modifier = Modifier.clickable(onClick = onClick).padding(10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Box(Size55Modifier) { channelPicture() }
|
||||
|
||||
Spacer(modifier = DoubleHorzSpacer)
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
Box(Size55Modifier) { channelPicture() }
|
||||
|
||||
Spacer(modifier = DoubleHorzSpacer)
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
firstRow()
|
||||
}
|
||||
firstRow()
|
||||
}
|
||||
|
||||
Spacer(modifier = Height4dpModifier)
|
||||
Spacer(modifier = Height4dpModifier)
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
secondRow()
|
||||
}
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
secondRow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -252,24 +252,47 @@ private fun UserRoomCompose(
|
||||
) {
|
||||
val route = "Room/${room.hashCode()}"
|
||||
|
||||
val lastReadTime by accountViewModel.account.loadLastReadFlow(route).collectAsStateWithLifecycle()
|
||||
ChatHeaderLayout(
|
||||
channelPicture = {
|
||||
NonClickableUserPictures(
|
||||
room = room,
|
||||
accountViewModel = accountViewModel,
|
||||
size = Size55dp,
|
||||
)
|
||||
},
|
||||
firstRow = {
|
||||
RoomNameDisplay(room, Modifier.weight(1f), accountViewModel)
|
||||
TimeAgo(note.createdAt())
|
||||
},
|
||||
secondRow = {
|
||||
LoadDecryptedContentOrNull(note, accountViewModel) { content ->
|
||||
if (content != null) {
|
||||
Text(
|
||||
content,
|
||||
color = MaterialTheme.colorScheme.grayText,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
style = LocalTextStyle.current.copy(textDirection = TextDirection.Content),
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
} else {
|
||||
Text(
|
||||
stringRes(R.string.referenced_event_not_found),
|
||||
color = MaterialTheme.colorScheme.grayText,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
LoadDecryptedContentOrNull(note, accountViewModel) { content ->
|
||||
ChannelName(
|
||||
channelPicture = {
|
||||
NonClickableUserPictures(
|
||||
room = room,
|
||||
accountViewModel = accountViewModel,
|
||||
size = Size55dp,
|
||||
)
|
||||
},
|
||||
channelTitle = { RoomNameDisplay(room, it, accountViewModel) },
|
||||
channelLastTime = note.createdAt(),
|
||||
channelLastContent = content,
|
||||
hasNewMessages = (note.createdAt() ?: Long.MIN_VALUE) > lastReadTime,
|
||||
onClick = { nav(route) },
|
||||
)
|
||||
}
|
||||
val lastReadTime by accountViewModel.account.loadLastReadFlow(route).collectAsStateWithLifecycle()
|
||||
if ((note.createdAt() ?: Long.MIN_VALUE) > lastReadTime) {
|
||||
NewItemsBubble()
|
||||
}
|
||||
},
|
||||
onClick = { nav(route) },
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
|
@ -75,7 +75,11 @@ fun LoadDecryptedContentOrNull(
|
||||
) {
|
||||
val decryptedContent by
|
||||
produceState(initialValue = accountViewModel.cachedDecrypt(note), key1 = note.event?.id()) {
|
||||
accountViewModel.decrypt(note) { value = it }
|
||||
accountViewModel.decrypt(note) {
|
||||
if (value != it) {
|
||||
value = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inner(decryptedContent)
|
||||
|
@ -179,16 +179,16 @@ fun NonClickableUserPictures(
|
||||
size: Dp,
|
||||
accountViewModel: AccountViewModel,
|
||||
) {
|
||||
val userList = remember(room) { room.users.toList() }
|
||||
|
||||
Box(Modifier.size(size), contentAlignment = Alignment.TopEnd) {
|
||||
when (userList.size) {
|
||||
when (room.users.size) {
|
||||
0 -> {}
|
||||
1 ->
|
||||
LoadUser(baseUserHex = userList[0], accountViewModel) {
|
||||
LoadUser(baseUserHex = room.users.first(), accountViewModel) {
|
||||
it?.let { BaseUserPicture(it, size, accountViewModel, outerModifier = Modifier) }
|
||||
}
|
||||
2 -> {
|
||||
val userList = room.users.toList()
|
||||
|
||||
LoadUser(baseUserHex = userList[0], accountViewModel) {
|
||||
it?.let {
|
||||
BaseUserPicture(
|
||||
@ -211,6 +211,8 @@ fun NonClickableUserPictures(
|
||||
}
|
||||
}
|
||||
3 -> {
|
||||
val userList = room.users.toList()
|
||||
|
||||
LoadUser(baseUserHex = userList[0], accountViewModel) {
|
||||
it?.let {
|
||||
BaseUserPicture(
|
||||
@ -243,6 +245,8 @@ fun NonClickableUserPictures(
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
val userList = room.users.toList()
|
||||
|
||||
LoadUser(baseUserHex = userList[0], accountViewModel) {
|
||||
it?.let {
|
||||
BaseUserPicture(
|
||||
|
Loading…
x
Reference in New Issue
Block a user