diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java index 27f564bbf3..867f6b7bb0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java @@ -94,6 +94,7 @@ public final class ConversationUpdateItem extends FrameLayout private TextView body; private MaterialButton actionButton; private View background; + private View bodyBackground; private ConversationMessage conversationMessage; private Recipient conversationRecipient; private Optional previousMessageRecord; @@ -119,6 +120,7 @@ public final class ConversationUpdateItem extends FrameLayout private int latestFrame; private SpannableString displayBody; private ExpirationTimer timer; + private boolean hasWallpaper; private final PassthroughClickListener passthroughClickListener = new PassthroughClickListener(); @@ -138,6 +140,7 @@ public final class ConversationUpdateItem extends FrameLayout this.body = findViewById(R.id.conversation_update_body); this.actionButton = findViewById(R.id.conversation_update_action); this.background = findViewById(R.id.conversation_update_background); + this.bodyBackground = findViewById(R.id.conversation_update_body_background); this.collapsedButton = findViewById(R.id.conversation_update_collapsed); body.setOnClickListener(v -> { @@ -198,6 +201,7 @@ public final class ConversationUpdateItem extends FrameLayout this.nextMessageRecord = nextMessageRecord; this.conversationRecipient = conversationRecipient; this.isMessageRequestAccepted = isMessageRequestAccepted; + this.hasWallpaper = hasWallpaper; senderObserver.observe(lifecycleOwner, messageRecord.getFromRecipient()); @@ -209,9 +213,11 @@ public final class ConversationUpdateItem extends FrameLayout groupObserver.observe(lifecycleOwner, null); } - int textColor = ContextCompat.getColor(getContext(), R.color.conversation_item_update_text_color); - if (ThemeUtil.isDarkTheme(getContext()) && hasWallpaper) { - textColor = ContextCompat.getColor(getContext(), R.color.core_grey_15); + int textColor; + if (hasWallpaper) { + textColor = ContextCompat.getColor(getContext(), org.signal.core.ui.R.color.signal_colorOnSurfaceVariant); + } else { + textColor = ContextCompat.getColor(getContext(), R.color.conversation_item_update_text_color); } UpdateDescription updateDescription = Objects.requireNonNull(messageRecord.getUpdateDisplayBody(getContext(), eventListener::onRecipientNameClicked)); @@ -227,13 +233,10 @@ public final class ConversationUpdateItem extends FrameLayout present(conversationMessage, nextMessageRecord, conversationRecipient, isMessageRequestAccepted); presentTimer(updateDescription); - presentBackground(shouldCollapse(messageRecord, previousMessageRecord), - shouldCollapse(messageRecord, nextMessageRecord), - hasWallpaper, - donationRequest); + presentBackground(hasWallpaper, donationRequest); presentActionButton(hasWallpaper, donationRequest); - presentCollapsedHead(conversationMessage.getMessageRecord().getCollapsedState()); + presentCollapsedHead(hasWallpaper, conversationMessage.getMessageRecord().getCollapsedState()); updateSelectedState(); } @@ -247,12 +250,11 @@ public final class ConversationUpdateItem extends FrameLayout } } - private static boolean shouldCollapse(@NonNull MessageRecord current, @NonNull Optional candidate) + private static boolean isSameDayUpdate(@NonNull MessageRecord current, @NonNull Optional candidate) { return candidate.isPresent() && candidate.get().isUpdate() && - DateUtils.isSameDay(current.getTimestamp(), candidate.get().getTimestamp()) && - isSameType(current, candidate.get()); + DateUtils.isSameDay(current.getTimestamp(), candidate.get().getTimestamp()); } /** After a short delay, if the main data hasn't shown yet, then a loading message is displayed. */ @@ -414,6 +416,7 @@ public final class ConversationUpdateItem extends FrameLayout private void update() { present(conversationMessage, nextMessageRecord, conversationRecipient, isMessageRequestAccepted); + presentBackground(hasWallpaper, conversationMessage.getMessageRecord().isReleaseChannelDonationRequest()); } } @@ -791,72 +794,43 @@ public final class ConversationUpdateItem extends FrameLayout (messageRecord.isGroupV2JoinRequest(toBlock.requireServiceId()) && previousMessageRecord.map(m -> m.isCollapsedGroupV2JoinUpdate(toBlock.requireServiceId())).orElse(false)); } - private void presentBackground(boolean collapseAbove, boolean collapseBelow, boolean hasWallpaper, boolean isDonationRequest) { - int marginDefault = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_vertical_margin); - int marginCollapsed = 0; - int paddingDefault = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_vertical_padding); - int paddingCollapsed = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_vertical_padding_collapsed); + private void presentBackground(boolean hasWallpaper, boolean isDonationRequest) { + int marginCompact; + int marginDefault; + int topMargin; + int bottomMargin; + if (!hasWallpaper) { + marginCompact = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_margin_compact); + marginDefault = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_margin); + } else { + marginCompact = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_margin_compact_wallpaper); + marginDefault = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_margin_wallpaper); + } + topMargin = isSameDayUpdate(messageRecord, previousMessageRecord) ? marginCompact : marginDefault; + bottomMargin = isSameDayUpdate(messageRecord, nextMessageRecord) ? marginCompact : marginDefault; - if (collapseAbove && collapseBelow) { - ViewUtil.setTopMargin(background, marginCollapsed); - ViewUtil.setBottomMargin(background, marginCollapsed); + int verticalPadding; + if (actionButton.getVisibility() == View.VISIBLE) { + verticalPadding = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_vertical_margin_action); + } else if (hasWallpaper) { + verticalPadding = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_vertical_margin); + } else { + verticalPadding = 0; + } - ViewUtil.setPaddingTop(background, paddingCollapsed); - ViewUtil.setPaddingBottom(background, paddingCollapsed); + ViewUtil.setTopMargin(background, topMargin); + ViewUtil.setBottomMargin(background, bottomMargin); + ViewUtil.setPaddingTop(bodyBackground, verticalPadding); + ViewUtil.setPaddingBottom(bodyBackground, verticalPadding); - ViewUtil.updateLayoutParams(background, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - - if (hasWallpaper) { - background.setBackgroundResource(R.drawable.conversation_update_wallpaper_background_middle); + if (hasWallpaper && !conversationMessage.isActiveCollapsedHead()) { + if (isDonationRequest) { + bodyBackground.setBackgroundResource(R.drawable.conversation_update_release_note_background); } else { - background.setBackground(null); - } - } else if (collapseAbove) { - ViewUtil.setTopMargin(background, marginCollapsed); - ViewUtil.setBottomMargin(background, marginDefault); - - ViewUtil.setPaddingTop(background, paddingDefault); - ViewUtil.setPaddingBottom(background, paddingDefault); - - ViewUtil.updateLayoutParams(background, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - - if (hasWallpaper) { - background.setBackgroundResource(R.drawable.conversation_update_wallpaper_background_bottom); - } else { - background.setBackground(null); - } - } else if (collapseBelow) { - ViewUtil.setTopMargin(background, marginDefault); - ViewUtil.setBottomMargin(background, marginCollapsed); - - ViewUtil.setPaddingTop(background, paddingDefault); - ViewUtil.setPaddingBottom(background, paddingCollapsed); - - ViewUtil.updateLayoutParams(background, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); - - if (hasWallpaper) { - background.setBackgroundResource(R.drawable.conversation_update_wallpaper_background_top); - } else { - background.setBackground(null); + bodyBackground.setBackgroundResource(R.drawable.conversation_update_wallpaper_background_singular); } } else { - ViewUtil.setTopMargin(background, marginDefault); - ViewUtil.setBottomMargin(background, marginDefault); - - ViewUtil.setPaddingTop(background, paddingDefault); - ViewUtil.setPaddingBottom(background, paddingDefault); - - ViewUtil.updateLayoutParams(background, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); - - if (hasWallpaper) { - if (isDonationRequest) { - background.setBackgroundResource(R.drawable.conversation_update_release_note_background); - } else { - background.setBackgroundResource(R.drawable.conversation_update_wallpaper_background_singular); - } - } else { - background.setBackground(null); - } + bodyBackground.setBackground(null); } } @@ -873,7 +847,7 @@ public final class ConversationUpdateItem extends FrameLayout } } - private void presentCollapsedHead(CollapsedState collapsedState) { + private void presentCollapsedHead(boolean hasWallpaper, CollapsedState collapsedState) { if (!conversationMessage.isActiveCollapsibleHead()) { collapsedButton.setVisibility(GONE); } else { @@ -898,6 +872,15 @@ public final class ConversationUpdateItem extends FrameLayout } }); ViewUtil.setBottomMargin(collapsedButton, (int) DimensionUnit.DP.toPixels(conversationMessage.isActiveCollapsedHead() ? 0 : 12)); + + if (hasWallpaper) { + collapsedButton.setBackgroundResource(R.drawable.conversation_update_wallpaper_background_singular); + collapsedButton.setBackgroundTintList(null); + } else { + collapsedButton.setBackgroundResource(R.drawable.rounded_rectangle_38); + collapsedButton.setBackgroundTintList(AppCompatResources.getColorStateList(getContext(), org.signal.core.ui.R.color.signal_colorSurface1)); + } + collapsedButton.setVisibility(VISIBLE); } else { Log.w(TAG, "Found a message that is a collapsible head but does not have a collapsible type."); @@ -925,14 +908,6 @@ public final class ConversationUpdateItem extends FrameLayout }; } - private static boolean isSameType(@NonNull MessageRecord current, @NonNull MessageRecord candidate) { - return (current.isGroupUpdate() && candidate.isGroupUpdate()) || - (current.isProfileChange() && candidate.isProfileChange()) || - (current.isGroupCall() && candidate.isGroupCall()) || - (current.isExpirationTimerUpdate() && candidate.isExpirationTimerUpdate()) || - (current.isChangeNumber() && candidate.isChangeNumber()); - } - private void presentTimer(UpdateDescription updateDescription) { if (updateDescription.hasExpiration() && messageRecord.getExpiresIn() > 0 && messageRecord.getExpireStarted() > 0) { timer = new ExpirationTimer(messageRecord.getExpireStarted(), messageRecord.getExpiresIn()); @@ -984,6 +959,7 @@ public final class ConversationUpdateItem extends FrameLayout if (recipient.getId() == conversationRecipient.getId() && (conversationRecipient == null || !conversationRecipient.hasSameContent(recipient))) { conversationRecipient = recipient; present(conversationMessage, nextMessageRecord, conversationRecipient, isMessageRequestAccepted); + presentBackground(hasWallpaper, conversationMessage.getMessageRecord().isReleaseChannelDonationRequest()); } } } diff --git a/app/src/main/res/layout/conversation_item_update.xml b/app/src/main/res/layout/conversation_item_update.xml index 3171465102..b1514298f5 100644 --- a/app/src/main/res/layout/conversation_item_update.xml +++ b/app/src/main/res/layout/conversation_item_update.xml @@ -15,14 +15,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" - android:layout_marginTop="@dimen/conversation_update_vertical_margin" - android:layout_marginBottom="@dimen/conversation_update_vertical_margin" android:orientation="vertical" - android:gravity="center" - android:paddingTop="@dimen/conversation_update_vertical_padding" - android:paddingBottom="@dimen/conversation_update_vertical_padding" - android:paddingStart="16dp" - android:paddingEnd="16dp"> + android:gravity="center"> - + android:layout_gravity="center" + android:orientation="vertical" + android:paddingHorizontal="12dp" + android:gravity="center" > - + + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index d43869817c..6fca784db4 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -156,9 +156,12 @@ 2dp + 12dp + 8dp + 8dp + 4dp 4dp - 20dp - 4dp + 12dp 64dp 32dp