diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt index 5db26212ec..17f63e5d6b 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/AbsMessageItem.kt @@ -115,15 +115,7 @@ abstract class AbsMessageItem : AbsBaseMessageItem holder.bubbleMemberNameView.setOnLongClickListener(null) } } - if (contentInBubble && attributes.informationData.showInformation) { - // Guess text width for name and time - val text = holder.bubbleMemberNameView.text.toString() + " " + holder.bubbleTimeView.text.toString() - val paint = Paint() - paint.textSize = max(holder.bubbleMemberNameView.textSize, holder.bubbleTimeView.textSize) - holder.viewStubContainer.minimumWidth = round(paint.measureText(text)).toInt() - } else { - holder.viewStubContainer.minimumWidth = 0 - } + holder.viewStubContainer.minimumWidth = getViewStubMinimumWidth(holder, contentInBubble, attributes.informationData.showInformation) updateMessageBubble(holder) } @@ -164,6 +156,18 @@ abstract class AbsMessageItem : AbsBaseMessageItem return false } + open fun getViewStubMinimumWidth(holder: H, contentInBubble: Boolean, showInformation: Boolean): Int { + return if (contentInBubble && attributes.informationData.showInformation) { + // Guess text width for name and time + val text = holder.bubbleMemberNameView.text.toString() + " " + holder.bubbleTimeView.text.toString() + val paint = Paint() + paint.textSize = max(holder.bubbleMemberNameView.textSize, holder.bubbleTimeView.textSize) + round(paint.measureText(text)).toInt() + } else { + 0 + } + } + fun infoInBubbles(context: Context): Boolean { return messageBubbleAllowed() && BubbleThemeUtils.getBubbleStyle(context) == BubbleThemeUtils.BUBBLE_STYLE_BOTH } diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt index b0fdcc0e2a..81c87a171d 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/MessageFileItem.kt @@ -27,6 +27,8 @@ import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass import im.vector.riotx.R import im.vector.riotx.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder +import kotlin.math.max +import kotlin.math.round @EpoxyModelClass(layout = R.layout.item_timeline_event_base) abstract class MessageFileItem : AbsMessageItem() { @@ -55,8 +57,6 @@ abstract class MessageFileItem : AbsMessageItem() { holder.fileImageView.setImageResource(iconRes) holder.filenameView.setOnClickListener(clickListener) holder.filenameView.paintFlags = (holder.filenameView.paintFlags or Paint.UNDERLINE_TEXT_FLAG) - // TODO calculate minimum width - holder.viewStubContainer.minimumWidth = 2000 } override fun unbind(holder: Holder) { @@ -70,6 +70,20 @@ abstract class MessageFileItem : AbsMessageItem() { return true } + override fun getViewStubMinimumWidth(holder: Holder, contentInBubble: Boolean, showInformation: Boolean): Int { + val superVal = super.getViewStubMinimumWidth(holder, contentInBubble, showInformation) + + // Guess text width for name and time + val paint = Paint() + paint.textSize = holder.filenameView.textSize + 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 = round(paint.measureText(filename.toString())).toInt() + imageWidth + 32*density.toInt() + val absoluteMinimumWidth = imageWidth*3 + return max(max(absoluteMinimumWidth, minimumWidthWithText), superVal) + } + class Holder : AbsMessageItem.Holder(STUB_ID) { val progressLayout by bind(R.id.messageFileUploadProgressLayout) val fileLayout by bind(R.id.messageFileLayout) diff --git a/vector/src/main/res/layout/item_timeline_event_file_stub.xml b/vector/src/main/res/layout/item_timeline_event_file_stub.xml index 1c185ca973..bf2520bb76 100644 --- a/vector/src/main/res/layout/item_timeline_event_file_stub.xml +++ b/vector/src/main/res/layout/item_timeline_event_file_stub.xml @@ -36,7 +36,8 @@ android:layout_height="wrap_content" android:layout_marginStart="4dp" android:layout_marginLeft="4dp" - android:layout_marginEnd="32dp" + android:layout_marginEnd="4dp" + android:layout_marginRight="4dp" android:autoLink="none" android:gravity="center_vertical" android:minHeight="@dimen/chat_avatar_size" @@ -58,8 +59,8 @@ android:layout_width="0dp" android:layout_height="46dp" android:layout_marginTop="8dp" - android:layout_marginEnd="32dp" - android:layout_marginRight="32dp" + android:layout_marginEnd="4dp" + android:layout_marginRight="4dp" android:visibility="gone" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent"