diff --git a/Delta/Base.lproj/Settings.storyboard b/Delta/Base.lproj/Settings.storyboard index 3e05720..b3670ac 100644 --- a/Delta/Base.lproj/Settings.storyboard +++ b/Delta/Base.lproj/Settings.storyboard @@ -227,11 +227,11 @@ - + - + @@ -254,11 +254,11 @@ - + - + @@ -278,11 +278,11 @@ - + - + @@ -827,6 +827,26 @@ + + + + + + + + + + + + + + + + + + + + @@ -838,6 +858,14 @@ + + + + + + + + diff --git a/Delta/Settings/Syncing/SyncStatusViewController.swift b/Delta/Settings/Syncing/SyncStatusViewController.swift index b60b69b..4a569f4 100644 --- a/Delta/Settings/Syncing/SyncStatusViewController.swift +++ b/Delta/Settings/Syncing/SyncStatusViewController.swift @@ -33,20 +33,30 @@ class SyncStatusViewController: UITableViewController override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - guard segue.identifier == "showGame" else { return } + guard let identifier = segue.identifier else { return } - guard let cell = sender as? UITableViewCell, let indexPath = self.tableView.indexPath(for: cell) else { return } - - let game = self.dataSource.item(at: indexPath) - - let gameSyncStatusViewController = segue.destination as! GameSyncStatusViewController - gameSyncStatusViewController.game = game + switch identifier + { + case "showGame": + guard let cell = sender as? UITableViewCell, let indexPath = self.tableView.indexPath(for: cell) else { return } + + let game = self.dataSource.item(at: indexPath) + + let gameSyncStatusViewController = segue.destination as! GameSyncStatusViewController + gameSyncStatusViewController.game = game + + case "showPreviousSyncResults": + let syncResultViewController = segue.destination as! SyncResultViewController + syncResultViewController.result = SyncManager.shared.previousSyncResult + + default: break + } } } private extension SyncStatusViewController { - func makeDataSource() -> RSTFetchedResultsTableViewDataSource + func makeDataSource() -> RSTCompositeTableViewDataSource { let fetchRequest = Game.fetchRequest() as NSFetchRequest fetchRequest.returnsObjectsAsFaults = false @@ -54,10 +64,9 @@ private extension SyncStatusViewController let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: DatabaseManager.shared.viewContext, sectionNameKeyPath: #keyPath(Game.gameCollection.name), cacheName: nil) - let dataSource = RSTFetchedResultsTableViewDataSource(fetchedResultsController: fetchedResultsController) - dataSource.proxy = self - dataSource.searchController.searchableKeyPaths = [#keyPath(Game.name)] - dataSource.cellConfigurationHandler = { (cell, game, indexPath) in + let fetchedDataSource = RSTFetchedResultsTableViewDataSource(fetchedResultsController: fetchedResultsController) + fetchedDataSource.searchController.searchableKeyPaths = [#keyPath(Game.name)] + fetchedDataSource.cellConfigurationHandler = { (cell, game, indexPath) in let cell = cell as! BadgedTableViewCell cell.textLabel?.text = game.name cell.textLabel?.numberOfLines = 0 @@ -89,6 +98,14 @@ private extension SyncStatusViewController } } + let dynamicDataSource = RSTDynamicTableViewDataSource() + dynamicDataSource.numberOfSectionsHandler = { (SyncManager.shared.previousSyncResult != nil) ? 1 : 0 } + dynamicDataSource.numberOfItemsHandler = { _ in 1 } + dynamicDataSource.cellIdentifierHandler = { _ in "PreviousSyncCell" } + dynamicDataSource.cellConfigurationHandler = { (cell, _, indexPath) in } + + let dataSource = RSTCompositeTableViewDataSource(dataSources: [dynamicDataSource, fetchedDataSource]) + dataSource.proxy = self return dataSource } @@ -149,7 +166,18 @@ extension SyncStatusViewController { override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - let section = self.dataSource.fetchedResultsController.sections?[section] - return section?.name + var section = section + + if SyncManager.shared.previousSyncResult != nil + { + guard section > 0 else { return nil } + + section -= 1 + } + + let dataSource = self.dataSource.dataSources[1] as! RSTFetchedResultsTableViewDataSource + + let sectionInfo = dataSource.fetchedResultsController.sections?[section] + return sectionInfo?.name } } diff --git a/Delta/Syncing/SyncResultViewController.swift b/Delta/Syncing/SyncResultViewController.swift index 878a724..6774056 100644 --- a/Delta/Syncing/SyncResultViewController.swift +++ b/Delta/Syncing/SyncResultViewController.swift @@ -47,7 +47,7 @@ extension SyncResultViewController class SyncResultViewController: UITableViewController { - private(set) var result: Result<[Record: Result], SyncError>! + var result: Result<[Record: Result], SyncError>! private lazy var dataSource = self.makeDataSource() diff --git a/Delta/Syncing/SyncResultsViewController.storyboard b/Delta/Syncing/SyncResultsViewController.storyboard index 86d00ce..eb3bcc6 100644 --- a/Delta/Syncing/SyncResultsViewController.storyboard +++ b/Delta/Syncing/SyncResultsViewController.storyboard @@ -11,7 +11,7 @@ - + diff --git a/External/Harmony b/External/Harmony index 3ac5af8..c5e7c42 160000 --- a/External/Harmony +++ b/External/Harmony @@ -1 +1 @@ -Subproject commit 3ac5af8d95bc9c9be04ddcc0da471b532366f4e4 +Subproject commit c5e7c42f6af20791e65097c7ce2f69774bee8b14