dm-6
This commit is contained in:
parent
284e89924a
commit
c22bbbcaa0
1 changed files with 125 additions and 68 deletions
|
|
@ -2,6 +2,7 @@ package com.example.login_v3.home.Message.UI
|
|||
|
||||
import androidx.compose.animation.AnimatedContentTransitionScope
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
|
|
@ -11,6 +12,7 @@ import androidx.compose.foundation.layout.Box
|
|||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
|
|
@ -273,7 +275,7 @@ fun Loaded_Tg_Message(
|
|||
room = room,
|
||||
onClick = onRoomClick
|
||||
)
|
||||
Spacer(modifier = Modifier.height(10.dp))
|
||||
Spacer(modifier = Modifier.height(6.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -296,20 +298,41 @@ fun RoomItem(
|
|||
.clickable { onClick(room.roomId) },
|
||||
shape = RoundedCornerShape(16.dp), // 較大的圓角看起來更現代
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = Color.White.copy(alpha = 0.85f) // 半透明白色,透出後方的漸層背景
|
||||
containerColor = Color.Transparent // ✅ 透明背景
|
||||
),
|
||||
elevation = CardDefaults.cardElevation(
|
||||
defaultElevation = 0.dp // 增加輕微陰影
|
||||
)
|
||||
) {
|
||||
Row(
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.background(Color.Transparent)
|
||||
.padding(16.dp), // Card 內部的填充
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
.fillMaxSize()
|
||||
){
|
||||
//glass effect
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.matchParentSize()
|
||||
.blur(10.dp)
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.matchParentSize()
|
||||
.background(
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
RoundedCornerShape(16.dp)
|
||||
)
|
||||
.border(
|
||||
1.dp,
|
||||
Color.White.copy(alpha = 0.3f),
|
||||
RoundedCornerShape(16.dp)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier.padding(12.dp),
|
||||
) {
|
||||
// 1. 頭像
|
||||
val imageUrl = room.roomIconUrl ?: room.partner?.fullContactAvatarUrl
|
||||
AsyncImage(
|
||||
|
|
@ -326,7 +349,9 @@ fun RoomItem(
|
|||
Spacer(modifier = Modifier.width(16.dp))
|
||||
|
||||
// 2. 中間內容
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Column(
|
||||
modifier = Modifier.weight(1f)
|
||||
) {
|
||||
Text(
|
||||
text = room.roomName.orEmpty().ifEmpty {
|
||||
room.partner?.displayName ?: "Unknown"
|
||||
|
|
@ -347,6 +372,7 @@ fun RoomItem(
|
|||
else -> "尚未有訊息"
|
||||
}
|
||||
|
||||
Row() {
|
||||
Text(
|
||||
text = lastMsgText,
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
|
|
@ -354,21 +380,6 @@ fun RoomItem(
|
|||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
|
||||
// 3. 右側:時間與未讀計數
|
||||
Column(
|
||||
horizontalAlignment = Alignment.End,
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
val time = room.lastMessage?.createdAt?.take(10) ?: ""
|
||||
Text(
|
||||
text = time,
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = Color.Gray
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
if (room.unreadCount > 0) {
|
||||
Badge(
|
||||
|
|
@ -382,6 +393,52 @@ fun RoomItem(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(2.dp))
|
||||
}
|
||||
|
||||
// 3. 右側:時間與未讀計數
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
|
||||
val partner = room.partner // 先從 room 取得 partner
|
||||
if (partner != null) {
|
||||
val status = UserStatus.fromString(partner.status)
|
||||
if (status != UserStatus.UNKNOWN) {
|
||||
Canvas(
|
||||
modifier = Modifier
|
||||
.size(14.dp)
|
||||
// 注意:在 Column 中 Alignment.BottomEnd 可能不適用
|
||||
// 如果你要讓點跟在文字旁邊,建議用 Box 或是調整 Alignment
|
||||
.border(2.dp, Color.White, CircleShape)
|
||||
) {
|
||||
drawCircle(color = status.color)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class UserStatus(val color: Color) {
|
||||
ONLINE(Color.Green),
|
||||
AWAY(Color.Yellow),
|
||||
OFFLINE(Color.Gray),
|
||||
UNKNOWN(Color.DarkGray);
|
||||
|
||||
companion object {
|
||||
fun fromString(status: String?): UserStatus {
|
||||
return when (status?.lowercase()) {
|
||||
"online" -> ONLINE
|
||||
"away" -> AWAY
|
||||
"offline" -> OFFLINE
|
||||
else -> UNKNOWN
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue