summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicoleYarroch <nicole@livio.io>2021-02-10 11:43:47 -0500
committerNicoleYarroch <nicole@livio.io>2021-02-10 11:43:47 -0500
commit65ffc8cd42c7dc40611341fcd3bbf9eb0ba3e5e3 (patch)
tree413fe7d3fddb305575cc13baaf013faac525c4d5
parent2953b252a1aa49f77872271c81d23068e26fec9e (diff)
downloadsdl_ios-bugfix/issue_1891_fix_choice_set_default_timeout.tar.gz
Added caps to choice set timeoutbugfix/issue_1891_fix_choice_set_default_timeout
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r--SmartDeviceLink/public/SDLChoiceSet.h9
-rw-r--r--SmartDeviceLink/public/SDLChoiceSet.m43
-rw-r--r--SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetSpec.m24
3 files changed, 52 insertions, 24 deletions
diff --git a/SmartDeviceLink/public/SDLChoiceSet.h b/SmartDeviceLink/public/SDLChoiceSet.h
index 8deb33d0c..85253e624 100644
--- a/SmartDeviceLink/public/SDLChoiceSet.h
+++ b/SmartDeviceLink/public/SDLChoiceSet.h
@@ -35,7 +35,7 @@ typedef NS_ENUM(NSUInteger, SDLChoiceSetLayout) {
@interface SDLChoiceSet: NSObject
/**
- Set this to change the default timeout for all choice sets. If a timeout is not set on an individual choice set object (or if it is set to 0.0), then it will use this timeout instead. See `timeout` for more details. If this is not set by you, it will default to 10 seconds.
+ Set this to change the default timeout for all choice sets. If a timeout is not set on an individual choice set object (or if it is set to 0.0), then it will use this timeout instead. See `timeout` for more details. If this is not set by you, it will default to 10 seconds. The minimum is 5 seconds, the maximum is 100 seconds. If this is set below the minimum, it will be capped at 5 seconds. If this is set above the maximum, it will be capped at 100 seconds.
*/
@property (class, assign, nonatomic) NSTimeInterval defaultTimeout;
@@ -60,7 +60,7 @@ typedef NS_ENUM(NSUInteger, SDLChoiceSetLayout) {
@property (assign, nonatomic) SDLChoiceSetLayout layout;
/**
- Maps to PerformInteraction.timeout. Timeout in seconds. Defaults to 0, which will use `defaultTimeout`. If not set to 0, the timeout value must be between 5 and 100 seconds.
+ Maps to PerformInteraction.timeout. Timeout in seconds. Defaults to 0, which will use `defaultTimeout`. If this is set below the minimum, it will be capped at 5 seconds. Minimum 5 seconds, maximum 100 seconds. If this is set above the maximum, it will be capped at 100 seconds. Defaults to 0.
@note This applies only to a manual selection (not a voice selection, which has its timeout handled by the system).
*/
@@ -111,7 +111,7 @@ typedef NS_ENUM(NSUInteger, SDLChoiceSetLayout) {
@param title The choice set's title
@param delegate The choice set delegate called after the user has interacted with your choice set
@param layout The layout of choice options (Manual/touch only)
- @param timeout The timeout of a touch interaction (Manual/touch only)
+ @param timeout The timeout of a touch interaction in seconds (Manual/touch only)
@param initialPrompt A voice prompt spoken to the user when this set is displayed
@param timeoutPrompt A voice prompt spoken to the user when the set times out (Voice only)
@param helpPrompt A voice prompt spoken to the user when the user asks for "help"
@@ -127,7 +127,7 @@ typedef NS_ENUM(NSUInteger, SDLChoiceSetLayout) {
@param title The choice set's title
@param delegate The choice set delegate called after the user has interacted with your choice set
@param layout The layout of choice options (Manual/touch only)
- @param timeout The timeout of a touch interaction (Manual/touch only)
+ @param timeout The timeout of a touch interaction in seconds (Manual/touch only)
@param initialPrompt A voice prompt spoken to the user when this set is displayed
@param timeoutPrompt A voice prompt spoken to the user when the set times out (Voice only)
@param helpPrompt A voice prompt spoken to the user when the user asks for "help"
@@ -137,7 +137,6 @@ typedef NS_ENUM(NSUInteger, SDLChoiceSetLayout) {
*/
- (instancetype)initWithTitle:(NSString *)title delegate:(id<SDLChoiceSetDelegate>)delegate layout:(SDLChoiceSetLayout)layout timeout:(NSTimeInterval)timeout initialPrompt:(nullable NSArray<SDLTTSChunk *> *)initialPrompt timeoutPrompt:(nullable NSArray<SDLTTSChunk *> *)timeoutPrompt helpPrompt:(nullable NSArray<SDLTTSChunk *> *)helpPrompt vrHelpList:(nullable NSArray<SDLVRHelpItem *> *)helpList choices:(NSArray<SDLChoiceCell *> *)choices;
-
/**
Cancels the choice set. If the choice set has not yet been sent to Core, it will not be sent. If the choice set is already presented on Core, the choice set will be immediately dismissed. Canceling an already presented choice set will only work if connected to Core versions 6.0+. On older versions of Core, the choice set will not be dismissed.
*/
diff --git a/SmartDeviceLink/public/SDLChoiceSet.m b/SmartDeviceLink/public/SDLChoiceSet.m
index f2f5c14e3..3ac77d3cf 100644
--- a/SmartDeviceLink/public/SDLChoiceSet.m
+++ b/SmartDeviceLink/public/SDLChoiceSet.m
@@ -23,8 +23,10 @@ NS_ASSUME_NONNULL_BEGIN
@implementation SDLChoiceSet
-static NSTimeInterval _defaultTimeout = 10.0;
static const float TimeoutDefault = 0.0;
+static const float TimeoutMinCap = 5.0;
+static const float TimeoutMaxCap = 100.0;
+static NSTimeInterval _defaultTimeout = 10.0;
static SDLChoiceSetLayout _defaultLayout = SDLChoiceSetLayoutList;
- (instancetype)init {
@@ -58,13 +60,6 @@ static SDLChoiceSetLayout _defaultLayout = SDLChoiceSetLayoutList;
return nil;
}
- if (timeout == 0) {
- SDLLogV(@"Creating a choice set with a 0 second timeout; the default timeout will be used: %f seconds", SDLChoiceSet.defaultTimeout);
- } else if (timeout < 5 || timeout > 100) {
- SDLLogW(@"Attempted to create a choice set with a %f second timeout; Only 5 - 100 seconds is valid", timeout);
- return nil;
- }
-
if (title.length == 0 || title.length > 500) {
SDLLogW(@"Attempted to create a choice set title with a %lu length. Only 500 characters are supported", (unsigned long)title.length);
return nil;
@@ -104,7 +99,7 @@ static SDLChoiceSetLayout _defaultLayout = SDLChoiceSetLayoutList;
_title = title;
_delegate = delegate;
_layout = layout;
- _timeout = timeout;
+ self.timeout = timeout;
_initialPrompt = initialPrompt;
_timeoutPrompt = timeoutPrompt;
_helpPrompt = helpPrompt;
@@ -123,12 +118,30 @@ static SDLChoiceSetLayout _defaultLayout = SDLChoiceSetLayoutList;
#pragma mark - Getters / Setters
++ (void)setDefaultTimeout:(NSTimeInterval)defaultTimeout {
+ _defaultTimeout = defaultTimeout;
+}
+
+ (NSTimeInterval)defaultTimeout {
+ if (_defaultTimeout < TimeoutMinCap) {
+ return TimeoutMinCap;
+ } else if (_defaultTimeout > TimeoutMaxCap) {
+ return TimeoutMaxCap;
+ }
+
return _defaultTimeout;
}
-+ (void)setDefaultTimeout:(NSTimeInterval)defaultTimeout {
- _defaultTimeout = defaultTimeout;
+- (NSTimeInterval)timeout {
+ if (_timeout == TimeoutDefault) {
+ return SDLChoiceSet.defaultTimeout;
+ } else if (_timeout < TimeoutMinCap) {
+ return TimeoutMinCap;
+ } else if (_timeout > TimeoutMaxCap) {
+ return TimeoutMaxCap;
+ }
+
+ return _timeout;
}
+ (SDLChoiceSetLayout)defaultLayout {
@@ -147,14 +160,6 @@ static SDLChoiceSetLayout _defaultLayout = SDLChoiceSetLayoutList;
}
}
-- (NSTimeInterval)timeout {
- if (_timeout == TimeoutDefault) {
- return SDLChoiceSet.defaultTimeout;
- }
-
- return _timeout;
-}
-
#pragma mark - Etc.
- (NSString *)description {
diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetSpec.m
index e4df8ba62..d1fdeda01 100644
--- a/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetSpec.m
+++ b/SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetSpec.m
@@ -208,6 +208,20 @@ describe(@"an SDLChoiceSet", ^{
expect(SDLChoiceSet.defaultTimeout).to(equal(testDefaultTimeout));
expect(testChoiceSet.timeout).to(equal(testTimeout));
});
+
+ it(@"should return 100 if a value greater than 100 has been set", ^{
+ SDLChoiceSet.defaultTimeout = 155.0;
+
+ expect(SDLChoiceSet.defaultTimeout).to(equal(100.0));
+ expect(testChoiceSet.timeout).to(equal(100.0));
+ });
+
+ it(@"should return 5 if a value less than 5 has been set", ^{
+ SDLChoiceSet.defaultTimeout = -3.0;
+
+ expect(SDLChoiceSet.defaultTimeout).to(equal(5.0));
+ expect(testChoiceSet.timeout).to(equal(5.0));
+ });
});
describe(@"setting the timeout", ^{
@@ -233,6 +247,16 @@ describe(@"an SDLChoiceSet", ^{
testChoiceSet.timeout = testTimeout;
expect(testChoiceSet.timeout).to(equal(testTimeout));
});
+
+ it(@"should return 100 if a value greater than 100 has been set", ^{
+ testChoiceSet.timeout = 214.0;
+ expect(testChoiceSet.timeout).to(equal(100.0));
+ });
+
+ it(@"should return 5 if a value less than 5 has been set", ^{
+ testChoiceSet.timeout = 2.25;
+ expect(testChoiceSet.timeout).to(equal(5.0));
+ });
});
describe(@"canceling the choice set", ^{