mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-28 05:59:05 +03:00
Better determine MessageFileItem width
This commit is contained in:
parent
d8e5697168
commit
02e3e2b12e
3 changed files with 33 additions and 14 deletions
|
@ -115,15 +115,7 @@ abstract class AbsMessageItem<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
|
|||
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<H : AbsMessageItem.Holder> : AbsBaseMessageItem<H>
|
|||
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
|
||||
}
|
||||
|
|
|
@ -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<MessageFileItem.Holder>() {
|
||||
|
@ -55,8 +57,6 @@ abstract class MessageFileItem : AbsMessageItem<MessageFileItem.Holder>() {
|
|||
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<MessageFileItem.Holder>() {
|
|||
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<ViewGroup>(R.id.messageFileUploadProgressLayout)
|
||||
val fileLayout by bind<ViewGroup>(R.id.messageFileLayout)
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue