Make url clickable on the preview of event in the bottom sheet - avoid instantiating objects in the bind() method
This commit is contained in:
parent
6d7f2670df
commit
c69852c849
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package im.vector.riotx.core.epoxy.bottomsheet
|
||||
|
||||
import android.text.method.MovementMethod
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
|
@ -25,8 +26,6 @@ import im.vector.riotx.core.epoxy.VectorEpoxyHolder
|
|||
import im.vector.riotx.core.epoxy.VectorEpoxyModel
|
||||
import im.vector.riotx.core.extensions.setTextOrHide
|
||||
import im.vector.riotx.features.home.AvatarRenderer
|
||||
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.riotx.features.home.room.detail.timeline.tools.createLinkMovementMethod
|
||||
import im.vector.riotx.features.home.room.detail.timeline.tools.findPillsAndProcess
|
||||
|
||||
/**
|
||||
|
@ -48,12 +47,12 @@ abstract class BottomSheetItemMessagePreview : VectorEpoxyModel<BottomSheetItemM
|
|||
@EpoxyAttribute
|
||||
var time: CharSequence? = null
|
||||
@EpoxyAttribute
|
||||
var urlClickCallback: TimelineEventController.UrlClickCallback? = null
|
||||
var movementMethod: MovementMethod? = null
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
avatarRenderer.render(avatarUrl, senderId, senderName, holder.avatar)
|
||||
holder.sender.setTextOrHide(senderName)
|
||||
holder.body.movementMethod = createLinkMovementMethod(urlClickCallback)
|
||||
holder.body.movementMethod = movementMethod
|
||||
holder.body.text = body
|
||||
body.findPillsAndProcess { it.bind(holder.body) }
|
||||
holder.timestamp.setTextOrHide(time)
|
||||
|
|
|
@ -24,6 +24,7 @@ import im.vector.riotx.core.epoxy.bottomsheet.*
|
|||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.features.home.AvatarRenderer
|
||||
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.riotx.features.home.room.detail.timeline.tools.createLinkMovementMethod
|
||||
import im.vector.riotx.features.home.room.detail.timeline.tools.linkify
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -46,7 +47,7 @@ class MessageActionsEpoxyController @Inject constructor(private val stringProvid
|
|||
avatarUrl(state.informationData.avatarUrl ?: "")
|
||||
senderId(state.informationData.senderId)
|
||||
senderName(state.senderName())
|
||||
urlClickCallback(listener)
|
||||
movementMethod(createLinkMovementMethod(listener))
|
||||
body(body.linkify(listener))
|
||||
time(state.time())
|
||||
}
|
||||
|
|
|
@ -25,9 +25,10 @@ import im.vector.riotx.core.resources.ColorProvider
|
|||
import im.vector.riotx.core.resources.StringProvider
|
||||
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.riotx.features.home.room.detail.timeline.helper.AvatarSizeProvider
|
||||
import im.vector.riotx.features.home.room.detail.timeline.item.MessageTextItem_
|
||||
import im.vector.riotx.features.home.room.detail.timeline.helper.MessageInformationDataFactory
|
||||
import im.vector.riotx.features.home.room.detail.timeline.helper.MessageItemAttributesFactory
|
||||
import im.vector.riotx.features.home.room.detail.timeline.item.MessageTextItem_
|
||||
import im.vector.riotx.features.home.room.detail.timeline.tools.createLinkMovementMethod
|
||||
import me.gujun.android.span.span
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -57,7 +58,7 @@ class EncryptedItemFactory @Inject constructor(private val messageInformationDat
|
|||
}
|
||||
|
||||
val message = stringProvider.getString(R.string.encrypted_message).takeIf { cryptoError == null }
|
||||
?: stringProvider.getString(R.string.notice_crypto_unable_to_decrypt, errorDescription)
|
||||
?: stringProvider.getString(R.string.notice_crypto_unable_to_decrypt, errorDescription)
|
||||
val spannableStr = span(message) {
|
||||
textStyle = "italic"
|
||||
textColor = colorProvider.getColorFromAttribute(R.attr.riotx_text_secondary)
|
||||
|
@ -72,7 +73,7 @@ class EncryptedItemFactory @Inject constructor(private val messageInformationDat
|
|||
.highlighted(highlight)
|
||||
.attributes(attributes)
|
||||
.message(spannableStr)
|
||||
.urlClickCallback(callback)
|
||||
.movementMethod(createLinkMovementMethod(callback))
|
||||
}
|
||||
else -> null
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import im.vector.riotx.core.utils.isLocalFile
|
|||
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.riotx.features.home.room.detail.timeline.helper.*
|
||||
import im.vector.riotx.features.home.room.detail.timeline.item.*
|
||||
import im.vector.riotx.features.home.room.detail.timeline.tools.createLinkMovementMethod
|
||||
import im.vector.riotx.features.home.room.detail.timeline.tools.linkify
|
||||
import im.vector.riotx.features.html.CodeVisitor
|
||||
import im.vector.riotx.features.html.EventHtmlRenderer
|
||||
|
@ -270,7 +271,7 @@ class MessageItemFactory @Inject constructor(
|
|||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||
.attributes(attributes)
|
||||
.highlighted(highlight)
|
||||
.urlClickCallback(callback)
|
||||
.movementMethod(createLinkMovementMethod(callback))
|
||||
}
|
||||
|
||||
private fun buildCodeBlockItem(formattedBody: CharSequence,
|
||||
|
@ -348,7 +349,7 @@ class MessageItemFactory @Inject constructor(
|
|||
.attributes(attributes)
|
||||
.message(message)
|
||||
.highlighted(highlight)
|
||||
.urlClickCallback(callback)
|
||||
.movementMethod(createLinkMovementMethod(callback))
|
||||
}
|
||||
|
||||
private fun buildEmoteMessageItem(messageContent: MessageEmoteContent,
|
||||
|
@ -372,7 +373,7 @@ class MessageItemFactory @Inject constructor(
|
|||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||
.attributes(attributes)
|
||||
.highlighted(highlight)
|
||||
.urlClickCallback(callback)
|
||||
.movementMethod(createLinkMovementMethod(callback))
|
||||
}
|
||||
|
||||
private fun buildRedactedItem(attributes: AbsMessageItem.Attributes,
|
||||
|
|
|
@ -16,14 +16,13 @@
|
|||
|
||||
package im.vector.riotx.features.home.room.detail.timeline.item
|
||||
|
||||
import android.text.method.MovementMethod
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.core.text.PrecomputedTextCompat
|
||||
import androidx.core.widget.TextViewCompat
|
||||
import com.airbnb.epoxy.EpoxyAttribute
|
||||
import com.airbnb.epoxy.EpoxyModelClass
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
|
||||
import im.vector.riotx.features.home.room.detail.timeline.tools.createLinkMovementMethod
|
||||
import im.vector.riotx.features.home.room.detail.timeline.tools.findPillsAndProcess
|
||||
|
||||
@EpoxyModelClass(layout = R.layout.item_timeline_event_base)
|
||||
|
@ -36,11 +35,11 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
|
|||
@EpoxyAttribute
|
||||
var useBigFont: Boolean = false
|
||||
@EpoxyAttribute
|
||||
var urlClickCallback: TimelineEventController.UrlClickCallback? = null
|
||||
var movementMethod: MovementMethod? = null
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
holder.messageView.movementMethod = createLinkMovementMethod(urlClickCallback)
|
||||
holder.messageView.movementMethod = movementMethod
|
||||
if (useBigFont) {
|
||||
holder.messageView.textSize = 44F
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue