diff --git a/core/domain/src/main/kotlin/com/idle/domain/usecase/chatting/GetChatRoomListUseCase.kt b/core/domain/src/main/kotlin/com/idle/domain/usecase/chatting/GetChatRoomListUseCase.kt index 9ba7c408..59c0c1cf 100644 --- a/core/domain/src/main/kotlin/com/idle/domain/usecase/chatting/GetChatRoomListUseCase.kt +++ b/core/domain/src/main/kotlin/com/idle/domain/usecase/chatting/GetChatRoomListUseCase.kt @@ -15,7 +15,7 @@ class GetChatRoomListUseCase @Inject constructor( createdAt = LocalDateTime.now().minusDays(1), lastMessage = "안녕하세요!안녕하세요!안녕하세요!안녕하세요!안녕하세요!안녕하세요!", lastSentAt = LocalDateTime.now().minusHours(1), - unReadMessageCount = 3, + unReadMessageCount = 99, profileImageUrl = "", ), ChatRoom( @@ -25,7 +25,7 @@ class GetChatRoomListUseCase @Inject constructor( createdAt = LocalDateTime.now().minusDays(3), lastMessage = "오늘 만날 수 있을까요?", lastSentAt = LocalDateTime.now().minusHours(5), - unReadMessageCount = 99, + unReadMessageCount = 100, profileImageUrl = "", ), ChatRoom( diff --git a/core/domain/src/main/kotlin/com/idle/domain/util/NumberUtil.kt b/core/domain/src/main/kotlin/com/idle/domain/util/NumberUtil.kt index 3b9f6768..fb98ba0d 100644 --- a/core/domain/src/main/kotlin/com/idle/domain/util/NumberUtil.kt +++ b/core/domain/src/main/kotlin/com/idle/domain/util/NumberUtil.kt @@ -39,4 +39,12 @@ fun formatBusinessRegistrationNumber(businessRegistrationNumber: String): String else -> throw IllegalArgumentException("사업자 등록번호 형식이 맞지 않습니다.") } +} + +fun Int.formatUnReadNumber(): String { + return when { + this < 0 -> "0" + this >= 100 -> "99+" + else -> this.toString() + } } \ No newline at end of file diff --git a/core/domain/src/test/kotlin/com/idle/domain/util/NumberUtilTest.kt b/core/domain/src/test/kotlin/com/idle/domain/util/NumberUtilTest.kt index fc376ab8..9caea9ed 100644 --- a/core/domain/src/test/kotlin/com/idle/domain/util/NumberUtilTest.kt +++ b/core/domain/src/test/kotlin/com/idle/domain/util/NumberUtilTest.kt @@ -118,4 +118,40 @@ class NumberUtilTest { formatBusinessRegistrationNumber(businessRegistrationNumber) } } + + @Test + fun `음수일 경우 0으로 반환된다`() { + // Given + val number = -5 + + // When + val result = number.formatUnReadNumber() + + // Then + assertEquals("0", result) + } + + @Test + fun `99 이하의 숫자는 그대로 문자열로 반환된다`() { + // Given + val number = 99 + + // When + val result = number.formatUnReadNumber() + + // Then + assertEquals("99", result) + } + + @Test + fun `100 이상의 숫자는 '99+'로 반환된다`() { + // Given + val number = 100 + + // When + val result = number.formatUnReadNumber() + + // Then + assertEquals("99+", result) + } } \ No newline at end of file diff --git a/feature/center/chatting/src/main/java/com/idle/center/chatting/CenterChattingFragment.kt b/feature/center/chatting/src/main/java/com/idle/center/chatting/CenterChattingFragment.kt index fb028c4f..9dd67531 100644 --- a/feature/center/chatting/src/main/java/com/idle/center/chatting/CenterChattingFragment.kt +++ b/feature/center/chatting/src/main/java/com/idle/center/chatting/CenterChattingFragment.kt @@ -44,6 +44,7 @@ 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 com.idle.domain.util.formatUnReadNumber import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint @@ -234,7 +235,7 @@ internal fun ChatRoomItem( ) { Text( text = if (chatRoom.unReadMessageCount != 0) - chatRoom.unReadMessageCount.toString() else "", + chatRoom.unReadMessageCount.formatUnReadNumber() else "", style = CareTheme.typography.caption1.copy(fontWeight = FontWeight.Bold), color = CareTheme.colors.white000, textAlign = TextAlign.Center, diff --git a/feature/worker/chatting/src/main/java/com/idle/worker/chatting/WorkerChattingFragment.kt b/feature/worker/chatting/src/main/java/com/idle/worker/chatting/WorkerChattingFragment.kt index 8ff0a0a6..62066807 100644 --- a/feature/worker/chatting/src/main/java/com/idle/worker/chatting/WorkerChattingFragment.kt +++ b/feature/worker/chatting/src/main/java/com/idle/worker/chatting/WorkerChattingFragment.kt @@ -47,6 +47,7 @@ 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 com.idle.domain.util.formatUnReadNumber import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint @@ -239,7 +240,7 @@ internal fun ChatRoomItem( ) { Text( text = if (chatRoom.unReadMessageCount != 0) - chatRoom.unReadMessageCount.toString() else "", + chatRoom.unReadMessageCount.formatUnReadNumber() else "", style = CareTheme.typography.caption1.copy(fontWeight = FontWeight.Bold), color = CareTheme.colors.white000, textAlign = TextAlign.Center,