Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IDLE-465] 채팅방 UI 구현 #143

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ sealed class DeepLinkDestination(

data class ChattingDetail(
val chattingRoomId: String,
val userId: String
val receiverId: String,
val receiverUserType: String,
val senderId: String,
) : DeepLinkDestination(
addressRes = R.string.chatting_detail_deeplink_url,
params = mapOf(
"chattingRoomId" to chattingRoomId,
"userId" to userId,
"receiverId" to receiverId,
"receiverUserType" to receiverUserType,
"senderId" to senderId,
)
)

Expand Down
2 changes: 1 addition & 1 deletion core/designresource/src/main/res/values/deeplinks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<string name="withdrawal_deeplink_url">care://withdrawal/{userType}</string>
<string name="signup_complete_deeplink_url">care://signup/complete</string>
<string name="new_password_deeplink_url">care://newPassword</string>
<string name="chatting_detail_deeplink_url">care://chatting/detail/{chattingRoomId}/{userId}</string>
<string name="chatting_detail_deeplink_url">care://chatting/detail/{chattingRoomId}/{receiverId}/{receiverUserType}/{senderId}</string>

<string name="worker_signup_deeplink_url">care://signup/worker</string>
<string name="worker_home_deeplink_url">care://worker/home</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ enum class UserType(val apiValue: String) {

companion object {
fun create(value: String?): UserType {
return UserType.entries.firstOrNull { it.name == value } ?: CENTER
return UserType.entries.firstOrNull { it.apiValue == value } ?: CENTER
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.time.LocalDateTime
data class ChatMessage(
val id: String,
val roomId: String,
val senderId: String,
val senderType: SenderType,
val contents: List<Content>,
val createdAt: LocalDateTime,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.idle.domain.usecase.chatting

import com.idle.domain.model.chatting.ChatMessage
import com.idle.domain.model.chatting.Content
import com.idle.domain.model.chatting.ContentType
import com.idle.domain.model.chatting.SenderType
import java.time.LocalDateTime
import javax.inject.Inject

class GetChatMessagesUseCase @Inject constructor() {
suspend operator fun invoke(roomId: String): Result<List<ChatMessage>> = Result.success(
listOf(
ChatMessage(
id = "1",
roomId = "room1",
senderId = "user1",
senderType = SenderType.USER,
contents = listOf(
Content(
type = ContentType.TEXT,
value = "안녕하세요! 문의드리고 싶어서 연락드렸습니다."
)
),
createdAt = LocalDateTime.now().minusDays(3)
),
ChatMessage(
id = "2",
roomId = "room1",
senderId = "user2",
senderType = SenderType.USER,
contents = listOf(Content(type = ContentType.TEXT, value = "안녕하세요! 어떤 문의사항이신가요?")),
createdAt = LocalDateTime.now().minusDays(2)
),
ChatMessage(
id = "3",
roomId = "room1",
senderId = "user1",
senderType = SenderType.USER,
contents = listOf(Content(type = ContentType.TEXT, value = "추가로 여쭤보고 싶은 게 있습니다.")),
createdAt = LocalDateTime.now().minusDays(1)
),
ChatMessage(
id = "4",
roomId = "room1",
senderId = "user2",
senderType = SenderType.USER,
contents = listOf(Content(type = ContentType.TEXT, value = "알겠습니다. 무엇이 궁금하신가요?")),
createdAt = LocalDateTime.now().minusMinutes(3)
),
ChatMessage(
id = "5",
roomId = "room1",
senderId = "user1",
senderType = SenderType.USER,
contents = listOf(Content(type = ContentType.TEXT, value = "감사합니다! 친절한 답변 감사합니다.")),
createdAt = LocalDateTime.now().minusMinutes(1)
)
)
)
}
10 changes: 10 additions & 0 deletions core/domain/src/main/kotlin/com/idle/domain/util/TimeUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ fun LocalDateTime.formatRelativeTimeDescription(): String {
daysDifference < 7 -> "${daysDifference}일 전"
else -> "${daysDifference / 7}주 전"
}
}

fun LocalDateTime.formatTimeToHourMinute24(): String {
val formatter = DateTimeFormatter.ofPattern("HH:mm")
return this.format(formatter)
}

fun LocalDateTime.formatYearMonthDate(): String {
val formatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일")
return this.format(formatter)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
Expand All @@ -21,6 +22,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
Expand All @@ -39,6 +41,7 @@ import com.idle.compose.clickable
import com.idle.designsystem.compose.component.CareHeadingTopBar
import com.idle.designsystem.compose.component.LoadingCircle
import com.idle.designsystem.compose.foundation.CareTheme
import com.idle.domain.model.auth.UserType
import com.idle.domain.model.chatting.ChatRoom
import com.idle.domain.util.formatRelativeDateTime
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -125,7 +128,9 @@ internal fun ChatRoomItem(
navigateTo(
DeepLinkDestination.ChattingDetail(
chattingRoomId = chatRoom.id,
userId = chatRoom.receiver,
receiverId = chatRoom.receiver,
receiverUserType = UserType.CENTER.apiValue,
senderId = chatRoom.sender,
)
)
},
Expand All @@ -142,9 +147,11 @@ internal fun ChatRoomItem(
error = painterResource(com.idle.designresource.R.drawable.ic_notification_placeholder),
onError = { Log.d("test", chatRoom.profileImageUrl) },
contentDescription = "",
contentScale = ContentScale.Crop,
modifier = Modifier
.align(Alignment.CenterVertically)
.padding(end = 12.dp)
.align(Alignment.CenterVertically)
.clip(CircleShape)
.size(48.dp),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ internal fun CenterHomeScreen(
Spacer(
modifier = Modifier
.fillMaxWidth()
.height(28.dp)
.height(80.dp)
)
}
}
Expand Down
Loading