For bottom timestamps, we can hide member names also when hiding avatars

Member names not really important in direct chats or for outgoing
messages.

Change-Id: I1d3328444daf571488b1d9b4d2d188d695c515b3
This commit is contained in:
SpiritCroc 2020-11-02 10:40:30 +01:00
parent 0b2d98b116
commit be2983053a

View file

@ -64,11 +64,13 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
val contentInBubble = infoInBubbles(holder.memberNameView.context) val contentInBubble = infoInBubbles(holder.memberNameView.context)
val avatarImageView: ImageView? val avatarImageView: ImageView?
val memberNameView: TextView? var memberNameView: TextView?
var timeView: TextView? var timeView: TextView?
val hiddenViews = ArrayList<View>() val hiddenViews = ArrayList<View>()
val invisibleViews = ArrayList<View>() val invisibleViews = ArrayList<View>()
val avatarUnnecessary = canHideAvatars()
// Select which views are visible, based on bubble style and other criteria // Select which views are visible, based on bubble style and other criteria
if (attributes.informationData.showInformation) { if (attributes.informationData.showInformation) {
if (contentInBubble) { if (contentInBubble) {
@ -114,8 +116,15 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
if (BubbleThemeUtils.getBubbleTimeLocation(holder.bubbleTimeView.context) == BubbleThemeUtils.BUBBLE_TIME_BOTTOM) { if (BubbleThemeUtils.getBubbleTimeLocation(holder.bubbleTimeView.context) == BubbleThemeUtils.BUBBLE_TIME_BOTTOM) {
timeView = holder.bubbleFooterTimeView timeView = holder.bubbleFooterTimeView
if (attributes.informationData.showInformation) { if (attributes.informationData.showInformation) {
// Don't hide, so our relative layout rules still work if (avatarUnnecessary) {
invisibleViews.add(holder.bubbleTimeView) // In the case of footer time, we can also hide the names without making it look awkward
hiddenViews.add(holder.bubbleMemberNameView)
memberNameView = null
hiddenViews.add(holder.bubbleTimeView)
} else {
// Don't completely remove, just hide, so our relative layout rules still work
invisibleViews.add(holder.bubbleTimeView)
}
} else { } else {
// Do hide, or we accidentally reserve space // Do hide, or we accidentally reserve space
hiddenViews.add(holder.bubbleTimeView) hiddenViews.add(holder.bubbleTimeView)
@ -127,7 +136,7 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
// Dual-side bubbles: hide own avatar, and all in direct chats // Dual-side bubbles: hide own avatar, and all in direct chats
if ((!attributes.informationData.showInformation) || if ((!attributes.informationData.showInformation) ||
(contentInBubble && (attributes.informationData.sentByMe || attributes.informationData.isDirect))) { (contentInBubble && avatarUnnecessary)) {
avatarImageView = null avatarImageView = null
hiddenViews.add(holder.avatarImageView) hiddenViews.add(holder.avatarImageView)
} else { } else {
@ -293,6 +302,10 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
open fun reserveFooterSpace(holder: H, width: Int, height: Int) { open fun reserveFooterSpace(holder: H, width: Int, height: Int) {
} }
open fun canHideAvatars(): Boolean {
return attributes.informationData.sentByMe || attributes.informationData.isDirect
}
override fun setBubbleLayout(holder: H, bubbleStyle: String, bubbleStyleSetting: String, reverseBubble: Boolean) { override fun setBubbleLayout(holder: H, bubbleStyle: String, bubbleStyleSetting: String, reverseBubble: Boolean) {
super.setBubbleLayout(holder, bubbleStyle, bubbleStyleSetting, reverseBubble) super.setBubbleLayout(holder, bubbleStyle, bubbleStyleSetting, reverseBubble)