Skip to content

Commit

Permalink
[FEAT] NotificationActivity - SpannableString을 활용한 TimeStamp 형식 적용 (#208
Browse files Browse the repository at this point in the history
)
  • Loading branch information
KxxHyoRim authored and 915dbfl committed Mar 8, 2024
1 parent 9c33df1 commit 96fd2cb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.lgtm.android.common_ui.model

import android.text.SpannableString

data class NotificationUI(
val title: String,
val body: String,
val isRead: Boolean,
val notificationId: Int,
val date: String,
val time: String,
val dateTime: SpannableString,
)
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import java.time.LocalDateTime

const val LGTM_RED = "#fe504f"
const val LGTM_GRAY_3 = "#cfd8e7"
const val LGTM_GRAY_5 = "#78879f"

fun MissionDetailVO.toUiModel(): MissionDetailUI = MissionDetailUI(
currentPeopleNumber = currentPeopleNumber,
Expand Down Expand Up @@ -136,20 +137,29 @@ fun createRedSpannableText(text: String, redTextStart: Int, redTextEnd: Int): Sp
return spannableText
}

fun createLgtmDateTimeSpannable(localDateTime: LocalDateTime?): SpannableString {
fun createLgtmDateTimeSpannable(
localDateTime: LocalDateTime?,
): SpannableString {
return when (localDateTime) {
null -> SpannableString("-")

else -> {
val time = localDateTime.format(korean12HourTimeFormatter)
val date = localDateTime.format(dotStyleDateFormatter)
val spannableText = SpannableString("$date | $time")
spannableText.setSpan(
ForegroundColorSpan(Color.parseColor(LGTM_GRAY_3)),
date.length + 1,
date.length + 2,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE
)
val spannableText = SpannableString("$date | $time").apply {
setSpan(
ForegroundColorSpan(Color.parseColor(LGTM_GRAY_5)),
0,
this@apply.length,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE
)
setSpan(
ForegroundColorSpan(Color.parseColor(LGTM_GRAY_3)),
date.length + 1,
date.length + 2,
Spannable.SPAN_EXCLUSIVE_INCLUSIVE
)
}
spannableText
}
}
Expand Down Expand Up @@ -261,7 +271,6 @@ fun NotificationVO.toUiModel(): NotificationUI {
body = body,
notificationId = notificationId,
isRead = isRead,
time = date?.format(korean12HourTimeFormatter) ?: "",
date = date?.format(dotStyleDateFormatter) ?: ""
dateTime = createLgtmDateTimeSpannable(dateTime)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data class NotificationDTO(
body = body.orEmpty(),
isRead = isRead ?: false,
notificationId = requireNotNull(notificationId) { "notificationId is null" },
date = parseDate(createdAt)
dateTime = parseDate(createdAt)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ data class NotificationVO(
val body: String,
val isRead: Boolean,
val notificationId: Int,
val date: LocalDateTime?,
val dateTime: LocalDateTime?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ class NotificationViewHolder(
) : RecyclerView.ViewHolder(binding.root) {
fun onBind(item: NotificationUI) {
binding.data = item
binding.lgtmTimestamp.setTimeStamp(item.date, item.time)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@
app:layout_constraintTop_toBottomOf="@id/tv_notification_title"
tools:text="This is Body Part." />

<com.lgtm.android.common_ui.ui.LGTMTimestamp
<TextView
android:id="@+id/lgtm_timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="20dp"
android:text="@{data.dateTime}"
android:textAppearance="@style/Description"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@id/tv_notification_body"
app:layout_constraintTop_toBottomOf="@id/tv_notification_body" />
Expand Down

0 comments on commit 96fd2cb

Please sign in to comment.