dm-4
This commit is contained in:
parent
b055ef8643
commit
1b7555f9af
1 changed files with 85 additions and 67 deletions
|
|
@ -6,6 +6,7 @@ import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.border
|
import androidx.compose.foundation.border
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
|
|
@ -25,6 +26,7 @@ import androidx.compose.material.icons.filled.Add
|
||||||
import androidx.compose.material.icons.filled.Create
|
import androidx.compose.material.icons.filled.Create
|
||||||
import androidx.compose.material.icons.filled.Person
|
import androidx.compose.material.icons.filled.Person
|
||||||
import androidx.compose.material.icons.filled.QrCode
|
import androidx.compose.material.icons.filled.QrCode
|
||||||
|
import androidx.compose.material3.Badge
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.Divider
|
import androidx.compose.material3.Divider
|
||||||
|
|
@ -251,6 +253,8 @@ fun Loaded_Tg_Message(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
|
Spacer(modifier = Modifier.height(20.dp))
|
||||||
|
|
||||||
if (rooms.isEmpty()) {
|
if (rooms.isEmpty()) {
|
||||||
// 顯示空狀態或 Loading (這部分可根據需求擴充)
|
// 顯示空狀態或 Loading (這部分可根據需求擴充)
|
||||||
Box(
|
Box(
|
||||||
|
|
@ -289,40 +293,56 @@ fun RoomItem(
|
||||||
room: ChatRoom,
|
room: ChatRoom,
|
||||||
onClick: (String) -> Unit
|
onClick: (String) -> Unit
|
||||||
) {
|
) {
|
||||||
|
Card(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 12.dp, vertical = 6.dp) // 增加外邊距,讓 Card 之間有呼吸感
|
||||||
|
.clickable { onClick(room.roomId) },
|
||||||
|
shape = RoundedCornerShape(16.dp), // 較大的圓角看起來更現代
|
||||||
|
colors = CardDefaults.cardColors(
|
||||||
|
containerColor = Color.White.copy(alpha = 0.85f) // 半透明白色,透出後方的漸層背景
|
||||||
|
),
|
||||||
|
elevation = CardDefaults.cardElevation(
|
||||||
|
defaultElevation = 0.dp // 增加輕微陰影
|
||||||
|
)
|
||||||
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.clickable { onClick(room.roomId) }
|
.background(Color.Transparent)
|
||||||
.padding(horizontal = 16.dp, vertical = 12.dp),
|
.padding(16.dp), // Card 內部的填充
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically
|
||||||
) {
|
) {
|
||||||
// 1. 頭像處理
|
// 1. 頭像
|
||||||
val imageUrl = room.roomIconUrl ?: room.partner?.fullContactAvatarUrl
|
val imageUrl = room.roomIconUrl ?: room.partner?.fullContactAvatarUrl
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
model = imageUrl,
|
model = imageUrl,
|
||||||
contentDescription = "Avatar",
|
contentDescription = "Avatar",
|
||||||
contentScale = ContentScale.Crop,
|
contentScale = ContentScale.Crop,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(50.dp)
|
.size(56.dp) // 稍微加大一點
|
||||||
.clip(CircleShape)
|
.clip(CircleShape)
|
||||||
.background(Color.LightGray) // 載入前的底色
|
.border(1.dp, Color.White, CircleShape) // 頭像加個細白邊
|
||||||
|
.background(Color.LightGray)
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
|
||||||
// 2. 中間內容:名稱與最後訊息
|
// 2. 中間內容
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
Text(
|
Text(
|
||||||
// 使用 orEmpty() 先把 String? 轉成 String
|
|
||||||
text = room.roomName.orEmpty().ifEmpty {
|
text = room.roomName.orEmpty().ifEmpty {
|
||||||
room.partner?.displayName ?: "Unknown"
|
room.partner?.displayName ?: "Unknown"
|
||||||
},
|
},
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = Color(0xFF333333),
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
overflow = TextOverflow.Ellipsis
|
overflow = TextOverflow.Ellipsis
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
|
|
||||||
val lastMsgText = when {
|
val lastMsgText = when {
|
||||||
room.lastMessage?.isDeleted == true -> "訊息已刪除"
|
room.lastMessage?.isDeleted == true -> "訊息已刪除"
|
||||||
room.lastMessage?.content != null -> room.lastMessage.content
|
room.lastMessage?.content != null -> room.lastMessage.content
|
||||||
|
|
@ -340,8 +360,10 @@ fun RoomItem(
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 右側:時間與未讀計數
|
// 3. 右側:時間與未讀計數
|
||||||
Column(horizontalAlignment = Alignment.End) {
|
Column(
|
||||||
// 這裡簡單截取時間字串,實際建議用 DateTimeFormatter 轉格式
|
horizontalAlignment = Alignment.End,
|
||||||
|
verticalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
val time = room.lastMessage?.createdAt?.take(10) ?: ""
|
val time = room.lastMessage?.createdAt?.take(10) ?: ""
|
||||||
Text(
|
Text(
|
||||||
text = time,
|
text = time,
|
||||||
|
|
@ -349,24 +371,20 @@ fun RoomItem(
|
||||||
color = Color.Gray
|
color = Color.Gray
|
||||||
)
|
)
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(4.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
|
|
||||||
if (room.unreadCount > 0) {
|
if (room.unreadCount > 0) {
|
||||||
Box(
|
Badge(
|
||||||
modifier = Modifier
|
containerColor = Color(0xFFDA7029), // 使用你的主橘色
|
||||||
.size(20.dp)
|
contentColor = Color.White
|
||||||
.clip(CircleShape)
|
|
||||||
.background(MaterialTheme.colorScheme.primary),
|
|
||||||
contentAlignment = Alignment.Center
|
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = if (room.unreadCount > 99) "99+" else room.unreadCount.toString(),
|
text = if (room.unreadCount > 99) "99+" else room.unreadCount.toString(),
|
||||||
color = Color.White,
|
modifier = Modifier.padding(horizontal = 4.dp)
|
||||||
fontSize = 10.sp,
|
|
||||||
fontWeight = FontWeight.Bold
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue