summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2021-08-23 14:43:00 -0400
committerJoel Fischer <joeljfischer@gmail.com>2021-08-23 14:43:00 -0400
commit61dd2f7661b2f92932fc7c99ade542400151f847 (patch)
treece278da6a28c863ca2ef62f80ab663d016c9d95c
parentf49850b3f53651d5e7c559e5af4342f03dbe29de (diff)
downloadsdl_ios-61dd2f7661b2f92932fc7c99ade542400151f847.tar.gz
Lots of menu subcell update fixes
* Move transfer cell id method to menu replace utilities * Rename `updateIdsOnMenuCells` to `addIdsToMenuCells` on SDLMenuReplaceUtilities * Update menu replace operation: * Re-add transferring Ids on keeps * Update names of delete / add menu cell methods * Add menu cell method now doesn't send submenus
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceOperation.m65
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceUtilities.h4
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceUtilities.m20
3 files changed, 51 insertions, 38 deletions
diff --git a/SmartDeviceLink/private/SDLMenuReplaceOperation.m b/SmartDeviceLink/private/SDLMenuReplaceOperation.m
index 612c9ce41..5d561d379 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceOperation.m
+++ b/SmartDeviceLink/private/SDLMenuReplaceOperation.m
@@ -80,7 +80,7 @@ NS_ASSUME_NONNULL_BEGIN
[super start];
if (self.isCancelled) { return; }
- [SDLMenuReplaceUtilities updateIdsOnMenuCells:self.updatedMenu parentId:ParentIdNotFound];
+ [SDLMenuReplaceUtilities addIdsToMenuCells:self.updatedMenu parentId:ParentIdNotFound];
// Strip the "current menu" and the new menu of properties that are not displayed on the head unit
NSArray<SDLMenuCell *> *updatedStrippedMenu = [self.class sdl_cellsWithRemovedPropertiesFromCells:self.updatedMenu basedOnWindowCapability:self.windowCapability];
@@ -111,7 +111,7 @@ NS_ASSUME_NONNULL_BEGIN
NSArray<SDLMenuCell *> *newKeeps = [self sdl_filterKeepMenuItemsWithNewMenuItems:self.updatedMenu basedOnStatusList:runScore.updatedStatus];
// Since we are creating a new Menu but keeping old cells we must first transfer the old cellIDs to the new menus kept cells.
-// [self sdl_transferCellIDsFromOldCells:oldKeeps toKeptCells:newKeeps];
+ [SDLMenuReplaceUtilities transferCellIDsFromCells:oldKeeps toCells:newKeeps];
// Upload the artworks, then we will start updating the main menu
__weak typeof(self) weakSelf = self;
@@ -157,10 +157,10 @@ NS_ASSUME_NONNULL_BEGIN
/// @param handler A handler called when complete
- (void)sdl_updateMenuWithCellsToDelete:(NSArray<SDLMenuCell *> *)deleteCells cellsToAdd:(NSArray<SDLMenuCell *> *)addCells completionHandler:(void(^)(NSError *_Nullable error))handler {
__weak typeof(self) weakSelf = self;
- [self sdl_sendDeleteCurrentMenu:deleteCells withCompletionHandler:^(NSError * _Nullable error) {
+ [self sdl_sendDeleteMenuCells:deleteCells withCompletionHandler:^(NSError * _Nullable error) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (strongSelf.isCancelled) { return handler(error); }
- [strongSelf sdl_sendNewMenuCells:addCells oldMenu:strongSelf.currentMenu withCompletionHandler:^(NSError * _Nullable error) {
+ [strongSelf sdl_sendAddMenuCells:addCells withCompletionHandler:^(NSError * _Nullable error) {
handler(error);
}];
}];
@@ -188,11 +188,11 @@ NS_ASSUME_NONNULL_BEGIN
// [self sdl_transferCellIDsFromOldCells:oldKeeps toKeptCells:newKeeps];
__weak typeof(self) weakself = self;
- [self sdl_sendDeleteCurrentMenu:cellsToDelete withCompletionHandler:^(NSError * _Nullable error) {
+ [self sdl_sendDeleteMenuCells:cellsToDelete withCompletionHandler:^(NSError * _Nullable error) {
if (weakself.isCancelled) { return completionHandler([NSError sdl_menuManager_replaceOperationCancelled]); }
if (error != nil) { return completionHandler(error); }
- [weakself sdl_sendNewMenuCells:cellsToAdd oldMenu:weakself.currentMenu[startIndex].subCells withCompletionHandler:^(NSError * _Nullable error) {
+ [weakself sdl_sendAddMenuCells:cellsToAdd withCompletionHandler:^(NSError * _Nullable error) {
if (weakself.isCancelled) { return completionHandler([NSError sdl_menuManager_replaceOperationCancelled]); }
if (error != nil) { return completionHandler(error); }
@@ -215,7 +215,7 @@ NS_ASSUME_NONNULL_BEGIN
/// Send Delete RPCs for given menu cells
/// @param deleteMenuCells The menu cells to be deleted
/// @param completionHandler A handler called when the RPCs are finished with an error if any failed
-- (void)sdl_sendDeleteCurrentMenu:(nullable NSArray<SDLMenuCell *> *)deleteMenuCells withCompletionHandler:(void(^)(NSError *_Nullable error))completionHandler {
+- (void)sdl_sendDeleteMenuCells:(nullable NSArray<SDLMenuCell *> *)deleteMenuCells withCompletionHandler:(void(^)(NSError *_Nullable error))completionHandler {
if (deleteMenuCells.count == 0) { return completionHandler(nil); }
__block NSMutableDictionary<SDLRPCRequest *, NSError *> *errors = [NSMutableDictionary dictionary];
@@ -241,16 +241,15 @@ 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 oldMenu The old menu cells we no longer want displayed
/// @param completionHandler A handler called when the RPCs are finished with an error if any failed
-- (void)sdl_sendNewMenuCells:(NSArray<SDLMenuCell *> *)newMenuCells oldMenu:(NSArray<SDLMenuCell *> *)oldMenu withCompletionHandler:(void(^)(NSError *_Nullable error))completionHandler {
+- (void)sdl_sendAddMenuCells:(NSArray<SDLMenuCell *> *)newMenuCells withCompletionHandler:(void(^)(NSError *_Nullable error))completionHandler {
if (self.updatedMenu.count == 0 || newMenuCells.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 *> *subMenuCommands = [SDLMenuReplaceUtilities subMenuCommandsForCells:newMenuCells fileManager:self.fileManager windowCapability:self.windowCapability defaultSubmenuLayout:self.menuConfiguration.defaultSubmenuLayout];
__block NSMutableDictionary<SDLRPCRequest *, NSError *> *errors = [NSMutableDictionary dictionary];
__weak typeof(self) weakSelf = self;
@@ -267,26 +266,29 @@ NS_ASSUME_NONNULL_BEGIN
if (!success) {
SDLLogE(@"Failed to send main menu commands: %@", errors);
return completionHandler([NSError sdl_menuManager_failedToUpdateWithDictionary:errors]);
+ } else {
+ 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: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);
+// }];
}];
}
@@ -337,13 +339,6 @@ NS_ASSUME_NONNULL_BEGIN
return [keepMenuCells copy];
}
-- (void)sdl_transferCellIDsFromOldCells:(NSArray<SDLMenuCell *> *)oldCells toKeptCells:(NSArray<SDLMenuCell *> *)newCells {
- if (oldCells.count == 0) { return; }
- for (NSUInteger i = 0; i < newCells.count; i++) {
- newCells[i].cellId = oldCells[i].cellId;
- }
-}
-
#pragma mark - Menu Uniqueness
+ (NSArray<SDLMenuCell *> *)sdl_cellsWithRemovedPropertiesFromCells:(NSArray<SDLMenuCell *> *)menuCells basedOnWindowCapability:(SDLWindowCapability *)windowCapability {
diff --git a/SmartDeviceLink/private/SDLMenuReplaceUtilities.h b/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
index 35defac10..11896031f 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
+++ b/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
@@ -23,7 +23,9 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Ids
-+ (void)updateIdsOnMenuCells:(NSArray<SDLMenuCell *> *)menuCells parentId:(UInt32)parentId;
++ (void)addIdsToMenuCells:(NSArray<SDLMenuCell *> *)menuCells parentId:(UInt32)parentId;
+
++ (void)transferCellIDsFromCells:(NSArray<SDLMenuCell *> *)fromCells toCells:(NSArray<SDLMenuCell *> *)toCells;
#pragma mark - Artworks
diff --git a/SmartDeviceLink/private/SDLMenuReplaceUtilities.m b/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
index 22ab00762..b71488a9a 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
+++ b/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
@@ -53,14 +53,30 @@ static UInt32 _menuId = 0;
/// Assign cell ids on an array of menu cells given a parent id (or no parent id)
/// @param menuCells The array of menu cells to update
/// @param parentId The parent id to assign if needed
-+ (void)updateIdsOnMenuCells:(NSArray<SDLMenuCell *> *)menuCells parentId:(UInt32)parentId {
++ (void)addIdsToMenuCells:(NSArray<SDLMenuCell *> *)menuCells parentId:(UInt32)parentId {
for (SDLMenuCell *cell in menuCells) {
cell.cellId = self.class.nextMenuId;
if (parentId != ParentIdNotFound) {
cell.parentCellId = parentId;
}
if (cell.subCells.count > 0) {
- [self updateIdsOnMenuCells:cell.subCells parentId:cell.cellId];
+ [self addIdsToMenuCells:cell.subCells parentId:cell.cellId];
+ }
+ }
+}
+
++ (void)transferCellIDsFromCells:(NSArray<SDLMenuCell *> *)fromCells toCells:(NSArray<SDLMenuCell *> *)toCells {
+ if (fromCells.count == 0 || fromCells.count != toCells.count) { return; }
+ for (NSUInteger i = 0; i < toCells.count; i++) {
+ toCells[i].cellId = fromCells[i].cellId;
+ }
+
+ // Update parent ids
+ for (SDLMenuCell *cell in toCells) {
+ if (cell.subCells == nil) { continue; }
+
+ for (SDLMenuCell *subCell in cell.subCells) {
+ subCell.parentCellId = cell.cellId;
}
}
}