From 805d0db486bceea2b83f7cc3f4dc8a2504b38850 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Thu, 23 Mar 2023 19:08:09 +0100 Subject: [PATCH] show time underneath bubble --- .../android/ui/BindingAdapters.java | 26 ++++++++--- .../android/ui/adapter/MessageAdapter.java | 7 +-- .../res/drawable/ic_lock_outline_24dp.xml | 10 +++++ app/src/main/res/layout/fragment_chat.xml | 5 ++- .../main/res/layout/item_chat_overview.xml | 2 +- .../main/res/layout/item_message_received.xml | 43 ++++++++++++++++--- 6 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 app/src/main/res/drawable/ic_lock_outline_24dp.xml diff --git a/app/src/main/java/im/conversations/android/ui/BindingAdapters.java b/app/src/main/java/im/conversations/android/ui/BindingAdapters.java index 76172995f..3e217dbe4 100644 --- a/app/src/main/java/im/conversations/android/ui/BindingAdapters.java +++ b/app/src/main/java/im/conversations/android/ui/BindingAdapters.java @@ -53,8 +53,8 @@ public class BindingAdapters { return a.truncatedTo(ChronoUnit.DAYS).equals(b.truncatedTo(ChronoUnit.DAYS)); } - @BindingAdapter("instant") - public static void setInstant(final TextView textView, final Instant instant) { + @BindingAdapter("datetime") + public static void setDatetime(final TextView textView, final Instant instant) { if (instant == null || instant.getEpochSecond() <= 0) { textView.setVisibility(View.GONE); } else { @@ -65,13 +65,13 @@ public class BindingAdapters { textView.setText( DateUtils.formatDateTime( context, - instant.getEpochSecond() * 1000, + instant.toEpochMilli(), DateUtils.FORMAT_SHOW_TIME)); } else if (sameYear(instant, now) || now.minus(THREE_MONTH).isBefore(instant)) { textView.setText( DateUtils.formatDateTime( context, - instant.getEpochSecond() * 1000, + instant.toEpochMilli(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_YEAR | DateUtils.FORMAT_ABBREV_ALL)); @@ -79,7 +79,7 @@ public class BindingAdapters { textView.setText( DateUtils.formatDateTime( context, - instant.getEpochSecond() * 1000, + instant.toEpochMilli(), DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_NO_MONTH_DAY | DateUtils.FORMAT_ABBREV_ALL)); @@ -87,6 +87,22 @@ public class BindingAdapters { } } + @BindingAdapter("time") + public static void setTime(final TextView textView, final Instant instant) { + if (instant == null || instant.getEpochSecond() <= 0) { + textView.setVisibility(View.GONE); + } else { + final Context context = textView.getContext(); + final Instant now = Instant.now(); + textView.setVisibility(View.VISIBLE); + textView.setText( + DateUtils.formatDateTime( + context, + instant.toEpochMilli(), + DateUtils.FORMAT_SHOW_TIME)); + } + } + @BindingAdapter("android:text") public static void setSender(final TextView textView, final ChatOverviewItem.Sender sender) { if (sender == null) { diff --git a/app/src/main/java/im/conversations/android/ui/adapter/MessageAdapter.java b/app/src/main/java/im/conversations/android/ui/adapter/MessageAdapter.java index 7f3a118b4..c16de2bc5 100644 --- a/app/src/main/java/im/conversations/android/ui/adapter/MessageAdapter.java +++ b/app/src/main/java/im/conversations/android/ui/adapter/MessageAdapter.java @@ -64,12 +64,7 @@ public class MessageAdapter extends PagingDataAdapter + + diff --git a/app/src/main/res/layout/fragment_chat.xml b/app/src/main/res/layout/fragment_chat.xml index 8b335f046..35b75f219 100644 --- a/app/src/main/res/layout/fragment_chat.xml +++ b/app/src/main/res/layout/fragment_chat.xml @@ -59,6 +59,7 @@ android:layout_height="wrap_content">