From 9b7b364a254d42e3d522e7951188b5745e2e5bc5 Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 26 Dec 2021 11:21:48 +0100 Subject: [PATCH] Move more bubble dimens to dimens.xml to better ensure consistence Change-Id: I996501e0e81e278ec8cc60dba25791d9627b0a4d --- .../app/core/ui/views/FooteredTextView.kt | 8 +++- .../timeline/item/AbsBaseMessageItem.kt | 3 +- .../detail/timeline/item/AbsMessageItem.kt | 42 ++++++++----------- .../detail/timeline/item/MessageFileItem.kt | 6 ++- .../res/layout/item_timeline_event_base.xml | 3 +- vector/src/main/res/values/dimens_sc.xml | 15 +++++++ 6 files changed, 47 insertions(+), 30 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/ui/views/FooteredTextView.kt b/vector/src/main/java/im/vector/app/core/ui/views/FooteredTextView.kt index 294205689d..790b9204fd 100644 --- a/vector/src/main/java/im/vector/app/core/ui/views/FooteredTextView.kt +++ b/vector/src/main/java/im/vector/app/core/ui/views/FooteredTextView.kt @@ -6,6 +6,7 @@ import android.graphics.Rect import android.text.Layout import android.util.AttributeSet import androidx.appcompat.widget.AppCompatTextView +import im.vector.app.R import kotlin.math.ceil import kotlin.math.max @@ -82,7 +83,12 @@ class FooteredTextView @JvmOverloads constructor( val widthLastLine = layout.getLineWidth(lastLine) // Required width if putting footer in the same line as the last line - val widthWithHorizontalFooter = (if (looksLikeRtl == viewIsRtl) widthLastLine else (maxLineWidth + 4*resources.displayMetrics.density)) + footerWidth + val widthWithHorizontalFooter = ( + if (looksLikeRtl == viewIsRtl) + widthLastLine + else + (maxLineWidth + resources.getDimensionPixelSize(R.dimen.sc_footer_rtl_mismatch_extra_padding)) + ) + footerWidth // Is there space for a horizontal footer? if (widthWithHorizontalFooter <= widthLimit) { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt index 4326aff8d9..5365d66935 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsBaseMessageItem.kt @@ -124,9 +124,8 @@ abstract class AbsBaseMessageItem : BaseEventItem BubbleThemeUtils.BUBBLE_STYLE_BOTH, BubbleThemeUtils.BUBBLE_STYLE_BOTH_HIDDEN, BubbleThemeUtils.BUBBLE_STYLE_START_HIDDEN -> { - val density = holder.informationBottom.resources.displayMetrics.density // Padding for views that align with the bubble (should be roughly the bubble tail width) - val bubbleStartAlignWidth = round(12 * density).toInt() + val bubbleStartAlignWidth = holder.informationBottom.resources.getDimensionPixelSize(R.dimen.sc_bubble_tail_size) if (reverseBubble) { // Align reactions container to bubble holder.informationBottom.setPaddingRelative( diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt index f299ce6803..fe2676c82a 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -479,7 +479,6 @@ abstract class AbsMessageItem : AbsBaseMessageItem longPaddingDp = bubbleView.resources.getDimensionPixelSize(R.dimen.sc_bubble_tail_size) shortPaddingDp = 0//if (attributes.informationData.showInformation && !hideSenderInformation()) { 8 } else { 0 } } - val density = bubbleView.resources.displayMetrics.density if (reverseBubble != defaultRtl) { // Use left/right instead of start/end: bubbleView is always LTR (bubbleView.layoutParams as ViewGroup.MarginLayoutParams).leftMargin = getBubbleMargin(bubbleView.resources, bubbleStyle, reverseBubble) @@ -488,11 +487,6 @@ abstract class AbsMessageItem : AbsBaseMessageItem (bubbleView.layoutParams as ViewGroup.MarginLayoutParams).leftMargin = 0 (bubbleView.layoutParams as ViewGroup.MarginLayoutParams).rightMargin = getBubbleMargin(bubbleView.resources, bubbleStyle, reverseBubble) } - /* - (bubbleView.layoutParams as RelativeLayout.LayoutParams).marginStart = round(20*density).toInt() - (bubbleView.layoutParams as RelativeLayout.LayoutParams).topMargin = round(8*density).toInt() - (bubbleView.layoutParams as RelativeLayout.LayoutParams).bottomMargin = round(8*density).toInt() - */ if (reverseBubble != defaultRtl) { // Use left/right instead of start/end: bubbleView is always LTR bubbleView.setPadding( @@ -531,8 +525,8 @@ abstract class AbsMessageItem : AbsBaseMessageItem val endOf = if(defaultRtl) RelativeLayout.LEFT_OF else RelativeLayout.RIGHT_OF val footerLayoutParams = holder.bubbleFootView.layoutParams as RelativeLayout.LayoutParams - var footerMarginStartDp = 4 - var footerMarginEndDp = 1 + var footerMarginStartDp = holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_margin_start) + var footerMarginEndDp = holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_margin_end) if (allowFooterOverlay(holder)) { footerLayoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.viewStubContainer) footerLayoutParams.addRule(alignEnd, R.id.viewStubContainer) @@ -542,7 +536,7 @@ abstract class AbsMessageItem : AbsBaseMessageItem footerLayoutParams.removeRule(startOf) if (needsFooterReservation(holder)) { // Remove style used when not having reserved space - removeFooterOverlayStyle(holder, density) + removeFooterOverlayStyle(holder) // Calculate required footer space val footerMeasures = getFooterMeasures(holder, anonymousReadReceipt) @@ -552,7 +546,7 @@ abstract class AbsMessageItem : AbsBaseMessageItem reserveFooterSpace(holder, footerWidth, footerHeight) } else { // We have no reserved space -> style it to ensure readability on arbitrary backgrounds - styleFooterOverlay(holder, density) + styleFooterOverlay(holder) } } else { when { @@ -574,9 +568,8 @@ abstract class AbsMessageItem : AbsBaseMessageItem footerLayoutParams.removeRule(startOf) footerLayoutParams.removeRule(RelativeLayout.BELOW) // Reverse margins - footerMarginStartDp = 1 - // 4 as previously the start margin, +4 to compensate the missing inner padding for the textView which we have on the other side - footerMarginEndDp = 8 + footerMarginStartDp = holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_reverse_margin_start) + footerMarginEndDp = holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_reverse_margin_end) } else -> /* footer on the right / at the end */ { footerLayoutParams.addRule(endOf, R.id.viewStubContainer) @@ -588,15 +581,15 @@ abstract class AbsMessageItem : AbsBaseMessageItem footerLayoutParams.removeRule(RelativeLayout.START_OF) } } - removeFooterOverlayStyle(holder, density) + removeFooterOverlayStyle(holder) } if (defaultRtl) { - footerLayoutParams.rightMargin = round(footerMarginStartDp * density).toInt() - footerLayoutParams.leftMargin = round(footerMarginEndDp * density).toInt() + footerLayoutParams.rightMargin = footerMarginStartDp + footerLayoutParams.leftMargin = footerMarginEndDp holder.bubbleMemberNameView.gravity = Gravity.RIGHT } else { - footerLayoutParams.leftMargin = round(footerMarginStartDp * density).toInt() - footerLayoutParams.rightMargin = round(footerMarginEndDp * density).toInt() + footerLayoutParams.leftMargin = footerMarginStartDp + footerLayoutParams.rightMargin = footerMarginEndDp holder.bubbleMemberNameView.gravity = Gravity.LEFT } } @@ -653,26 +646,27 @@ abstract class AbsMessageItem : AbsBaseMessageItem holder.bubbleFooterTimeView.setTextColor(tintList) } - private fun styleFooterOverlay(holder: H, density: Float) { + private fun styleFooterOverlay(holder: H) { holder.bubbleFootView.setBackgroundResource(R.drawable.timestamp_overlay) tintFooter(holder, ThemeUtils.getColor(holder.bubbleFootView.context, R.attr.timestamp_overlay_fg)) - val padding = round(2*density).toInt() + val padding = holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_overlay_padding) holder.bubbleFootView.setPaddingRelative( padding, padding, - padding + round(4*density).toInt(), // compensate from inner view padding on the other side + // compensate from inner view padding on the other side + padding + holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_padding_compensation), padding ) } - private fun removeFooterOverlayStyle(holder: H, density: Float) { + private fun removeFooterOverlayStyle(holder: H) { holder.bubbleFootView.background = null tintFooter(holder, ThemeUtils.getColor(holder.bubbleFootView.context, R.attr.vctr_content_secondary)) holder.bubbleFootView.setPaddingRelative( 0, - round(4*density).toInt(), + holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_noverlay_padding_top), 0, - -round(1.5*density).toInt() + holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_noverlay_padding_bottom) ) } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt index cfb6314a51..afd7b184f5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt @@ -109,10 +109,12 @@ abstract class MessageFileItem : AbsMessageItem() { val superVal = super.getViewStubMinimumWidth(holder, contentInBubble, showInformation) // Guess text width for name and time - val density = holder.filenameView.resources.displayMetrics.density // On first call, holder.fileImageView.width is not initialized yet val imageWidth = holder.fileImageView.resources.getDimensionPixelSize(R.dimen.chat_avatar_size) - val minimumWidthWithText = ceil(BubbleThemeUtils.guessTextWidth(holder.filenameView, filename)).toInt() + imageWidth + 32*density.toInt() + val minimumWidthWithText = + ceil(BubbleThemeUtils.guessTextWidth(holder.filenameView, filename)).toInt() + + imageWidth + + holder.filenameView.resources.getDimensionPixelSize(R.dimen.sc_bubble_guess_minimum_width_padding) val absoluteMinimumWidth = imageWidth*3 return max(max(absoluteMinimumWidth, minimumWidthWithText), superVal) } diff --git a/vector/src/main/res/layout/item_timeline_event_base.xml b/vector/src/main/res/layout/item_timeline_event_base.xml index ad5556514e..a5403dccac 100644 --- a/vector/src/main/res/layout/item_timeline_event_base.xml +++ b/vector/src/main/res/layout/item_timeline_event_base.xml @@ -212,7 +212,8 @@ tools:layout_marginEnd="1dp" tools:layout_alignBottom="@id/viewStubContainer" tools:layout_alignEnd="@id/viewStubContainer" - tools:paddingTop="4dp" + tools:paddingTop="@dimen/sc_footer_noverlay_padding_top" + tools:paddingBottom="@dimen/sc_footer_noverlay_padding_bottom" android:id="@+id/bubbleFootView"> 8dp 20dp + + 32dp + + + 2dp + 4dp + -1.5dp + + 4dp + 4dp + 1dp + @dimen/sc_footer_margin_end + + 8dp + 4dp