summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Gluck <justin.gluck@livio.io>2019-06-10 13:19:40 -0400
committerJustin Gluck <justin.gluck@livio.io>2019-06-10 13:19:40 -0400
commit7b3972399f7cc650303af8171301428dcd7c2dad (patch)
treea84eb6e72ce02baab3c554633dc0daa8b128bc29
parent02465d1dbeb8eb4dce1af6ca8d8749eafb511862 (diff)
downloadsdl_ios-feature/issue-1144-Dynamic-Menu-Manager.tar.gz
fixing pr issues, formatting, spelling, documentationfeature/issue-1144-Dynamic-Menu-Manager
-rw-r--r--SmartDeviceLink/SDLDynamicMenuUpdateAlgorithm.m24
-rw-r--r--SmartDeviceLink/SDLMenuManager.m55
-rw-r--r--SmartDeviceLink/SDLScreenManager.h7
3 files changed, 47 insertions, 39 deletions
diff --git a/SmartDeviceLink/SDLDynamicMenuUpdateAlgorithm.m b/SmartDeviceLink/SDLDynamicMenuUpdateAlgorithm.m
index 552bf6644..51bfd14e2 100644
--- a/SmartDeviceLink/SDLDynamicMenuUpdateAlgorithm.m
+++ b/SmartDeviceLink/SDLDynamicMenuUpdateAlgorithm.m
@@ -18,11 +18,11 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Update Menu Cells
+ (nullable SDLDynamicMenuUpdateRunScore *)compareOldMenuCells:(NSArray<SDLMenuCell *> *)oldMenuCells updatedMenuCells:(NSArray<SDLMenuCell *> *)updatedMenuCells{
- if(oldMenuCells.count > 0 && updatedMenuCells.count == 0) {
+ if (oldMenuCells.count > 0 && updatedMenuCells.count == 0) {
return [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:[SDLDynamicMenuUpdateAlgorithm sdl_buildAllDeleteStatusesforMenu:oldMenuCells] updatedStatus:@[] score:0];
- }else if(oldMenuCells.count == 0 && updatedMenuCells.count > 0) {
+ }else if (oldMenuCells.count == 0 && updatedMenuCells.count > 0) {
return [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:@[] updatedStatus:[SDLDynamicMenuUpdateAlgorithm sdl_buildAllAddStatusesForMenu:updatedMenuCells] score:updatedMenuCells.count];
- } else if(oldMenuCells.count == 0 && updatedMenuCells.count == 0) {
+ } else if (oldMenuCells.count == 0 && updatedMenuCells.count == 0) {
return nil;
}
@@ -38,10 +38,10 @@ NS_ASSUME_NONNULL_BEGIN
NSMutableArray<NSNumber *> *newMenuStatus = [SDLDynamicMenuUpdateAlgorithm sdl_buildAllAddStatusesForMenu:updatedMenuCells];
NSUInteger startIndex = 0;
- for(NSUInteger oldCellIndex = run; oldCellIndex < oldMenuCells.count; oldCellIndex++) { //For each old item
+ for (NSUInteger oldCellIndex = run; oldCellIndex < oldMenuCells.count; oldCellIndex++) { //For each old item
// Create inner loop to compare old cells to new cells to find a match, if a match if found we mark the index at match for both the old and the new status to keep since we do not want to send RPCs for those cases
- for(NSUInteger newCellIndex = startIndex; newCellIndex < updatedMenuCells.count; newCellIndex++) {
- if([oldMenuCells[oldCellIndex] isEqual:updatedMenuCells[newCellIndex]]) {
+ for (NSUInteger newCellIndex = startIndex; newCellIndex < updatedMenuCells.count; newCellIndex++) {
+ if ([oldMenuCells[oldCellIndex] isEqual:updatedMenuCells[newCellIndex]]) {
oldMenuStatus[oldCellIndex] = @(MenuCellStateKeep);
newMenuStatus[newCellIndex] = @(MenuCellStateKeep);
startIndex = newCellIndex + 1;
@@ -52,20 +52,20 @@ NS_ASSUME_NONNULL_BEGIN
// Add RPC are the biggest operation so we need to find the run with the least amount of Adds. We will reset the run we use each time a runscore is less than the current score.
NSUInteger numberOfAdds = 0;
- for(NSUInteger status = 0; status < newMenuStatus.count; status++) {
+ for (NSUInteger status = 0; status < newMenuStatus.count; status++) {
// 0 = Delete 1 = Add 2 = Keep
- if(newMenuStatus[status].integerValue == MenuCellStateAdd) {
+ if (newMenuStatus[status].integerValue == MenuCellStateAdd) {
numberOfAdds++;
}
}
// As soon as we a run that requires 0 Adds we will use it since we cant do better then 0
- if(numberOfAdds == 0) {
+ if (numberOfAdds == 0) {
bestScore = [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:oldMenuStatus updatedStatus:newMenuStatus score:numberOfAdds];
return bestScore;
}
// if we havent create the bestScore object or if the current score beats the old score then we will create a new bestScore
- if(bestScore == nil || numberOfAdds < bestScore.score) {
+ if (bestScore == nil || numberOfAdds < bestScore.score) {
bestScore = [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:oldMenuStatus updatedStatus:newMenuStatus score:numberOfAdds];
}
}
@@ -80,7 +80,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (NSMutableArray<NSNumber *> *)sdl_buildAllDeleteStatusesforMenu:(NSArray<SDLMenuCell *> *)oldMenu {
NSMutableArray<NSNumber *> *oldMenuStatus = [[NSMutableArray alloc] init];
- for(NSUInteger index = 0; index < oldMenu.count; index++) {
+ for (NSUInteger index = 0; index < oldMenu.count; index++) {
[oldMenuStatus addObject:@(MenuCellStateDelete)];
}
return [oldMenuStatus mutableCopy];
@@ -93,7 +93,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
+ (NSMutableArray<NSNumber *> *)sdl_buildAllAddStatusesForMenu:(NSArray<SDLMenuCell *> *)newMenu {
NSMutableArray<NSNumber *> *newMenuStatus = [[NSMutableArray alloc] init];
- for(NSUInteger index = 0; index < newMenu.count; index++) {
+ for (NSUInteger index = 0; index < newMenu.count; index++) {
[newMenuStatus addObject:@(MenuCellStateAdd)];
}
return [newMenuStatus mutableCopy];
diff --git a/SmartDeviceLink/SDLMenuManager.m b/SmartDeviceLink/SDLMenuManager.m
index f4728839c..b782d49c6 100644
--- a/SmartDeviceLink/SDLMenuManager.m
+++ b/SmartDeviceLink/SDLMenuManager.m
@@ -146,7 +146,7 @@ UInt32 const MenuCellIdMin = 1;
_oldMenuCells = _menuCells;
_menuCells = menuCells;
- if([self sdl_isDynamicMenuUpdateActive:self.dynamicMenuUpdatesMode]) {
+ if ([self sdl_isDynamicMenuUpdateActive:self.dynamicMenuUpdatesMode]) {
[self sdl_startDynamicMenuUpdate];
} else {
[self sdl_startNonDynamicMenuUpdate];
@@ -156,12 +156,12 @@ UInt32 const MenuCellIdMin = 1;
#pragma mark - Build Deletes, Keeps, Adds
- (void)sdl_startSubMenuUpdatesWithOldKeptCells:(NSArray<SDLMenuCell *> *)oldKeptCells newKeptCells:(NSArray<SDLMenuCell *> *)newKeptCells atIndex:(NSUInteger)startIndex {
- if(oldKeptCells.count == 0 || startIndex >= oldKeptCells.count) {
+ if (oldKeptCells.count == 0 || startIndex >= oldKeptCells.count) {
self.inProgressUpdate = nil;
return;
}
- if(oldKeptCells[startIndex].subCells.count > 0) {
+ if (oldKeptCells[startIndex].subCells.count > 0) {
SDLDynamicMenuUpdateRunScore *tempScore = [SDLDynamicMenuUpdateAlgorithm compareOldMenuCells:oldKeptCells[startIndex].subCells updatedMenuCells:newKeptCells[startIndex].subCells];
NSArray<NSNumber *> *deleteMenuStatus = tempScore.oldStatus;
NSArray<NSNumber *> *addMenuStatus = tempScore.updatedStatus;
@@ -192,8 +192,8 @@ UInt32 const MenuCellIdMin = 1;
NSMutableArray<SDLMenuCell *> *deleteCells = [[NSMutableArray alloc] init];
// The index of the status should corrleate 1-1 with the number of items in the menu
// [2,0,2,0] => [A,B,C,D] = [B,D]
- for(NSUInteger index = 0; index < oldMenuItems.count; index++) {
- if(oldMenuItems[index].integerValue == MenuCellStateDelete) {
+ for (NSUInteger index = 0; index < oldMenuItems.count; index++) {
+ if (oldMenuItems[index].integerValue == MenuCellStateDelete) {
[deleteCells addObject:oldList[index]];
}
}
@@ -204,8 +204,8 @@ UInt32 const MenuCellIdMin = 1;
NSMutableArray<SDLMenuCell *> *addCells = [[NSMutableArray alloc] init];
// The index of the status should corrleate 1-1 with the number of items in the menu
// [2,1,2,1] => [A,B,C,D] = [B,D]
- for(NSUInteger index = 0; index < newMenuItems.count; index++) {
- if(newMenuItems[index].integerValue == MenuCellStateAdd) {
+ for (NSUInteger index = 0; index < newMenuItems.count; index++) {
+ if (newMenuItems[index].integerValue == MenuCellStateAdd) {
[addCells addObject:statusList[index]];
}
}
@@ -215,8 +215,8 @@ UInt32 const MenuCellIdMin = 1;
- (NSArray<SDLMenuCell *> *)sdl_filterKeepMenuItemsWithOldMenuItems:(NSArray<NSNumber *> *)oldMenuItems basedOnStatusList:(NSArray<SDLMenuCell *> *)statusList {
NSMutableArray<SDLMenuCell *> *keepMenuCells = [[NSMutableArray alloc] init];
- for(NSUInteger index = 0; index < oldMenuItems.count; index++) {
- if(oldMenuItems[index].integerValue == MenuCellStateKeep) {
+ for (NSUInteger index = 0; index < oldMenuItems.count; index++) {
+ if (oldMenuItems[index].integerValue == MenuCellStateKeep) {
[keepMenuCells addObject:statusList[index]];
}
}
@@ -225,8 +225,8 @@ UInt32 const MenuCellIdMin = 1;
- (NSArray<SDLMenuCell *> *)sdl_filterKeepMenuItemsWithNewMenuItems:(NSArray<NSNumber *> *)newMenuItems basedOnStatusList:(NSArray<SDLMenuCell *> *)statusList {
NSMutableArray<SDLMenuCell *> *keepMenuCells = [[NSMutableArray alloc] init];
- for(NSUInteger index = 0; index < newMenuItems.count; index++) {
- if(newMenuItems[index].integerValue == MenuCellStateKeep) {
+ for (NSUInteger index = 0; index < newMenuItems.count; index++) {
+ if (newMenuItems[index].integerValue == MenuCellStateKeep) {
[keepMenuCells addObject:statusList[index]];
}
}
@@ -235,7 +235,7 @@ UInt32 const MenuCellIdMin = 1;
- (void)transferCellIDFromOldCells:(NSArray<SDLMenuCell *> *)oldCells toKeptCells:(NSArray<SDLMenuCell *> *)newCells {
if (oldCells.count == 0) { return; }
- for(NSUInteger i = 0; i < newCells.count; i++) {
+ for (NSUInteger i = 0; i < newCells.count; i++) {
newCells[i].cellId = oldCells[i].cellId;
}
}
@@ -365,7 +365,7 @@ UInt32 const MenuCellIdMin = 1;
*/
- (void)sdl_sendUpdatedMenu:(NSArray<SDLMenuCell *> *)updatedMenu usingMenu:(NSArray<SDLMenuCell *> *)menu withCompletionHandler:(SDLMenuUpdateCompletionHandler)completionHandler {
if (self.menuCells.count == 0 || updatedMenu.count == 0) {
- SDLLogD(@"No main menu to send");
+ SDLLogD(@"There are no cells to update.");
completionHandler(nil);
return;
}
@@ -375,11 +375,11 @@ UInt32 const MenuCellIdMin = 1;
if ([self sdl_findAllArtworksToBeUploadedFromCells:self.menuCells].count > 0 || ![self.displayCapabilities hasImageFieldOfName:SDLImageFieldNameCommandIcon]) {
// Send artwork-less menu
- mainMenuCommands = [self sdl_mainMenuCommandsForCells:updatedMenu withArtwork:NO usingIndexOf:menu];
+ mainMenuCommands = [self sdl_mainMenuCommandsForCells:updatedMenu withArtwork:NO usingIndexesFrom:menu];
subMenuCommands = [self sdl_subMenuCommandsForCells:updatedMenu withArtwork:NO];
} else {
// Send full artwork menu
- mainMenuCommands = [self sdl_mainMenuCommandsForCells:updatedMenu withArtwork:YES usingIndexOf:menu];
+ mainMenuCommands = [self sdl_mainMenuCommandsForCells:updatedMenu withArtwork:YES usingIndexesFrom:menu];
subMenuCommands = [self sdl_subMenuCommandsForCells:updatedMenu withArtwork:YES];
}
@@ -397,8 +397,7 @@ UInt32 const MenuCellIdMin = 1;
completionHandler([NSError sdl_menuManager_failedToUpdateWithDictionary:errors]);
return;
}
-
- //weakSelf.oldMenuCells = weakSelf.menuCells; // ASK about this what does oldMenuCells become now? Dont do this yet we need to delete // add subcells first
+
[weakSelf.connectionManager sendRequests:subMenuCommands progressHandler:^(__kindof SDLRPCRequest * _Nonnull request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error, float percentComplete) {
if (error != nil) {
errors[request] = error;
@@ -425,7 +424,11 @@ UInt32 const MenuCellIdMin = 1;
case SDLDynamicMenuUpdatesModeForceOff:
return NO;
case SDLDynamicMenuUpdatesModeOnWithCompatibility:
- return ![self.displayCapabilities.displayName isEqualToEnum:SDLDisplayTypeGen38Inch];
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ return ![self.displayCapabilities.displayType isEqualToEnum:SDLDisplayTypeGen38Inch];
+#pragma clang diagnostic pop
+
}
}
@@ -489,17 +492,17 @@ UInt32 const MenuCellIdMin = 1;
@param cells that will be added to the menu, this array must contain only cells that are not already in the menu.
@param shouldHaveArtwork artwork bool
- @param the new menu array, this array should contain all the values the develeoper has set to be included in the new menu. This is used for placing the newly added cells in the correct locaiton.
+ @param menu the new menu array, this array should contain all the values the develeoper has set to be included in the new menu. This is used for placing the newly added cells in the correct locaiton.
e.g. If the new menu array is [A, B, C, D] but only [C, D] are new we need to pass [A, B , C , D] so C and D can be added to index 2 and 3 respectively.
@return list of SDLRPCRequest addCommands
*/
-- (NSArray<SDLRPCRequest *> *)sdl_mainMenuCommandsForCells:(NSArray<SDLMenuCell *> *)cells withArtwork:(BOOL)shouldHaveArtwork usingIndexOf:(NSArray<SDLMenuCell *> *)menu {
+- (NSArray<SDLRPCRequest *> *)sdl_mainMenuCommandsForCells:(NSArray<SDLMenuCell *> *)cells withArtwork:(BOOL)shouldHaveArtwork usingIndexesFrom:(NSArray<SDLMenuCell *> *)menu {
NSMutableArray<SDLRPCRequest *> *mutableCommands = [NSMutableArray array];
- for(NSUInteger menuInteger = 0; menuInteger < menu.count; menuInteger++) {
- for(NSUInteger updateCellsIndex = 0; updateCellsIndex < cells.count; updateCellsIndex++) {
- if([menu[menuInteger] isEqual:cells[updateCellsIndex]]) {
- if(cells[updateCellsIndex].subCells.count > 0) {
+ for (NSUInteger menuInteger = 0; menuInteger < menu.count; menuInteger++) {
+ for (NSUInteger updateCellsIndex = 0; updateCellsIndex < cells.count; updateCellsIndex++) {
+ if ([menu[menuInteger] isEqual:cells[updateCellsIndex]]) {
+ if (cells[updateCellsIndex].subCells.count > 0) {
[mutableCommands addObject:[self sdl_subMenuCommandForMenuCell:cells[updateCellsIndex] withArtwork:shouldHaveArtwork position:(UInt16)menuInteger]];
} else {
[mutableCommands addObject:[self sdl_commandForMenuCell:cells[updateCellsIndex] withArtwork:shouldHaveArtwork position:(UInt16)menuInteger]];
@@ -525,8 +528,8 @@ UInt32 const MenuCellIdMin = 1;
- (NSArray<SDLRPCRequest *> *)sdl_allCommandsForCells:(NSArray<SDLMenuCell *> *)cells withArtwork:(BOOL)shouldHaveArtwork {
NSMutableArray<SDLRPCRequest *> *mutableCommands = [NSMutableArray array];
- for(NSUInteger cellIndex = 0; cellIndex < cells.count; cellIndex++) {
- if(cells[cellIndex].subCells.count > 0) {
+ for (NSUInteger cellIndex = 0; cellIndex < cells.count; cellIndex++) {
+ if (cells[cellIndex].subCells.count > 0) {
[mutableCommands addObject:[self sdl_subMenuCommandForMenuCell:cells[cellIndex] withArtwork:shouldHaveArtwork position:(UInt16)cellIndex]];
[mutableCommands addObjectsFromArray:[self sdl_allCommandsForCells:cells[cellIndex].subCells withArtwork:shouldHaveArtwork]];
} else {
diff --git a/SmartDeviceLink/SDLScreenManager.h b/SmartDeviceLink/SDLScreenManager.h
index 576cbd145..1bdb67db4 100644
--- a/SmartDeviceLink/SDLScreenManager.h
+++ b/SmartDeviceLink/SDLScreenManager.h
@@ -121,8 +121,13 @@ typedef void(^SDLPreloadChoiceCompletionHandler)(NSError *__nullable error);
@property (copy, nonatomic) NSArray<SDLMenuCell *> *menu;
/**
- The current status for dynamic menu updates. A dynamic menu update allows for smarter building of menu changes. If this status is set to SDLDynamicMenuUpdatesModeForceOn, menu updates will only create add commands for new items and delete commands for items no longer appearing in the menu. This helps reduce possible RPCs failures as there will be significantly less commands sent to the HMI. If set to SDLDynamicMenuUpdatesModeForceOff, menu updates will work the legacy way. This means when a new menu is set the entire old menu is deleted and add commands are created for every item regarldess if the item appears in both the old and new menu. This method is RPCs heavy and may cause some failures when creating and updating large menus. We reccomend using either SDLDynamicMenuUpdatesModeOnWithCompatibility or SDLDynamicMenuUpdatesModeForceOn. SDLDynamicMenuUpdatesModeOnWithCompatibility makes sure you have a head unit that supports dynamic updates. If the head unit does not support dynamic updates, dynamic updates will be set to off automatically.
+Change the mode of the dynamic menu updater to be enabled, disabled, or enabled on known compatible head units.
+The current status for dynamic menu updates. A dynamic menu update allows for smarter building of menu changes. If this status is set to `SDLDynamicMenuUpdatesModeForceOn`, menu updates will only create add commands for new items and delete commands for items no longer appearing in the menu. This helps reduce possible RPCs failures as there will be significantly less commands sent to the HMI.
+
+If set to `SDLDynamicMenuUpdatesModeForceOff`, menu updates will work the legacy way. This means when a new menu is set the entire old menu is deleted and add commands are created for every item regarldess if the item appears in both the old and new menu. This method is RPCs heavy and may cause some failures when creating and updating large menus.
+
+ We recommend using either `SDLDynamicMenuUpdatesModeOnWithCompatibility` or `SDLDynamicMenuUpdatesModeForceOn`. `SDLDynamicMenuUpdatesModeOnWithCompatibility` turns dynamic updates off for head units that we know have poor compatibility with dynamic updates (e.g. they have bugs that cause menu items to not be placed correctly).
*/
@property (assign, nonatomic) SDLDynamicMenuUpdatesMode dynamicMenuUpdatesMode;