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-443] 채팅방 목록 UI 구현 #128

Merged
merged 10 commits into from
Oct 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ sealed class DeepLinkDestination(
addressRes = R.string.notification_deeplink_url,
)

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

data class CenterSignIn(val toastMsg: String = "default") : DeepLinkDestination(
addressRes = R.string.center_signin_deeplink_url,
params = mapOf("toastMsg" to toastMsg)
Expand All @@ -62,6 +73,10 @@ sealed class DeepLinkDestination(
params = mapOf("status" to status)
)

data object CenterChatting : DeepLinkDestination(
addressRes = R.string.center_chatting_deeplink_url,
)

data class CenterProfile(val centerId: String = "default") : DeepLinkDestination(
addressRes = R.string.center_profile_deeplink_url,
params = mapOf("centerId" to centerId)
Expand Down Expand Up @@ -108,6 +123,10 @@ sealed class DeepLinkDestination(
addressRes = R.string.worker_home_deeplink_url,
)

data object WorkerChatting : DeepLinkDestination(
addressRes = R.string.worker_chatting_deeplink_url,
)

data class WorkerProfile(val workerId: String = "default") : DeepLinkDestination(
addressRes = R.string.worker_profile_deeplink_url,
params = mapOf("workerId" to workerId)
Expand Down
13 changes: 13 additions & 0 deletions core/designresource/src/main/res/drawable/ic_send_message.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:pathData="M13.332,18.667L27.998,4M13.332,18.667L17.998,28C18.057,28.128 18.151,28.236 18.269,28.312C18.387,28.388 18.524,28.428 18.665,28.428C18.805,28.428 18.943,28.388 19.061,28.312C19.179,28.236 19.273,28.128 19.331,28L27.998,4M13.332,18.667L3.998,14C3.87,13.941 3.762,13.848 3.686,13.729C3.611,13.611 3.57,13.474 3.57,13.333C3.57,13.193 3.611,13.055 3.686,12.937C3.762,12.819 3.87,12.725 3.998,12.667L27.998,4"
android:strokeLineJoin="round"
android:strokeWidth="2"
android:fillColor="#00000000"
android:strokeColor="#4B515C"
android:strokeLineCap="round"/>
</vector>
8 changes: 5 additions & 3 deletions core/designresource/src/main/res/values/deeplinks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@
<resources>
<string name="auth_deeplink_url">care://auth</string>
<string name="postcode_deeplink_url">care://postcode</string>
<string name="notification_deeplink_url">care://notification</string>
<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="worker_signup_deeplink_url">care://signup/worker</string>
<string name="worker_home_deeplink_url">care://worker/home</string>
<string name="worker_job_posting_deeplink_url">care://worker/jobposting</string>
<string name="worker_profile_deeplink_url">care://worker/profile/{workerId}</string>
<string name="worker_jobposting_detail_deeplink_url">care://worker/jobposting/detail/{jobPostingId}/{jobPostingType}</string>
<string name="worker_chatting_deeplink_url">care://worker/chatting</string>
<string name="worker_setting_deeplink_url">care://worker/setting</string>

<string name="center_signin_deeplink_url">care://center/signIn/{toastMsg}</string>
<string name="center_signup_deeplink_url">care://center/signUp</string>
<string name="new_password_deeplink_url">care://newPassword</string>
<string name="center_home_deeplink_url">care://center/home</string>
<string name="center_chatting_deeplink_url">care://cener/chatting</string>
<string name="center_pending_deeplink_url">care://center/pending/{status}}</string>
<string name="center_profile_deeplink_url">care://center/profile/{centerId}</string>
<string name="center_setting_deeplink_url">care://center/setting</string>
Expand All @@ -25,6 +29,4 @@
<string name="center_job_posting_post_complete_deeplink_url">care://center/jobposting/post/complete</string>
<string name="center_jobposting_detail_deeplink_url">care://center/jobposting/detail/{jobPostingId}/{isEditState}</string>
<string name="center_applicant_inquiry_deeplink_url">care://center/applicant/inquiry/{jobPostingId}</string>

<string name="notification_deeplink_url">care://notification</string>
</resources>
1 change: 1 addition & 0 deletions core/designresource/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,5 @@
<string name="inquiry_by_chat">채팅으로 문의하기</string>
<string name="app_update_title">최신 버전의 앱이 있어요</string>
<string name="app_update">앱 업데이트</string>
<string name="chatting">채팅</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.idle.domain.model.chatting

import java.time.LocalDateTime

data class ChatMessage(
val id: String,
val roomId: String,
val senderType: SenderType,
val contents: List<Content>,
val createdAt: LocalDateTime,
)

data class Content(
val type: ContentType,
val value: String,
)

enum class SenderType {
USER,
}

enum class ContentType {
TEXT, IMAGE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.idle.domain.model.chatting

import java.time.LocalDateTime

data class ChatRoom(
val id: String,
val sender: String,
val receiver: String,
val createdAt: LocalDateTime,
val lastMessage: String,
val lastSentAt: LocalDateTime,
val unReadMessageCount: Int,
val profileImageUrl: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.idle.domain.model.notification

import java.lang.reflect.Type
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.temporal.ChronoUnit

data class Notification(
val notificationType: NotificationType,
Expand All @@ -14,27 +12,7 @@ data class Notification(
val imageUrl: String?,
val createdAt: LocalDateTime,
val notificationDetails: NotificationContent,
) {
fun getNotificationTime(): String {
val currentTime = LocalDateTime.now(ZoneId.of("Asia/Seoul"))

if (createdAt.isAfter(currentTime)) {
return "곧 시작될 알림"
}

val minutesDifference = ChronoUnit.MINUTES.between(createdAt, currentTime)
val hoursDifference = ChronoUnit.HOURS.between(createdAt, currentTime)
val daysDifference = ChronoUnit.DAYS.between(createdAt, currentTime)

return when {
minutesDifference <= 1 -> "방금 전"
minutesDifference < 60 -> "${minutesDifference}분 전"
hoursDifference < 24 -> "${hoursDifference}시간 전"
daysDifference < 7 -> "${daysDifference}일 전"
else -> "${daysDifference / 7}주 전"
}
}
}
)

enum class NotificationType(private val notificationTypeClass: Type) {
APPLICANT(NotificationContent.ApplicantNotification::class.java),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.idle.domain.usecase.chatting

import com.idle.domain.model.chatting.ChatRoom
import java.time.LocalDateTime
import javax.inject.Inject

class GetChatRoomListUseCase @Inject constructor(
) {
suspend operator fun invoke(): Result<List<ChatRoom>> = Result.success(
listOf(
ChatRoom(
id = "1",
sender = "user1",
receiver = "user2",
createdAt = LocalDateTime.now().minusDays(1),
lastMessage = "안녕하세요!안녕하세요!안녕하세요!안녕하세요!안녕하세요!안녕하세요!",
lastSentAt = LocalDateTime.now().minusHours(1),
unReadMessageCount = 3,
profileImageUrl = "",
),
ChatRoom(
id = "2",
sender = "user3",
receiver = "user4",
createdAt = LocalDateTime.now().minusDays(3),
lastMessage = "오늘 만날 수 있을까요?",
lastSentAt = LocalDateTime.now().minusHours(5),
unReadMessageCount = 2,
profileImageUrl = "",
),
ChatRoom(
id = "3",
sender = "user5",
receiver = "user6",
createdAt = LocalDateTime.now().minusDays(7),
lastMessage = "네, 좋습니다!",
lastSentAt = LocalDateTime.now().minusDays(1).minusHours(2),
unReadMessageCount = 1,
profileImageUrl = "",
),
ChatRoom(
id = "4",
sender = "user7user7user7user7user7user7user7user7user7user7user7user7",
receiver = "user8",
createdAt = LocalDateTime.now().minusHours(2),
lastMessage = "곧 출발합니다.곧 출발합니다.곧 출발합니다.곧 출발합니다.곧 출발합니다.곧 출발합니다.곧 출발합니다.곧 출발합니다.",
lastSentAt = LocalDateTime.now().minusMinutes(30),
unReadMessageCount = 0,
profileImageUrl = "",
),
ChatRoom(
id = "5",
sender = "user9",
receiver = "user10",
createdAt = LocalDateTime.now().minusWeeks(1),
lastMessage = "다음 주에 봐요!",
lastSentAt = LocalDateTime.now().minusDays(3),
unReadMessageCount = 0,
profileImageUrl = "https://cdn.pixabay.com/photo/2020/05/17/20/21/cat-5183427_1280.jpg",
)
)
)
}
Comment on lines +9 to +63
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

더미 데이터

52 changes: 52 additions & 0 deletions core/domain/src/main/kotlin/com/idle/domain/util/TimeUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.idle.domain.util

import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit

private val seoulZone = ZoneId.of("Asia/Seoul")

fun LocalDateTime.formatRelativeDateTime(): String {
val nowInSeoul = LocalDateTime.now(seoulZone)

return when {
this.isAfter(nowInSeoul) -> "미래"

ChronoUnit.DAYS.between(this.toLocalDate(), nowInSeoul.toLocalDate()) < 1 -> {
// 하루 이내일 경우: "오후 XX시 XX분"
val formatter = DateTimeFormatter.ofPattern("a hh:mm").withZone(seoulZone)

this.format(formatter)
.replace("AM", "오전")
.replace("PM", "오후")
}

else -> {
// 하루 이상일 경우: "X월 X일"
val formatter = DateTimeFormatter.ofPattern("M월 d일").withZone(seoulZone)

this.format(formatter)
}
}
}

fun LocalDateTime.formatRelativeTimeDescription(): String {
val currentTime = LocalDateTime.now(seoulZone)

if (this.isAfter(currentTime)) {
return "미래"
}

val minutesDifference = ChronoUnit.MINUTES.between(this, currentTime)
val hoursDifference = ChronoUnit.HOURS.between(this, currentTime)
val daysDifference = ChronoUnit.DAYS.between(this, currentTime)

return when {
minutesDifference <= 1 -> "방금 전"
minutesDifference < 60 -> "${minutesDifference}분 전"
hoursDifference < 24 -> "${hoursDifference}시간 전"
daysDifference < 7 -> "${daysDifference}일 전"
else -> "${daysDifference / 7}주 전"
}
}
Loading