Uniform bubble width in group chats

Previously, we had a fixed margin for bubbles to the other side.
However, in group chats, we currently display avatars on one side and
not on the other, which leads to inhomogeneous message bubbles widths.

This patch leaves the width for direct chats unchanged, but adapts the
widths in group chats as following:
- Incoming messages a little bit wider, as these already are "missing"
  the avatar space.
- Outgoin messages a little bit narrower, so we have a more homogeneous
  look in group chats, and also do not start nearly at the same x-offset
  as incoming messages.

Closes https://github.com/SchildiChat/SchildiChat-android/issues/42.

Change-Id: Ic5391f1d512d4425ce4694182049ba0630ec9498
This commit is contained in:
SpiritCroc 2021-01-16 14:24:48 +01:00
parent aca8715ec8
commit e58a13ea91
3 changed files with 23 additions and 5 deletions

View file

@ -294,7 +294,21 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
return when (bubbleStyle) {
BubbleThemeUtils.BUBBLE_STYLE_START,
BubbleThemeUtils.BUBBLE_STYLE_START_HIDDEN -> 0
else -> resources.getDimensionPixelSize(R.dimen.dual_bubble_other_side_margin)
// else: dual-side bubbles (getBubbleMargin should not get called for other bubbleStyles)
else -> {
when {
// Direct chats usually have avatars hidden on both sides
attributes.informationData.isDirect -> resources.getDimensionPixelSize(R.dimen.dual_bubble_both_sides_without_avatar_margin)
// No direct chat, but sent by me: other side has an avatar
attributes.informationData.sentByMe -> {
resources.getDimensionPixelSize(R.dimen.dual_bubble_one_side_without_avatar_margin) +
resources.getDimensionPixelSize(R.dimen.dual_bubble_one_side_avatar_offset) +
attributes.avatarSize
}
// No direct chat, sent by other: my side has hidden avatar
else -> resources.getDimensionPixelSize(R.dimen.dual_bubble_one_side_without_avatar_margin)
}
}
}
}
@ -309,7 +323,7 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
open fun reserveFooterSpace(holder: H, width: Int, height: Int) {
}
open fun canHideAvatars(): Boolean {
private fun canHideAvatars(): Boolean {
return attributes.informationData.sentByMe ||
(attributes.informationData.isDirect && attributes.informationData.senderId == attributes.informationData.dmChatPartnerId)
}

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="dual_bubble_other_side_margin">96dp</dimen>
<dimen name="dual_bubble_one_side_without_avatar_margin">80dp</dimen>
<dimen name="dual_bubble_both_sides_without_avatar_margin">96dp</dimen>
</resources>
</resources>

View file

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="dual_bubble_other_side_margin">48dp</dimen>
<dimen name="dual_bubble_one_side_without_avatar_margin">32dp</dimen>
<dimen name="dual_bubble_both_sides_without_avatar_margin">48dp</dimen>
<!-- messageAvatarImageView.marginStart -->
<dimen name="dual_bubble_one_side_avatar_offset">8dp</dimen>
</resources>