diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2018-06-21 13:29:51 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2018-06-21 13:29:51 -0400 |
commit | 910b20802fa3b20537021f81ae05a53d02451294 (patch) | |
tree | d1a6aca9832b45aa269bd161d623b63019747acb | |
parent | 193b1465bd2b5267ce7b2f748a11e68d62389590 (diff) | |
download | sdl_ios-910b20802fa3b20537021f81ae05a53d02451294.tar.gz |
Implement SDL-0085 Submenu icon
-rw-r--r-- | SmartDeviceLink/SDLAddSubMenu.h | 13 | ||||
-rw-r--r-- | SmartDeviceLink/SDLAddSubMenu.m | 21 | ||||
-rw-r--r-- | SmartDeviceLink/SDLMenuCell.h | 29 | ||||
-rw-r--r-- | SmartDeviceLink/SDLMenuCell.m | 5 | ||||
-rw-r--r-- | SmartDeviceLink/SDLMenuManager.m | 5 |
5 files changed, 62 insertions, 11 deletions
diff --git a/SmartDeviceLink/SDLAddSubMenu.h b/SmartDeviceLink/SDLAddSubMenu.h index 7a4471f60..d623fdac8 100644 --- a/SmartDeviceLink/SDLAddSubMenu.h +++ b/SmartDeviceLink/SDLAddSubMenu.h @@ -3,6 +3,8 @@ #import "SDLRPCRequest.h" +@class SDLImage; + /** * Add a SDLSubMenu to the Command Menu * <p> @@ -23,7 +25,9 @@ NS_ASSUME_NONNULL_BEGIN - (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName; -- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName position:(UInt8)position; +- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName position:(UInt8)position __deprecated_msg(("Use initWithId:menuName:menuIcon:position: instead")); + +- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName menuIcon:(nullable SDLImage *)icon position:(UInt8)position; /** * a Menu ID that identifies a sub menu @@ -32,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN * <p> */ @property (strong, nonatomic) NSNumber<SDLInt> *menuID; + /** * a position of menu * @discussion An NSNumber pointer representing the position within the items @@ -51,12 +56,18 @@ NS_ASSUME_NONNULL_BEGIN * </ul> */ @property (nullable, strong, nonatomic) NSNumber<SDLInt> *position; + /** * a menuName which is displayed representing this submenu item * @discussion NSString which will be displayed representing this submenu item */ @property (strong, nonatomic) NSString *menuName; +/** + An image that is displayed alongside this submenu item + */ +@property (strong, nonatomic) SDLImage *menuIcon; + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLAddSubMenu.m b/SmartDeviceLink/SDLAddSubMenu.m index 4f8ef5109..474e8646d 100644 --- a/SmartDeviceLink/SDLAddSubMenu.m +++ b/SmartDeviceLink/SDLAddSubMenu.m @@ -3,6 +3,7 @@ #import "SDLAddSubMenu.h" #import "NSMutableDictionary+Store.h" +#import "SDLImage.h" #import "SDLNames.h" NS_ASSUME_NONNULL_BEGIN @@ -15,18 +16,20 @@ NS_ASSUME_NONNULL_BEGIN return self; } - -- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName position:(UInt8)position { +- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName menuIcon:(nullable SDLImage *)icon position:(UInt8)position { self = [self initWithId:menuId menuName:menuName]; - if (!self) { - return nil; - } + if (!self) { return nil; } self.position = @(position); + self.menuIcon = icon; return self; } +- (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName position:(UInt8)position { + return [self initWithId:menuId menuName:menuName menuIcon:nil position:position]; +} + - (instancetype)initWithId:(UInt32)menuId menuName:(NSString *)menuName { self = [self init]; if (!self) { @@ -63,6 +66,14 @@ NS_ASSUME_NONNULL_BEGIN return [parameters sdl_objectForName:SDLNameMenuName]; } +- (void)setMenuIcon:(SDLImage *)menuIcon { + [parameters sdl_setObject:menuIcon forName:SDLNameMenuIcon]; +} + +- (SDLImage *)menuIcon { + return [parameters sdl_objectForName:SDLNameMenuIcon ofClass:[SDLImage class]]; +} + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLMenuCell.h b/SmartDeviceLink/SDLMenuCell.h index 80edc70b1..1c9c8dcbc 100644 --- a/SmartDeviceLink/SDLMenuCell.h +++ b/SmartDeviceLink/SDLMenuCell.h @@ -43,8 +43,35 @@ typedef void(^SDLMenuCellSelectionHandler)(SDLTriggerSource triggerSource); */ @property (copy, nonatomic, readonly, nullable) NSArray<SDLMenuCell *> *subCells; +/** + Create a menu cell that has no subcells. + + @param title The cell's primary text + @param icon The cell's image + @param voiceCommands Voice commands that will activate the menu cell + @param handler The code that will be run when the menu cell is selected + @return The menu cell + */ - (instancetype)initWithTitle:(NSString *)title icon:(nullable SDLArtwork *)icon voiceCommands:(nullable NSArray<NSString *> *)voiceCommands handler:(SDLMenuCellSelectionHandler)handler; -- (instancetype)initWithTitle:(NSString *)title subCells:(NSArray<SDLMenuCell *> *)subCells; + +/** + Create a menu cell that has subcells and when selected will go into a deeper part of the menu + + @param title The cell's primary text + @param subCells The subcells that will appear when the cell is selected + @return The menu cell + */ +- (instancetype)initWithTitle:(NSString *)title subCells:(NSArray<SDLMenuCell *> *)subCells __deprecated_msg(("Use initWithTitle:icon:subcells: instead")); + +/** + Create a menu cell that has subcells and when selected will go into a deeper part of the menu + + @param title The cell's primary text + @param icon The cell's image + @param subCells The subcells that will appear when the cell is selected + @return The menu cell + */ +- (instancetype)initWithTitle:(NSString *)title icon:(nullable SDLArtwork *)icon subCells:(NSArray<SDLMenuCell *> *)subCells; @end diff --git a/SmartDeviceLink/SDLMenuCell.m b/SmartDeviceLink/SDLMenuCell.m index 0d2d9f03e..cc7bfd53c 100644 --- a/SmartDeviceLink/SDLMenuCell.m +++ b/SmartDeviceLink/SDLMenuCell.m @@ -37,10 +37,15 @@ NS_ASSUME_NONNULL_BEGIN } - (instancetype)initWithTitle:(NSString *)title subCells:(NSArray<SDLMenuCell *> *)subCells { + return [self initWithTitle:title icon:nil subCells:subCells]; +} + +- (instancetype)initWithTitle:(NSString *)title icon:(nullable SDLArtwork *)icon subCells:(NSArray<SDLMenuCell *> *)subCells { self = [super init]; if (!self) { return nil; } _title = title; + _icon = icon; _subCells = subCells; _cellId = UINT32_MAX; diff --git a/SmartDeviceLink/SDLMenuManager.m b/SmartDeviceLink/SDLMenuManager.m index 4ad83d939..b1a2ec0ef 100644 --- a/SmartDeviceLink/SDLMenuManager.m +++ b/SmartDeviceLink/SDLMenuManager.m @@ -369,10 +369,7 @@ UInt32 const MenuCellIdMin = 1; } - (SDLAddSubMenu *)sdl_subMenuCommandForMenuCell:(SDLMenuCell *)cell position:(UInt16)position { - SDLAddSubMenu *submenu = [[SDLAddSubMenu alloc] initWithId:cell.cellId menuName:cell.title]; - submenu.position = @(position); - - return submenu; + return [[SDLAddSubMenu alloc] initWithId:cell.cellId menuName:cell.title menuIcon:cell.icon position:(UInt8)position]; } #pragma mark - Calling handlers |