mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Simplify code
This commit is contained in:
+12
-13
@@ -44,7 +44,7 @@ class TimelineMediaItemsFactory(
|
|||||||
when (val currentTimelineItem = timelineItems[index]) {
|
when (val currentTimelineItem = timelineItems[index]) {
|
||||||
is MatrixTimelineItem.Event -> {
|
is MatrixTimelineItem.Event -> {
|
||||||
val cachedItems = cache[currentTimelineItem.uniqueId]
|
val cachedItems = cache[currentTimelineItem.uniqueId]
|
||||||
val items = if (cachedItems != null && isItemUnchanged(currentTimelineItem, previousTimelineItems)) {
|
val items = if (cachedItems != null && currentTimelineItem.isUnchanged(previousTimelineItems)) {
|
||||||
cachedItems
|
cachedItems
|
||||||
} else {
|
} else {
|
||||||
eventItemFactory.create(currentTimelineItem).also { newItems ->
|
eventItemFactory.create(currentTimelineItem).also { newItems ->
|
||||||
@@ -65,16 +65,15 @@ class TimelineMediaItemsFactory(
|
|||||||
_timelineItems.emit(newTimelineItemStates.toImmutableList())
|
_timelineItems.emit(newTimelineItemStates.toImmutableList())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
private fun isItemUnchanged(
|
|
||||||
currentTimelineItem: MatrixTimelineItem.Event,
|
private fun MatrixTimelineItem.Event.isUnchanged(
|
||||||
previousItems: List<MatrixTimelineItem>,
|
previousItems: List<MatrixTimelineItem>,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (previousItems.isEmpty()) return false
|
val previousItem = previousItems
|
||||||
val previousIndex = previousItems.indexOfFirst { it is MatrixTimelineItem.Event && it.uniqueId == currentTimelineItem.uniqueId }
|
.filterIsInstance<MatrixTimelineItem.Event>()
|
||||||
if (previousIndex < 0) return false
|
.find { it.uniqueId == uniqueId }
|
||||||
val previousItem = previousItems[previousIndex] as? MatrixTimelineItem.Event ?: return false
|
return previousItem != null &&
|
||||||
return previousItem.event.eventId == currentTimelineItem.event.eventId &&
|
previousItem.event.eventId == event.eventId &&
|
||||||
previousItem.event.timestamp == currentTimelineItem.event.timestamp
|
previousItem.event.timestamp == event.timestamp
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user