Merge branch 'feature/cancellable_alerts' into 'develop'

Add methods that will cancel pending or executing alert operations.

See merge request BPHV_MIPS/mvm_core!50
This commit is contained in:
Pfeil, Scott Robert 2020-02-12 09:24:53 -05:00
commit fd76691410
3 changed files with 63 additions and 18 deletions

View File

@ -16,15 +16,15 @@
@interface MVMCoreAlertHandler : NSObject @interface MVMCoreAlertHandler : NSObject
// Returns the shared instance of this singleton /// Returns the shared instance of this singleton
+ (nullable instancetype)sharedAlertHandler; + (nullable instancetype)sharedAlertHandler;
#pragma mark - Popup Alert Functions #pragma mark - Popup Alert Functions
// Returns if any alert is currently showing (even if supressed). /// Returns if any alert is currently showing (even if supressed).
- (BOOL)alertCurrentlyShowing; - (BOOL)alertCurrentlyShowing;
// Returns if a greedy alert is currently showing (even if supressed). /// Returns if a greedy alert is currently showing (even if supressed).
- (BOOL)greedyAlertShowing; - (BOOL)greedyAlertShowing;
/** Shows the popup with the passed in parameter. /** Shows the popup with the passed in parameter.
@ -53,38 +53,51 @@
*/ */
- (nonnull UIAlertController *)showAlertWithAlertObject:(nonnull MVMCoreAlertObject *)alertObject; - (nonnull UIAlertController *)showAlertWithAlertObject:(nonnull MVMCoreAlertObject *)alertObject;
// Removes all alerts. /** Cancels and removes an alert operation for the given alertObject.
* @param alertObject The alertObject scheduled to be shown.
*/
- (void)removeAlertViewForObject:(nonnull MVMCoreAlertObject *)alertObject;
/** Iterates through all scheduled alerts and cancels any that match the provided predicate.
* @param predicate The predicate block to decide whether to cancel an alert.
*/
- (void)removeAlertViewUsingPredicate:(BOOL(^_Nonnull)(MVMCoreAlertObject * _Nonnull obj))predicate;
/// Removes all alerts.
- (void)removeAllAlertViews; - (void)removeAllAlertViews;
#pragma mark - Supression Functions #pragma mark - Supression Functions
// Returns true if alerts are supressed. /// Returns true if alerts are supressed.
- (BOOL)mfAlertsSupressed; - (BOOL)mfAlertsSupressed;
// Supresses the alerts (Used by other "apps" in our app). /// Supresses the alerts (Used by other "apps" in our app).
- (void)supressMFAlerts; - (void)supressMFAlerts;
// Unsupresses the alerts (Used by other "apps" in our app). /// Unsupresses the alerts (Used by other "apps" in our app).
- (void)unSupressMFAlerts; - (void)unSupressMFAlerts;
#pragma mark - Top Alert Functions #pragma mark - Top Alert Functions
// Show based on the object. Will be used by the architecture. /// Show based on the object. Will be used by the architecture.
- (void)showTopAlertWithObject:(nullable MVMCoreTopAlertObject *)topAlertObject; - (void)showTopAlertWithObject:(nullable MVMCoreTopAlertObject *)topAlertObject;
// Convenience functions /// Convenience functions
- (void)showTopAlertErrorWithMessage:(nullable NSString *)message; - (void)showTopAlertErrorWithMessage:(nullable NSString *)message;
- (void)showTopAlertConfirmationWithMessage:(nullable NSString *)message; - (void)showTopAlertConfirmationWithMessage:(nullable NSString *)message;
- (void)showTopAlertWithType:(nullable NSString *)type message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage persistent:(BOOL)persistent actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData; - (void)showTopAlertWithType:(nullable NSString *)type message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage persistent:(BOOL)persistent actionMap:(nullable NSDictionary *)actionMap additionalData:(nullable NSDictionary *)additionalData;
- (void)showTopAlertWithType:(nullable NSString *)type message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage persistent:(BOOL)persistent buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler; - (void)showTopAlertWithType:(nullable NSString *)type message:(nullable NSString *)message subMessage:(nullable NSString *)subMessage persistent:(BOOL)persistent buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler;
// Hides the current alert view. /// Hides the current alert view.
- (void)hideTopAlertView; - (void)hideTopAlertView;
// Hides a persistent alert based on the type string. /// Hides a persistent alert based on the type string.
- (void)hidePersistentTopAlertViewOfType:(nullable NSString *)type; - (void)hidePersistentTopAlertViewOfType:(nullable NSString *)type;
// Removes all top alerts. /// Removes a scheduled top alert given its top alert object.
- (void)removeTopAlertForObject:(nonnull MVMCoreTopAlertObject *)topAlertObject;
/// Removes all top alerts.
- (void)removeAllTopAlerts; - (void)removeAllTopAlerts;
/// Returns YES if the persistent type is already registered in the alert queue. /// Returns YES if the persistent type is already registered in the alert queue.

View File

@ -107,6 +107,25 @@
return controller; return controller;
} }
- (void)removeAlertViewForObject:(MVMCoreAlertObject *)alertObject {
for (MVMCoreAlertOperation *operation in self.popupAlertQueue.operations) {
if ([operation.currentAlertView isKindOfClass:[MVMCoreAlertController class]] && [(MVMCoreAlertController *)operation.currentAlertView alertObject] == alertObject) {
[operation cancel];
}
}
}
- (void)removeAlertViewUsingPredicate:(BOOL(^)(MVMCoreAlertObject *obj))predicate {
for (MVMCoreAlertOperation *operation in self.popupAlertQueue.operations) {
if ([operation.currentAlertView isKindOfClass:[MVMCoreAlertController class]]) {
MVMCoreAlertObject *alertObject = [(MVMCoreAlertController *)operation.currentAlertView alertObject];
if (alertObject && predicate(alertObject)) {
[operation cancel];
}
}
}
}
- (void)removeAllAlertViews { - (void)removeAllAlertViews {
[self.popupAlertQueue cancelAllOperations]; [self.popupAlertQueue cancelAllOperations];
} }
@ -225,6 +244,16 @@
} }
} }
- (void)removeTopAlertForObject:(MVMCoreTopAlertObject *)topAlertObject {
for (MVMCoreTopAlertOperation *operation in self.topAlertQueue.operations) {
// Finds an cancels top alerts associated with the object.
if (operation.topAlertObject == topAlertObject) {
operation.reAddAfterCancel = NO;
[operation cancel];
}
}
}
- (void)removeAllTopAlerts { - (void)removeAllTopAlerts {
[self.topAlertQueue cancelAllOperations]; [self.topAlertQueue cancelAllOperations];
} }

View File

@ -14,23 +14,26 @@
@interface MVMCoreAlertOperation : MVMCoreOperation @interface MVMCoreAlertOperation : MVMCoreOperation
// If this operation is temporarily paused. /// Alert controller to be displayed.
@property (nonnull, readonly) UIAlertController *currentAlertView;
/// If this operation is temporarily paused.
@property (readonly, getter=isPaused) BOOL paused; @property (readonly, getter=isPaused) BOOL paused;
// If this alert is a greedy alert (See MVMCoreAlertHandler). /// If this alert is a greedy alert (See MVMCoreAlertHandler).
@property (readonly, getter=isGreedy) BOOL greedy; @property (readonly, getter=isGreedy) BOOL greedy;
// The alert delegate if needed. /// The alert delegate if needed.
@property (readonly, nullable, nonatomic, weak) NSObject <MVMCoreAlertDelegateProtocol> *alertDelegate; @property (readonly, nullable, nonatomic, weak) NSObject <MVMCoreAlertDelegateProtocol> *alertDelegate;
// Initializes the operation with the alert to display and if it is greedy or not. /// Initializes the operation with the alert to display and if it is greedy or not.
- (nullable instancetype)initWithAlert:(nonnull UIAlertController *)alert isGreedy:(BOOL)isGreedy; - (nullable instancetype)initWithAlert:(nonnull UIAlertController *)alert isGreedy:(BOOL)isGreedy;
- (nullable instancetype)initWithAlert:(nonnull UIAlertController *)alert isGreedy:(BOOL)isGreedy alertDelegate:(nullable id <MVMCoreAlertDelegateProtocol>)alertDelegate; - (nullable instancetype)initWithAlert:(nonnull UIAlertController *)alert isGreedy:(BOOL)isGreedy alertDelegate:(nullable id <MVMCoreAlertDelegateProtocol>)alertDelegate;
// Pauses the operation. Temporarily removes any alert. /// Pauses the operation. Temporarily removes any alert.
- (void)pause; - (void)pause;
// Unpauses the operation, resuming any alert. /// Unpauses the operation, resuming any alert.
- (void)unpause; - (void)unpause;
@end @end