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

Commit

Permalink
Get current instant when creating the timestamp in notifications list
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed May 27, 2024
1 parent 59df13a commit e4462b2
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import java.time.format.DateTimeFormatter
import kotlin.math.hypot

class NotificationsListAdapter(
utcClock: UtcClock,
private val utcClock: UtcClock,
private val userClock: UserClock,
private val scheduleDateFormatter: DateTimeFormatter,
private val scheduleTimeFormatter: DateTimeFormatter,
Expand All @@ -38,8 +38,6 @@ class NotificationsListAdapter(
private val onRemoveNotificationScheduleClicked: (PinnitNotification) -> Unit
) : ListAdapter<PinnitNotification, RecyclerView.ViewHolder>(NotificationsDiffCallback) {

private val now = Instant.now(utcClock)

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val context = parent.context
val layoutInflater = LayoutInflater.from(context)
Expand All @@ -59,6 +57,7 @@ class NotificationsListAdapter(
val notification = currentList[adapterPosition]
onEditNotificationScheduleClicked(notification)
}

R.id.removeSchedule -> {
val notification = currentList[adapterPosition]
onRemoveNotificationScheduleClicked(notification)
Expand Down Expand Up @@ -107,7 +106,7 @@ class NotificationsListAdapter(

binding.timeStamp.text = DateUtils.getRelativeTimeSpanString(
notification.updatedAt.toEpochMilli(),
now.toEpochMilli(),
Instant.now(utcClock).toEpochMilli(),
SECOND_IN_MILLIS,
FORMAT_ABBREV_RELATIVE
)
Expand Down Expand Up @@ -169,18 +168,21 @@ class NotificationsListAdapter(
scheduleTimeFormatter.format(scheduleDateTime.toLocalTime())
)
}

scheduleDateTime.toLocalDate().isEqual(yesterday.toLocalDate()) -> {
context.getString(
R.string.notification_schedule_button_yesterday,
scheduleTimeFormatter.format(scheduleDateTime.toLocalTime())
)
}

scheduleDateTime.toLocalDate().isEqual(tomorrow.toLocalDate()) -> {
context.getString(
R.string.notification_schedule_button_tomorrow,
scheduleTimeFormatter.format(scheduleDateTime.toLocalTime())
)
}

else -> {
context.getString(
R.string.notification_schedule_button,
Expand Down

0 comments on commit e4462b2

Please sign in to comment.