From 718471917f0b5d4acac9aa05c600231cd38dedf0 Mon Sep 17 00:00:00 2001 From: Alan Evans Date: Sat, 6 Jun 2020 11:29:05 -0300 Subject: [PATCH] Separate text only message layouts. --- .../securesms/MessageDetailsActivity.java | 4 +- .../securesms/components/AudioView.java | 5 +- .../conversation/ConversationAdapter.java | 50 +++-- .../conversation/ConversationFragment.java | 4 +- .../conversation/ConversationItem.java | 122 ++++++------ .../securesms/util/ThemeUtil.java | 3 +- .../thoughtcrime/securesms/util/ViewUtil.java | 6 + ...conversation_item_received_multimedia.xml} | 1 - .../conversation_item_received_text_only.xml | 175 ++++++++++++++++++ ... => conversation_item_sent_multimedia.xml} | 19 -- .../conversation_item_sent_text_only.xml | 115 ++++++++++++ 11 files changed, 403 insertions(+), 101 deletions(-) rename app/src/main/res/layout/{conversation_item_received.xml => conversation_item_received_multimedia.xml} (99%) create mode 100644 app/src/main/res/layout/conversation_item_received_text_only.xml rename app/src/main/res/layout/{conversation_item_sent.xml => conversation_item_sent_multimedia.xml} (92%) create mode 100644 app/src/main/res/layout/conversation_item_sent_text_only.xml diff --git a/app/src/main/java/org/thoughtcrime/securesms/MessageDetailsActivity.java b/app/src/main/java/org/thoughtcrime/securesms/MessageDetailsActivity.java index 8dada14466..65ad3b0df1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MessageDetailsActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/MessageDetailsActivity.java @@ -282,9 +282,9 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity if (messageRecord.isGroupAction()) { conversationItem = (ConversationItem) inflater.inflate(R.layout.conversation_item_update, itemParent, false); } else if (messageRecord.isOutgoing()) { - conversationItem = (ConversationItem) inflater.inflate(R.layout.conversation_item_sent, itemParent, false); + conversationItem = (ConversationItem) inflater.inflate(R.layout.conversation_item_sent_multimedia, itemParent, false); } else { - conversationItem = (ConversationItem) inflater.inflate(R.layout.conversation_item_received, itemParent, false); + conversationItem = (ConversationItem) inflater.inflate(R.layout.conversation_item_received_multimedia, itemParent, false); } itemParent.addView(conversationItem); } diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/AudioView.java b/app/src/main/java/org/thoughtcrime/securesms/components/AudioView.java index 9ddb6c2448..27cefe7780 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/AudioView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/AudioView.java @@ -99,8 +99,7 @@ public final class AudioView extends FrameLayout implements AudioSlidePlayer.Lis this.playPauseButton.setOnClickListener(new PlayPauseClickedListener()); this.seekBar.setOnSeekBarChangeListener(new SeekBarModifiedListener()); - setTint(typedArray.getColor(R.styleable.AudioView_foregroundTintColor, Color.WHITE), - typedArray.getColor(R.styleable.AudioView_backgroundTintColor, Color.WHITE)); + setTint(typedArray.getColor(R.styleable.AudioView_foregroundTintColor, Color.WHITE)); this.waveFormPlayedBarsColor = typedArray.getColor(R.styleable.AudioView_waveformPlayedBarsColor, Color.WHITE); this.waveFormUnplayedBarsColor = typedArray.getColor(R.styleable.AudioView_waveformUnplayedBarsColor, Color.WHITE); @@ -255,7 +254,7 @@ public final class AudioView extends FrameLayout implements AudioSlidePlayer.Lis } } - public void setTint(int foregroundTint, int backgroundTint) { + public void setTint(int foregroundTint) { post(()-> this.playPauseButton.addValueCallback(new KeyPath("**"), LottieProperty.COLOR_FILTER, new LottieValueCallback<>(new SimpleColorFilter(foregroundTint)))); diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java index b4e05c0c79..afc1cafafd 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java @@ -72,12 +72,14 @@ public class ConversationAdapter private static final String TAG = Log.tag(ConversationAdapter.class); - private static final int MESSAGE_TYPE_OUTGOING = 0; - private static final int MESSAGE_TYPE_INCOMING = 1; - private static final int MESSAGE_TYPE_UPDATE = 2; - private static final int MESSAGE_TYPE_HEADER = 3; - private static final int MESSAGE_TYPE_FOOTER = 4; - private static final int MESSAGE_TYPE_PLACEHOLDER = 5; + private static final int MESSAGE_TYPE_OUTGOING_MULTIMEDIA = 0; + private static final int MESSAGE_TYPE_OUTGOING_TEXT = 1; + private static final int MESSAGE_TYPE_INCOMING_MULTIMEDIA = 2; + private static final int MESSAGE_TYPE_INCOMING_TEXT = 3; + private static final int MESSAGE_TYPE_UPDATE = 4; + private static final int MESSAGE_TYPE_HEADER = 5; + private static final int MESSAGE_TYPE_FOOTER = 6; + private static final int MESSAGE_TYPE_PLACEHOLDER = 7; private static final long HEADER_ID = Long.MIN_VALUE; private static final long FOOTER_ID = Long.MIN_VALUE + 1; @@ -136,9 +138,9 @@ public class ConversationAdapter } else if (messageRecord.isUpdate()) { return MESSAGE_TYPE_UPDATE; } else if (messageRecord.isOutgoing()) { - return MESSAGE_TYPE_OUTGOING; + return messageRecord.isMms() ? MESSAGE_TYPE_OUTGOING_MULTIMEDIA : MESSAGE_TYPE_OUTGOING_TEXT; } else { - return MESSAGE_TYPE_INCOMING; + return messageRecord.isMms() ? MESSAGE_TYPE_INCOMING_MULTIMEDIA : MESSAGE_TYPE_INCOMING_TEXT; } } @@ -167,8 +169,10 @@ public class ConversationAdapter @Override public @NonNull RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { switch (viewType) { - case MESSAGE_TYPE_INCOMING: - case MESSAGE_TYPE_OUTGOING: + case MESSAGE_TYPE_INCOMING_TEXT: + case MESSAGE_TYPE_INCOMING_MULTIMEDIA: + case MESSAGE_TYPE_OUTGOING_TEXT: + case MESSAGE_TYPE_OUTGOING_MULTIMEDIA: case MESSAGE_TYPE_UPDATE: long start = System.currentTimeMillis(); @@ -189,7 +193,7 @@ public class ConversationAdapter itemView.setEventListener(clickListener); - Log.d(TAG, "Inflate time: " + (System.currentTimeMillis() - start)); + Log.d(TAG, String.format(Locale.US, "Inflate time: %d ms for View type: %d", System.currentTimeMillis() - start, viewType)); return new ConversationViewHolder(itemView); case MESSAGE_TYPE_PLACEHOLDER: View v = new FrameLayout(parent.getContext()); @@ -206,8 +210,10 @@ public class ConversationAdapter @Override public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { switch (getItemViewType(position)) { - case MESSAGE_TYPE_INCOMING: - case MESSAGE_TYPE_OUTGOING: + case MESSAGE_TYPE_INCOMING_TEXT: + case MESSAGE_TYPE_INCOMING_MULTIMEDIA: + case MESSAGE_TYPE_OUTGOING_TEXT: + case MESSAGE_TYPE_OUTGOING_MULTIMEDIA: case MESSAGE_TYPE_UPDATE: ConversationViewHolder conversationViewHolder = (ConversationViewHolder) holder; MessageRecord messageRecord = Objects.requireNonNull(getItem(position)); @@ -424,8 +430,10 @@ public class ConversationAdapter */ @MainThread static void initializePool(@NonNull RecyclerView.RecycledViewPool pool) { - pool.setMaxRecycledViews(MESSAGE_TYPE_INCOMING, 15); - pool.setMaxRecycledViews(MESSAGE_TYPE_OUTGOING, 15); + pool.setMaxRecycledViews(MESSAGE_TYPE_INCOMING_TEXT, 15); + pool.setMaxRecycledViews(MESSAGE_TYPE_INCOMING_MULTIMEDIA, 15); + pool.setMaxRecycledViews(MESSAGE_TYPE_OUTGOING_TEXT, 15); + pool.setMaxRecycledViews(MESSAGE_TYPE_OUTGOING_MULTIMEDIA, 15); pool.setMaxRecycledViews(MESSAGE_TYPE_PLACEHOLDER, 15); pool.setMaxRecycledViews(MESSAGE_TYPE_HEADER, 1); pool.setMaxRecycledViews(MESSAGE_TYPE_FOOTER, 1); @@ -464,12 +472,14 @@ public class ConversationAdapter return hasFooter() && position == (getItemCount() - 1); } - private @LayoutRes int getLayoutForViewType(int viewType) { + private static @LayoutRes int getLayoutForViewType(int viewType) { switch (viewType) { - case MESSAGE_TYPE_OUTGOING: return R.layout.conversation_item_sent; - case MESSAGE_TYPE_INCOMING: return R.layout.conversation_item_received; - case MESSAGE_TYPE_UPDATE: return R.layout.conversation_item_update; - default: throw new IllegalArgumentException("Unknown type!"); + case MESSAGE_TYPE_OUTGOING_TEXT: return R.layout.conversation_item_sent_text_only; + case MESSAGE_TYPE_OUTGOING_MULTIMEDIA: return R.layout.conversation_item_sent_multimedia; + case MESSAGE_TYPE_INCOMING_TEXT: return R.layout.conversation_item_received_text_only; + case MESSAGE_TYPE_INCOMING_MULTIMEDIA: return R.layout.conversation_item_received_multimedia; + case MESSAGE_TYPE_UPDATE: return R.layout.conversation_item_update; + default: throw new IllegalArgumentException("Unknown type!"); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java index 991f11bc2e..e21c3c6c01 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java @@ -167,8 +167,8 @@ public class ConversationFragment extends Fragment { FrameLayout parent = new FrameLayout(context); parent.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)); - CachedInflater.from(context).cacheUntilLimit(R.layout.conversation_item_received, parent, 10); - CachedInflater.from(context).cacheUntilLimit(R.layout.conversation_item_sent, parent, 10); + CachedInflater.from(context).cacheUntilLimit(R.layout.conversation_item_received_multimedia, parent, 10); + CachedInflater.from(context).cacheUntilLimit(R.layout.conversation_item_sent_multimedia, parent, 10); CachedInflater.from(context).cacheUntilLimit(R.layout.conversation_item_update, parent, 5); CachedInflater.from(context).cacheUntilLimit(R.layout.cursor_adapter_header_footer_view, parent, 2); } 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 065febd50c..c04b44842d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -104,7 +104,6 @@ import org.thoughtcrime.securesms.recipients.LiveRecipient; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.recipients.RecipientForeverObserver; import org.thoughtcrime.securesms.recipients.RecipientId; -import org.thoughtcrime.securesms.recipients.ui.bottomsheet.RecipientBottomSheetDialogFragment; import org.thoughtcrime.securesms.revealable.ViewOnceMessageView; import org.thoughtcrime.securesms.revealable.ViewOnceUtil; import org.thoughtcrime.securesms.stickers.StickerUrl; @@ -150,20 +149,20 @@ public class ConversationItem extends LinearLayout implements BindableConversati private LiveRecipient recipient; private GlideRequests glideRequests; - protected ConversationItemBodyBubble bodyBubble; - protected View reply; - protected ViewGroup contactPhotoHolder; - private QuoteView quoteView; - private EmojiTextView bodyText; - private ConversationItemFooter footer; - private ConversationItemFooter stickerFooter; - private TextView groupSender; - private TextView groupSenderProfileName; - private View groupSenderHolder; - private AvatarImageView contactPhoto; - private AlertView alertView; - private ViewGroup container; - protected ReactionsConversationView reactionsView; + protected ConversationItemBodyBubble bodyBubble; + protected View reply; + @Nullable protected ViewGroup contactPhotoHolder; + @Nullable private QuoteView quoteView; + private EmojiTextView bodyText; + private ConversationItemFooter footer; + private ConversationItemFooter stickerFooter; + @Nullable private TextView groupSender; + @Nullable private TextView groupSenderProfileName; + @Nullable private View groupSenderHolder; + private AvatarImageView contactPhoto; + private AlertView alertView; + private ViewGroup container; + protected ReactionsConversationView reactionsView; private @NonNull Set batchSelected = new HashSet<>(); private @NonNull Outliner outliner = new Outliner(); @@ -312,6 +311,9 @@ public class ConversationItem extends LinearLayout implements BindableConversati boolean needsMeasure = false; if (hasQuote(messageRecord)) { + if (quoteView == null) { + throw new AssertionError(); + } int quoteWidth = quoteView.getMeasuredWidth(); int availableWidth = getAvailableMessageBubbleWidth(quoteView); @@ -344,9 +346,10 @@ public class ConversationItem extends LinearLayout implements BindableConversati @Override public void onRecipientChanged(@NonNull Recipient modified) { setBubbleState(messageRecord); - setContactPhoto(recipient.get()); - setGroupMessageStatus(messageRecord, recipient.get()); - setAudioViewTint(messageRecord, conversationRecipient.get()); + if (recipient.getId().equals(modified.getId())) { + setContactPhoto(modified); + setGroupMessageStatus(messageRecord, modified); + } } private int getAvailableMessageBubbleWidth(@NonNull View forView) { @@ -407,19 +410,21 @@ public class ConversationItem extends LinearLayout implements BindableConversati bodyBubble.setOutliner(shouldDrawBodyBubbleOutline(messageRecord) ? outliner : null); if (audioViewStub.resolved()) { - setAudioViewTint(messageRecord, this.conversationRecipient.get()); + setAudioViewTint(messageRecord); } } - private void setAudioViewTint(MessageRecord messageRecord, Recipient recipient) { - if (messageRecord.isOutgoing()) { - if (DynamicTheme.isDarkTheme(context)) { - audioViewStub.get().setTint(Color.WHITE, defaultBubbleColor); + private void setAudioViewTint(MessageRecord messageRecord) { + if (hasAudio(messageRecord)) { + if (messageRecord.isOutgoing()) { + if (DynamicTheme.isDarkTheme(context)) { + audioViewStub.get().setTint(Color.WHITE); + } else { + audioViewStub.get().setTint(getContext().getResources().getColor(R.color.core_grey_60)); + } } else { - audioViewStub.get().setTint(getContext().getResources().getColor(R.color.core_grey_60), defaultBubbleColor); + audioViewStub.get().setTint(Color.WHITE); } - } else { - audioViewStub.get().setTint(Color.WHITE, recipient.getColor().toConversationColor(context)); } } @@ -590,7 +595,7 @@ public class ConversationItem extends LinearLayout implements BindableConversati setSharedContactCorners(messageRecord, previousRecord, nextRecord, isGroupThread); ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); footer.setVisibility(GONE); } else if (hasLinkPreview(messageRecord)) { linkPreviewStub.get().setVisibility(View.VISIBLE); @@ -617,13 +622,13 @@ public class ConversationItem extends LinearLayout implements BindableConversati setLinkPreviewCorners(messageRecord, previousRecord, nextRecord, isGroupThread, true); ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } else { linkPreviewStub.get().setLinkPreview(glideRequests, linkPreview, true); linkPreviewStub.get().setDownloadClickedListener(downloadClickListener); setLinkPreviewCorners(messageRecord, previousRecord, nextRecord, isGroupThread, false); ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); } linkPreviewStub.get().setOnClickListener(linkPreviewClickListener); @@ -646,7 +651,7 @@ public class ConversationItem extends LinearLayout implements BindableConversati audioViewStub.get().setOnLongClickListener(passthroughClickListener); ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); footer.setVisibility(VISIBLE); } else if (hasDocument(messageRecord)) { @@ -665,7 +670,7 @@ public class ConversationItem extends LinearLayout implements BindableConversati documentViewStub.get().setOnLongClickListener(passthroughClickListener); ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); footer.setVisibility(VISIBLE); } else if (hasSticker(messageRecord) && isCaptionlessMms(messageRecord)) { @@ -687,7 +692,7 @@ public class ConversationItem extends LinearLayout implements BindableConversati stickerStub.get().setOnClickListener(passthroughClickListener); ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); footer.setVisibility(VISIBLE); } else if (hasThumbnail(messageRecord)) { @@ -717,7 +722,7 @@ public class ConversationItem extends LinearLayout implements BindableConversati setThumbnailCorners(messageRecord, previousRecord, nextRecord, isGroupThread); ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); + ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); footer.setVisibility(VISIBLE); } else { @@ -730,7 +735,7 @@ public class ConversationItem extends LinearLayout implements BindableConversati if (revealableStub.resolved()) revealableStub.get().setVisibility(View.GONE); ViewUtil.updateLayoutParams(bodyText, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - ViewUtil.updateLayoutParams(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); + ViewUtil.updateLayoutParamsIfNonNull(groupSenderHolder, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); footer.setVisibility(VISIBLE); } @@ -874,6 +879,9 @@ public class ConversationItem extends LinearLayout implements BindableConversati private void setQuote(@NonNull MessageRecord current, @NonNull Optional previous, @NonNull Optional next, boolean isGroupThread) { if (current.isMms() && !current.isMmsNotification() && ((MediaMmsMessageRecord)current).getQuote() != null) { + if (quoteView == null) { + throw new AssertionError(); + } Quote quote = ((MediaMmsMessageRecord)current).getQuote(); //noinspection ConstantConditions quoteView.setQuote(glideRequests, quote.getId(), Recipient.live(quote.getAuthor()).get(), quote.getText(), quote.isOriginalMissing(), quote.getAttachment()); @@ -910,7 +918,9 @@ public class ConversationItem extends LinearLayout implements BindableConversati ViewUtil.setTopMargin(mediaThumbnailStub.get(), readDimen(R.dimen.message_bubble_top_padding)); } } else { - quoteView.dismiss(); + if (quoteView != null) { + quoteView.dismiss(); + } if (mediaThumbnailStub.resolved()) { ViewUtil.setTopMargin(mediaThumbnailStub.get(), 0); @@ -991,38 +1001,42 @@ public class ConversationItem extends LinearLayout implements BindableConversati @SuppressLint("SetTextI18n") private void setGroupMessageStatus(MessageRecord messageRecord, Recipient recipient) { - if (groupThread && !messageRecord.isOutgoing()) { + if (groupThread && !messageRecord.isOutgoing() && groupSender != null && groupSenderProfileName != null) { if (FeatureFlags.profileDisplay()) { - this.groupSender.setText(recipient.getDisplayName(getContext())); - this.groupSenderProfileName.setVisibility(View.GONE); + groupSender.setText(recipient.getDisplayName(getContext())); + groupSenderProfileName.setVisibility(View.GONE); } else { - this.groupSender.setText(recipient.toShortString(context)); + groupSender.setText(recipient.toShortString(context)); if (recipient.getName(context) == null && !recipient.getProfileName().isEmpty()) { - this.groupSenderProfileName.setText("~" + recipient.getProfileName().toString()); - this.groupSenderProfileName.setVisibility(View.VISIBLE); + groupSenderProfileName.setText("~" + recipient.getProfileName().toString()); + groupSenderProfileName.setVisibility(View.VISIBLE); } else { - this.groupSenderProfileName.setText(null); - this.groupSenderProfileName.setVisibility(View.GONE); + groupSenderProfileName.setText(null); + groupSenderProfileName.setVisibility(View.GONE); } } } } private void setGroupAuthorColor(@NonNull MessageRecord messageRecord) { - if (shouldDrawBodyBubbleOutline(messageRecord)) { - groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color)); - groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color)); - } else if (hasSticker(messageRecord)) { - groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color)); - groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color)); - } else { - groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color)); - groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color)); + if (groupSender != null && groupSenderProfileName != null) { + int stickerAuthorColor = ThemeUtil.getThemedColor(context, R.attr.conversation_sticker_author_color); + if (shouldDrawBodyBubbleOutline(messageRecord)) { + groupSender.setTextColor(stickerAuthorColor); + groupSenderProfileName.setTextColor(stickerAuthorColor); + } else if (hasSticker(messageRecord)) { + groupSender.setTextColor(stickerAuthorColor); + groupSenderProfileName.setTextColor(stickerAuthorColor); + } else { + groupSender.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color)); + groupSenderProfileName.setTextColor(ThemeUtil.getThemedColor(context, R.attr.conversation_item_received_text_primary_color)); + } } } + @SuppressWarnings("ConstantConditions") private void setAuthor(@NonNull MessageRecord current, @NonNull Optional previous, @NonNull Optional next, boolean isGroupThread) { if (isGroupThread && !current.isOutgoing()) { contactPhotoHolder.setVisibility(VISIBLE); @@ -1041,7 +1055,9 @@ public class ConversationItem extends LinearLayout implements BindableConversati contactPhoto.setVisibility(GONE); } } else { - groupSenderHolder.setVisibility(GONE); + if (groupSenderHolder != null) { + groupSenderHolder.setVisibility(GONE); + } if (contactPhotoHolder != null) { contactPhotoHolder.setVisibility(GONE); diff --git a/app/src/main/java/org/thoughtcrime/securesms/util/ThemeUtil.java b/app/src/main/java/org/thoughtcrime/securesms/util/ThemeUtil.java index f6c9fbc75b..edfb9f9c41 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/ThemeUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/ThemeUtil.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.res.Resources; import android.graphics.Color; import androidx.annotation.AttrRes; +import androidx.annotation.ColorInt; import androidx.annotation.DimenRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -35,7 +36,7 @@ public class ThemeUtil { return false; } - public static int getThemedColor(@NonNull Context context, @AttrRes int attr) { + public static @ColorInt int getThemedColor(@NonNull Context context, @AttrRes int attr) { TypedValue typedValue = new TypedValue(); Resources.Theme theme = context.getTheme(); 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 38cb6462b9..7c411a01ca 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/util/ViewUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/util/ViewUtil.java @@ -181,6 +181,12 @@ public final class ViewUtil { view.requestLayout(); } + public static void updateLayoutParamsIfNonNull(@Nullable View view, int width, int height) { + if (view != null) { + updateLayoutParams(view, width, height); + } + } + public static int getLeftMargin(@NonNull View view) { if (ViewCompat.getLayoutDirection(view) == ViewCompat.LAYOUT_DIRECTION_LTR) { return ((ViewGroup.MarginLayoutParams) view.getLayoutParams()).leftMargin; diff --git a/app/src/main/res/layout/conversation_item_received.xml b/app/src/main/res/layout/conversation_item_received_multimedia.xml similarity index 99% rename from app/src/main/res/layout/conversation_item_received.xml rename to app/src/main/res/layout/conversation_item_received_multimedia.xml index 8231ea930b..8cf555cb7d 100644 --- a/app/src/main/res/layout/conversation_item_received.xml +++ b/app/src/main/res/layout/conversation_item_received_multimedia.xml @@ -7,7 +7,6 @@ android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" - android:background="@drawable/conversation_item_background" android:focusable="true" android:nextFocusLeft="@+id/container" android:nextFocusRight="@+id/embedded_text_editor" 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 new file mode 100644 index 0000000000..3e6b630df1 --- /dev/null +++ b/app/src/main/res/layout/conversation_item_received_text_only.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/conversation_item_sent.xml b/app/src/main/res/layout/conversation_item_sent_multimedia.xml similarity index 92% rename from app/src/main/res/layout/conversation_item_sent.xml rename to app/src/main/res/layout/conversation_item_sent_multimedia.xml index 0725815006..829e8323fb 100644 --- a/app/src/main/res/layout/conversation_item_sent.xml +++ b/app/src/main/res/layout/conversation_item_sent_multimedia.xml @@ -5,7 +5,6 @@ android:id="@+id/conversation_item" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:background="@drawable/conversation_item_background" android:clipChildren="false" android:clipToPadding="false" android:focusable="true" @@ -130,24 +129,6 @@ app:scaleEmojis="true" tools:text="Mango pickle lorem ipsum" /> - - - - - - + + + + + + + + + + + + + + + + + + + + + + +