Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ORK1Kit/ORK1Kit/Common/ORK1TaskViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <NSObject>
/// 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
Expand Down Expand Up @@ -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<ORK1EndTaskPromptConfiguration>)taskViewControllerEndTaskPromptConfiguration:(ORK1TaskViewController *)taskViewController;

/**
Asks the delegate if there is Learn More content for this step.

Expand Down
13 changes: 11 additions & 2 deletions ORK1Kit/ORK1Kit/Common/ORK1TaskViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1253,6 +1253,11 @@ - (void)presentCancelOptions:(BOOL)saveable sender:(UIBarButtonItem *)sender {
supportSaving = [self.delegate taskViewControllerSupportsSaveAndRestore:self];
}

id <ORK1EndTaskPromptConfiguration> configuration = nil;
if ([self.delegate respondsToSelector:@selector(taskViewControllerEndTaskPromptConfiguration:)]) {
configuration = [self.delegate taskViewControllerEndTaskPromptConfiguration:self];
}

UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil
message:nil
preferredStyle:UIAlertControllerStyleActionSheet];
Expand All @@ -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
Expand All @@ -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]];

Expand Down