Adjust timestamp alignment.

This commit is contained in:
Lucio Maciel 2021-08-17 17:22:23 -03:00 committed by GitHub
parent c65761a034
commit e7c259b1e9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 30 additions and 53 deletions

View file

@ -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();

View file

@ -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;

View file

@ -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" />

View file

@ -127,21 +127,6 @@
app:footer_reveal_dot_color="@color/signal_icon_tint_secondary"
app:footer_text_color="@color/signal_text_secondary" />
<org.thoughtcrime.securesms.components.ConversationItemFooter
android:id="@+id/conversation_item_sticker_footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/message_bubble_horizontal_padding"
android:layout_marginTop="6dp"
android:layout_marginEnd="@dimen/message_bubble_horizontal_padding"
android:clipChildren="false"
android:clipToPadding="false"
android:visibility="gone"
app:footer_icon_color="@color/signal_icon_tint_secondary"
app:footer_mode="incoming"
app:footer_reveal_dot_color="@color/signal_icon_tint_secondary"
app:footer_text_color="@color/signal_text_secondary" />
</org.thoughtcrime.securesms.conversation.ConversationItemBodyBubble>
<org.thoughtcrime.securesms.components.AlertView
@ -158,7 +143,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" />

View file

@ -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" />

View file

@ -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" />
<org.thoughtcrime.securesms.components.ConversationItemFooter
android:id="@+id/conversation_item_sticker_footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/message_bubble_horizontal_padding"
android:layout_marginTop="6dp"
android:layout_marginEnd="@dimen/message_bubble_horizontal_padding"
android:clipChildren="false"
android:clipToPadding="false"
android:visibility="gone"
app:footer_mode="outgoing"
app:footer_icon_color="@color/signal_icon_tint_secondary"
app:footer_reveal_dot_color="@color/signal_icon_tint_secondary"
app:footer_text_color="@color/signal_text_secondary" />
</org.thoughtcrime.securesms.conversation.ConversationItemBodyBubble>
<org.thoughtcrime.securesms.components.AlertView
@ -112,7 +97,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" />

View file

@ -42,6 +42,7 @@
<dimen name="message_bubble_collapsed_footer_padding">6dp</dimen>
<dimen name="message_bubble_edge_margin">32dp</dimen>
<dimen name="message_bubble_bottom_padding">7dp</dimen>
<dimen name="message_bubble_collapsed_bottom_padding">7dp</dimen>
<dimen name="message_bubble_revealable_padding">12dp</dimen>
<dimen name="media_bubble_remove_button_size">24dp</dimen>
<dimen name="media_bubble_edit_button_size">24dp</dimen>