From c977c651a24bf048a2e8fc8d638ebbfaa3cf5af1 Mon Sep 17 00:00:00 2001 From: ganfra Date: Tue, 19 Feb 2019 11:57:17 +0100 Subject: [PATCH] Epoxy : timeline messages to holder WIP --- .../room/detail/timeline/AbsMessageItem.kt | 38 ++++++++++--------- .../room/detail/timeline/MessageImageItem.kt | 26 +++++++------ .../detail/timeline/MessageItemFactory.kt | 14 ++++--- .../room/detail/timeline/MessageTextItem.kt | 31 +++++++++------ .../detail/timeline/TimelineItemFactory.kt | 4 +- 5 files changed, 64 insertions(+), 49 deletions(-) diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/AbsMessageItem.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/AbsMessageItem.kt index fb10badb..3127cb5b 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/AbsMessageItem.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/AbsMessageItem.kt @@ -19,31 +19,33 @@ package im.vector.riotredesign.features.home.room.detail.timeline import android.view.View import android.widget.ImageView import android.widget.TextView -import androidx.annotation.LayoutRes -import im.vector.riotredesign.core.epoxy.KotlinModel +import com.airbnb.epoxy.EpoxyModelWithHolder +import im.vector.riotredesign.core.epoxy.KotlinEpoxyHolder import im.vector.riotredesign.features.home.AvatarRenderer -abstract class AbsMessageItem(private val informationData: MessageInformationData, - @LayoutRes layoutRes: Int -) : KotlinModel(layoutRes) { +abstract class AbsMessageItem : EpoxyModelWithHolder() { - protected abstract val avatarImageView: ImageView - protected abstract val memberNameView: TextView - protected abstract val timeView: TextView + abstract val informationData: MessageInformationData - override fun bind() { + override fun bind(holder: H) { if (informationData.showInformation) { - avatarImageView.visibility = View.VISIBLE - memberNameView.visibility = View.VISIBLE - timeView.visibility = View.VISIBLE - timeView.text = informationData.time - memberNameView.text = informationData.memberName - AvatarRenderer.render(informationData.avatarUrl, informationData.memberName?.toString(), avatarImageView) + holder.avatarImageView.visibility = View.VISIBLE + holder.memberNameView.visibility = View.VISIBLE + holder.timeView.visibility = View.VISIBLE + holder.timeView.text = informationData.time + holder.memberNameView.text = informationData.memberName + AvatarRenderer.render(informationData.avatarUrl, informationData.memberName?.toString(), holder.avatarImageView) } else { - avatarImageView.visibility = View.GONE - memberNameView.visibility = View.GONE - timeView.visibility = View.GONE + holder.avatarImageView.visibility = View.GONE + holder.memberNameView.visibility = View.GONE + holder.timeView.visibility = View.GONE } } + abstract class Holder : KotlinEpoxyHolder() { + abstract val avatarImageView: ImageView + abstract val memberNameView: TextView + abstract val timeView: TextView + } + } \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageImageItem.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageImageItem.kt index dc93c89d..310ffd46 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageImageItem.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageImageItem.kt @@ -18,23 +18,27 @@ package im.vector.riotredesign.features.home.room.detail.timeline import android.widget.ImageView import android.widget.TextView +import com.airbnb.epoxy.EpoxyAttribute +import com.airbnb.epoxy.EpoxyModelClass import im.vector.riotredesign.R import im.vector.riotredesign.features.media.MediaContentRenderer -class MessageImageItem( - private val mediaData: MediaContentRenderer.Data, - informationData: MessageInformationData -) : AbsMessageItem(informationData, R.layout.item_timeline_event_image_message) { +@EpoxyModelClass(layout = R.layout.item_timeline_event_image_message) +abstract class MessageImageItem : AbsMessageItem() { - override val avatarImageView by bind(R.id.messageAvatarImageView) - override val memberNameView by bind(R.id.messageMemberNameView) - override val timeView by bind(R.id.messageTimeView) - private val imageView by bind(R.id.messageImageView) + @EpoxyAttribute lateinit var mediaData: MediaContentRenderer.Data + @EpoxyAttribute override lateinit var informationData: MessageInformationData - override fun bind() { - super.bind() - MediaContentRenderer.render(mediaData, MediaContentRenderer.Mode.THUMBNAIL, imageView) + override fun bind(holder: Holder) { + super.bind(holder) + MediaContentRenderer.render(mediaData, MediaContentRenderer.Mode.THUMBNAIL, holder.imageView) } + class Holder : AbsMessageItem.Holder() { + override val avatarImageView by bind(R.id.messageAvatarImageView) + override val memberNameView by bind(R.id.messageMemberNameView) + override val timeView by bind(R.id.messageTimeView) + val imageView by bind(R.id.messageImageView) + } } \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt index 314bf774..ba57c086 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageItemFactory.kt @@ -18,6 +18,7 @@ package im.vector.riotredesign.features.home.room.detail.timeline import android.text.SpannableStringBuilder import android.text.util.Linkify +import com.airbnb.epoxy.EpoxyModel import im.vector.matrix.android.api.permalinks.MatrixLinkify import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan import im.vector.matrix.android.api.session.events.model.EventType @@ -39,7 +40,7 @@ class MessageItemFactory(private val timelineMediaSizeProvider: TimelineMediaSiz fun create(event: TimelineEvent, nextEvent: TimelineEvent?, callback: TimelineEventController.Callback? - ): KotlinModel? { + ): EpoxyModel<*>? { val roomMember = event.roomMember val nextRoomMember = nextEvent?.roomMember @@ -89,7 +90,9 @@ class MessageItemFactory(private val timelineMediaSizeProvider: TimelineMediaSiz rotation = messageContent.info?.rotation, orientation = messageContent.info?.orientation ) - return MessageImageItem(data, informationData) + return MessageImageItem_() + .informationData(informationData) + .mediaData(data) } private fun buildTextMessageItem(messageContent: MessageTextContent, @@ -106,10 +109,9 @@ class MessageItemFactory(private val timelineMediaSizeProvider: TimelineMediaSiz Linkify.addLinks(spannable, Linkify.ALL) spannable } - return MessageTextItem( - message = message, - informationData = informationData - ) + return MessageTextItem_() + .message(message) + .informationData(informationData) } diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageTextItem.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageTextItem.kt index 20446329..8265313d 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageTextItem.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/MessageTextItem.kt @@ -18,22 +18,29 @@ package im.vector.riotredesign.features.home.room.detail.timeline import android.widget.ImageView import android.widget.TextView +import com.airbnb.epoxy.EpoxyAttribute +import com.airbnb.epoxy.EpoxyModelClass import im.vector.matrix.android.api.permalinks.MatrixLinkify import im.vector.riotredesign.R -class MessageTextItem( - val message: CharSequence? = null, - informationData: MessageInformationData -) : AbsMessageItem(informationData, R.layout.item_timeline_event_text_message) { +@EpoxyModelClass(layout = R.layout.item_timeline_event_text_message) +abstract class MessageTextItem : AbsMessageItem() { - override val avatarImageView by bind(R.id.messageAvatarImageView) - override val memberNameView by bind(R.id.messageMemberNameView) - override val timeView by bind(R.id.messageTimeView) - private val messageView by bind(R.id.messageTextView) + @EpoxyAttribute var message: CharSequence? = null + @EpoxyAttribute override lateinit var informationData: MessageInformationData - override fun bind() { - super.bind() - messageView.text = message - MatrixLinkify.addLinkMovementMethod(messageView) + override fun bind(holder: Holder) { + super.bind(holder) + holder.messageView.text = message + MatrixLinkify.addLinkMovementMethod(holder.messageView) } + + class Holder : AbsMessageItem.Holder() { + override val avatarImageView by bind(R.id.messageAvatarImageView) + override val memberNameView by bind(R.id.messageMemberNameView) + override val timeView by bind(R.id.messageTimeView) + val messageView by bind(R.id.messageTextView) + } + + } \ No newline at end of file diff --git a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineItemFactory.kt b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineItemFactory.kt index 83a41cf6..4becea35 100644 --- a/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineItemFactory.kt +++ b/app/src/main/java/im/vector/riotredesign/features/home/room/detail/timeline/TimelineItemFactory.kt @@ -16,9 +16,9 @@ package im.vector.riotredesign.features.home.room.detail.timeline +import com.airbnb.epoxy.EpoxyModel import im.vector.matrix.android.api.session.events.model.EventType import im.vector.matrix.android.api.session.room.timeline.TimelineEvent -import im.vector.riotredesign.core.epoxy.KotlinModel class TimelineItemFactory(private val messageItemFactory: MessageItemFactory, private val roomNameItemFactory: RoomNameItemFactory, @@ -28,7 +28,7 @@ class TimelineItemFactory(private val messageItemFactory: MessageItemFactory, fun create(event: TimelineEvent, nextEvent: TimelineEvent?, - callback: TimelineEventController.Callback?): KotlinModel? { + callback: TimelineEventController.Callback?): EpoxyModel<*>? { return try { when (event.root.type) {