diff options
author | NicoleYarroch <nicole@livio.io> | 2017-10-09 10:52:03 -0400 |
---|---|---|
committer | NicoleYarroch <nicole@livio.io> | 2017-10-09 10:52:03 -0400 |
commit | 6e689e049cd6ff002e09f101856cf99147fd046d (patch) | |
tree | 60500cdd6724bda2f2776f3a31434fd85f13bd6f | |
parent | 32dcb92238092fb304c75bea60a6185efe47dde4 (diff) | |
download | sdl_ios-6e689e049cd6ff002e09f101856cf99147fd046d.tar.gz |
Added managers
Signed-off-by: NicoleYarroch <nicole@livio.io>
-rw-r--r-- | SmartDeviceLink-iOS.xcodeproj/project.pbxproj | 60 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/AddCommandManager.h | 21 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/AddCommandManager.m | 38 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/AlertManager.h | 21 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/AlertManager.m | 32 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/MediaClockTimerManager.h | 21 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/MediaClockTimerManager.m | 33 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/ShowManager.h | 22 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/ShowManager.m | 74 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/SoftButtonManager.h | 32 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/SoftButtonManager.m | 199 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/SubscribeButtonManager.h | 24 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/SubscribeButtonManager.m | 50 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/TemplateManager.h | 20 | ||||
-rw-r--r-- | SmartDeviceLink_Example/Managers/TemplateManager.m | 91 |
15 files changed, 729 insertions, 9 deletions
diff --git a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj index b8a6bf6e9..3d8c13a82 100644 --- a/SmartDeviceLink-iOS.xcodeproj/project.pbxproj +++ b/SmartDeviceLink-iOS.xcodeproj/project.pbxproj @@ -1011,6 +1011,13 @@ 5DE5ABB71B0E38C90067BB02 /* SDLSystemRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FBD21A84238B00846EE7 /* SDLSystemRequest.h */; }; 5DE5ABB81B0E38C90067BB02 /* SDLSystemRequestResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 5D61FBD41A84238B00846EE7 /* SDLSystemRequestResponse.h */; }; 5DFFB9151BD7C89700DB3F04 /* SDLConnectionManagerType.h in Headers */ = {isa = PBXBuildFile; fileRef = 5DFFB9141BD7C89700DB3F04 /* SDLConnectionManagerType.h */; }; + 882255811F8BAB0F00C13EED /* TemplateManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 882255801F8BAB0F00C13EED /* TemplateManager.m */; }; + 882255841F8BABE700C13EED /* SoftButtonManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 882255831F8BABE700C13EED /* SoftButtonManager.m */; }; + 882255871F8BACCC00C13EED /* SubscribeButtonManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 882255861F8BACCC00C13EED /* SubscribeButtonManager.m */; }; + 8822558A1F8BADDC00C13EED /* MediaClockTimerManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 882255891F8BADDC00C13EED /* MediaClockTimerManager.m */; }; + 8822558D1F8BAE4600C13EED /* AddCommandManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8822558C1F8BAE4600C13EED /* AddCommandManager.m */; }; + 882255911F8BB0A600C13EED /* ShowManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 882255901F8BB0A600C13EED /* ShowManager.m */; }; + 8850CC351F8BBAAC0098615C /* AlertManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8850CC341F8BBAAC0098615C /* AlertManager.m */; }; 8850DB601F4475D30053A48D /* TestMultipleFilesConnectionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 8850DB5F1F4475D30053A48D /* TestMultipleFilesConnectionManager.m */; }; 8877F5EB1F34A3BE00DC128A /* SDLSendHapticDataSpec.m in Sources */ = {isa = PBXBuildFile; fileRef = 8877F5EA1F34A3BE00DC128A /* SDLSendHapticDataSpec.m */; }; 8877F5EE1F34A72200DC128A /* SDLSendHapticDataResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 8877F5EC1F34A72200DC128A /* SDLSendHapticDataResponse.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -2226,6 +2233,20 @@ 5DEE55BF1B8509CB004F0D0F /* SDLURLRequestTaskSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLURLRequestTaskSpec.m; path = "UtilitiesSpecs/HTTP Connection/SDLURLRequestTaskSpec.m"; sourceTree = "<group>"; }; 5DF2BB9C1B94E38A00CE5994 /* SDLURLSessionSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDLURLSessionSpec.m; path = "UtilitiesSpecs/HTTP Connection/SDLURLSessionSpec.m"; sourceTree = "<group>"; }; 5DFFB9141BD7C89700DB3F04 /* SDLConnectionManagerType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDLConnectionManagerType.h; sourceTree = "<group>"; }; + 8822557F1F8BAB0F00C13EED /* TemplateManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TemplateManager.h; sourceTree = "<group>"; }; + 882255801F8BAB0F00C13EED /* TemplateManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TemplateManager.m; sourceTree = "<group>"; }; + 882255821F8BABE700C13EED /* SoftButtonManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SoftButtonManager.h; sourceTree = "<group>"; }; + 882255831F8BABE700C13EED /* SoftButtonManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SoftButtonManager.m; sourceTree = "<group>"; }; + 882255851F8BACCC00C13EED /* SubscribeButtonManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SubscribeButtonManager.h; sourceTree = "<group>"; }; + 882255861F8BACCC00C13EED /* SubscribeButtonManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SubscribeButtonManager.m; sourceTree = "<group>"; }; + 882255881F8BADDC00C13EED /* MediaClockTimerManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MediaClockTimerManager.h; sourceTree = "<group>"; }; + 882255891F8BADDC00C13EED /* MediaClockTimerManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MediaClockTimerManager.m; sourceTree = "<group>"; }; + 8822558B1F8BAE4600C13EED /* AddCommandManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AddCommandManager.h; sourceTree = "<group>"; }; + 8822558C1F8BAE4600C13EED /* AddCommandManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AddCommandManager.m; sourceTree = "<group>"; }; + 8822558F1F8BB0A600C13EED /* ShowManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShowManager.h; sourceTree = "<group>"; }; + 882255901F8BB0A600C13EED /* ShowManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ShowManager.m; sourceTree = "<group>"; }; + 8850CC331F8BBAAC0098615C /* AlertManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AlertManager.h; sourceTree = "<group>"; }; + 8850CC341F8BBAAC0098615C /* AlertManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AlertManager.m; sourceTree = "<group>"; }; 8850DB5E1F4475D30053A48D /* TestMultipleFilesConnectionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestMultipleFilesConnectionManager.h; sourceTree = "<group>"; }; 8850DB5F1F4475D30053A48D /* TestMultipleFilesConnectionManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TestMultipleFilesConnectionManager.m; sourceTree = "<group>"; }; 8877F5EA1F34A3BE00DC128A /* SDLSendHapticDataSpec.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDLSendHapticDataSpec.m; sourceTree = "<group>"; }; @@ -2770,13 +2791,6 @@ path = MessageSpecs; sourceTree = "<group>"; }; - 5D0218E71A8D611600D1BF62 /* Frameworks */ = { - isa = PBXGroup; - children = ( - ); - name = Frameworks; - sourceTree = "<group>"; - }; 5D0218EB1A8E795700D1BF62 /* UI */ = { isa = PBXGroup; children = ( @@ -2884,13 +2898,12 @@ 5D4019B21A76EC350006B0C2 /* Supporting Files */, ); name = Example; - path = "SmartDeviceLink-iOS"; + path = SmartDeviceLink_Example; sourceTree = "<group>"; }; 5D4019B21A76EC350006B0C2 /* Supporting Files */ = { isa = PBXGroup; children = ( - 5D0218E71A8D611600D1BF62 /* Frameworks */, 5D5935111A855EBE00687FB9 /* main.m */, 5D4029D51A76F0410006B0C2 /* Info.plist */, ); @@ -2983,6 +2996,7 @@ children = ( 5D48329F1A92868E00252386 /* ProxyManager.h */, 5D4832A01A92868E00252386 /* ProxyManager.m */, + 8822558E1F8BB09500C13EED /* Managers */, ); name = SDL; sourceTree = "<group>"; @@ -4381,6 +4395,27 @@ name = "HTTP Connection"; sourceTree = "<group>"; }; + 8822558E1F8BB09500C13EED /* Managers */ = { + isa = PBXGroup; + children = ( + 8822558B1F8BAE4600C13EED /* AddCommandManager.h */, + 8822558C1F8BAE4600C13EED /* AddCommandManager.m */, + 8850CC331F8BBAAC0098615C /* AlertManager.h */, + 8850CC341F8BBAAC0098615C /* AlertManager.m */, + 882255881F8BADDC00C13EED /* MediaClockTimerManager.h */, + 882255891F8BADDC00C13EED /* MediaClockTimerManager.m */, + 8822558F1F8BB0A600C13EED /* ShowManager.h */, + 882255901F8BB0A600C13EED /* ShowManager.m */, + 882255821F8BABE700C13EED /* SoftButtonManager.h */, + 882255831F8BABE700C13EED /* SoftButtonManager.m */, + 882255851F8BACCC00C13EED /* SubscribeButtonManager.h */, + 882255861F8BACCC00C13EED /* SubscribeButtonManager.m */, + 8822557F1F8BAB0F00C13EED /* TemplateManager.h */, + 882255801F8BAB0F00C13EED /* TemplateManager.m */, + ); + path = Managers; + sourceTree = "<group>"; + }; 88B848C41F45E20900DED768 /* Helpers */ = { isa = PBXGroup; children = ( @@ -5092,12 +5127,19 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 882255871F8BACCC00C13EED /* SubscribeButtonManager.m in Sources */, 5D4832A51A94F90D00252386 /* ConnectionTransitionContext.m in Sources */, + 882255911F8BB0A600C13EED /* ShowManager.m in Sources */, 5D0218FC1A8E7E1700D1BF62 /* ConnectionContainerViewController.m in Sources */, + 882255841F8BABE700C13EED /* SoftButtonManager.m in Sources */, 5D0218FF1A8E9E0D00D1BF62 /* ConnectionIAPTableViewController.m in Sources */, + 882255811F8BAB0F00C13EED /* TemplateManager.m in Sources */, 5D48329D1A8EA33D00252386 /* Preferences.m in Sources */, + 8822558A1F8BADDC00C13EED /* MediaClockTimerManager.m in Sources */, 5D59350F1A855EB300687FB9 /* AppDelegate.m in Sources */, + 8822558D1F8BAE4600C13EED /* AddCommandManager.m in Sources */, 5D5935121A855EBE00687FB9 /* main.m in Sources */, + 8850CC351F8BBAAC0098615C /* AlertManager.m in Sources */, 5D4832A81A95191B00252386 /* ConnectionAnimatedTransition.m in Sources */, 5D4832A11A92868E00252386 /* ProxyManager.m in Sources */, 5D0218F61A8E79C400D1BF62 /* ConnectionTCPTableViewController.m in Sources */, diff --git a/SmartDeviceLink_Example/Managers/AddCommandManager.h b/SmartDeviceLink_Example/Managers/AddCommandManager.h new file mode 100644 index 000000000..852effb16 --- /dev/null +++ b/SmartDeviceLink_Example/Managers/AddCommandManager.h @@ -0,0 +1,21 @@ +// +// AddCommandManager.h +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import <Foundation/Foundation.h> +#import "SmartDeviceLink.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface AddCommandManager : NSObject + ++ (SDLAddCommand *)addCommandWithManager:(SDLManager *)manager commandId:(int)commandId menuName:(NSString *)menuName handler:(void (^)(void))handler; ++ (SDLDeleteCommand *)deleteCommandWithId:(int)commandId; + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/AddCommandManager.m b/SmartDeviceLink_Example/Managers/AddCommandManager.m new file mode 100644 index 000000000..ceea14aee --- /dev/null +++ b/SmartDeviceLink_Example/Managers/AddCommandManager.m @@ -0,0 +1,38 @@ +// +// AddCommandManager.m +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import "AddCommandManager.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation AddCommandManager + ++ (SDLAddCommand *)addCommandWithManager:(SDLManager *)manager commandId:(int)commandId menuName:(NSString *)menuName handler:(void (^)(void))handler { + SDLMenuParams *commandMenuParams = [[SDLMenuParams alloc] init]; + commandMenuParams.menuName = menuName; + + SDLAddCommand *addCommand = [[SDLAddCommand alloc] init]; + addCommand.vrCommands = [NSMutableArray arrayWithObject:menuName]; + addCommand.menuParams = commandMenuParams; + addCommand.cmdID = @(commandId); + + addCommand.handler = ^void(SDLOnCommand *notification) { + if (handler == nil) { return; } + handler(); + }; + + return addCommand; +} + ++ (SDLDeleteCommand *)deleteCommandWithId:(int)commandId { + return [[SDLDeleteCommand alloc] initWithId:commandId]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/AlertManager.h b/SmartDeviceLink_Example/Managers/AlertManager.h new file mode 100644 index 000000000..7d52364ab --- /dev/null +++ b/SmartDeviceLink_Example/Managers/AlertManager.h @@ -0,0 +1,21 @@ +// +// AlertManager.h +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import <Foundation/Foundation.h> +#import "SmartDeviceLink.h" +#import "SDLManager.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface AlertManager : NSObject + ++ (void)alertCommand_showText:(NSString *)text softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons duration:(int)duration withManager:(SDLManager *)manager; + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/AlertManager.m b/SmartDeviceLink_Example/Managers/AlertManager.m new file mode 100644 index 000000000..75a5c28bf --- /dev/null +++ b/SmartDeviceLink_Example/Managers/AlertManager.m @@ -0,0 +1,32 @@ +// +// AlertManager.m +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import "AlertManager.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation AlertManager + ++ (void)alertCommand_showText:(NSString *)text softButtons:(nullable NSArray<SDLSoftButton *> *)softButtons duration:(int)duration withManager:(SDLManager *)manager { + SDLAlert *alert = [[SDLAlert alloc] initWithAlertText1:text alertText2:nil alertText3:nil duration:duration softButtons:softButtons]; + alert.ttsChunks = [SDLTTSChunk textChunksFromString:text]; + + [manager sendRequest:alert withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + if (error != nil) { + SDLLogE(@"Error showing the alert (%@)", text); + } else if (![response.resultCode isEqualToEnum:SDLResultSuccess]) { + SDLLogE(@"The alert was not shown successfully wiht error: %@, (%@)", response.resultCode, text); + } else { + SDLLogD(@"Alert shown successfully"); + } + }]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/MediaClockTimerManager.h b/SmartDeviceLink_Example/Managers/MediaClockTimerManager.h new file mode 100644 index 000000000..c318c8dc0 --- /dev/null +++ b/SmartDeviceLink_Example/Managers/MediaClockTimerManager.h @@ -0,0 +1,21 @@ +// +// MediaClockTimerManager.h +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import <Foundation/Foundation.h> +#import "SmartDeviceLink.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface MediaClockTimerManager : NSObject + ++ (SDLSetMediaClockTimer *)addMediaClockTimerWithManager:(SDLManager *)manager; ++ (SDLSetMediaClockTimer *)removeMediaClockTimer; + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/MediaClockTimerManager.m b/SmartDeviceLink_Example/Managers/MediaClockTimerManager.m new file mode 100644 index 000000000..f0e998162 --- /dev/null +++ b/SmartDeviceLink_Example/Managers/MediaClockTimerManager.m @@ -0,0 +1,33 @@ +// +// MediaClockTimerManager.m +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import "MediaClockTimerManager.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation MediaClockTimerManager + ++ (SDLSetMediaClockTimer *)addMediaClockTimerWithManager:(SDLManager *)manager { + SDLStartTime *startTime = [[SDLStartTime alloc] initWithHours:0 minutes:0 seconds:0]; + SDLStartTime *endTime = [[SDLStartTime alloc] initWithHours:0 minutes:1 seconds:45]; + SDLSetMediaClockTimer *timer = [[SDLSetMediaClockTimer alloc] init]; + timer.startTime = startTime; + timer.endTime = endTime; + timer.updateMode = SDLUpdateModeCountUp; + return timer; +} + ++ (SDLSetMediaClockTimer *)removeMediaClockTimer { + SDLSetMediaClockTimer *timer = [[SDLSetMediaClockTimer alloc] init]; + timer.updateMode = SDLUpdateModeClear; + return timer; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/ShowManager.h b/SmartDeviceLink_Example/Managers/ShowManager.h new file mode 100644 index 000000000..c03aab8c5 --- /dev/null +++ b/SmartDeviceLink_Example/Managers/ShowManager.h @@ -0,0 +1,22 @@ +// +// ShowManager.h +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import <Foundation/Foundation.h> +#import "SmartDeviceLink.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface ShowManager : NSObject + ++ (SDLShow *)showCommand_showText:(Boolean)showText showMediaTrack:(Boolean)showMediaTrack showSoftButtons:(Boolean)showSoftButtons showImage:(nullable SDLImage *)showImage withManager:(SDLManager *)manager; ++ (void)showAll_mediaTemplate_withManager:(SDLManager *)manager image:(nullable SDLImage *)image; ++ (void)updateShowAll_mediaTemplate_withManager:(SDLManager *)manager image:(nullable SDLImage *)image; + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/ShowManager.m b/SmartDeviceLink_Example/Managers/ShowManager.m new file mode 100644 index 000000000..f6c247160 --- /dev/null +++ b/SmartDeviceLink_Example/Managers/ShowManager.m @@ -0,0 +1,74 @@ +// +// ShowManager.m +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import "ShowManager.h" +#import "MediaClockTimerManager.h" +#import "SoftButtonManager.h" +#import "SubscribeButtonManager.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation ShowManager + ++ (SDLShow *)showCommand_showText:(Boolean)showText showMediaTrack:(Boolean)showMediaTrack showSoftButtons:(Boolean)showSoftButtons showImage:(nullable SDLImage *)showImage withManager:(SDLManager *)manager { + SDLShow *show = [[SDLShow alloc] init]; + + if (showText) { + show.mainField1 = @"Main field 1"; + show.mainField2 = @"Main field 2"; + show.mainField3 = @"Main field 3"; + show.mainField4 = @"Main field 4"; + } + if (showMediaTrack) { + show.mediaTrack = @"Media Track"; + } + if (showSoftButtons) { + show.softButtons = [SoftButtonManager softButtonsWithManager:manager]; + } + if (showImage != nil) { + show.graphic = showImage; + } + + return show; +} + ++ (void)showAll_mediaTemplate_withManager:(SDLManager *)manager image:(nullable SDLImage *)image withSubscribeButtons:(Boolean)withSubscribeButtons withMediaTimer:(Boolean)withMediaTimer { + // Text, soft buttons, image + [self.class sdlex_showMediaWithManager:manager image:image]; + + // Subscribe buttons + if (withSubscribeButtons) { + for(SDLSubscribeButton *subscribeButton in [SubscribeButtonManager mediaTemplateSubscribeButtonsWithManager:manager]) { + [manager sendRequest:subscribeButton]; + } + } + + // Progress bar + if (withMediaTimer) { + [manager sendRequest:[MediaClockTimerManager addMediaClockTimerWithManager:manager]]; + } +} + ++ (void)showAll_mediaTemplate_withManager:(SDLManager *)manager image:(nullable SDLImage *)image { + [self.class showAll_mediaTemplate_withManager:manager image:image withSubscribeButtons:YES withMediaTimer:YES]; +} + ++ (void)updateShowAll_mediaTemplate_withManager:(SDLManager *)manager image:(nullable SDLImage *)image { + [self.class showAll_mediaTemplate_withManager:manager image:image withSubscribeButtons:NO withMediaTimer:NO]; +} + ++ (void)sdlex_showMediaWithManager:(SDLManager *)manager image:(nullable SDLImage *)image { + SDLShow *show = [self.class showCommand_showText:YES showMediaTrack:YES showSoftButtons:NO showImage:image withManager:manager]; + show.softButtons = [SoftButtonManager mediaTemplateSoftButtonsWithManager:manager image:image]; + + [manager sendRequest:show]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/SoftButtonManager.h b/SmartDeviceLink_Example/Managers/SoftButtonManager.h new file mode 100644 index 000000000..3247b6873 --- /dev/null +++ b/SmartDeviceLink_Example/Managers/SoftButtonManager.h @@ -0,0 +1,32 @@ +// +// SoftButtonManager.h +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import <Foundation/Foundation.h> +#import "SmartDeviceLink.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SoftButtonManager : NSObject + +#pragma mark - Soft button init + ++ (SDLSoftButton *)createSoftButtonWithText:(NSString *)text softButtonId:(int)softButtonId manager:(SDLManager *)manager handler:(nullable void (^)(void))handler; + ++ (SDLSoftButton *)createSoftButtonWithImage:(NSString *)text imageName:(NSString *)imageName softButtonId:(int)softButtonId manager:(SDLManager *)manager handler:(nullable void (^)(void))handler; + ++ (SDLSoftButton *)createSoftButtonWithTextAndImage:(NSString *)text imageName:(NSString *)imageName softButtonId:(int)softButtonId manager:(SDLManager *)manager handler:(nullable void (^)(void))handler; + +#pragma mark - Soft button array + ++ (NSMutableArray<SDLSoftButton *> *)softButtonsWithManager:(SDLManager *)manager; ++ (NSMutableArray<SDLSoftButton *> *)mediaTemplateSoftButtonsWithManager:(SDLManager *)manager image:(SDLImage *)image; ++ (NSArray<SDLSoftButton *> *)alertButtonsWithManager:(SDLManager *)manager; + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/SoftButtonManager.m b/SmartDeviceLink_Example/Managers/SoftButtonManager.m new file mode 100644 index 000000000..24ff9b479 --- /dev/null +++ b/SmartDeviceLink_Example/Managers/SoftButtonManager.m @@ -0,0 +1,199 @@ +// +// SoftButtonManager.m +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import "SoftButtonManager.h" +#import "AddCommandManager.h" +#import "AlertManager.h" +#import "MediaClockTimerManager.h" +#import "ShowManager.h" +#import "SubscribeButtonManager.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation SoftButtonManager + ++ (SDLSoftButton *)createSoftButtonWithText:(NSString *)text softButtonId:(int)softButtonId manager:(SDLManager *)manager handler:(nullable void (^)(void))handler { + return [self sdlex_createSoftButton:text softButtonId:softButtonId imageName:nil buttonType:SDLSoftButtonTypeText manager:manager handler:handler]; +} + ++ (SDLSoftButton *)createSoftButtonWithImage:(NSString *)text imageName:(NSString *)imageName softButtonId:(int)softButtonId manager:(SDLManager *)manager handler:(nullable void (^)(void))handler { + return [self sdlex_createSoftButton:text softButtonId:softButtonId imageName:imageName buttonType:SDLSoftButtonTypeImage manager:manager handler:handler]; +} + ++ (SDLSoftButton *)createSoftButtonWithTextAndImage:(NSString *)text imageName:(NSString *)imageName softButtonId:(int)softButtonId manager:(SDLManager *)manager handler:(nullable void (^)(void))handler { + return [self sdlex_createSoftButton:text softButtonId:softButtonId imageName:imageName buttonType:SDLSoftButtonTypeBoth manager:manager handler:handler]; +} + ++ (SDLSoftButton *)sdlex_createSoftButton:(NSString *)text softButtonId:(int)softButtonId imageName:(nullable NSString *)imageName buttonType:(SDLSoftButtonType)buttonType manager:(SDLManager *)manager handler:(void (^)(void))handler { + SDLSoftButton *softButton = [[SDLSoftButton alloc] initWithHandler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) { + if (![buttonEvent.buttonEventMode isEqualToEnum:SDLButtonEventModeButtonDown]) { return; } + if (handler == nil) { + SDLAlert* alert = [[SDLAlert alloc] init]; + alert.alertText1 = [NSString stringWithFormat:@"You tapped the soft button: %@", text]; + [manager sendRequest:alert]; + return; + } else { + handler(); + } + }]; + + softButton.text = text; + softButton.softButtonID = @(softButtonId); + softButton.type = buttonType; + + if ([buttonType isEqualToEnum:SDLSoftButtonTypeImage] || [buttonType isEqualToEnum:SDLSoftButtonTypeBoth]) { + SDLImage* image = [[SDLImage alloc] init]; + image.imageType = SDLImageTypeDynamic; + image.value = imageName; + softButton.image = image; + } + + return softButton; +} + ++ (NSMutableArray<SDLSoftButton *> *)softButtonsWithManager:(SDLManager *)manager { + NSMutableArray<SDLSoftButton *> *softButtons = [NSMutableArray array]; + void (^softButtonHandler)(void); + for(int i = 1; i < 9; i += 1) { + softButtonHandler = ^{ + [AlertManager + alertCommand_showText:[NSString stringWithFormat:@"Button %d Pressed", i] + softButtons:[SoftButtonManager alertButtonsWithManager:manager] + duration:5 + withManager:manager]; + }; + [softButtons addObject:[self.class createSoftButtonWithText:[NSString stringWithFormat:@"Button%d", i] softButtonId:i manager:manager handler:softButtonHandler]]; + } + return softButtons; +} + ++ (void)sdlex_subscribeButtonStateWithManager:(SDLManager *)manager subscribeButtonName:(SDLButtonName)subscribeButtonName isSubscribed:(Boolean)isSubscribed image:(SDLImage *)image { + if (isSubscribed) { + [manager sendRequest:[SubscribeButtonManager removeSubscribeButtonWithName:subscribeButtonName] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + if (![response.resultCode isEqualToEnum:SDLResultSuccess]) { return; } + [ShowManager updateShowAll_mediaTemplate_withManager:manager image:image]; + }]; + } else { + [manager sendRequest:[SubscribeButtonManager createSubscribeButtonWithName:subscribeButtonName withManager:manager] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + if (![response.resultCode isEqualToEnum:SDLResultSuccess]) { return; } + [ShowManager updateShowAll_mediaTemplate_withManager:manager image:image]; + }]; + } +} + ++ (NSArray<SDLSoftButton *> *)alertButtonsWithManager:(SDLManager *)manager { + return @[[self.class createSoftButtonWithText:@"Close Alert" softButtonId:200 manager:manager handler:nil]]; +} + +#pragma mark - Individual buttons + ++ (NSMutableArray<SDLSoftButton *> *)mediaTemplateSoftButtonsWithManager:(SDLManager *)manager image:(SDLImage *)image { + return [[NSMutableArray alloc] initWithObjects: + [self.class seekLeft_SoftButton_withManager:manager image:image buttonId:1], + [self.class play_SoftButton_withManager:manager image:image buttonId:2], + [self.class seekRight_SoftButton_withManager:manager image:image buttonId:3], + [self.class timer_SoftButton_withManager:manager image:image buttonId:4], + [self.class subMenu_SoftButton_withManager:manager image:image buttonId:5], + [self.class menu_SoftButton_withManager:manager image:image buttonId:6], + nil]; +} + + +static Boolean isSubscribedToSkipBackwardsButton = true; ++ (SDLSoftButton *)seekLeft_SoftButton_withManager:(SDLManager *)manager image:(SDLImage *)image buttonId:(int)buttonId { + return [self.class createSoftButtonWithText:(isSubscribedToSkipBackwardsButton ? @"- <<" : @"+ <<") softButtonId:buttonId manager:manager handler:^{ + [self.class sdlex_subscribeButtonStateWithManager:manager subscribeButtonName:SDLButtonNameSeekLeft isSubscribed:isSubscribedToSkipBackwardsButton image:image]; + isSubscribedToSkipBackwardsButton = !isSubscribedToSkipBackwardsButton; + }]; +} + +static Boolean isSubscribedToSkipForwardButton = true; ++ (SDLSoftButton *)seekRight_SoftButton_withManager:(SDLManager *)manager image:(SDLImage *)image buttonId:(int)buttonId { + return [self.class createSoftButtonWithText:(isSubscribedToSkipForwardButton ? @"- >>" : @"+ >>") softButtonId:buttonId manager:manager handler:^{ + [self.class sdlex_subscribeButtonStateWithManager:manager subscribeButtonName:SDLButtonNameSeekRight isSubscribed:isSubscribedToSkipForwardButton image:image]; + isSubscribedToSkipForwardButton = !isSubscribedToSkipForwardButton; + }]; +} + +static Boolean isSubscribedToPlayButton = true; ++ (SDLSoftButton *)play_SoftButton_withManager:(SDLManager *)manager image:(SDLImage *)image buttonId:(int)buttonId { + return [self.class createSoftButtonWithText:(isSubscribedToPlayButton ? @"- Play" : @"+ Play") softButtonId:buttonId manager:manager handler:^{ + [self sdlex_subscribeButtonStateWithManager:manager subscribeButtonName:SDLButtonNameOk + isSubscribed:isSubscribedToPlayButton image:image]; + isSubscribedToPlayButton = !isSubscribedToPlayButton; + }]; +} + +static Boolean isSubscribedToMediaTimer = true; ++ (SDLSoftButton *)timer_SoftButton_withManager:(SDLManager *)manager image:(SDLImage *)image buttonId:(int)buttonId { + return [self.class createSoftButtonWithText:(isSubscribedToMediaTimer ? @"- Timer" : @"+ Timer") softButtonId:buttonId manager:manager handler:^{ + if (isSubscribedToMediaTimer) { + [manager sendRequest:[MediaClockTimerManager removeMediaClockTimer] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [ShowManager updateShowAll_mediaTemplate_withManager:manager image:image]; + }]; + } else { + [manager sendRequest:[MediaClockTimerManager addMediaClockTimerWithManager:manager] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [ShowManager updateShowAll_mediaTemplate_withManager:manager image:image]; + }]; + } + + isSubscribedToMediaTimer = !isSubscribedToMediaTimer;; + }]; +} + +static Boolean isTextVisible = false; ++ (SDLSoftButton *)text_SoftButton_withManager:(SDLManager *)manager image:(SDLImage *)image buttonId:(int)buttonId { + return [self.class createSoftButtonWithText:(isTextVisible ? @"- Text" : @"+ Text") softButtonId:buttonId manager:manager handler:^{ + isTextVisible = !isTextVisible; + [ShowManager updateShowAll_mediaTemplate_withManager:manager image:image]; + }]; +} + +static Boolean isSubmenuVisible = false; ++ (SDLSoftButton *)subMenu_SoftButton_withManager:(SDLManager *)manager image:(SDLImage *)image buttonId:(int)buttonId { + return [self.class createSoftButtonWithText:(isSubmenuVisible ? @"- Submenu" : @"+ Submenu") softButtonId:buttonId manager:manager handler:^{ + int commandId = 200; + NSString *menuName = @"Submenu Example: Use sofbutton to add/delete"; + if (isSubmenuVisible) { + [manager sendRequest:[[SDLDeleteSubMenu alloc] initWithId:commandId] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [ShowManager updateShowAll_mediaTemplate_withManager:manager image:image]; + }]; + } else { + [manager sendRequest:[[SDLAddSubMenu alloc] initWithId:commandId menuName:menuName] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [ShowManager updateShowAll_mediaTemplate_withManager:manager image:image]; + }]; + } + isSubmenuVisible = !isSubmenuVisible; + }]; +} + +static Boolean isAddCommandVisible = false; ++ (SDLSoftButton *)menu_SoftButton_withManager:(SDLManager *)manager image:(SDLImage *)image buttonId:(int)buttonId { + return [self.class createSoftButtonWithText:(isAddCommandVisible ? @"- Menu" : @"+ Menu") softButtonId:buttonId manager:manager handler:^{ + int commandId = 201; + NSString *menuName = @"Add Command Example: Use softbutton to add/delete"; + if (isAddCommandVisible) { + [manager sendRequest:[AddCommandManager deleteCommandWithId:commandId] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [ShowManager updateShowAll_mediaTemplate_withManager:manager image:image]; + }]; + } else { + [manager sendRequest:[AddCommandManager addCommandWithManager:manager commandId:commandId menuName:menuName handler:^{ + SDLAlert* alert = [[SDLAlert alloc] init]; + alert.alertText1 = [NSString stringWithFormat:@"You tapped the Add Command: %@", menuName]; + [manager sendRequest:alert]; + }] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + [ShowManager updateShowAll_mediaTemplate_withManager:manager image:image]; + }]; + } + isAddCommandVisible = !isAddCommandVisible; + }]; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/SubscribeButtonManager.h b/SmartDeviceLink_Example/Managers/SubscribeButtonManager.h new file mode 100644 index 000000000..08cc06e9f --- /dev/null +++ b/SmartDeviceLink_Example/Managers/SubscribeButtonManager.h @@ -0,0 +1,24 @@ +// +// SubscribeButtonManager.h +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import <Foundation/Foundation.h> +#import "SmartDeviceLink.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface SubscribeButtonManager : NSObject + ++ (SDLSubscribeButton *)createSubscribeButtonWithName:(SDLButtonName)subscribeButtonName withManager:(SDLManager *)manager; ++ (SDLUnsubscribeButton *)removeSubscribeButtonWithName:(SDLButtonName)subscribeButtonName ; + ++ (NSArray<SDLSubscribeButton *> *)mediaTemplateSubscribeButtonsWithManager:(SDLManager *)manager; ++ (NSArray<SDLSubscribeButton *> *)anyTemplateSubscribeButtonsWithManager:(SDLManager *)manager; + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/SubscribeButtonManager.m b/SmartDeviceLink_Example/Managers/SubscribeButtonManager.m new file mode 100644 index 000000000..4cd253a5a --- /dev/null +++ b/SmartDeviceLink_Example/Managers/SubscribeButtonManager.m @@ -0,0 +1,50 @@ +// +// SubscribeButtonManager.m +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import "SubscribeButtonManager.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation SubscribeButtonManager + ++ (SDLSubscribeButton *)createSubscribeButtonWithName:(SDLButtonName)subscribeButtonName withManager:(SDLManager *)manager { + return [[SDLSubscribeButton alloc] initWithButtonName:subscribeButtonName handler:^(SDLOnButtonPress * _Nullable buttonPress, SDLOnButtonEvent * _Nullable buttonEvent) { + if (![buttonEvent.buttonEventMode isEqualToEnum:SDLButtonEventModeButtonDown]) { return; } + SDLAlert* alert = [[SDLAlert alloc] init]; + alert.alertText1 = [NSString stringWithFormat:@"You tapped the subscribe button: %@", subscribeButtonName]; + [manager sendRequest:alert]; + }]; +} + ++ (SDLUnsubscribeButton *)removeSubscribeButtonWithName:(SDLButtonName)subscribeButtonName { + return [[SDLUnsubscribeButton alloc] initWithButtonName:subscribeButtonName]; +} + ++ (NSArray<SDLSubscribeButton *> *)mediaTemplateSubscribeButtonsWithManager:(SDLManager *)manager { + NSMutableArray *subscribeButtons = [NSMutableArray array]; + // Tuneup and Tunedown are hard buttons only, the rest are both hard and soft buttons + NSArray<SDLButtonName> *mediaTemplateSubscribeButtons = [[NSArray alloc] initWithObjects:SDLButtonNameOk, SDLButtonNameSeekLeft, SDLButtonNameSeekRight, SDLButtonNameTuneUp, SDLButtonNameTuneDown, nil]; + for(SDLButtonName buttonName in mediaTemplateSubscribeButtons) { + [subscribeButtons addObject:[self.class createSubscribeButtonWithName:buttonName withManager:manager]]; + } + return subscribeButtons; +} + ++ (NSArray<SDLSubscribeButton *> *)anyTemplateSubscribeButtonsWithManager:(SDLManager *)manager { + NSMutableArray *subscribeButtons = [NSMutableArray array]; + // Hard buttons only (i.e. no corresponding soft button will show up on the screen) + NSArray<SDLButtonName> *allTemplateSubscribeButtons = [[NSArray alloc] initWithObjects:SDLButtonNameSearch, SDLButtonNameCustomButton, SDLButtonNamePreset0, SDLButtonNamePreset1, SDLButtonNamePreset2, SDLButtonNamePreset3, SDLButtonNamePreset4, SDLButtonNamePreset5, SDLButtonNamePreset6, SDLButtonNamePreset7, SDLButtonNamePreset8, SDLButtonNamePreset9, nil]; + for(SDLButtonName buttonName in allTemplateSubscribeButtons) { + [subscribeButtons addObject:[self.class createSubscribeButtonWithName:buttonName withManager:manager]]; + } + return subscribeButtons; +} + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/TemplateManager.h b/SmartDeviceLink_Example/Managers/TemplateManager.h new file mode 100644 index 000000000..5416a0cf6 --- /dev/null +++ b/SmartDeviceLink_Example/Managers/TemplateManager.h @@ -0,0 +1,20 @@ +// +// TemplateManager.h +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import <Foundation/Foundation.h> +#import "SmartDeviceLink.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface TemplateManager : NSObject + ++ (void)changeTemplateWithManager:(SDLManager *)manager toTemplate:(SDLPredefinedLayout)template image:(SDLImage *)image; + +@end + +NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink_Example/Managers/TemplateManager.m b/SmartDeviceLink_Example/Managers/TemplateManager.m new file mode 100644 index 000000000..6d4bca1ca --- /dev/null +++ b/SmartDeviceLink_Example/Managers/TemplateManager.m @@ -0,0 +1,91 @@ +// +// TemplateManager.m +// SmartDeviceLink-Example +// +// Created by Nicole on 10/9/17. +// Copyright © 2017 smartdevicelink. All rights reserved. +// + +#import "TemplateManager.h" +#import "AddCommandManager.h" +#import "MediaClockTimerManager.h" +#import "ShowManager.h" +#import "SoftButtonManager.h" +#import "SubscribeButtonManager.h" + +NS_ASSUME_NONNULL_BEGIN + +@implementation TemplateManager + ++ (void)changeTemplateWithManager:(SDLManager *)manager toTemplate:(SDLPredefinedLayout)template image:(SDLImage *)image { + void (^templateChangedHandler)(void); + + if ([template isEqualToEnum:SDLPredefinedLayoutMedia]) { + templateChangedHandler = ^{ + [ShowManager showAll_mediaTemplate_withManager:manager image:image]; + }; + } else if ([template isEqualToEnum:SDLPredefinedLayoutNonMedia]) { + templateChangedHandler = ^{ + [manager sendRequest:[ShowManager showCommand_showText:YES showMediaTrack:NO showSoftButtons:YES showImage:image withManager:manager]]; + }; + } else if ([template isEqualToEnum:SDLPredefinedLayoutTextWithGraphic] || [template isEqualToEnum:SDLPredefinedLayoutGraphicWithText]) { + templateChangedHandler = ^{ + [manager sendRequest:[ShowManager showCommand_showText:YES showMediaTrack:NO showSoftButtons:NO showImage:image withManager:manager] withResponseHandler:nil]; + }; + } else if ([template isEqualToEnum:SDLPredefinedLayoutTilesOnly]) { + templateChangedHandler = ^{ + [manager sendRequest:[ShowManager showCommand_showText:NO showMediaTrack:NO showSoftButtons:YES showImage:nil withManager:manager] withResponseHandler:nil]; + }; + } else if ([template isEqualToEnum:SDLPredefinedLayoutTilesWithGraphic] || [template isEqualToEnum:SDLPredefinedLayoutGraphicWithTiles]) { + templateChangedHandler = ^{ + [manager sendRequest:[ShowManager showCommand_showText:NO showMediaTrack:NO showSoftButtons:YES showImage:image withManager:manager] withResponseHandler:nil]; + }; + } else if ([template isEqualToEnum:SDLPredefinedLayoutTextAndSoftButtonsWithGraphic] || [template isEqualToEnum:SDLPredefinedLayoutGraphicWithTextAndSoftButtons]) { + templateChangedHandler = ^{ + [manager sendRequest:[ShowManager showCommand_showText:YES showMediaTrack:NO showSoftButtons:YES showImage:image withManager:manager]]; + }; + } else if ([template isEqualToEnum:SDLPredefinedLayoutDoubleGraphicWithSoftButtons]) { + templateChangedHandler = ^{ + SDLShow* show = [ShowManager showCommand_showText:NO showMediaTrack:NO showSoftButtons:YES showImage:image withManager:manager]; + show.secondaryGraphic = image; + [manager sendRequest:show withResponseHandler:nil]; + }; + } else if ([template isEqualToEnum:SDLPredefinedLayoutTextButtonsWithGraphic] || [template isEqualToEnum:SDLPredefinedLayoutGraphicWithTextButtons]) { + templateChangedHandler = ^{ + [manager sendRequest:[ShowManager showCommand_showText:NO showMediaTrack:NO showSoftButtons:YES showImage:image withManager:manager]]; + }; + } else if ([template isEqualToEnum:SDLPredefinedLayoutTextButtonsOnly]) { + templateChangedHandler = ^{ + [manager sendRequest:[ShowManager showCommand_showText:NO showMediaTrack:NO showSoftButtons:YES showImage:nil withManager:manager]]; + }; + } else if ([template isEqualToEnum:SDLPredefinedLayoutLargeGraphicWithSoftButtons]) { + templateChangedHandler = ^{ + [manager sendRequest:[ShowManager showCommand_showText:NO showMediaTrack:NO showSoftButtons:YES showImage:image withManager:manager]]; + }; + } else if ([template isEqualToEnum:SDLPredefinedLayoutLargeGraphicOnly]) { + templateChangedHandler = ^{ + [manager sendRequest:[ShowManager showCommand_showText:NO showMediaTrack:NO showSoftButtons:NO showImage:image withManager:manager]]; + }; + } else { + SDLAlert* alert = [[SDLAlert alloc] init]; + alert.alertText1 = [NSString stringWithFormat:@"No template for: %@", template]; + [manager sendRequest:alert]; + return; + } + + [self.class sdlex_setTemplate:template manager:manager image:image handler:templateChangedHandler]; +} + ++ (void)sdlex_setTemplate:(SDLPredefinedLayout)template manager:(SDLManager *)manager image:(SDLImage *)image handler:(void (^)(void))handler { + [manager sendRequest:[[SDLSetDisplayLayout alloc] initWithPredefinedLayout:template] withResponseHandler:^(__kindof SDLRPCRequest * _Nullable request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error) { + if([[response resultCode] isEqualToEnum:SDLResultSuccess]) { + handler(); + } else { + SDLLogE(@"The template was not changed successfully"); + } + }]; +} + +@end + +NS_ASSUME_NONNULL_END |