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:
commit
fd76691410
@ -16,15 +16,15 @@
|
||||
|
||||
@interface MVMCoreAlertHandler : NSObject
|
||||
|
||||
// Returns the shared instance of this singleton
|
||||
/// Returns the shared instance of this singleton
|
||||
+ (nullable instancetype)sharedAlertHandler;
|
||||
|
||||
#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;
|
||||
|
||||
// Returns if a greedy alert is currently showing (even if supressed).
|
||||
/// Returns if a greedy alert is currently showing (even if supressed).
|
||||
- (BOOL)greedyAlertShowing;
|
||||
|
||||
/** Shows the popup with the passed in parameter.
|
||||
@ -53,38 +53,51 @@
|
||||
*/
|
||||
- (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;
|
||||
|
||||
#pragma mark - Supression Functions
|
||||
|
||||
// Returns true if alerts are supressed.
|
||||
/// Returns true if alerts are supressed.
|
||||
- (BOOL)mfAlertsSupressed;
|
||||
|
||||
// Supresses the alerts (Used by other "apps" in our app).
|
||||
/// Supresses the alerts (Used by other "apps" in our app).
|
||||
- (void)supressMFAlerts;
|
||||
|
||||
// Unsupresses the alerts (Used by other "apps" in our app).
|
||||
/// Unsupresses the alerts (Used by other "apps" in our app).
|
||||
- (void)unSupressMFAlerts;
|
||||
|
||||
#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;
|
||||
|
||||
// Convenience functions
|
||||
/// Convenience functions
|
||||
- (void)showTopAlertErrorWithMessage:(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 buttonTitle:(nullable NSString *)buttonTitle userActionHandler:(nullable void (^)(id _Nonnull sender))userActionHandler;
|
||||
|
||||
// Hides the current alert view.
|
||||
/// Hides the current alert view.
|
||||
- (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;
|
||||
|
||||
// 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;
|
||||
|
||||
/// Returns YES if the persistent type is already registered in the alert queue.
|
||||
|
||||
@ -107,6 +107,25 @@
|
||||
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 {
|
||||
[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 {
|
||||
[self.topAlertQueue cancelAllOperations];
|
||||
}
|
||||
|
||||
@ -14,23 +14,26 @@
|
||||
|
||||
@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;
|
||||
|
||||
// If this alert is a greedy alert (See MVMCoreAlertHandler).
|
||||
/// If this alert is a greedy alert (See MVMCoreAlertHandler).
|
||||
@property (readonly, getter=isGreedy) BOOL greedy;
|
||||
|
||||
// The alert delegate if needed.
|
||||
/// The alert delegate if needed.
|
||||
@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 alertDelegate:(nullable id <MVMCoreAlertDelegateProtocol>)alertDelegate;
|
||||
|
||||
// Pauses the operation. Temporarily removes any alert.
|
||||
/// Pauses the operation. Temporarily removes any alert.
|
||||
- (void)pause;
|
||||
|
||||
// Unpauses the operation, resuming any alert.
|
||||
/// Unpauses the operation, resuming any alert.
|
||||
- (void)unpause;
|
||||
|
||||
@end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user