Move more bubble dimens to dimens.xml to better ensure consistence

Change-Id: I996501e0e81e278ec8cc60dba25791d9627b0a4d
This commit is contained in:
SpiritCroc 2021-12-26 11:21:48 +01:00
parent 127e151c41
commit 9b7b364a25
6 changed files with 47 additions and 30 deletions

View file

@ -6,6 +6,7 @@ import android.graphics.Rect
import android.text.Layout import android.text.Layout
import android.util.AttributeSet import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatTextView import androidx.appcompat.widget.AppCompatTextView
import im.vector.app.R
import kotlin.math.ceil import kotlin.math.ceil
import kotlin.math.max import kotlin.math.max
@ -82,7 +83,12 @@ class FooteredTextView @JvmOverloads constructor(
val widthLastLine = layout.getLineWidth(lastLine) val widthLastLine = layout.getLineWidth(lastLine)
// Required width if putting footer in the same line as the last line // 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? // Is there space for a horizontal footer?
if (widthWithHorizontalFooter <= widthLimit) { if (widthWithHorizontalFooter <= widthLimit) {

View file

@ -124,9 +124,8 @@ abstract class AbsBaseMessageItem<H : AbsBaseMessageItem.Holder> : BaseEventItem
BubbleThemeUtils.BUBBLE_STYLE_BOTH, BubbleThemeUtils.BUBBLE_STYLE_BOTH,
BubbleThemeUtils.BUBBLE_STYLE_BOTH_HIDDEN, BubbleThemeUtils.BUBBLE_STYLE_BOTH_HIDDEN,
BubbleThemeUtils.BUBBLE_STYLE_START_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) // 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) { if (reverseBubble) {
// Align reactions container to bubble // Align reactions container to bubble
holder.informationBottom.setPaddingRelative( holder.informationBottom.setPaddingRelative(

View file

@ -479,7 +479,6 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
longPaddingDp = bubbleView.resources.getDimensionPixelSize(R.dimen.sc_bubble_tail_size) longPaddingDp = bubbleView.resources.getDimensionPixelSize(R.dimen.sc_bubble_tail_size)
shortPaddingDp = 0//if (attributes.informationData.showInformation && !hideSenderInformation()) { 8 } else { 0 } shortPaddingDp = 0//if (attributes.informationData.showInformation && !hideSenderInformation()) { 8 } else { 0 }
} }
val density = bubbleView.resources.displayMetrics.density
if (reverseBubble != defaultRtl) { if (reverseBubble != defaultRtl) {
// Use left/right instead of start/end: bubbleView is always LTR // Use left/right instead of start/end: bubbleView is always LTR
(bubbleView.layoutParams as ViewGroup.MarginLayoutParams).leftMargin = getBubbleMargin(bubbleView.resources, bubbleStyle, reverseBubble) (bubbleView.layoutParams as ViewGroup.MarginLayoutParams).leftMargin = getBubbleMargin(bubbleView.resources, bubbleStyle, reverseBubble)
@ -488,11 +487,6 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
(bubbleView.layoutParams as ViewGroup.MarginLayoutParams).leftMargin = 0 (bubbleView.layoutParams as ViewGroup.MarginLayoutParams).leftMargin = 0
(bubbleView.layoutParams as ViewGroup.MarginLayoutParams).rightMargin = getBubbleMargin(bubbleView.resources, bubbleStyle, reverseBubble) (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) { if (reverseBubble != defaultRtl) {
// Use left/right instead of start/end: bubbleView is always LTR // Use left/right instead of start/end: bubbleView is always LTR
bubbleView.setPadding( bubbleView.setPadding(
@ -531,8 +525,8 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
val endOf = if(defaultRtl) RelativeLayout.LEFT_OF else RelativeLayout.RIGHT_OF val endOf = if(defaultRtl) RelativeLayout.LEFT_OF else RelativeLayout.RIGHT_OF
val footerLayoutParams = holder.bubbleFootView.layoutParams as RelativeLayout.LayoutParams val footerLayoutParams = holder.bubbleFootView.layoutParams as RelativeLayout.LayoutParams
var footerMarginStartDp = 4 var footerMarginStartDp = holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_margin_start)
var footerMarginEndDp = 1 var footerMarginEndDp = holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_margin_end)
if (allowFooterOverlay(holder)) { if (allowFooterOverlay(holder)) {
footerLayoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.viewStubContainer) footerLayoutParams.addRule(RelativeLayout.ALIGN_BOTTOM, R.id.viewStubContainer)
footerLayoutParams.addRule(alignEnd, R.id.viewStubContainer) footerLayoutParams.addRule(alignEnd, R.id.viewStubContainer)
@ -542,7 +536,7 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
footerLayoutParams.removeRule(startOf) footerLayoutParams.removeRule(startOf)
if (needsFooterReservation(holder)) { if (needsFooterReservation(holder)) {
// Remove style used when not having reserved space // Remove style used when not having reserved space
removeFooterOverlayStyle(holder, density) removeFooterOverlayStyle(holder)
// Calculate required footer space // Calculate required footer space
val footerMeasures = getFooterMeasures(holder, anonymousReadReceipt) val footerMeasures = getFooterMeasures(holder, anonymousReadReceipt)
@ -552,7 +546,7 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
reserveFooterSpace(holder, footerWidth, footerHeight) reserveFooterSpace(holder, footerWidth, footerHeight)
} else { } else {
// We have no reserved space -> style it to ensure readability on arbitrary backgrounds // We have no reserved space -> style it to ensure readability on arbitrary backgrounds
styleFooterOverlay(holder, density) styleFooterOverlay(holder)
} }
} else { } else {
when { when {
@ -574,9 +568,8 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
footerLayoutParams.removeRule(startOf) footerLayoutParams.removeRule(startOf)
footerLayoutParams.removeRule(RelativeLayout.BELOW) footerLayoutParams.removeRule(RelativeLayout.BELOW)
// Reverse margins // Reverse margins
footerMarginStartDp = 1 footerMarginStartDp = holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_reverse_margin_start)
// 4 as previously the start margin, +4 to compensate the missing inner padding for the textView which we have on the other side footerMarginEndDp = holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_reverse_margin_end)
footerMarginEndDp = 8
} }
else -> /* footer on the right / at the end */ { else -> /* footer on the right / at the end */ {
footerLayoutParams.addRule(endOf, R.id.viewStubContainer) footerLayoutParams.addRule(endOf, R.id.viewStubContainer)
@ -588,15 +581,15 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
footerLayoutParams.removeRule(RelativeLayout.START_OF) footerLayoutParams.removeRule(RelativeLayout.START_OF)
} }
} }
removeFooterOverlayStyle(holder, density) removeFooterOverlayStyle(holder)
} }
if (defaultRtl) { if (defaultRtl) {
footerLayoutParams.rightMargin = round(footerMarginStartDp * density).toInt() footerLayoutParams.rightMargin = footerMarginStartDp
footerLayoutParams.leftMargin = round(footerMarginEndDp * density).toInt() footerLayoutParams.leftMargin = footerMarginEndDp
holder.bubbleMemberNameView.gravity = Gravity.RIGHT holder.bubbleMemberNameView.gravity = Gravity.RIGHT
} else { } else {
footerLayoutParams.leftMargin = round(footerMarginStartDp * density).toInt() footerLayoutParams.leftMargin = footerMarginStartDp
footerLayoutParams.rightMargin = round(footerMarginEndDp * density).toInt() footerLayoutParams.rightMargin = footerMarginEndDp
holder.bubbleMemberNameView.gravity = Gravity.LEFT holder.bubbleMemberNameView.gravity = Gravity.LEFT
} }
} }
@ -653,26 +646,27 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
holder.bubbleFooterTimeView.setTextColor(tintList) holder.bubbleFooterTimeView.setTextColor(tintList)
} }
private fun styleFooterOverlay(holder: H, density: Float) { private fun styleFooterOverlay(holder: H) {
holder.bubbleFootView.setBackgroundResource(R.drawable.timestamp_overlay) holder.bubbleFootView.setBackgroundResource(R.drawable.timestamp_overlay)
tintFooter(holder, ThemeUtils.getColor(holder.bubbleFootView.context, R.attr.timestamp_overlay_fg)) 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( holder.bubbleFootView.setPaddingRelative(
padding, padding,
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 padding
) )
} }
private fun removeFooterOverlayStyle(holder: H, density: Float) { private fun removeFooterOverlayStyle(holder: H) {
holder.bubbleFootView.background = null holder.bubbleFootView.background = null
tintFooter(holder, ThemeUtils.getColor(holder.bubbleFootView.context, R.attr.vctr_content_secondary)) tintFooter(holder, ThemeUtils.getColor(holder.bubbleFootView.context, R.attr.vctr_content_secondary))
holder.bubbleFootView.setPaddingRelative( holder.bubbleFootView.setPaddingRelative(
0, 0,
round(4*density).toInt(), holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_noverlay_padding_top),
0, 0,
-round(1.5*density).toInt() holder.bubbleFootView.resources.getDimensionPixelSize(R.dimen.sc_footer_noverlay_padding_bottom)
) )
} }
} }

View file

@ -109,10 +109,12 @@ abstract class MessageFileItem : AbsMessageItem<MessageFileItem.Holder>() {
val superVal = super.getViewStubMinimumWidth(holder, contentInBubble, showInformation) val superVal = super.getViewStubMinimumWidth(holder, contentInBubble, showInformation)
// Guess text width for name and time // Guess text width for name and time
val density = holder.filenameView.resources.displayMetrics.density
// On first call, holder.fileImageView.width is not initialized yet // On first call, holder.fileImageView.width is not initialized yet
val imageWidth = holder.fileImageView.resources.getDimensionPixelSize(R.dimen.chat_avatar_size) 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 val absoluteMinimumWidth = imageWidth*3
return max(max(absoluteMinimumWidth, minimumWidthWithText), superVal) return max(max(absoluteMinimumWidth, minimumWidthWithText), superVal)
} }

View file

@ -212,7 +212,8 @@
tools:layout_marginEnd="1dp" tools:layout_marginEnd="1dp"
tools:layout_alignBottom="@id/viewStubContainer" tools:layout_alignBottom="@id/viewStubContainer"
tools:layout_alignEnd="@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"> android:id="@+id/bubbleFootView">
<TextView <TextView
android:id="@+id/bubbleFooterMessageTimeView" android:id="@+id/bubbleFooterMessageTimeView"

View file

@ -16,5 +16,20 @@
<dimen name="sc_bubble_inner_padding_short_side">8dp</dimen> <dimen name="sc_bubble_inner_padding_short_side">8dp</dimen>
<!-- long_side = short_side + tail --> <!-- long_side = short_side + tail -->
<dimen name="sc_bubble_inner_padding_long_side">20dp</dimen> <dimen name="sc_bubble_inner_padding_long_side">20dp</dimen>
<!-- inner_padding_short_side + inner_padding_long_side (+ some extra to make sure?) -->
<dimen name="sc_bubble_guess_minimum_width_padding">32dp</dimen>
<!-- Footer dimensions -->
<dimen name="sc_footer_overlay_padding">2dp</dimen>
<dimen name="sc_footer_noverlay_padding_top">4dp</dimen>
<dimen name="sc_footer_noverlay_padding_bottom">-1.5dp</dimen>
<!-- to compensate the missing inner padding padding for the textView which we have on the other side -->
<dimen name="sc_footer_padding_compensation">4dp</dimen>
<dimen name="sc_footer_margin_start">4dp</dimen>
<dimen name="sc_footer_margin_end">1dp</dimen>
<dimen name="sc_footer_reverse_margin_start">@dimen/sc_footer_margin_end</dimen>
<!-- sc_footer_margin_start + sc_footer_padding_compensation -->
<dimen name="sc_footer_reverse_margin_end">8dp</dimen>
<dimen name="sc_footer_rtl_mismatch_extra_padding">4dp</dimen>
</resources> </resources>