Nearly same code for DefaultItem and NoticeItem
This commit is contained in:
parent
d530c64a84
commit
632832a651
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package im.vector.riotx.features.home.room.detail.timeline.factory
|
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.matrix.android.api.session.room.timeline.TimelineEvent
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.resources.StringProvider
|
import im.vector.riotx.core.resources.StringProvider
|
||||||
|
@ -37,14 +38,19 @@ class DefaultItemFactory @Inject constructor(private val avatarSizeProvider: Ava
|
||||||
informationData: MessageInformationData,
|
informationData: MessageInformationData,
|
||||||
highlight: Boolean,
|
highlight: Boolean,
|
||||||
callback: TimelineEventController.Callback?): DefaultItem {
|
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_()
|
return DefaultItem_()
|
||||||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||||
.highlighted(highlight)
|
.highlighted(highlight)
|
||||||
.text(text)
|
.attributes(attributes)
|
||||||
.avatarRenderer(avatarRenderer)
|
|
||||||
.informationData(informationData)
|
|
||||||
.baseCallback(callback)
|
|
||||||
.readReceiptsCallback(callback)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun create(event: TimelineEvent,
|
fun create(event: TimelineEvent,
|
||||||
|
|
|
@ -30,45 +30,39 @@ import im.vector.riotx.features.home.room.detail.timeline.TimelineEventControlle
|
||||||
abstract class DefaultItem : BaseEventItem<DefaultItem.Holder>() {
|
abstract class DefaultItem : BaseEventItem<DefaultItem.Holder>() {
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
lateinit var informationData: MessageInformationData
|
lateinit var attributes: Attributes
|
||||||
@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
|
|
||||||
|
|
||||||
private val _readReceiptsClickListener = DebouncedClickListener(View.OnClickListener {
|
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) {
|
override fun bind(holder: Holder) {
|
||||||
super.bind(holder)
|
super.bind(holder)
|
||||||
holder.view.setOnLongClickListener(longClickListener)
|
holder.messageTextView.text = attributes.text
|
||||||
avatarRenderer.render(informationData.matrixItem, holder.avatarView)
|
attributes.avatarRenderer.render(attributes.informationData.matrixItem, holder.avatarImageView)
|
||||||
holder.messageView.text = text
|
holder.view.setOnLongClickListener(attributes.itemLongClickListener)
|
||||||
holder.readReceiptsView.render(informationData.readReceipts, avatarRenderer, _readReceiptsClickListener)
|
holder.readReceiptsView.render(attributes.informationData.readReceipts, attributes.avatarRenderer, _readReceiptsClickListener)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getEventIds(): List<String> {
|
override fun getEventIds(): List<String> {
|
||||||
return listOf(informationData.eventId)
|
return listOf(attributes.informationData.eventId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getViewType() = STUB_ID
|
override fun getViewType() = STUB_ID
|
||||||
|
|
||||||
class Holder : BaseHolder(STUB_ID) {
|
class Holder : BaseHolder(STUB_ID) {
|
||||||
val avatarView by bind<ImageView>(R.id.itemDefaultAvatarView)
|
val avatarImageView by bind<ImageView>(R.id.itemDefaultAvatarView)
|
||||||
val messageView by bind<TextView>(R.id.itemDefaultTextView)
|
val messageTextView by bind<TextView>(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 {
|
companion object {
|
||||||
private const val STUB_ID = R.id.messageContentDefaultStub
|
private const val STUB_ID = R.id.messageContentDefaultStub
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue