Displays more detailed sync progress in RSTToastView
This commit is contained in:
parent
72f4da6bc4
commit
84e44f5aee
@ -48,7 +48,15 @@ class GamesViewController: UIViewController
|
||||
|
||||
private var searchController: RSTSearchController?
|
||||
|
||||
private var syncingToastView: RSTToastView?
|
||||
private var syncingToastView: RSTToastView? {
|
||||
didSet {
|
||||
if self.syncingToastView == nil
|
||||
{
|
||||
self.syncingProgressObservation = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
private var syncingProgressObservation: NSKeyValueObservation?
|
||||
|
||||
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
|
||||
fatalError("initWithNibName: not implemented")
|
||||
@ -382,13 +390,21 @@ private extension GamesViewController
|
||||
|
||||
func showSyncingToastViewIfNeeded()
|
||||
{
|
||||
guard let coordinator = SyncManager.shared.coordinator, coordinator.isSyncing && self.syncingToastView == nil else { return }
|
||||
|
||||
let toastView = RSTToastView(text: NSLocalizedString("Syncing...", comment: ""), detailText: nil)
|
||||
guard let coordinator = SyncManager.shared.coordinator, let syncProgress = SyncManager.shared.syncProgress, coordinator.isSyncing && self.syncingToastView == nil else { return }
|
||||
|
||||
let toastView = RSTToastView(text: NSLocalizedString("Syncing...", comment: ""), detailText: syncProgress.localizedAdditionalDescription)
|
||||
toastView.activityIndicatorView.startAnimating()
|
||||
toastView.addTarget(self, action: #selector(GamesViewController.hideSyncingToastView), for: .touchUpInside)
|
||||
toastView.show(in: self.view)
|
||||
|
||||
self.syncingProgressObservation = syncProgress.observe(\.localizedAdditionalDescription) { [weak toastView, weak self] (progress, change) in
|
||||
DispatchQueue.main.async {
|
||||
// Prevent us from updating text right as we're dismissing the toast view.
|
||||
guard self?.syncingToastView != nil else { return }
|
||||
toastView?.detailTextLabel.text = progress.localizedAdditionalDescription
|
||||
}
|
||||
}
|
||||
|
||||
self.syncingToastView = toastView
|
||||
}
|
||||
|
||||
@ -402,6 +418,7 @@ private extension GamesViewController
|
||||
case .failure(let error): toastView = RSTToastView(text: NSLocalizedString("Sync Failed", comment: ""), detailText: error.failureReason)
|
||||
}
|
||||
|
||||
toastView.textLabel.textAlignment = .center
|
||||
toastView.addTarget(self, action: #selector(GamesViewController.presentSyncResultsViewController), for: .touchUpInside)
|
||||
|
||||
toastView.show(in: self.view, duration: 2.0)
|
||||
|
||||
@ -92,6 +92,8 @@ final class SyncManager
|
||||
return self.coordinator?.recordController
|
||||
}
|
||||
|
||||
private(set) var syncProgress: Progress?
|
||||
|
||||
private(set) var previousSyncResult: SyncResult?
|
||||
|
||||
private(set) var coordinator: SyncCoordinator?
|
||||
@ -187,7 +189,8 @@ extension SyncManager
|
||||
|
||||
func sync()
|
||||
{
|
||||
self.coordinator?.sync()
|
||||
let progress = self.coordinator?.sync()
|
||||
self.syncProgress = progress
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,6 +201,8 @@ private extension SyncManager
|
||||
guard let result = notification.userInfo?[SyncCoordinator.syncResultKey] as? SyncResult else { return }
|
||||
self.previousSyncResult = result
|
||||
|
||||
self.syncProgress = nil
|
||||
|
||||
print("Finished syncing!")
|
||||
}
|
||||
|
||||
|
||||
2
External/Harmony
vendored
2
External/Harmony
vendored
@ -1 +1 @@
|
||||
Subproject commit 39311d36660c98bc6f240d7134c39f8361fc7b3e
|
||||
Subproject commit 0301f3ea5d3ede4f8eb3c06227a4f63b9b7b247c
|
||||
2
External/Roxas
vendored
2
External/Roxas
vendored
@ -1 +1 @@
|
||||
Subproject commit ffd65b85417db90895361446ea848d68a8ef9e4c
|
||||
Subproject commit 8ab1eecff273609896dff9bb18f17185ffa08f26
|
||||
Loading…
Reference in New Issue
Block a user