Adopt the new limited lists API

This commit is contained in:
Stefan Ceriu
2023-09-18 11:49:07 +03:00
committed by Stefan Ceriu
parent 472ff53fe1
commit 40735fba39
2 changed files with 99 additions and 79 deletions
@@ -94,74 +94,76 @@ class RoomTimelineProvider: RoomTimelineProviderProtocol {
var changes = [CollectionDifference<TimelineItemProxy>.Change]()
switch diff.change() {
case .pushFront:
guard let item = diff.pushFront() else { fatalError() }
MXLog.verbose("Push Front: \(item.debugIdentifier)")
let itemProxy = TimelineItemProxy(item: item)
changes.append(.insert(offset: 0, element: itemProxy, associatedWith: nil))
case .pushBack:
guard let item = diff.pushBack() else { fatalError() }
MXLog.verbose("Push Back \(item.debugIdentifier)")
let itemProxy = TimelineItemProxy(item: item)
changes.append(.insert(offset: Int(itemProxies.count), element: itemProxy, associatedWith: nil))
case .insert:
guard let update = diff.insert() else { fatalError() }
MXLog.verbose("Insert \(update.item.debugIdentifier) at \(update.index)")
let itemProxy = TimelineItemProxy(item: update.item)
changes.append(.insert(offset: Int(update.index), element: itemProxy, associatedWith: nil))
case .append:
guard let items = diff.append() else { fatalError() }
MXLog.verbose("Append \(items.map(\.debugIdentifier))")
for (index, item) in items.enumerated() {
changes.append(.insert(offset: Int(itemProxies.count) + index, element: TimelineItemProxy(item: item), associatedWith: nil))
}
case .set:
guard let update = diff.set() else { fatalError() }
MXLog.verbose("Set \(update.item.debugIdentifier) at index \(update.index)")
let itemProxy = TimelineItemProxy(item: update.item)
changes.append(.remove(offset: Int(update.index), element: itemProxy, associatedWith: nil))
changes.append(.insert(offset: Int(update.index), element: itemProxy, associatedWith: nil))
case .popFront:
guard let itemProxy = itemProxies.first else { fatalError() }
MXLog.verbose("Pop Front \(itemProxy.debugIdentifier)")
changes.append(.remove(offset: 0, element: itemProxy, associatedWith: nil))
case .popBack:
guard let itemProxy = itemProxies.last else { fatalError() }
MXLog.verbose("Pop Back \(itemProxy.debugIdentifier)")
changes.append(.remove(offset: itemProxies.count - 1, element: itemProxy, associatedWith: nil))
case .remove:
guard let index = diff.remove() else { fatalError() }
let itemProxy = itemProxies[Int(index)]
MXLog.verbose("Remove \(itemProxy.debugIdentifier) at: \(index)")
changes.append(.remove(offset: Int(index), element: itemProxy, associatedWith: nil))
case .clear:
MXLog.verbose("Clear all items")
for (index, itemProxy) in itemProxies.enumerated() {
changes.append(.remove(offset: index, element: itemProxy, associatedWith: nil))
}
case .insert:
guard let update = diff.insert() else { fatalError() }
MXLog.verbose("Insert \(update.item.debugIdentifier) at \(update.index)")
let itemProxy = TimelineItemProxy(item: update.item)
changes.append(.insert(offset: Int(update.index), element: itemProxy, associatedWith: nil))
case .popBack:
guard let itemProxy = itemProxies.last else { fatalError() }
MXLog.verbose("Pop Back \(itemProxy.debugIdentifier)")
changes.append(.remove(offset: itemProxies.count - 1, element: itemProxy, associatedWith: nil))
case .popFront:
guard let itemProxy = itemProxies.first else { fatalError() }
MXLog.verbose("Pop Front \(itemProxy.debugIdentifier)")
changes.append(.remove(offset: 0, element: itemProxy, associatedWith: nil))
case .pushBack:
guard let item = diff.pushBack() else { fatalError() }
MXLog.verbose("Push Back \(item.debugIdentifier)")
let itemProxy = TimelineItemProxy(item: item)
changes.append(.insert(offset: Int(itemProxies.count), element: itemProxy, associatedWith: nil))
case .pushFront:
guard let item = diff.pushFront() else { fatalError() }
MXLog.verbose("Push Front: \(item.debugIdentifier)")
let itemProxy = TimelineItemProxy(item: item)
changes.append(.insert(offset: 0, element: itemProxy, associatedWith: nil))
case .remove:
guard let index = diff.remove() else { fatalError() }
let itemProxy = itemProxies[Int(index)]
MXLog.verbose("Remove \(itemProxy.debugIdentifier) at: \(index)")
changes.append(.remove(offset: Int(index), element: itemProxy, associatedWith: nil))
case .reset:
guard let items = diff.reset() else { fatalError() }
MXLog.verbose("Replace all items with \(items.map(\.debugIdentifier))")
for (index, itemProxy) in itemProxies.enumerated() {
changes.append(.remove(offset: index, element: itemProxy, associatedWith: nil))
}
for (index, timelineItem) in items.enumerated() {
changes.append(.insert(offset: index, element: TimelineItemProxy(item: timelineItem), associatedWith: nil))
}
case .set:
guard let update = diff.set() else { fatalError() }
MXLog.verbose("Set \(update.item.debugIdentifier) at index \(update.index)")
let itemProxy = TimelineItemProxy(item: update.item)
changes.append(.remove(offset: Int(update.index), element: itemProxy, associatedWith: nil))
changes.append(.insert(offset: Int(update.index), element: itemProxy, associatedWith: nil))
case .truncate:
break
}
return CollectionDifference(changes)