Read marker: only show banner until scrolled to read marker

This commit is contained in:
ganfra 2019-09-12 16:35:45 +02:00
parent b8ebe3570b
commit d4111d053d
4 changed files with 15 additions and 14 deletions

View File

@ -637,7 +637,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
.combineLatest(
room.rx().liveRoomSummary(),
visibleEventsObservable.distinctUntilChanged(),
isEventVisibleObservable { it.hasReadMarker }.startWith(false),
isEventVisibleObservable { it.hasReadMarker }.startWith(false).takeUntil { it },
Function3<RoomSummary, RoomDetailActions.TimelineEventTurnsVisible, Boolean, Boolean> { roomSummary, currentVisibleEvent, isReadMarkerViewVisible ->
val readMarkerId = roomSummary.readMarkerId
if (readMarkerId == null || isReadMarkerViewVisible || !timeline.isLive) {
@ -646,7 +646,7 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
val readMarkerPosition = timeline.getIndexOfEvent(readMarkerId)
?: Int.MAX_VALUE
val currentVisibleEventPosition = timeline.getIndexOfEvent(currentVisibleEvent.event.root.eventId)
?: Int.MIN_VALUE
?: Int.MAX_VALUE
readMarkerPosition > currentVisibleEventPosition
}
}

View File

@ -24,6 +24,7 @@ import im.vector.riotx.core.epoxy.VectorEpoxyModel
import im.vector.riotx.core.resources.ColorProvider
import im.vector.riotx.core.resources.StringProvider
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
import im.vector.riotx.features.home.room.detail.timeline.helper.AvatarSizeProvider
import im.vector.riotx.features.home.room.detail.timeline.item.MessageTextItem_
import im.vector.riotx.features.home.room.detail.timeline.helper.MessageInformationDataFactory
import im.vector.riotx.features.home.room.detail.timeline.helper.MessageItemAttributesFactory
@ -34,6 +35,7 @@ import javax.inject.Inject
class EncryptedItemFactory @Inject constructor(private val messageInformationDataFactory: MessageInformationDataFactory,
private val colorProvider: ColorProvider,
private val stringProvider: StringProvider,
private val avatarSizeProvider: AvatarSizeProvider,
private val attributesFactory: MessageItemAttributesFactory) {
fun create(event: TimelineEvent,
@ -65,6 +67,7 @@ class EncryptedItemFactory @Inject constructor(private val messageInformationDat
val informationData = messageInformationDataFactory.create(event, nextEvent)
val attributes = attributesFactory.create(null, informationData, callback)
return MessageTextItem_()
.leftGuideline(avatarSizeProvider.leftGuideline)
.highlighted(highlight)
.attributes(attributes)
.message(spannableStr)

View File

@ -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.features.home.AvatarRenderer
import im.vector.riotx.features.home.room.detail.timeline.TimelineEventController
@ -42,7 +43,10 @@ class NoticeItemFactory @Inject constructor(
avatarRenderer = avatarRenderer,
informationData = informationData,
noticeText = formattedText,
callback = callback
itemLongClickListener = View.OnLongClickListener { view ->
callback?.onEventLongClicked(informationData, null, view) ?: false
},
readReceiptsCallback = callback
)
return NoticeItem_()
.leftGuideline(avatarSizeProvider.leftGuideline)

View File

@ -34,20 +34,13 @@ abstract class NoticeItem : BaseEventItem<NoticeItem.Holder>() {
@EpoxyAttribute
lateinit var attributes: Attributes
private var longClickListener = View.OnLongClickListener {
return@OnLongClickListener attributes.callback?.onEventLongClicked(attributes.informationData, null, it) == true
}
@EpoxyAttribute
var readReceiptsCallback: TimelineEventController.ReadReceiptsCallback? = null
private val _readReceiptsClickListener = DebouncedClickListener(View.OnClickListener {
readReceiptsCallback?.onReadReceiptsClicked(attributes.informationData.readReceipts)
attributes.readReceiptsCallback?.onReadReceiptsClicked(attributes.informationData.readReceipts)
})
private val _readMarkerCallback = object : ReadMarkerView.Callback {
override fun onReadMarkerDisplayed() {
readReceiptsCallback?.onReadMarkerLongDisplayed(attributes.informationData)
attributes.readReceiptsCallback?.onReadMarkerLongDisplayed(attributes.informationData)
}
}
@ -61,7 +54,7 @@ abstract class NoticeItem : BaseEventItem<NoticeItem.Holder>() {
?: attributes.informationData.senderId,
holder.avatarImageView
)
holder.view.setOnLongClickListener(longClickListener)
holder.view.setOnLongClickListener(attributes.itemLongClickListener)
holder.readReceiptsView.render(attributes.informationData.readReceipts, attributes.avatarRenderer, _readReceiptsClickListener)
holder.readMarkerView.bindView(attributes.informationData, _readMarkerCallback)
}
@ -84,7 +77,8 @@ abstract class NoticeItem : BaseEventItem<NoticeItem.Holder>() {
val avatarRenderer: AvatarRenderer,
val informationData: MessageInformationData,
val noticeText: CharSequence,
val callback: TimelineEventController.BaseCallback? = null
val itemLongClickListener: View.OnLongClickListener? = null,
val readReceiptsCallback: TimelineEventController.ReadReceiptsCallback? = null
)
companion object {