From e7c259b1e986721c94ade45aa1f4b3484f371479 Mon Sep 17 00:00:00 2001 From: Lucio Maciel Date: Tue, 17 Aug 2021 17:22:23 -0300 Subject: [PATCH] Adjust timestamp alignment. --- .../conversation/ConversationItem.java | 33 +++++++++++-------- .../thoughtcrime/securesms/util/ViewUtil.java | 9 +++-- .../conversation_item_received_multimedia.xml | 3 +- .../conversation_item_received_text_only.xml | 17 +--------- .../conversation_item_sent_multimedia.xml | 3 +- .../conversation_item_sent_text_only.xml | 17 +--------- app/src/main/res/values/dimens.xml | 1 + 7 files changed, 30 insertions(+), 53 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java index 7b4ef324a..59098c964 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -179,7 +179,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo @Nullable private QuoteView quoteView; private EmojiTextView bodyText; private ConversationItemFooter footer; - private ConversationItemFooter stickerFooter; + @Nullable private ConversationItemFooter stickerFooter; @Nullable private TextView groupSender; @Nullable private View groupSenderHolder; private AvatarImageView contactPhoto; @@ -386,7 +386,9 @@ public final class ConversationItem extends RelativeLayout implements BindableCo } } - int defaultMargin = readDimen(R.dimen.message_bubble_default_footer_bottom_margin); + int defaultTopMargin = readDimen(R.dimen.message_bubble_default_footer_bottom_margin); + int defaultBottomMargin = readDimen(R.dimen.message_bubble_bottom_padding); + int collapsedBottomMargin = readDimen(R.dimen.message_bubble_collapsed_bottom_padding); if (!updatingFooter && !isCaptionlessMms(messageRecord) && !isViewOnceMessage(messageRecord) && @@ -394,36 +396,39 @@ public final class ConversationItem extends RelativeLayout implements BindableCo isFooterVisible(messageRecord, nextMessageRecord, groupThread) && bodyText.getLastLineWidth() > 0) { - TextView dateView = footer.getDateView(); - int footerWidth = footer.getMeasuredWidth(); - int availableWidth = getAvailableMessageBubbleWidth(bodyText); - int bottomDiff = (int) (bodyText.getPaint().getFontMetrics().bottom - dateView.getPaint().getFontMetrics().bottom); - int topMargin = -1 * (dateView.getMeasuredHeight() + ViewUtil.dpToPx(7) + bottomDiff) + 1; + TextView dateView = footer.getDateView(); + int footerWidth = footer.getMeasuredWidth(); + int availableWidth = getAvailableMessageBubbleWidth(bodyText); + int collapsedTopMargin = -1 * (dateView.getMeasuredHeight() + ViewUtil.dpToPx(4)); if (bodyText.isSingleLine()) { int maxBubbleWidth = hasBigImageLinkPreview(messageRecord) || hasThumbnail(messageRecord) ? readDimen(R.dimen.media_bubble_max_width) : getMaxBubbleWidth(); int bodyMargins = ViewUtil.getLeftMargin(bodyText) + ViewUtil.getRightMargin(bodyText); int sizeWithMargins = bodyText.getMeasuredWidth() + ViewUtil.dpToPx(6) + footerWidth + bodyMargins; int minSize = Math.min(maxBubbleWidth, Math.max(bodyText.getMeasuredWidth() + ViewUtil.dpToPx(6) + footerWidth + bodyMargins, bodyBubble.getMeasuredWidth())); if (hasQuote(messageRecord) && sizeWithMargins < availableWidth) { - ViewUtil.setTopMargin(footer, topMargin); + ViewUtil.setTopMargin(footer, collapsedTopMargin); + ViewUtil.setBottomMargin(footer, collapsedBottomMargin); needsMeasure = true; updatingFooter = true; } else if (sizeWithMargins != bodyText.getMeasuredWidth() && sizeWithMargins <= minSize) { bodyBubble.getLayoutParams().width = minSize; - ViewUtil.setTopMargin(footer, topMargin); + ViewUtil.setTopMargin(footer, collapsedTopMargin); + ViewUtil.setBottomMargin(footer, collapsedBottomMargin); needsMeasure = true; updatingFooter = true; } } if (!updatingFooter && bodyText.getLastLineWidth() + ViewUtil.dpToPx(6) + footerWidth <= bodyText.getMeasuredWidth()) { - ViewUtil.setTopMargin(footer, topMargin); + ViewUtil.setTopMargin(footer, collapsedTopMargin); + ViewUtil.setBottomMargin(footer, collapsedBottomMargin); updatingFooter = true; needsMeasure = true; } } - if (!updatingFooter && ViewUtil.getTopMargin(footer) != defaultMargin) { - ViewUtil.setTopMargin(footer, defaultMargin); + if (!updatingFooter && ViewUtil.getTopMargin(footer) != defaultTopMargin) { + ViewUtil.setTopMargin(footer, defaultTopMargin); + ViewUtil.setBottomMargin(footer, defaultBottomMargin); needsMeasure = true; } @@ -1370,7 +1375,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo ViewUtil.setTopMargin(footer, readDimen(R.dimen.message_bubble_default_footer_bottom_margin)); footer.setVisibility(GONE); - stickerFooter.setVisibility(GONE); + ViewUtil.setVisibilityIfNonNull(stickerFooter, GONE); if (sharedContactStub.resolved()) sharedContactStub.get().getFooter().setVisibility(GONE); if (mediaThumbnailStub.resolved()) mediaThumbnailStub.require().getFooter().setVisibility(GONE); @@ -1405,7 +1410,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo } private ConversationItemFooter getActiveFooter(@NonNull MessageRecord messageRecord) { - if (hasNoBubble(messageRecord)) { + if (hasNoBubble(messageRecord) && stickerFooter != null) { return stickerFooter; } else if (hasSharedContact(messageRecord) && TextUtils.isEmpty(messageRecord.getDisplayBody(getContext()))) { return sharedContactStub.get().getFooter(); diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/ViewUtil.java b/app/src/main/java/org/thoughtcrime/securesms/util/ViewUtil.java index c9afd6e37..4d1e11319 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/ViewUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/ViewUtil.java @@ -19,9 +19,7 @@ package org.thoughtcrime.securesms.util; import android.annotation.SuppressLint; import android.app.Activity; import android.content.Context; -import android.content.res.Configuration; import android.content.res.Resources; -import android.graphics.Paint; import android.util.TypedValue; import android.view.Gravity; import android.view.LayoutInflater; @@ -41,7 +39,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.view.ContextThemeWrapper; -import androidx.core.view.ViewCompat; import androidx.interpolator.view.animation.FastOutSlowInInterpolator; import androidx.lifecycle.Lifecycle; @@ -229,6 +226,12 @@ public final class ViewUtil { } } + public static void setVisibilityIfNonNull(@Nullable View view, int visibility) { + if (view != null) { + view.setVisibility(visibility); + } + } + public static int getLeftMargin(@NonNull View view) { if (isLtr(view)) { return ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).leftMargin; diff --git a/app/src/main/res/layout/conversation_item_received_multimedia.xml b/app/src/main/res/layout/conversation_item_received_multimedia.xml index e5b5a35cf..039a3e224 100644 --- a/app/src/main/res/layout/conversation_item_received_multimedia.xml +++ b/app/src/main/res/layout/conversation_item_received_multimedia.xml @@ -203,7 +203,6 @@ android:layout_height="wrap_content" android:layout_marginStart="@dimen/message_bubble_horizontal_padding" android:layout_marginTop="2dp" - android:layout_marginBottom="@dimen/message_bubble_bottom_padding" android:layout_gravity="end" android:clipChildren="false" android:clipToPadding="false" @@ -233,7 +232,7 @@ android:layout_height="wrap_content" android:layout_below="@id/body_bubble" android:layout_alignStart="@id/body_bubble" - android:layout_marginTop="-8dp" + android:layout_marginTop="-4dp" android:orientation="horizontal" app:rcv_outgoing="false" /> diff --git a/app/src/main/res/layout/conversation_item_received_text_only.xml b/app/src/main/res/layout/conversation_item_received_text_only.xml index 85cac408d..500b254ad 100644 --- a/app/src/main/res/layout/conversation_item_received_text_only.xml +++ b/app/src/main/res/layout/conversation_item_received_text_only.xml @@ -127,21 +127,6 @@ app:footer_reveal_dot_color="@color/signal_icon_tint_secondary" app:footer_text_color="@color/signal_text_secondary" /> - - diff --git a/app/src/main/res/layout/conversation_item_sent_multimedia.xml b/app/src/main/res/layout/conversation_item_sent_multimedia.xml index 404a25574..be39ba70f 100644 --- a/app/src/main/res/layout/conversation_item_sent_multimedia.xml +++ b/app/src/main/res/layout/conversation_item_sent_multimedia.xml @@ -154,7 +154,6 @@ android:layout_height="wrap_content" android:layout_gravity="end" android:layout_marginTop="2dp" - android:layout_marginBottom="@dimen/message_bubble_bottom_padding" android:clipChildren="false" android:clipToPadding="false" android:paddingStart="@dimen/message_bubble_horizontal_padding" @@ -185,7 +184,7 @@ android:layout_height="wrap_content" android:layout_below="@id/body_bubble" android:layout_alignEnd="@id/body_bubble" - android:layout_marginTop="-8dp" + android:layout_marginTop="-4dp" android:orientation="horizontal" app:rcv_outgoing="true" /> diff --git a/app/src/main/res/layout/conversation_item_sent_text_only.xml b/app/src/main/res/layout/conversation_item_sent_text_only.xml index 60a2c9070..f33b5657c 100644 --- a/app/src/main/res/layout/conversation_item_sent_text_only.xml +++ b/app/src/main/res/layout/conversation_item_sent_text_only.xml @@ -79,21 +79,6 @@ app:footer_reveal_dot_color="@color/conversation_item_sent_text_secondary_color" app:footer_text_color="@color/conversation_item_sent_text_secondary_color" /> - - diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 55d7a7eb5..7d5387d58 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -42,6 +42,7 @@ 6dp 32dp 7dp + 7dp 12dp 24dp 24dp