2021-10-21 03:37:29 +02:00
|
|
|
//
|
|
|
|
// ShadowTableChanges.swift
|
|
|
|
// NetNewsWire-iOS
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 10/20/21.
|
|
|
|
// Copyright © 2021 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct ShadowTableChanges {
|
|
|
|
|
|
|
|
struct Move: Hashable {
|
|
|
|
var from: Int
|
|
|
|
var to: Int
|
|
|
|
|
|
|
|
init(_ from: Int, _ to: Int) {
|
|
|
|
self.from = from
|
|
|
|
self.to = to
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RowChanges {
|
|
|
|
|
|
|
|
var section: Int
|
|
|
|
var deletes: Set<Int>?
|
|
|
|
var inserts: Set<Int>?
|
2022-03-01 18:14:41 +01:00
|
|
|
var reloads: Set<Int>?
|
2021-10-21 03:37:29 +02:00
|
|
|
var moves: Set<ShadowTableChanges.Move>?
|
|
|
|
|
|
|
|
var isEmpty: Bool {
|
|
|
|
return (deletes?.isEmpty ?? true) && (inserts?.isEmpty ?? true) && (moves?.isEmpty ?? true)
|
|
|
|
}
|
|
|
|
|
|
|
|
var deleteIndexPaths: [IndexPath]? {
|
|
|
|
guard let deletes = deletes else { return nil }
|
|
|
|
return deletes.map { IndexPath(row: $0, section: section) }
|
|
|
|
}
|
|
|
|
|
|
|
|
var insertIndexPaths: [IndexPath]? {
|
|
|
|
guard let inserts = inserts else { return nil }
|
|
|
|
return inserts.map { IndexPath(row: $0, section: section) }
|
|
|
|
}
|
|
|
|
|
2022-03-01 18:14:41 +01:00
|
|
|
var reloadIndexPaths: [IndexPath]? {
|
|
|
|
guard let reloads = reloads else { return nil }
|
|
|
|
return reloads.map { IndexPath(row: $0, section: section) }
|
|
|
|
}
|
|
|
|
|
2021-10-21 03:37:29 +02:00
|
|
|
var moveIndexPaths: [(IndexPath, IndexPath)]? {
|
|
|
|
guard let moves = moves else { return nil }
|
|
|
|
return moves.map { (IndexPath(row: $0.from, section: section), IndexPath(row: $0.to, section: section)) }
|
|
|
|
}
|
|
|
|
|
2022-03-01 18:14:41 +01:00
|
|
|
init(section: Int, deletes: Set<Int>?, inserts: Set<Int>?, reloads: Set<Int>?, moves: Set<Move>?) {
|
2021-10-21 03:37:29 +02:00
|
|
|
self.section = section
|
|
|
|
self.deletes = deletes
|
|
|
|
self.inserts = inserts
|
2022-03-01 18:14:41 +01:00
|
|
|
self.reloads = reloads
|
2021-10-21 03:37:29 +02:00
|
|
|
self.moves = moves
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var deletes: Set<Int>?
|
|
|
|
var inserts: Set<Int>?
|
|
|
|
var moves: Set<Move>?
|
|
|
|
var rowChanges: [RowChanges]?
|
|
|
|
|
|
|
|
init(deletes: Set<Int>?, inserts: Set<Int>?, moves: Set<Move>?, rowChanges: [RowChanges]?) {
|
|
|
|
self.deletes = deletes
|
|
|
|
self.inserts = inserts
|
|
|
|
self.moves = moves
|
|
|
|
self.rowChanges = rowChanges
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|