rendering image in a bubble

This commit is contained in:
Adam Brown 2022-04-01 19:53:44 +01:00
parent d0b2627eb2
commit b817929a2b
1 changed files with 54 additions and 17 deletions

View File

@ -180,9 +180,7 @@ private fun LazyItemScope.Image(self: UserId, message: RoomEvent.Image, wasPrevi
isNotSelf = false, isNotSelf = false,
wasPreviousMessageSameSender = wasPreviousMessageSameSender wasPreviousMessageSameSender = wasPreviousMessageSameSender
) { ) {
Box { MessageImage(selfBackgroundShape, SmallTalkTheme.extendedColors.selfBubble, false, message)
MessageImage(message)
}
} }
} }
} }
@ -194,9 +192,7 @@ private fun LazyItemScope.Image(self: UserId, message: RoomEvent.Image, wasPrevi
isNotSelf = true, isNotSelf = true,
wasPreviousMessageSameSender = wasPreviousMessageSameSender wasPreviousMessageSameSender = wasPreviousMessageSameSender
) { ) {
Box { MessageImage(othersBackgroundShape, SmallTalkTheme.extendedColors.othersBubble, true, message)
MessageImage(message)
}
} }
} }
} }
@ -204,10 +200,33 @@ private fun LazyItemScope.Image(self: UserId, message: RoomEvent.Image, wasPrevi
} }
@Composable @Composable
private fun MessageImage(message: RoomEvent.Image) { private fun MessageImage(shape: RoundedCornerShape, background: Color, isNotSelf: Boolean, message: RoomEvent.Image) {
Box(modifier = Modifier.padding(start = 6.dp)) {
Box(
Modifier
.padding(4.dp)
.clip(shape)
.background(background)
.height(IntrinsicSize.Max),
) {
Column(
Modifier
.padding(8.dp)
.width(IntrinsicSize.Max)
.defaultMinSize(minWidth = 50.dp)
) {
if (isNotSelf) {
Text(
fontSize = 11.sp,
text = message.author.displayName ?: message.author.id.value,
maxLines = 1,
color = MaterialTheme.colors.onPrimary
)
}
val width = with(LocalDensity.current) { message.imageMeta.width.toDp() } val width = with(LocalDensity.current) { message.imageMeta.width.toDp() }
val height = with(LocalDensity.current) { message.imageMeta.height.toDp() } val height = with(LocalDensity.current) { message.imageMeta.height.toDp() }
Spacer(modifier = Modifier.height(4.dp))
Image( Image(
modifier = Modifier.size(width, height), modifier = Modifier.size(width, height),
painter = rememberImagePainter( painter = rememberImagePainter(
@ -216,6 +235,24 @@ private fun MessageImage(message: RoomEvent.Image) {
), ),
contentDescription = null, contentDescription = null,
) )
Spacer(modifier = Modifier.height(4.dp))
Row(horizontalArrangement = Arrangement.End, verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) {
val editedPrefix = if (message.edited) "(edited) " else null
Text(
fontSize = 9.sp,
text = "${editedPrefix ?: ""}${message.time}",
textAlign = TextAlign.End,
color = MaterialTheme.colors.onPrimary,
modifier = Modifier.wrapContentSize()
)
SendStatus(message)
}
}
}
}
} }
@Composable @Composable