preventMutation is not needed anymore, since we now uses EpoxyCharSequence

This commit is contained in:
Benoit Marty 2022-01-03 14:17:29 +01:00 committed by Benoit Marty
parent ca44d8f4d8
commit 27161bf794
7 changed files with 5 additions and 51 deletions

View file

@ -108,7 +108,6 @@ class SpanUtilsTest : InstrumentedTest {
val string = SpannableString("Text")
val result = spanUtils.getBindingOptions(string)
result.canUseTextFuture shouldBeEqualTo true
result.preventMutation shouldBeEqualTo false
}
@Test
@ -117,7 +116,6 @@ class SpanUtilsTest : InstrumentedTest {
string.setSpan(StrikethroughSpan(), 10, 23, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
val result = spanUtils.getBindingOptions(string)
result.canUseTextFuture shouldBeEqualTo false
result.preventMutation shouldBeEqualTo false
}
@Test
@ -125,7 +123,6 @@ class SpanUtilsTest : InstrumentedTest {
val string = SpannableString("Emoji \uD83D\uDE2E\u200D\uD83D\uDCA8")
val result = spanUtils.getBindingOptions(string)
result.canUseTextFuture shouldBeEqualTo false
result.preventMutation shouldBeEqualTo true
}
private fun trueIfAlwaysAllowed() = Build.VERSION.SDK_INT < Build.VERSION_CODES.P

View file

@ -28,14 +28,12 @@ import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.VectorEpoxyModel
import im.vector.app.core.epoxy.charsequence.EpoxyCharSequence
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.epoxy.util.preventMutation
import im.vector.app.core.extensions.setTextOrHide
import im.vector.app.features.displayname.getBestName
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.detail.timeline.item.BindingOptions
import im.vector.app.features.home.room.detail.timeline.tools.findPillsAndProcess
import im.vector.app.features.media.ImageContentRenderer
import org.matrix.android.sdk.api.extensions.orFalse
import org.matrix.android.sdk.api.util.MatrixItem
/**
@ -85,11 +83,7 @@ abstract class BottomSheetMessagePreviewItem : VectorEpoxyModel<BottomSheetMessa
}
holder.imagePreview.isVisible = data != null
holder.body.movementMethod = movementMethod
holder.body.text = if (bindingOptions?.preventMutation.orFalse()) {
body.charSequence.preventMutation()
} else {
body.charSequence
}
holder.body.text = body.charSequence
holder.bodyDetails.setTextOrHide(bodyDetails?.charSequence)
body.charSequence.findPillsAndProcess(coroutineScope) { it.bind(holder.body) }
holder.timestamp.setTextOrHide(time)

View file

@ -1,21 +0,0 @@
/*
* Copyright (c) 2021 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.core.epoxy.util
import android.text.SpannableString
fun CharSequence?.preventMutation(): CharSequence? = this?.let { SpannableString(it) }

View file

@ -18,7 +18,5 @@ package im.vector.app.features.home.room.detail.timeline.item
data class BindingOptions(
// Allowed by default
val canUseTextFuture: Boolean = true,
// No need to prevent mutation by default
val preventMutation: Boolean = false
val canUseTextFuture: Boolean = true
)

View file

@ -27,7 +27,6 @@ import im.vector.app.R
import im.vector.app.core.epoxy.charsequence.EpoxyCharSequence
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.epoxy.onLongClickIgnoringLinks
import im.vector.app.core.epoxy.util.preventMutation
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
import im.vector.app.features.home.room.detail.timeline.tools.findPillsAndProcess
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever
@ -105,11 +104,7 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
if (bindingOptions?.canUseTextFuture.orFalse()) {
holder.messageView.setTextFuture(textFuture)
} else {
holder.messageView.text = if (bindingOptions?.preventMutation.orFalse()) {
message?.charSequence.preventMutation()
} else {
message?.charSequence
}
holder.messageView.text = message?.charSequence
}
}

View file

@ -26,7 +26,6 @@ import im.vector.app.core.epoxy.ClickListener
import im.vector.app.core.epoxy.VectorEpoxyHolder
import im.vector.app.core.epoxy.charsequence.EpoxyCharSequence
import im.vector.app.core.epoxy.onClick
import im.vector.app.core.epoxy.util.preventMutation
/**
* Item displaying an emoji reaction (single line with emoji, author, time)
@ -48,7 +47,7 @@ abstract class ReactionInfoSimpleItem : EpoxyModelWithHolder<ReactionInfoSimpleI
override fun bind(holder: Holder) {
super.bind(holder)
holder.emojiReactionView.text = reactionKey.charSequence.preventMutation()
holder.emojiReactionView.text = reactionKey.charSequence
holder.displayNameView.text = authorDisplayName
timeStamp?.let {
holder.timeStampView.text = it

View file

@ -35,8 +35,7 @@ class SpanUtils @Inject constructor(
}
return BindingOptions(
canUseTextFuture = canUseTextFuture(emojiCharSequence),
preventMutation = mustPreventMutation(emojiCharSequence)
canUseTextFuture = canUseTextFuture(emojiCharSequence)
)
}
@ -49,11 +48,4 @@ class SpanUtils @Inject constructor(
.getSpans(0, spanned.length, Any::class.java)
.all { it !is StrikethroughSpan && it !is UnderlineSpan && it !is MetricAffectingSpan }
}
// Workaround for setting text during binding which mutate the text itself
private fun mustPreventMutation(spanned: Spanned): Boolean {
return spanned
.getSpans(0, spanned.length, Any::class.java)
.any { it is MetricAffectingSpan }
}
}