Overview: display the year instead of the weekday for old chats

i.e. chats that are older than one year

Change-Id: I439e78df1425eb57cf597449f09ef5549e90f9b8
This commit is contained in:
SpiritCroc 2020-09-10 10:35:58 +02:00
parent c20a6b8001
commit 5e4d9c18be
2 changed files with 12 additions and 1 deletions

View File

@ -51,6 +51,10 @@ class VectorDateFormatter @Inject constructor(private val context: Context,
DateTimeFormatter.ofPattern(DateFormat.getBestDateTimePattern(localeProvider.current(), "EEE d MMM"))
}
private val messageDayWithYearFormatter by lazy {
DateTimeFormatter.ofPattern(DateFormat.getBestDateTimePattern(localeProvider.current(), "d MMM YYYY"))
}
fun formatMessageHour(localDateTime: LocalDateTime): String {
return messageHourFormatter.format(localDateTime)
}
@ -59,6 +63,10 @@ class VectorDateFormatter @Inject constructor(private val context: Context,
return messageDayFormatter.format(localDateTime)
}
fun formatMessageDayWithYear(localDateTime: LocalDateTime): String {
return messageDayWithYearFormatter.format(localDateTime)
}
/**
* Formats a localized relative date time for the last 2 days, e.g, "Today, HH:MM", "Yesterday, HH:MM" or
* "2 days ago, HH:MM".

View File

@ -92,11 +92,14 @@ class RoomSummaryItemFactory @Inject constructor(private val displayableEventFor
val date = latestEvent.root.localDateTime()
val currentDate = DateProvider.currentLocalDateTime()
val isSameDay = date.toLocalDate() == currentDate.toLocalDate()
val withinOneYear = currentDate.minusYears(1).isBefore(date)
latestFormattedEvent = displayableEventFormatter.format(latestEvent, roomSummary.isDirect.not())
latestEventTime = if (isSameDay) {
dateFormatter.formatMessageHour(date)
} else {
} else if (withinOneYear) {
dateFormatter.formatMessageDay(date)
} else {
dateFormatter.formatMessageDayWithYear(date)
}
}
val typingMessage = typingHelper.getTypingMessage(roomSummary.typingUsers)