Epoxy : timeline messages to holder WIP
This commit is contained in:
parent
5c78991ae1
commit
c977c651a2
@ -19,31 +19,33 @@ package im.vector.riotredesign.features.home.room.detail.timeline
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.annotation.LayoutRes
|
import com.airbnb.epoxy.EpoxyModelWithHolder
|
||||||
import im.vector.riotredesign.core.epoxy.KotlinModel
|
import im.vector.riotredesign.core.epoxy.KotlinEpoxyHolder
|
||||||
import im.vector.riotredesign.features.home.AvatarRenderer
|
import im.vector.riotredesign.features.home.AvatarRenderer
|
||||||
|
|
||||||
abstract class AbsMessageItem(private val informationData: MessageInformationData,
|
abstract class AbsMessageItem<H : AbsMessageItem.Holder> : EpoxyModelWithHolder<H>() {
|
||||||
@LayoutRes layoutRes: Int
|
|
||||||
) : KotlinModel(layoutRes) {
|
|
||||||
|
|
||||||
protected abstract val avatarImageView: ImageView
|
abstract val informationData: MessageInformationData
|
||||||
protected abstract val memberNameView: TextView
|
|
||||||
protected abstract val timeView: TextView
|
|
||||||
|
|
||||||
override fun bind() {
|
override fun bind(holder: H) {
|
||||||
if (informationData.showInformation) {
|
if (informationData.showInformation) {
|
||||||
avatarImageView.visibility = View.VISIBLE
|
holder.avatarImageView.visibility = View.VISIBLE
|
||||||
memberNameView.visibility = View.VISIBLE
|
holder.memberNameView.visibility = View.VISIBLE
|
||||||
timeView.visibility = View.VISIBLE
|
holder.timeView.visibility = View.VISIBLE
|
||||||
timeView.text = informationData.time
|
holder.timeView.text = informationData.time
|
||||||
memberNameView.text = informationData.memberName
|
holder.memberNameView.text = informationData.memberName
|
||||||
AvatarRenderer.render(informationData.avatarUrl, informationData.memberName?.toString(), avatarImageView)
|
AvatarRenderer.render(informationData.avatarUrl, informationData.memberName?.toString(), holder.avatarImageView)
|
||||||
} else {
|
} else {
|
||||||
avatarImageView.visibility = View.GONE
|
holder.avatarImageView.visibility = View.GONE
|
||||||
memberNameView.visibility = View.GONE
|
holder.memberNameView.visibility = View.GONE
|
||||||
timeView.visibility = View.GONE
|
holder.timeView.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract class Holder : KotlinEpoxyHolder() {
|
||||||
|
abstract val avatarImageView: ImageView
|
||||||
|
abstract val memberNameView: TextView
|
||||||
|
abstract val timeView: TextView
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -18,23 +18,27 @@ package im.vector.riotredesign.features.home.room.detail.timeline
|
|||||||
|
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import com.airbnb.epoxy.EpoxyAttribute
|
||||||
|
import com.airbnb.epoxy.EpoxyModelClass
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
import im.vector.riotredesign.features.media.MediaContentRenderer
|
import im.vector.riotredesign.features.media.MediaContentRenderer
|
||||||
|
|
||||||
class MessageImageItem(
|
@EpoxyModelClass(layout = R.layout.item_timeline_event_image_message)
|
||||||
private val mediaData: MediaContentRenderer.Data,
|
abstract class MessageImageItem : AbsMessageItem<MessageImageItem.Holder>() {
|
||||||
informationData: MessageInformationData
|
|
||||||
) : AbsMessageItem(informationData, R.layout.item_timeline_event_image_message) {
|
|
||||||
|
|
||||||
|
@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 avatarImageView by bind<ImageView>(R.id.messageAvatarImageView)
|
||||||
override val memberNameView by bind<TextView>(R.id.messageMemberNameView)
|
override val memberNameView by bind<TextView>(R.id.messageMemberNameView)
|
||||||
override val timeView by bind<TextView>(R.id.messageTimeView)
|
override val timeView by bind<TextView>(R.id.messageTimeView)
|
||||||
private val imageView by bind<ImageView>(R.id.messageImageView)
|
val imageView by bind<ImageView>(R.id.messageImageView)
|
||||||
|
|
||||||
override fun bind() {
|
|
||||||
super.bind()
|
|
||||||
MediaContentRenderer.render(mediaData, MediaContentRenderer.Mode.THUMBNAIL, imageView)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -18,6 +18,7 @@ package im.vector.riotredesign.features.home.room.detail.timeline
|
|||||||
|
|
||||||
import android.text.SpannableStringBuilder
|
import android.text.SpannableStringBuilder
|
||||||
import android.text.util.Linkify
|
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.MatrixLinkify
|
||||||
import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan
|
import im.vector.matrix.android.api.permalinks.MatrixPermalinkSpan
|
||||||
import im.vector.matrix.android.api.session.events.model.EventType
|
import im.vector.matrix.android.api.session.events.model.EventType
|
||||||
@ -39,7 +40,7 @@ class MessageItemFactory(private val timelineMediaSizeProvider: TimelineMediaSiz
|
|||||||
fun create(event: TimelineEvent,
|
fun create(event: TimelineEvent,
|
||||||
nextEvent: TimelineEvent?,
|
nextEvent: TimelineEvent?,
|
||||||
callback: TimelineEventController.Callback?
|
callback: TimelineEventController.Callback?
|
||||||
): KotlinModel? {
|
): EpoxyModel<*>? {
|
||||||
|
|
||||||
val roomMember = event.roomMember
|
val roomMember = event.roomMember
|
||||||
val nextRoomMember = nextEvent?.roomMember
|
val nextRoomMember = nextEvent?.roomMember
|
||||||
@ -89,7 +90,9 @@ class MessageItemFactory(private val timelineMediaSizeProvider: TimelineMediaSiz
|
|||||||
rotation = messageContent.info?.rotation,
|
rotation = messageContent.info?.rotation,
|
||||||
orientation = messageContent.info?.orientation
|
orientation = messageContent.info?.orientation
|
||||||
)
|
)
|
||||||
return MessageImageItem(data, informationData)
|
return MessageImageItem_()
|
||||||
|
.informationData(informationData)
|
||||||
|
.mediaData(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildTextMessageItem(messageContent: MessageTextContent,
|
private fun buildTextMessageItem(messageContent: MessageTextContent,
|
||||||
@ -106,10 +109,9 @@ class MessageItemFactory(private val timelineMediaSizeProvider: TimelineMediaSiz
|
|||||||
Linkify.addLinks(spannable, Linkify.ALL)
|
Linkify.addLinks(spannable, Linkify.ALL)
|
||||||
spannable
|
spannable
|
||||||
}
|
}
|
||||||
return MessageTextItem(
|
return MessageTextItem_()
|
||||||
message = message,
|
.message(message)
|
||||||
informationData = informationData
|
.informationData(informationData)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,22 +18,29 @@ package im.vector.riotredesign.features.home.room.detail.timeline
|
|||||||
|
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import android.widget.TextView
|
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.matrix.android.api.permalinks.MatrixLinkify
|
||||||
import im.vector.riotredesign.R
|
import im.vector.riotredesign.R
|
||||||
|
|
||||||
class MessageTextItem(
|
@EpoxyModelClass(layout = R.layout.item_timeline_event_text_message)
|
||||||
val message: CharSequence? = null,
|
abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
|
||||||
informationData: MessageInformationData
|
|
||||||
) : AbsMessageItem(informationData, R.layout.item_timeline_event_text_message) {
|
|
||||||
|
|
||||||
|
@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 avatarImageView by bind<ImageView>(R.id.messageAvatarImageView)
|
||||||
override val memberNameView by bind<TextView>(R.id.messageMemberNameView)
|
override val memberNameView by bind<TextView>(R.id.messageMemberNameView)
|
||||||
override val timeView by bind<TextView>(R.id.messageTimeView)
|
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -16,9 +16,9 @@
|
|||||||
|
|
||||||
package im.vector.riotredesign.features.home.room.detail.timeline
|
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.events.model.EventType
|
||||||
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
import im.vector.matrix.android.api.session.room.timeline.TimelineEvent
|
||||||
import im.vector.riotredesign.core.epoxy.KotlinModel
|
|
||||||
|
|
||||||
class TimelineItemFactory(private val messageItemFactory: MessageItemFactory,
|
class TimelineItemFactory(private val messageItemFactory: MessageItemFactory,
|
||||||
private val roomNameItemFactory: RoomNameItemFactory,
|
private val roomNameItemFactory: RoomNameItemFactory,
|
||||||
@ -28,7 +28,7 @@ class TimelineItemFactory(private val messageItemFactory: MessageItemFactory,
|
|||||||
|
|
||||||
fun create(event: TimelineEvent,
|
fun create(event: TimelineEvent,
|
||||||
nextEvent: TimelineEvent?,
|
nextEvent: TimelineEvent?,
|
||||||
callback: TimelineEventController.Callback?): KotlinModel? {
|
callback: TimelineEventController.Callback?): EpoxyModel<*>? {
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
when (event.root.type) {
|
when (event.root.type) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user