Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
⚡️ :: 댓글 시간 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
Tmdhoon2 committed Nov 30, 2023
1 parent bf0f76b commit 1822964
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import com.signal.signal_android.designsystem.foundation.Body2
import com.signal.signal_android.designsystem.foundation.BodyLarge2
import com.signal.signal_android.designsystem.foundation.SignalColor
import com.signal.signal_android.designsystem.textfield.SignalTextField
import java.time.LocalDateTime

@Composable
internal fun CommentDialog(
Expand Down Expand Up @@ -80,7 +81,10 @@ internal fun CommentDialog(
.fillMaxWidth()
.padding(vertical = 10.dp),
)
Comments(commentEntities = state.comments)
Comments(
commentEntities = state.comments,
feedViewModel = feedViewModel,
)
}
Box(
modifier = Modifier
Expand Down Expand Up @@ -126,6 +130,7 @@ private fun Input(
@Composable
private fun Comments(
commentEntities: List<PostCommentsEntity.CommentEntity>,
feedViewModel: FeedViewModel,
) {
LazyColumn(
modifier = Modifier
Expand All @@ -136,7 +141,7 @@ private fun Comments(
Comment(
profileImageUrl = it.profile,
writer = it.name,
time = it.dateTime,
time = feedViewModel.getCommentTime(LocalDateTime.parse(it.dateTime)),
content = it.content,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import com.signal.domain.repository.FeedRepository
import com.signal.signal_android.BaseViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.time.LocalDateTime
import java.time.temporal.ChronoUnit
import java.util.UUID

internal class FeedViewModel(
Expand Down Expand Up @@ -224,27 +226,19 @@ internal class FeedViewModel(
setState(state.value.copy(comment = comment))
}

private fun getTimeMillis(createdDate: String) {
val date = createdDate.split('T')[0].split('.')
}
internal fun getCommentTime(date: LocalDateTime): String {
val today = LocalDateTime.now()

private fun getTime(time: Long): String {
val currentTime = System.currentTimeMillis()
var differentTime = (currentTime - time) / 1000
var message = ""
if (differentTime < TimeValue.SEC.value) {
message = "방금 전"
} else {
for (i in TimeValue.values()) {
differentTime /= i.value
if (differentTime < i.max) {
message = i.message
break
}
}
}
val daysDiff = ChronoUnit.DAYS.between(date.toLocalDate(), today.toLocalDate())
val hoursDiff = ChronoUnit.HOURS.between(date.toLocalTime(), today.toLocalTime())
val minutesDiff = ChronoUnit.MINUTES.between(date.toLocalTime(), today.toLocalTime())

return message
return when {
daysDiff > 30 -> "${daysDiff / 30}달 전"
daysDiff in 1..30 -> "${daysDiff}일 전"
hoursDiff > 0 -> "${hoursDiff}시간 전"
else -> "${minutesDiff}분 전"
}.let { if (it == "0분 전") "방금 전" else it }
}
}

Expand Down

0 comments on commit 1822964

Please sign in to comment.