diff --git a/vector/src/main/java/im/vector/app/core/ui/views/AbstractFooteredTextView.kt b/vector/src/main/java/im/vector/app/core/ui/views/AbstractFooteredTextView.kt index 85be24fcd8..01c573c740 100644 --- a/vector/src/main/java/im/vector/app/core/ui/views/AbstractFooteredTextView.kt +++ b/vector/src/main/java/im/vector/app/core/ui/views/AbstractFooteredTextView.kt @@ -26,6 +26,13 @@ interface AbstractFooteredTextView { val footerState: FooterState + var footerHeight: Int + get() = footerState.footerHeight + set(value) { footerState.footerHeight = value } + var footerWidth: Int + get() = footerState.footerWidth + set(value) { footerState.footerWidth = value } + class FooterState { var footerHeight: Int = 0 var footerWidth: Int = 0 diff --git a/vector/src/main/java/im/vector/app/core/ui/views/FooteredEditorStyledTextView.kt b/vector/src/main/java/im/vector/app/core/ui/views/FooteredEditorStyledTextView.kt index 39692cdd03..bb655d2162 100644 --- a/vector/src/main/java/im/vector/app/core/ui/views/FooteredEditorStyledTextView.kt +++ b/vector/src/main/java/im/vector/app/core/ui/views/FooteredEditorStyledTextView.kt @@ -9,8 +9,9 @@ import io.element.android.wysiwyg.EditorStyledTextView class FooteredEditorStyledTextView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, - defStyleAttr: Int = 0 -): EditorStyledTextView(context, attrs, defStyleAttr), AbstractFooteredTextView { + // Note: Upstream EditorStyledTextView only does required initialization in (context, attrs) variant + //defStyleAttr: Int = 0 +): EditorStyledTextView(context, attrs/*, defStyleAttr*/), AbstractFooteredTextView { override val footerState: AbstractFooteredTextView.FooterState = AbstractFooteredTextView.FooterState() override fun getAppCompatTextView(): AppCompatTextView = this @@ -24,7 +25,7 @@ class FooteredEditorStyledTextView @JvmOverloads constructor( setMeasuredDimension(updatedMeasures.first, updatedMeasures.second) } - override fun onDraw(canvas: Canvas?) { + override fun onDraw(canvas: Canvas) { updateFooterOnPreDraw(canvas) super.onDraw(canvas) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageAudioItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageAudioItem.kt index c6e09319bf..2e5c5ab9df 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageAudioItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageAudioItem.kt @@ -210,8 +210,10 @@ abstract class MessageAudioItem : AbsMessageItem() { } override fun reserveFooterSpace(holder: Holder, width: Int, height: Int) { - holder.captionView.footerWidth = width - holder.captionView.footerHeight = height + (holder.captionView as? AbstractFooteredTextView)?.apply { + footerWidth = width + footerHeight = height + } } override fun getViewStubId() = STUB_ID @@ -224,7 +226,7 @@ abstract class MessageAudioItem : AbsMessageItem() { val audioPlaybackTime by bind(R.id.audioPlaybackTime) val progressLayout by bind(R.id.messageFileUploadProgressLayout) val fileSize by bind(R.id.fileSize) - val captionView by bind(R.id.messageCaptionView) + val captionView by bind(R.id.messageCaptionView) val audioPlaybackDuration by bind(R.id.audioPlaybackDuration) val audioSeekBar by bind(R.id.audioSeekBar) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt index 828854f129..2b795df8de 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageFileItem.kt @@ -24,6 +24,7 @@ import android.widget.ImageView import android.widget.ProgressBar import android.widget.TextView import androidx.annotation.DrawableRes +import androidx.appcompat.widget.AppCompatTextView import androidx.core.view.isVisible import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass @@ -140,8 +141,10 @@ abstract class MessageFileItem : AbsMessageItem() { } override fun reserveFooterSpace(holder: Holder, width: Int, height: Int) { - holder.captionView.footerWidth = width - holder.captionView.footerHeight = height + (holder.captionView as? AbstractFooteredTextView)?.apply { + footerWidth = width + footerHeight = height + } } override fun getViewStubId() = STUB_ID @@ -154,7 +157,7 @@ abstract class MessageFileItem : AbsMessageItem() { val fileImageWrapper by bind(R.id.messageFileImageView) val fileDownloadProgress by bind(R.id.messageFileProgressbar) val filenameView by bind(R.id.messageFilenameView) - val captionView by bind(R.id.messageCaptionView) + val captionView by bind(R.id.messageCaptionView) } companion object { diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt index 479f5d60d5..8aed6f8ede 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageImageVideoItem.kt @@ -21,6 +21,7 @@ import android.graphics.Bitmap import android.view.View import android.view.ViewGroup import android.widget.ImageView +import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.ViewCompat import androidx.core.view.isVisible @@ -222,8 +223,10 @@ abstract class MessageImageVideoItem : AbsMessageItem(R.id.messageMediaUploadProgressLayout) val imageView by bind(R.id.messageThumbnailView) - val captionView by bind(R.id.messageCaptionView) + val captionView by bind(R.id.messageCaptionView) val playContentView by bind(R.id.messageMediaPlayView) val mediaContentView by bind(R.id.messageContentMedia) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt index 12f42780bc..8707429bb4 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageTextItem.kt @@ -100,7 +100,7 @@ abstract class MessageTextItem : AbsMessageItem() { holder.previewUrlView.delegate = previewUrlCallback holder.previewUrlView.renderMessageLayout(attributes.informationData.messageLayout) - val messageView: AbstractFooteredTextView = holder.messageView(useRichTextEditorStyle) //if (useRichTextEditorStyle) holder.richMessageView else holder.plainMessageView + val messageView: AppCompatTextView = holder.messageView(useRichTextEditorStyle) //if (useRichTextEditorStyle) holder.richMessageView else holder.plainMessageView if (useBigFont) { messageView.textSize = 44F } else { @@ -150,10 +150,10 @@ abstract class MessageTextItem : AbsMessageItem() { lateinit var previewUrlView: AbstractPreviewUrlView // set to either previewUrlViewElement or previewUrlViewSc by layout private val richMessageStub by bind(R.id.richMessageTextViewStub) private val plainMessageStub by bind(R.id.plainMessageTextViewStub) - val richMessageView: AbstractFooteredTextView by lazy { + val richMessageView: AppCompatTextView by lazy { richMessageStub.inflate().findViewById(R.id.messageTextView) } - val plainMessageView: AbstractFooteredTextView by lazy { + val plainMessageView: AppCompatTextView by lazy { plainMessageStub.inflate().findViewById(R.id.messageTextView) } fun messageView(useRichTextEditorStyle: Boolean) = if (useRichTextEditorStyle) richMessageView else plainMessageView @@ -176,13 +176,15 @@ abstract class MessageTextItem : AbsMessageItem() { ///* // disabled for now: just set all in reserveFooterSpace to ensure space in all scenarios // Currently, all states except data imply hidden preview - if (state is PreviewUrlUiState.Data) { - // Don't reserve footer space in message view, but preview view - messageView?.footerWidth = 0 - messageView?.footerHeight = 0 - } else { - messageView?.footerWidth = footerWidth - messageView?.footerHeight = footerHeight + (messageView as? AbstractFooteredTextView)?.apply { + if (state is PreviewUrlUiState.Data) { + // Don't reserve footer space in message view, but preview view + footerWidth = 0 + footerHeight = 0 + } else { + footerWidth = footerWidth + footerHeight = footerHeight + } } //messageView?.invalidate() messageView?.requestLayout() @@ -209,8 +211,10 @@ abstract class MessageTextItem : AbsMessageItem() { // This might be a race condition, but the UI-isssue if evaluated wrongly is negligible if (!holder.previewUrlView.isVisible) { val messageView = holder.messageView(useRichTextEditorStyle) - messageView.footerWidth = width - messageView.footerHeight = height + (messageView as? AbstractFooteredTextView)?.apply { + footerWidth = width + footerHeight = height + } } // else: will be handled in onStateUpdated holder.previewUrlViewSc.footerWidth = height holder.previewUrlViewSc.footerHeight = height diff --git a/vector/src/main/res/layout/item_timeline_event_text_message_rich_stub.xml b/vector/src/main/res/layout/item_timeline_event_text_message_rich_stub.xml index 23d1ffa09e..0854e49f8b 100644 --- a/vector/src/main/res/layout/item_timeline_event_text_message_rich_stub.xml +++ b/vector/src/main/res/layout/item_timeline_event_text_message_rich_stub.xml @@ -6,7 +6,7 @@ but it also makes it align better for RTL texts in RTL locales - at least until the user pill is touched... --> -