Review Changes
This commit is contained in:
parent
987c178c35
commit
4a47ec13c1
@ -9,22 +9,20 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public extension MVMCoreAlertHandler {
|
public extension MVMCoreAlertHandler {
|
||||||
|
|
||||||
/// Re-evaluates the queue operations
|
/// Re-evaluates the queue operations
|
||||||
@objc func reevaluteQueue() {
|
@objc func reevaluteQueue() {
|
||||||
var higherPriorityOperationIsReady = false
|
var highestReadyOperation: MVMCoreTopAlertOperation?
|
||||||
var executingOperation: MVMCoreTopAlertOperation?
|
var executingOperation: MVMCoreTopAlertOperation?
|
||||||
let pageType = (MVMCoreUISplitViewController.main()?.getCurrentDetailViewController() as? MVMCoreViewControllerProtocol)?.pageType
|
for case let operation as MVMCoreTopAlertOperation in topAlertQueue.operations {
|
||||||
let sortedOperations = topAlertQueue.operations.sorted { $0.queuePriority.rawValue > $1.queuePriority.rawValue }
|
|
||||||
for case let operation as MVMCoreTopAlertOperation in sortedOperations {
|
|
||||||
guard !operation.isCancelled,
|
guard !operation.isCancelled,
|
||||||
!operation.isFinished else { continue }
|
!operation.isFinished else { continue }
|
||||||
updatePageReadiness(for: operation, with: pageType)
|
if operation.isReady,
|
||||||
|
highestReadyOperation == nil || operation.queuePriority.rawValue > highestReadyOperation!.queuePriority.rawValue {
|
||||||
|
highestReadyOperation = operation
|
||||||
|
}
|
||||||
if operation.isExecuting {
|
if operation.isExecuting {
|
||||||
executingOperation = operation
|
executingOperation = operation
|
||||||
} else if operation.isReady,
|
|
||||||
executingOperation == nil {
|
|
||||||
higherPriorityOperationIsReady = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
guard let currentOperation = executingOperation else { return }
|
guard let currentOperation = executingOperation else { return }
|
||||||
@ -37,34 +35,30 @@ public extension MVMCoreAlertHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the highest priority operation is not executing, and the executing operation is persistent, cancel it.
|
// If the highest priority operation is not executing, and the executing operation is persistent, cancel it.
|
||||||
if higherPriorityOperationIsReady,
|
if let newOperation = highestReadyOperation,
|
||||||
|
currentOperation != newOperation,
|
||||||
currentOperation.topAlertObject.persistent {
|
currentOperation.topAlertObject.persistent {
|
||||||
currentOperation.reAddAfterCancel = true
|
currentOperation.reAddAfterCancel = true
|
||||||
currentOperation.cancel()
|
currentOperation.cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Registers with the notification center to know when pages change.
|
/// Registers to know when pages change.
|
||||||
@objc func registerWithNotificationCenter() {
|
@objc func registerForPageChanges() {
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(viewControllerChanged(notification:)), name: NSNotification.Name(rawValue: MVMCoreNotificationViewControllerChanged), object: nil)
|
MVMCoreNavigationHandler.shared()?.addDelegate(self)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
/// Updates the operation isDisplayable based on the page type.
|
|
||||||
private func updatePageReadiness(for topOperation: MVMCoreTopAlertOperation, with pageType: String?) {
|
extension MVMCoreAlertHandler: MVMCorePresentationDelegateProtocol {
|
||||||
guard let pages = topOperation.topAlertObject.json?.optionalArrayForKey("pages") as? [String],
|
// Update displayable for each top alert operation when page type changes, in top queue priority order.
|
||||||
pages.count != 0 else {
|
public func navigationController(_ navigationController: UINavigationController, displayedViewController viewController: UIViewController) {
|
||||||
topOperation.isDisplayable = true
|
guard navigationController == MVMCoreUISplitViewController.main()?.navigationController else { return }
|
||||||
return
|
let pageType = (viewController as? MVMCoreViewControllerProtocol)?.pageType
|
||||||
|
let sortedOperations = topAlertQueue.operations.sorted { $0.queuePriority.rawValue > $1.queuePriority.rawValue }
|
||||||
|
for case let operation as MVMCoreTopAlertOperation in sortedOperations {
|
||||||
|
operation.updateDisplayable(byPageType: pageType)
|
||||||
}
|
}
|
||||||
guard let pageType = pageType else {
|
|
||||||
topOperation.isDisplayable = false
|
|
||||||
return
|
|
||||||
}
|
|
||||||
topOperation.isDisplayable = pages.contains(pageType)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// When a detail page changes, check top alerts.
|
|
||||||
@objc private func viewControllerChanged(notification: Notification) {
|
|
||||||
reevaluteQueue()
|
reevaluteQueue()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -42,7 +42,7 @@
|
|||||||
self.popupAlertQueue.maxConcurrentOperationCount = 1;
|
self.popupAlertQueue.maxConcurrentOperationCount = 1;
|
||||||
self.topAlertQueue = [[NSOperationQueue alloc] init];
|
self.topAlertQueue = [[NSOperationQueue alloc] init];
|
||||||
self.topAlertQueue.maxConcurrentOperationCount = 1;
|
self.topAlertQueue.maxConcurrentOperationCount = 1;
|
||||||
[self registerWithNotificationCenter];
|
[self registerForPageChanges];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -172,6 +172,9 @@
|
|||||||
alertOperation = nil;
|
alertOperation = nil;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
|
NSString *currentPageType = ((UIViewController<MVMCoreViewControllerProtocol> *)[[MVMCoreUISplitViewController mainSplitViewController] getCurrentDetailViewController]).pageType;
|
||||||
|
[alertOperation updateDisplayableByPageType:currentPageType];
|
||||||
|
|
||||||
[self.topAlertQueue addOperation:alertOperation];
|
[self.topAlertQueue addOperation:alertOperation];
|
||||||
[self reevaluteQueue];
|
[self reevaluteQueue];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,6 +27,9 @@
|
|||||||
/// Updates the operation with a new object
|
/// Updates the operation with a new object
|
||||||
- (void)updateWithTopAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject;
|
- (void)updateWithTopAlertObject:(nonnull MVMCoreTopAlertObject *)topAlertObject;
|
||||||
|
|
||||||
|
/// Updates the operation isDisplayable based on the page type.
|
||||||
|
- (void)updateDisplayableByPageType:(nullable NSString *)pageType;
|
||||||
|
|
||||||
// Pauses the operation. Temporarily removes any alert.
|
// Pauses the operation. Temporarily removes any alert.
|
||||||
- (void)pause;
|
- (void)pause;
|
||||||
|
|
||||||
|
|||||||
@ -71,6 +71,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)updateDisplayableByPageType:(nullable NSString *)pageType {
|
||||||
|
NSArray <NSString *>*pages = [self.topAlertObject.json array:@"pages"];
|
||||||
|
if (pages.count == 0) {
|
||||||
|
self.displayable = YES;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (pageType.length == 0) {
|
||||||
|
self.displayable = NO;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.displayable = [pages containsObject:pageType];
|
||||||
|
}
|
||||||
|
|
||||||
- (BOOL)isPaused {
|
- (BOOL)isPaused {
|
||||||
__block BOOL isPaused;
|
__block BOOL isPaused;
|
||||||
dispatch_sync(self.pausedQueue, ^{
|
dispatch_sync(self.pausedQueue, ^{
|
||||||
|
|||||||
@ -68,6 +68,8 @@ public extension MVMCoreUITopAlertView {
|
|||||||
guard topAlertObject.json != nil,
|
guard topAlertObject.json != nil,
|
||||||
operation.topAlertObject.type == topAlertObject.type else { continue }
|
operation.topAlertObject.type == topAlertObject.type else { continue }
|
||||||
operation.update(with: topAlertObject)
|
operation.update(with: topAlertObject)
|
||||||
|
let pageType = (MVMCoreUISplitViewController.main()?.getCurrentDetailViewController() as? MVMCoreViewControllerProtocol)?.pageType
|
||||||
|
operation.updateDisplayable(byPageType: pageType)
|
||||||
MVMCoreAlertHandler.shared()?.reevaluteQueue()
|
MVMCoreAlertHandler.shared()?.reevaluteQueue()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user