Epoxy : timeline messages to holder WIP

This commit is contained in:
ganfra 2019-02-19 11:57:17 +01:00
parent 5c78991ae1
commit c977c651a2
5 changed files with 64 additions and 49 deletions

View file

@ -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<H : AbsMessageItem.Holder> : EpoxyModelWithHolder<H>() {
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
}
}

View file

@ -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<MessageImageItem.Holder>() {
@EpoxyAttribute lateinit var mediaData: MediaContentRenderer.Data
@EpoxyAttribute override lateinit var informationData: MessageInformationData
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<ImageView>(R.id.messageAvatarImageView)
override val memberNameView by bind<TextView>(R.id.messageMemberNameView)
override val timeView by bind<TextView>(R.id.messageTimeView)
private val imageView by bind<ImageView>(R.id.messageImageView)
override fun bind() {
super.bind()
MediaContentRenderer.render(mediaData, MediaContentRenderer.Mode.THUMBNAIL, imageView)
val imageView by bind<ImageView>(R.id.messageImageView)
}
}

View file

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

View file

@ -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<MessageTextItem.Holder>() {
@EpoxyAttribute var message: CharSequence? = null
@EpoxyAttribute override lateinit var informationData: MessageInformationData
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<ImageView>(R.id.messageAvatarImageView)
override val memberNameView by bind<TextView>(R.id.messageMemberNameView)
override val timeView by bind<TextView>(R.id.messageTimeView)
private val messageView by bind<TextView>(R.id.messageTextView)
val messageView by bind<TextView>(R.id.messageTextView)
}
override fun bind() {
super.bind()
messageView.text = message
MatrixLinkify.addLinkMovementMethod(messageView)
}
}

View file

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