summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2021-08-24 10:48:24 -0400
committerJoel Fischer <joeljfischer@gmail.com>2021-08-24 10:48:24 -0400
commitfd0c9c5d7031f638b9aa0c1250109218d2ada5c8 (patch)
treed2854e036b6a22223c837e188b8bc6b22b2c3826
parent9ff204a57dfdb9245c780e719b61e2e5f80290d7 (diff)
downloadsdl_ios-fd0c9c5d7031f638b9aa0c1250109218d2ada5c8.tar.gz
Transfer menu cell handlers from new cells to old
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceOperation.m14
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceUtilities.h2
-rw-r--r--SmartDeviceLink/private/SDLMenuReplaceUtilities.m8
3 files changed, 18 insertions, 6 deletions
diff --git a/SmartDeviceLink/private/SDLMenuReplaceOperation.m b/SmartDeviceLink/private/SDLMenuReplaceOperation.m
index e50aab451..8265ae360 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceOperation.m
+++ b/SmartDeviceLink/private/SDLMenuReplaceOperation.m
@@ -110,9 +110,12 @@ NS_ASSUME_NONNULL_BEGIN
NSArray<SDLMenuCell *> *oldKeeps = [self sdl_filterKeepMenuItemsWithOldMenuItems:self.currentMenu basedOnStatusList:runScore.oldStatus];
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.
+ // Old kept cells ids need to be moved to the new kept cells so that submenu changes have correct parent ids
[SDLMenuReplaceUtilities transferCellIDsFromCells:oldKeeps toCells:newKeeps];
+ // Transfer new cells' handlers to the old cells, which are stored in the current menu
+ [SDLMenuReplaceUtilities transferCellHandlersFromCells:newKeeps toCells:oldKeeps];
+
// Upload the artworks, then we will start updating the main menu
__weak typeof(self) weakSelf = self;
[self sdl_uploadMenuArtworksWithCompletionHandler:^(NSError * _Nullable error) {
@@ -182,11 +185,10 @@ NS_ASSUME_NONNULL_BEGIN
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];
-// NSArray<SDLMenuCell *> *newKeeps = [self sdl_filterKeepMenuItemsWithNewMenuItems:newKeptCells[startIndex].subCells basedOnStatusList:addMenuStatus];
-//
-// [self sdl_transferCellIDsFromOldCells:oldKeeps toKeptCells:newKeeps];
+ // Transfer ids from subcell keeps to old subcells, which are stored in the current menu
+ NSArray<SDLMenuCell *> *oldSubcellKeeps = [self sdl_filterKeepMenuItemsWithOldMenuItems:oldKeptCells[startIndex].subCells basedOnStatusList:deleteMenuStatus];
+ NSArray<SDLMenuCell *> *newSubcellKeeps = [self sdl_filterKeepMenuItemsWithNewMenuItems:newKeptCells[startIndex].subCells basedOnStatusList:addMenuStatus];
+ [SDLMenuReplaceUtilities transferCellHandlersFromCells:newSubcellKeeps toCells:oldSubcellKeeps];
__weak typeof(self) weakself = self;
[self sdl_sendDeleteMenuCells:cellsToDelete withCompletionHandler:^(NSError * _Nullable error) {
diff --git a/SmartDeviceLink/private/SDLMenuReplaceUtilities.h b/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
index ec78dcf92..4488d0d4b 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
+++ b/SmartDeviceLink/private/SDLMenuReplaceUtilities.h
@@ -27,6 +27,8 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)transferCellIDsFromCells:(NSArray<SDLMenuCell *> *)fromCells toCells:(NSArray<SDLMenuCell *> *)toCells;
++ (void)transferCellHandlersFromCells:(NSArray<SDLMenuCell *> *)fromCells toCells:(NSArray<SDLMenuCell *> *)toCells;
+
#pragma mark - Artworks
/// Finds all artworks that need to be uploaded from the given list of menu cells
diff --git a/SmartDeviceLink/private/SDLMenuReplaceUtilities.m b/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
index c2f377529..4977a4794 100644
--- a/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
+++ b/SmartDeviceLink/private/SDLMenuReplaceUtilities.m
@@ -28,6 +28,7 @@
@property (assign, nonatomic) UInt32 parentCellId;
@property (assign, nonatomic) UInt32 cellId;
@property (copy, nonatomic, readwrite, nullable) NSArray<SDLMenuCell *> *subCells;
+@property (copy, nonatomic, readwrite, nullable) SDLMenuCellSelectionHandler handler;
@end
@@ -81,6 +82,13 @@ static UInt32 _menuId = 0;
}
}
++ (void)transferCellHandlersFromCells:(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].handler = fromCells[i].handler;
+ }
+}
+
#pragma mark Artworks
+ (NSArray<SDLArtwork *> *)findAllArtworksToBeUploadedFromCells:(NSArray<SDLMenuCell *> *)cells fileManager:(SDLFileManager *)fileManager windowCapability:(SDLWindowCapability *)windowCapability {