From 632832a651340413be0940b73f0d7d10822019cd Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 23 Jan 2020 15:44:41 +0100 Subject: [PATCH] Nearly same code for DefaultItem and NoticeItem --- .../timeline/factory/DefaultItemFactory.kt | 16 +++++--- .../room/detail/timeline/item/DefaultItem.kt | 40 ++++++++----------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/DefaultItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/DefaultItemFactory.kt index 377975554a..89e21e04a2 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/DefaultItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/DefaultItemFactory.kt @@ -16,6 +16,7 @@ package im.vector.riotx.features.home.room.detail.timeline.factory +import android.view.View import im.vector.matrix.android.api.session.room.timeline.TimelineEvent import im.vector.riotx.R import im.vector.riotx.core.resources.StringProvider @@ -37,14 +38,19 @@ class DefaultItemFactory @Inject constructor(private val avatarSizeProvider: Ava informationData: MessageInformationData, highlight: Boolean, callback: TimelineEventController.Callback?): DefaultItem { + val attributes = DefaultItem.Attributes( + avatarRenderer = avatarRenderer, + informationData = informationData, + text = text, + itemLongClickListener = View.OnLongClickListener { view -> + callback?.onEventLongClicked(informationData, null, view) ?: false + }, + readReceiptsCallback = callback + ) return DefaultItem_() .leftGuideline(avatarSizeProvider.leftGuideline) .highlighted(highlight) - .text(text) - .avatarRenderer(avatarRenderer) - .informationData(informationData) - .baseCallback(callback) - .readReceiptsCallback(callback) + .attributes(attributes) } fun create(event: TimelineEvent, diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/DefaultItem.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/DefaultItem.kt index 3bf564577f..0ccc982c4c 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/DefaultItem.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/item/DefaultItem.kt @@ -30,45 +30,39 @@ import im.vector.riotx.features.home.room.detail.timeline.TimelineEventControlle abstract class DefaultItem : BaseEventItem() { @EpoxyAttribute - lateinit var informationData: MessageInformationData - @EpoxyAttribute - lateinit var avatarRenderer: AvatarRenderer - @EpoxyAttribute - var baseCallback: TimelineEventController.BaseCallback? = null - - private var longClickListener = View.OnLongClickListener { - return@OnLongClickListener baseCallback?.onEventLongClicked(informationData, null, it) == true - } - - @EpoxyAttribute - var readReceiptsCallback: TimelineEventController.ReadReceiptsCallback? = null + lateinit var attributes: Attributes private val _readReceiptsClickListener = DebouncedClickListener(View.OnClickListener { - readReceiptsCallback?.onReadReceiptsClicked(informationData.readReceipts) + attributes.readReceiptsCallback?.onReadReceiptsClicked(attributes.informationData.readReceipts) }) - @EpoxyAttribute - var text: CharSequence? = null - override fun bind(holder: Holder) { super.bind(holder) - holder.view.setOnLongClickListener(longClickListener) - avatarRenderer.render(informationData.matrixItem, holder.avatarView) - holder.messageView.text = text - holder.readReceiptsView.render(informationData.readReceipts, avatarRenderer, _readReceiptsClickListener) + holder.messageTextView.text = attributes.text + attributes.avatarRenderer.render(attributes.informationData.matrixItem, holder.avatarImageView) + holder.view.setOnLongClickListener(attributes.itemLongClickListener) + holder.readReceiptsView.render(attributes.informationData.readReceipts, attributes.avatarRenderer, _readReceiptsClickListener) } override fun getEventIds(): List { - return listOf(informationData.eventId) + return listOf(attributes.informationData.eventId) } override fun getViewType() = STUB_ID class Holder : BaseHolder(STUB_ID) { - val avatarView by bind(R.id.itemDefaultAvatarView) - val messageView by bind(R.id.itemDefaultTextView) + val avatarImageView by bind(R.id.itemDefaultAvatarView) + val messageTextView by bind(R.id.itemDefaultTextView) } + data class Attributes( + val avatarRenderer: AvatarRenderer, + val informationData: MessageInformationData, + val text: CharSequence, + val itemLongClickListener: View.OnLongClickListener? = null, + val readReceiptsCallback: TimelineEventController.ReadReceiptsCallback? = null + ) + companion object { private const val STUB_ID = R.id.messageContentDefaultStub }