[merge] Fix build and get footered rich editor styled textView to work

Change-Id: I75876d563760caec76673372ff560cbd17577f45
This commit is contained in:
SpiritCroc 2023-02-10 12:07:15 +01:00
parent 11b1e54429
commit 254393152d
7 changed files with 45 additions and 25 deletions

View file

@ -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

View file

@ -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)

View file

@ -210,8 +210,10 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
}
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<MessageAudioItem.Holder>() {
val audioPlaybackTime by bind<TextView>(R.id.audioPlaybackTime)
val progressLayout by bind<ViewGroup>(R.id.messageFileUploadProgressLayout)
val fileSize by bind<TextView>(R.id.fileSize)
val captionView by bind<AbstractFooteredTextView>(R.id.messageCaptionView)
val captionView by bind<TextView>(R.id.messageCaptionView)
val audioPlaybackDuration by bind<TextView>(R.id.audioPlaybackDuration)
val audioSeekBar by bind<SeekBar>(R.id.audioSeekBar)
}

View file

@ -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<MessageFileItem.Holder>() {
}
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<MessageFileItem.Holder>() {
val fileImageWrapper by bind<ViewGroup>(R.id.messageFileImageView)
val fileDownloadProgress by bind<ProgressBar>(R.id.messageFileProgressbar)
val filenameView by bind<TextView>(R.id.messageFilenameView)
val captionView by bind<AbstractFooteredTextView>(R.id.messageCaptionView)
val captionView by bind<TextView>(R.id.messageCaptionView)
}
companion object {

View file

@ -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<MessageImageVideoItem.Hold
}
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 applyScBubbleStyle(messageLayout: TimelineMessageLayout.ScBubble, holder: Holder) {
@ -253,7 +256,7 @@ abstract class MessageImageVideoItem : AbsMessageItem<MessageImageVideoItem.Hold
class Holder : AbsMessageItem.Holder(STUB_ID) {
val progressLayout by bind<ViewGroup>(R.id.messageMediaUploadProgressLayout)
val imageView by bind<ImageView>(R.id.messageThumbnailView)
val captionView by bind<AbstractFooteredTextView>(R.id.messageCaptionView)
val captionView by bind<TextView>(R.id.messageCaptionView)
val playContentView by bind<ImageView>(R.id.messageMediaPlayView)
val mediaContentView by bind<ViewGroup>(R.id.messageContentMedia)
}

View file

@ -100,7 +100,7 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
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<MessageTextItem.Holder>() {
lateinit var previewUrlView: AbstractPreviewUrlView // set to either previewUrlViewElement or previewUrlViewSc by layout
private val richMessageStub by bind<ViewStub>(R.id.richMessageTextViewStub)
private val plainMessageStub by bind<ViewStub>(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<MessageTextItem.Holder>() {
///* // 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<MessageTextItem.Holder>() {
// 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

View file

@ -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...
-->
<io.element.android.wysiwyg.EditorStyledTextView
<im.vector.app.core.ui.views.FooteredEditorStyledTextView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/messageTextView"