From e4462b2b9f2d5dceef845de18b86639a87212a09 Mon Sep 17 00:00:00 2001 From: Sasikanth Miriyampalli Date: Mon, 27 May 2024 09:09:07 +0530 Subject: [PATCH] Get current instant when creating the timestamp in notifications list --- .../notifications/adapter/NotificationsListAdapter.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/dev/sasikanth/pinnit/notifications/adapter/NotificationsListAdapter.kt b/app/src/main/java/dev/sasikanth/pinnit/notifications/adapter/NotificationsListAdapter.kt index 8e00ebd0..15d896e4 100644 --- a/app/src/main/java/dev/sasikanth/pinnit/notifications/adapter/NotificationsListAdapter.kt +++ b/app/src/main/java/dev/sasikanth/pinnit/notifications/adapter/NotificationsListAdapter.kt @@ -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, @@ -38,8 +38,6 @@ class NotificationsListAdapter( private val onRemoveNotificationScheduleClicked: (PinnitNotification) -> Unit ) : ListAdapter(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) @@ -59,6 +57,7 @@ class NotificationsListAdapter( val notification = currentList[adapterPosition] onEditNotificationScheduleClicked(notification) } + R.id.removeSchedule -> { val notification = currentList[adapterPosition] onRemoveNotificationScheduleClicked(notification) @@ -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 ) @@ -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,