diff --git a/ORK1Kit/ORK1Kit/Common/ORK1TaskViewController.h b/ORK1Kit/ORK1Kit/Common/ORK1TaskViewController.h index 0fca30e17..2bda16a3f 100644 --- a/ORK1Kit/ORK1Kit/Common/ORK1TaskViewController.h +++ b/ORK1Kit/ORK1Kit/Common/ORK1TaskViewController.h @@ -63,6 +63,16 @@ typedef NS_ENUM(NSInteger, ORK1TaskViewControllerFinishReason) { ORK1TaskViewControllerFinishReasonFailed }; +/// Configuration for customizing "end task"-related prompts during survey presentation. All properties are optional, a `nil` value indicates the ResearchKit default value should be used. +@protocol ORK1EndTaskPromptConfiguration +/// Button to dismiss a prompt and *not* end a task. +@property (readonly, nullable) NSString *cancelEndTaskButtonLocalizedTitle; +/// Button to confirm ending a task, for a task where results could be saved. +@property (readonly, nullable) NSString *discardResultsButtonLocalizedTitle; +/// Button to confirm ending a task, where there are no results to save. +@property (readonly, nullable) NSString *confirmEndTaskButtonLocalizedTitle; +@end + /** The task view controller delegate is responsible for processing the results of the task, exerting some control over how the controller behaves, and providing @@ -133,6 +143,12 @@ task view controller and pass that data to `initWithTask:restorationData:` when */ - (BOOL)taskViewControllerShouldConfirmCancel:(ORK1TaskViewController *)taskViewController; +@optional +/// Asks the delegate for optional custom configuration for end-task prompts. +/// @param taskViewController The calling `ORK1TaskViewController` instance. +/// @return A custom configuration. If `nil` or not implemented, a default configuration is used. +- (nullable id)taskViewControllerEndTaskPromptConfiguration:(ORK1TaskViewController *)taskViewController; + /** Asks the delegate if there is Learn More content for this step. diff --git a/ORK1Kit/ORK1Kit/Common/ORK1TaskViewController.m b/ORK1Kit/ORK1Kit/Common/ORK1TaskViewController.m index 41675c962..4311b14db 100644 --- a/ORK1Kit/ORK1Kit/Common/ORK1TaskViewController.m +++ b/ORK1Kit/ORK1Kit/Common/ORK1TaskViewController.m @@ -1253,6 +1253,11 @@ - (void)presentCancelOptions:(BOOL)saveable sender:(UIBarButtonItem *)sender { supportSaving = [self.delegate taskViewControllerSupportsSaveAndRestore:self]; } + id configuration = nil; + if ([self.delegate respondsToSelector:@selector(taskViewControllerEndTaskPromptConfiguration:)]) { + configuration = [self.delegate taskViewControllerEndTaskPromptConfiguration:self]; + } + UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; @@ -1268,7 +1273,9 @@ - (void)presentCancelOptions:(BOOL)saveable sender:(UIBarButtonItem *)sender { }]]; } - NSString *discardTitle = saveable ? ORK1LocalizedString(@"BUTTON_OPTION_DISCARD", nil) : ORK1LocalizedString(@"BUTTON_OPTION_STOP_TASK", nil); + NSString *discardTitle = saveable + ? (configuration.discardResultsButtonLocalizedTitle ?: ORK1LocalizedString(@"BUTTON_OPTION_DISCARD", nil)) + : (configuration.confirmEndTaskButtonLocalizedTitle ?: ORK1LocalizedString(@"BUTTON_OPTION_STOP_TASK", nil)); [alert addAction:[UIAlertAction actionWithTitle:discardTitle style:UIAlertActionStyleDestructive @@ -1278,7 +1285,9 @@ - (void)presentCancelOptions:(BOOL)saveable sender:(UIBarButtonItem *)sender { }); }]]; - [alert addAction:[UIAlertAction actionWithTitle:ORK1LocalizedString(@"BUTTON_CANCEL", nil) + NSString *cancelTitle = configuration.cancelEndTaskButtonLocalizedTitle ?: ORK1LocalizedString(@"BUTTON_CANCEL", nil); + + [alert addAction:[UIAlertAction actionWithTitle:cancelTitle style:UIAlertActionStyleCancel handler:nil]];