show time underneath bubble

This commit is contained in:
Daniel Gultsch 2023-03-23 19:08:09 +01:00
parent 779e6fa61e
commit 805d0db486
No known key found for this signature in database
GPG key ID: F43D18AD2A0982C2
6 changed files with 73 additions and 20 deletions

View file

@ -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) {

View file

@ -64,12 +64,7 @@ public class MessageAdapter extends PagingDataAdapter<MessageWithContentReaction
@Override
protected void setMessage(final MessageWithContentReactions message) {
if (message == null) {
this.binding.setMessage(null);
this.binding.text.setText("(placeholder)");
} else {
this.binding.setMessage(message);
}
this.binding.setMessage(message);
}
}
}

View file

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM9,6c0,-1.66 1.34,-3 3,-3s3,1.34 3,3v2L9,8L9,6zM18,20L6,20L6,10h12v10zM12,17c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2z" />
</vector>

View file

@ -59,6 +59,7 @@
android:layout_height="wrap_content">
<Button
android:layout_marginHorizontal="4dp"
android:id="@+id/add_content"
style="?attr/materialIconButtonStyle"
android:layout_width="wrap_content"
@ -76,7 +77,9 @@
android:theme="@style/ThemeOverlay.C3.TextSelection.Secondary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_marginVertical="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="4dp"
android:minHeight="48dp"
app:boxBackgroundColor="?colorTertiaryContainer"
app:boxCornerRadiusBottomEnd="24dp"

View file

@ -73,7 +73,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:textAppearance="?textAppearanceLabelMedium"
app:instant="@{chatOverviewItem.sentAt}"
app:datetime="@{chatOverviewItem.sentAt}"
app:layout_constraintBaseline_toBaselineOf="@+id/name"
app:layout_constraintEnd_toEndOf="parent"
tools:text="23:24" />

View file

@ -5,7 +5,8 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:paddingVertical="6dp">
<ImageView
android:id="@+id/avatar"
@ -13,42 +14,70 @@
android:layout_height="@dimen/avatar_chat_overview_size"
android:layout_marginStart="8dp"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toBottomOf="@id/content"
app:layout_constraintStart_toStartOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:background="@drawable/background_message_received"
android:minHeight="40dp"
android:padding="8dp"
android:layout_marginTop="4dp"
app:layout_constrainedWidth="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@id/avatar"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/text"
android:id="@+id/textContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{message.textContent}"
android:textAppearance="?textAppearanceBodyMedium"
android:textColor="?colorOnSecondaryContainer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="@{message.textContent}"
tools:text="Fusce vitae vehicula risus, nec ornare lorem. Quisque facilisis mattis velit ac porttitor. Aenean aliquet pretium varius. Quisque neque felis, mattis sit amet leo ac, tempus dapibus nibh." />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="2sp"
android:textAppearance="?textAppearanceLabelSmall"
android:textColor="?colorOnSurface"
app:layout_constraintStart_toStartOf="@+id/content"
app:layout_constraintTop_toBottomOf="@+id/content"
app:time="@{message.sentAt}"
tools:text="11:42 PM" />
<ImageView
android:id="@+id/encryption"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginStart="4sp"
android:src="@drawable/ic_lock_outline_24dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="@+id/time"
app:layout_constraintStart_toEndOf="@+id/time"
app:layout_constraintTop_toTopOf="@+id/time"
app:tint="?colorOnSurface" />
</androidx.constraintlayout.widget.ConstraintLayout>
<data>
<import type="android.view.View" />
<variable
name="message"
type="im.conversations.android.database.model.MessageWithContentReactions" />