Skip to content

Commit

Permalink
Update message bubble and date header timestamps.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucio-signal committed Jul 28, 2021
1 parent 1f1a4eb commit 138b7ea
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Expand Up @@ -307,7 +307,7 @@ private void presentDate(@NonNull MessageRecord messageRecord, @NonNull Locale l
} else if (messageRecord.isRateLimited()) {
dateView.setText(R.string.ConversationItem_send_paused);
} else {
dateView.setText(DateUtils.getExtendedRelativeTimeSpanString(getContext(), locale, messageRecord.getTimestamp()));
dateView.setText(DateUtils.getSimpleRelativeTimeSpanString(getContext(), locale, messageRecord.getTimestamp()));
}
}

Expand Down
Expand Up @@ -352,7 +352,7 @@ public void onBindHeaderViewHolder(StickyHeaderViewHolder viewHolder, int positi
Context context = viewHolder.itemView.getContext();
ConversationMessage conversationMessage = Objects.requireNonNull(getItem(position));

viewHolder.setText(DateUtils.getRelativeDate(viewHolder.itemView.getContext(), locale, conversationMessage.getMessageRecord().getDateReceived()));
viewHolder.setText(DateUtils.getConversationDateHeaderString(viewHolder.itemView.getContext(), locale, conversationMessage.getMessageRecord().getDateReceived()));

if (type == HEADER_TYPE_POPOVER_DATE) {
if (hasWallpaper) {
Expand Down
30 changes: 26 additions & 4 deletions app/src/main/java/org/thoughtcrime/securesms/util/DateUtils.java
Expand Up @@ -103,6 +103,18 @@ public static String getExtendedRelativeTimeSpanString(final Context c, final Lo
}
}

public static String getSimpleRelativeTimeSpanString(final Context context, final Locale locale, final long timestamp) {
if (isWithin(timestamp, 1, TimeUnit.MINUTES)) {
return context.getString(R.string.DateUtils_just_now);
} else if (isWithin(timestamp, 1, TimeUnit.HOURS)) {
int mins = (int) TimeUnit.MINUTES.convert(System.currentTimeMillis() - timestamp, TimeUnit.MILLISECONDS);
return context.getResources().getString(R.string.DateUtils_minutes_ago, mins);
} else {
String format = DateFormat.is24HourFormat(context) ? "HH:mm" : "hh:mm a";
return getFormattedDateTime(timestamp, format, locale);
}
}

public static String getTimeString(final Context c, final Locale locale, final long timestamp) {
StringBuilder format = new StringBuilder();

Expand Down Expand Up @@ -145,19 +157,29 @@ public static SimpleDateFormat getDetailedDateFormatter(Context context, Locale
return new SimpleDateFormat(dateFormatPattern, locale);
}

public static String getRelativeDate(@NonNull Context context,
@NonNull Locale locale,
long timestamp)
public static String getConversationDateHeaderString(@NonNull Context context,
@NonNull Locale locale,
long timestamp)
{
if (isToday(timestamp)) {
return context.getString(R.string.DateUtils_today);
} else if (isYesterday(timestamp)) {
return context.getString(R.string.DateUtils_yesterday);
} else if (isWithin(timestamp, 182, TimeUnit.DAYS)) {
return formatDateWithDayOfWeek(locale, timestamp);
} else {
return formatDate(locale, timestamp);
return formatDateWithYear(locale, timestamp);
}
}

public static String formatDateWithDayOfWeek(@NonNull Locale locale, long timestamp) {
return getFormattedDateTime(timestamp, "EEE, MMM d", locale);
}

public static String formatDateWithYear(@NonNull Locale locale, long timestamp) {
return getFormattedDateTime(timestamp, "MMM d, yyyy", locale);
}

public static String formatDate(@NonNull Locale locale, long timestamp) {
return getFormattedDateTime(timestamp, "EEE, MMM d, yyyy", locale);
}
Expand Down

0 comments on commit 138b7ea

Please sign in to comment.