summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2021-08-23 15:22:10 -0400
committerJoel Fischer <joeljfischer@gmail.com>2021-08-23 15:22:10 -0400
commit1797fe4f4e05ce58fb7e56bf16fd1a61ac2d199a (patch)
treeed68c675849044e984859d71ef63b218662ebcc0
parent61dd2f7661b2f92932fc7c99ade542400151f847 (diff)
downloadsdl_ios-1797fe4f4e05ce58fb7e56bf16fd1a61ac2d199a.tar.gz
Menu replace operation fixes
* Many method name clarification updates * Hopefully fix mis-using global updatedMenu when submenus are in view * Re-enable sending submenus for add cells that are not submenus of keeps
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceOperation.m76
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceUtilities.h2
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceUtilities.m2
3 files changed, 41 insertions, 39 deletions
diff --git a/SmartDeviceLink/private/SDLMenuReplaceOperation.m b/SmartDeviceLink/private/SDLMenuReplaceOperation.m
index 5d561d379..b295fe50f 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceOperation.m
+++ b/SmartDeviceLink/private/SDLMenuReplaceOperation.m
@@ -125,7 +125,7 @@ NS_ASSUME_NONNULL_BEGIN
if (strongSelf.isCancelled) { return [strongSelf finishOperation]; }
if (error != nil) { return [strongSelf finishOperationWithError:error]; }
- [strongSelf sdl_updateSubMenuWithOldKeptCells:oldKeeps newKeptCells:newKeeps atIndex:0 completionHandler:^(NSError * _Nullable error) {
+ [strongSelf sdl_updateSubMenuWithOldKeptCells:oldKeeps newKeptCells:newKeeps keptCellIndex:0 completionHandler:^(NSError * _Nullable error) {
return [strongSelf finishOperationWithError:error];
}];
}];
@@ -160,7 +160,7 @@ NS_ASSUME_NONNULL_BEGIN
[self sdl_sendDeleteMenuCells:deleteCells withCompletionHandler:^(NSError * _Nullable error) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (strongSelf.isCancelled) { return handler(error); }
- [strongSelf sdl_sendAddMenuCells:addCells withCompletionHandler:^(NSError * _Nullable error) {
+ [strongSelf sdl_sendAddMenuCells:addCells withPositionsFromMenu:self.updatedMenu completionHandler:^(NSError * _Nullable error) {
handler(error);
}];
}];
@@ -169,17 +169,18 @@ NS_ASSUME_NONNULL_BEGIN
/// Takes the submenu cells that are old keeps and new keeps and determines which cells need to be deleted or added
/// @param oldKeptCells The old kept cells
/// @param newKeptCells The new kept cells
-/// @param startIndex The index of the main menu to use
-- (void)sdl_updateSubMenuWithOldKeptCells:(NSArray<SDLMenuCell *> *)oldKeptCells newKeptCells:(NSArray<SDLMenuCell *> *)newKeptCells atIndex:(NSUInteger)startIndex completionHandler:(void(^)(NSError *_Nullable error))completionHandler {
- if (oldKeptCells.count == 0 || startIndex >= oldKeptCells.count) { return completionHandler(nil); }
+/// @param index The index of the main menu to use
+/// @param completionHandler The handler to call when all submenu updates are complete
+- (void)sdl_updateSubMenuWithOldKeptCells:(NSArray<SDLMenuCell *> *)oldKeptCells newKeptCells:(NSArray<SDLMenuCell *> *)newKeptCells keptCellIndex:(NSUInteger)index completionHandler:(void(^)(NSError *_Nullable error))completionHandler {
+ if (oldKeptCells.count == 0 || index >= oldKeptCells.count) { return completionHandler(nil); }
- if (oldKeptCells[startIndex].subCells.count > 0) {
- SDLDynamicMenuUpdateRunScore *tempScore = [SDLDynamicMenuUpdateAlgorithm dynamicRunScoreOldMenuCells:oldKeptCells[startIndex].subCells updatedMenuCells:newKeptCells[startIndex].subCells];
+ if (oldKeptCells[index].subCells.count > 0) {
+ SDLDynamicMenuUpdateRunScore *tempScore = [SDLDynamicMenuUpdateAlgorithm dynamicRunScoreOldMenuCells:oldKeptCells[index].subCells updatedMenuCells:newKeptCells[index].subCells];
NSArray<NSNumber *> *deleteMenuStatus = tempScore.oldStatus;
NSArray<NSNumber *> *addMenuStatus = tempScore.updatedStatus;
- NSArray<SDLMenuCell *> *cellsToDelete = [self sdl_filterDeleteMenuItemsWithOldMenuItems:oldKeptCells[startIndex].subCells basedOnStatusList:deleteMenuStatus];
- NSArray<SDLMenuCell *> *cellsToAdd = [self sdl_filterAddMenuItemsWithNewMenuItems:newKeptCells[startIndex].subCells basedOnStatusList:addMenuStatus];
+ NSArray<SDLMenuCell *> *cellsToDelete = [self sdl_filterDeleteMenuItemsWithOldMenuItems:oldKeptCells[index].subCells basedOnStatusList:deleteMenuStatus];
+ NSArray<SDLMenuCell *> *cellsToAdd = [self sdl_filterAddMenuItemsWithNewMenuItems:newKeptCells[index].subCells basedOnStatusList:addMenuStatus];
// TODO: These will be necessary once we do subcells of subcells
// NSArray<SDLMenuCell *> *oldKeeps = [self sdl_filterKeepMenuItemsWithOldMenuItems:oldKeptCells[startIndex].subCells basedOnStatusList:deleteMenuStatus];
@@ -192,19 +193,19 @@ NS_ASSUME_NONNULL_BEGIN
if (weakself.isCancelled) { return completionHandler([NSError sdl_menuManager_replaceOperationCancelled]); }
if (error != nil) { return completionHandler(error); }
- [weakself sdl_sendAddMenuCells:cellsToAdd withCompletionHandler:^(NSError * _Nullable error) {
+ [weakself sdl_sendAddMenuCells:cellsToAdd withPositionsFromMenu:newKeptCells[index].subCells completionHandler:^(NSError * _Nullable error) {
if (weakself.isCancelled) { return completionHandler([NSError sdl_menuManager_replaceOperationCancelled]); }
if (error != nil) { return completionHandler(error); }
// After the first set of submenu cells were added and deleted we must find the next set of subcells until we loop through all the elements
- [weakself sdl_updateSubMenuWithOldKeptCells:oldKeptCells newKeptCells:newKeptCells atIndex:(startIndex + 1) completionHandler:^(NSError * _Nullable error) {
+ [weakself sdl_updateSubMenuWithOldKeptCells:oldKeptCells newKeptCells:newKeptCells keptCellIndex:(index + 1) completionHandler:^(NSError * _Nullable error) {
completionHandler(error);
}];
}];
}];
} else {
// There are no subcells, we can skip to the next index.
- [self sdl_updateSubMenuWithOldKeptCells:oldKeptCells newKeptCells:newKeptCells atIndex:(startIndex + 1) completionHandler:^(NSError * _Nullable error) {
+ [self sdl_updateSubMenuWithOldKeptCells:oldKeptCells newKeptCells:newKeptCells keptCellIndex:(index + 1) completionHandler:^(NSError * _Nullable error) {
completionHandler(error);
}];
}
@@ -240,16 +241,17 @@ NS_ASSUME_NONNULL_BEGIN
}
/// Send Add RPCs for given new menu cells compared to old menu cells
-/// @param newMenuCells The new menu cells we want displayed
+/// @param addMenuCells The new menu cells we want displayed
+/// @param fullMenu The full menu from which the addMenuCells come. This allows us to grab the positions from that menu for the new cells
/// @param completionHandler A handler called when the RPCs are finished with an error if any failed
-- (void)sdl_sendAddMenuCells:(NSArray<SDLMenuCell *> *)newMenuCells withCompletionHandler:(void(^)(NSError *_Nullable error))completionHandler {
- if (self.updatedMenu.count == 0 || newMenuCells.count == 0) {
+- (void)sdl_sendAddMenuCells:(NSArray<SDLMenuCell *> *)addMenuCells withPositionsFromMenu:(NSArray<SDLMenuCell *> *)fullMenu completionHandler:(void(^)(NSError *_Nullable error))completionHandler {
+ if (addMenuCells.count == 0) {
SDLLogV(@"There are no cells to update.");
return completionHandler(nil);
}
- NSArray<SDLRPCRequest *> *mainMenuCommands = [SDLMenuReplaceUtilities mainMenuCommandsForCells:newMenuCells fileManager:self.fileManager usingIndexesFrom:self.updatedMenu windowCapability:self.windowCapability defaultSubmenuLayout:self.menuConfiguration.defaultSubmenuLayout];;
-// NSArray<SDLRPCRequest *> *subMenuCommands = [SDLMenuReplaceUtilities subMenuCommandsForCells:newMenuCells fileManager:self.fileManager windowCapability:self.windowCapability defaultSubmenuLayout:self.menuConfiguration.defaultSubmenuLayout];
+ NSArray<SDLRPCRequest *> *mainMenuCommands = [SDLMenuReplaceUtilities mainMenuCommandsForCells:addMenuCells fileManager:self.fileManager usingPositionsFromFullMenu:fullMenu windowCapability:self.windowCapability defaultSubmenuLayout:self.menuConfiguration.defaultSubmenuLayout];
+ NSArray<SDLRPCRequest *> *subMenuCommands = [SDLMenuReplaceUtilities subMenuCommandsForCells:addMenuCells fileManager:self.fileManager windowCapability:self.windowCapability defaultSubmenuLayout:self.menuConfiguration.defaultSubmenuLayout];
__block NSMutableDictionary<SDLRPCRequest *, NSError *> *errors = [NSMutableDictionary dictionary];
__weak typeof(self) weakSelf = self;
@@ -260,35 +262,35 @@ NS_ASSUME_NONNULL_BEGIN
// Find the id of the successful request and add it from the current menu list wherever it needs to be
UInt32 commandId = [SDLMenuReplaceUtilities commandIdForRPCRequest:request];
UInt16 position = [SDLMenuReplaceUtilities positionForRPCRequest:request];
- [SDLMenuReplaceUtilities addCellWithCellId:commandId position:position fromNewMenuList:newMenuCells toMainMenuList:weakSelf.mutableCurrentMenu];
+ [SDLMenuReplaceUtilities addCellWithCellId:commandId position:position fromNewMenuList:addMenuCells toMainMenuList:weakSelf.mutableCurrentMenu];
}
} completionHandler:^(BOOL success) {
if (!success) {
SDLLogE(@"Failed to send main menu commands: %@", errors);
return completionHandler([NSError sdl_menuManager_failedToUpdateWithDictionary:errors]);
- } else {
+ } else if (subMenuCommands.count == 0) {
SDLLogD(@"Finished sending new cells");
return completionHandler(nil);
}
-// [weakSelf.connectionManager sendRequests:subMenuCommands progressHandler:^(__kindof SDLRPCRequest * _Nonnull request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error, float percentComplete) {
-// if (error != nil) {
-// errors[request] = error;
-// } else {
-// // Find the id of the successful request and add it from the current menu list wherever it needs to be
-// UInt32 commandId = [SDLMenuReplaceUtilities commandIdForRPCRequest:request];
-// UInt16 position = [SDLMenuReplaceUtilities positionForRPCRequest:request];
-// [SDLMenuReplaceUtilities addCellWithCellId:commandId position:position fromNewMenuList:newMenuCells toMainMenuList:weakSelf.mutableCurrentMenu];
-// }
-// } completionHandler:^(BOOL success) {
-// if (!success) {
-// SDLLogE(@"Failed to send sub menu commands: %@", errors);
-// return completionHandler([NSError sdl_menuManager_failedToUpdateWithDictionary:errors]);
-// }
-//
-// SDLLogD(@"Finished updating menu");
-// completionHandler(nil);
-// }];
+ [weakSelf.connectionManager sendRequests:subMenuCommands progressHandler:^(__kindof SDLRPCRequest * _Nonnull request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error, float percentComplete) {
+ if (error != nil) {
+ errors[request] = error;
+ } else {
+ // Find the id of the successful request and add it from the current menu list wherever it needs to be
+ UInt32 commandId = [SDLMenuReplaceUtilities commandIdForRPCRequest:request];
+ UInt16 position = [SDLMenuReplaceUtilities positionForRPCRequest:request];
+ [SDLMenuReplaceUtilities addCellWithCellId:commandId position:position fromNewMenuList:addMenuCells toMainMenuList:weakSelf.mutableCurrentMenu];
+ }
+ } completionHandler:^(BOOL success) {
+ if (!success) {
+ SDLLogE(@"Failed to send sub menu commands: %@", errors);
+ return completionHandler([NSError sdl_menuManager_failedToUpdateWithDictionary:errors]);
+ }
+
+ SDLLogD(@"Finished sending new cells");
+ completionHandler(nil);
+ }];
}];
}
diff --git a/SmartDeviceLink/private/SDLMenuReplaceUtilities.h b/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
index 11896031f..ec78dcf92 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
+++ b/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
@@ -55,7 +55,7 @@ NS_ASSUME_NONNULL_BEGIN
/// @param menu The menu from which we will manage indexes
/// @param windowCapability The window capability with which to check available text fields / image fields
/// @param defaultSubmenuLayout The default submenu layout to use for displaying submenus
-+ (NSArray<SDLRPCRequest *> *)mainMenuCommandsForCells:(NSArray<SDLMenuCell *> *)cells fileManager:(SDLFileManager *)fileManager usingIndexesFrom:(NSArray<SDLMenuCell *> *)menu windowCapability:(SDLWindowCapability *)windowCapability defaultSubmenuLayout:(SDLMenuLayout)defaultSubmenuLayout;
++ (NSArray<SDLRPCRequest *> *)mainMenuCommandsForCells:(NSArray<SDLMenuCell *> *)cells fileManager:(SDLFileManager *)fileManager usingPositionsFromFullMenu:(NSArray<SDLMenuCell *> *)menu windowCapability:(SDLWindowCapability *)windowCapability defaultSubmenuLayout:(SDLMenuLayout)defaultSubmenuLayout;
/// Generate SDLAddCommand and SDLAddSubMenu RPCs for the given submenu cells
/// @param cells The cells to generate AddCommand / AddSubMenu RPCs for
diff --git a/SmartDeviceLink/private/SDLMenuReplaceUtilities.m b/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
index b71488a9a..c2f377529 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
+++ b/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
@@ -162,7 +162,7 @@ static UInt32 _menuId = 0;
return [mutableDeletes copy];
}
-+ (NSArray<SDLRPCRequest *> *)mainMenuCommandsForCells:(NSArray<SDLMenuCell *> *)cells fileManager:(SDLFileManager *)fileManager usingIndexesFrom:(NSArray<SDLMenuCell *> *)menu windowCapability:(SDLWindowCapability *)windowCapability defaultSubmenuLayout:(SDLMenuLayout)defaultSubmenuLayout {
++ (NSArray<SDLRPCRequest *> *)mainMenuCommandsForCells:(NSArray<SDLMenuCell *> *)cells fileManager:(SDLFileManager *)fileManager usingPositionsFromFullMenu:(NSArray<SDLMenuCell *> *)menu windowCapability:(SDLWindowCapability *)windowCapability defaultSubmenuLayout:(SDLMenuLayout)defaultSubmenuLayout {
NSMutableArray<SDLRPCRequest *> *mutableCommands = [NSMutableArray array];
for (NSUInteger menuInteger = 0; menuInteger < menu.count; menuInteger++) {
for (NSUInteger updateCellsIndex = 0; updateCellsIndex < cells.count; updateCellsIndex++) {