dm-1
This commit is contained in:
parent
6ecae41571
commit
809af3a86f
4 changed files with 10 additions and 5 deletions
|
|
@ -13,7 +13,7 @@ data class RoomListResponse(
|
||||||
@JsonClass(generateAdapter = true)
|
@JsonClass(generateAdapter = true)
|
||||||
data class ChatRoom(
|
data class ChatRoom(
|
||||||
@Json(name = "room_id") val roomId: String,
|
@Json(name = "room_id") val roomId: String,
|
||||||
@Json(name = "room_name") val roomName: String,
|
@Json(name = "room_name") val roomName: String?,
|
||||||
@Json(name = "room_type") val roomType: String,
|
@Json(name = "room_type") val roomType: String,
|
||||||
@Json(name = "room_icon_url") val roomIconUrl: String?,
|
@Json(name = "room_icon_url") val roomIconUrl: String?,
|
||||||
@Json(name = "is_muted") val isMuted: Boolean,
|
@Json(name = "is_muted") val isMuted: Boolean,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import com.example.login_v3.data.api.api_class.RoomListResponse
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import javax.inject.Singleton
|
import javax.inject.Singleton
|
||||||
|
|
||||||
@Singleton // 如果你希望整個 App 週期內只存在一個實體
|
@Singleton
|
||||||
class ChatRoomsRepository @Inject constructor(
|
class ChatRoomsRepository @Inject constructor(
|
||||||
private val api: TecnologiaApi
|
private val api: TecnologiaApi
|
||||||
) {
|
) {
|
||||||
|
|
@ -310,7 +310,10 @@ fun RoomItem(
|
||||||
// 2. 中間內容:名稱與最後訊息
|
// 2. 中間內容:名稱與最後訊息
|
||||||
Column(modifier = Modifier.weight(1f)) {
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
Text(
|
Text(
|
||||||
text = room.roomName.ifEmpty { room.partner?.displayName ?: "Unknown" },
|
// 使用 orEmpty() 先把 String? 轉成 String
|
||||||
|
text = room.roomName.orEmpty().ifEmpty {
|
||||||
|
room.partner?.displayName ?: "Unknown"
|
||||||
|
},
|
||||||
style = MaterialTheme.typography.titleMedium,
|
style = MaterialTheme.typography.titleMedium,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
maxLines = 1,
|
maxLines = 1,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Message_ViewModel.kt
|
// Message_ViewModel.kt
|
||||||
package com.example.login_v3.home.Message.ViewModel
|
package com.example.login_v3.home.Message.ViewModel
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.example.login_v3.R
|
import com.example.login_v3.R
|
||||||
|
|
@ -26,8 +27,9 @@ class ChatRoomsViewModel @Inject constructor(
|
||||||
val result = repository.fetchRooms()
|
val result = repository.fetchRooms()
|
||||||
result.onSuccess { response ->
|
result.onSuccess { response ->
|
||||||
_roomsState.value = response.rooms
|
_roomsState.value = response.rooms
|
||||||
}.onFailure {
|
}.onFailure { error ->
|
||||||
// 處理錯誤,例如更新一個 error state
|
// 這裡非常重要!
|
||||||
|
Log.e("Technologia", "讀取失敗!原因:${error.message}", error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue