Timeline call tiles: remove usage of TimelineControllerInterceptorHelper.

This commit is contained in:
ganfra 2021-07-29 19:13:15 +02:00
parent f405532e4c
commit dc7cc2ed5c
3 changed files with 3 additions and 43 deletions

View File

@ -230,9 +230,7 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
private val interceptorHelper = TimelineControllerInterceptorHelper(
::positionOfReadMarker,
adapterPositionMapping,
userPreferencesProvider,
callManager
adapterPositionMapping
)
init {

View File

@ -16,16 +16,11 @@
package im.vector.app.features.home.room.detail.timeline.helper
import android.telecom.Conference
import com.airbnb.epoxy.EpoxyModel
import com.airbnb.epoxy.VisibilityState
import im.vector.app.core.epoxy.LoadingItem_
import im.vector.app.core.epoxy.TimelineEmptyItem_
import im.vector.app.core.resources.UserPreferencesProvider
import im.vector.app.features.call.webrtc.WebRtcCallManager
import im.vector.app.features.home.room.detail.UnreadState
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
import im.vector.app.features.home.room.detail.timeline.item.CallTileTimelineItem
import im.vector.app.features.home.room.detail.timeline.item.DaySeparatorItem
import im.vector.app.features.home.room.detail.timeline.item.ItemWithEvents
import im.vector.app.features.home.room.detail.timeline.item.TimelineReadMarkerItem_
@ -35,9 +30,7 @@ import kotlin.reflect.KMutableProperty0
private const val DEFAULT_PREFETCH_THRESHOLD = 30
class TimelineControllerInterceptorHelper(private val positionOfReadMarker: KMutableProperty0<Int?>,
private val adapterPositionMapping: MutableMap<String, Int>,
private val userPreferencesProvider: UserPreferencesProvider,
private val callManager: WebRtcCallManager
private val adapterPositionMapping: MutableMap<String, Int>
) {
private var previousModelsSize = 0
@ -51,14 +44,12 @@ class TimelineControllerInterceptorHelper(private val positionOfReadMarker: KMut
) {
positionOfReadMarker.set(null)
adapterPositionMapping.clear()
val callIds = mutableSetOf<String>()
// Add some prefetch loader if needed
models.addBackwardPrefetchIfNeeded(timeline, callback)
models.addForwardPrefetchIfNeeded(timeline, callback)
val modelsIterator = models.listIterator()
val showHiddenEvents = userPreferencesProvider.shouldShowHiddenEvents()
var index = 0
val firstUnreadEventId = (unreadState as? UnreadState.HasUnread)?.firstUnreadEventId
var atLeastOneVisibleItemSinceLastDaySeparator = false
@ -84,11 +75,6 @@ class TimelineControllerInterceptorHelper(private val positionOfReadMarker: KMut
return@forEach
}
atLeastOneVisibleItemSinceLastDaySeparator = false
} else if (epoxyModel is CallTileTimelineItem) {
val hasBeenRemoved = modelsIterator.removeCallItemIfNeeded(epoxyModel, callIds, showHiddenEvents)
if (!hasBeenRemoved) {
atLeastOneVisibleItemSinceLastDaySeparator = true
}
}
if (appendReadMarker) {
modelsIterator.addReadMarkerItem(callback)
@ -110,30 +96,6 @@ class TimelineControllerInterceptorHelper(private val positionOfReadMarker: KMut
add(readMarker)
}
private fun MutableListIterator<EpoxyModel<*>>.removeCallItemIfNeeded(
epoxyModel: CallTileTimelineItem,
callIds: MutableSet<String>,
showHiddenEvents: Boolean
): Boolean {
val attributes = epoxyModel.attributes
val callId = attributes.callId
// We should remove the call tile if we already have one for this call or
// if this is an active call tile without an actual call (which can happen with permalink)
val shouldRemoveCallItem = callIds.contains(callId)
|| (!callManager.getAdvertisedCalls().contains(callId) && attributes.callStatus.isActive() && attributes.callKind != CallTileTimelineItem.CallKind.CONFERENCE)
val removed = shouldRemoveCallItem && !showHiddenEvents
if (removed) {
remove()
val emptyItem = TimelineEmptyItem_()
.id(epoxyModel.id())
.eventId(epoxyModel.attributes.informationData.eventId)
.notBlank(false)
add(emptyItem)
}
callIds.add(callId)
return removed
}
private fun MutableList<EpoxyModel<*>>.addBackwardPrefetchIfNeeded(timeline: Timeline?, callback: TimelineEventController.Callback?) {
val shouldAddBackwardPrefetch = timeline?.hasMoreToLoad(Timeline.Direction.BACKWARDS) ?: false
if (shouldAddBackwardPrefetch) {

View File

@ -46,7 +46,7 @@ abstract class CallTileTimelineItem : AbsBaseMessageItem<CallTileTimelineItem.Ho
get() = attributes
override fun isCacheable(): Boolean {
return attributes.callKind != CallKind.CONFERENCE
return attributes.callKind == CallKind.CONFERENCE
}
@EpoxyAttribute