diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2018-04-30 14:17:03 -0400 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2018-04-30 14:17:03 -0400 |
commit | 852c621a40670ec149fdeb99ad2051203b15f222 (patch) | |
tree | cc602ed0bf6f810d6ffef8dbebcbb0c0f6dc622d | |
parent | ed0ec83de7ad23d58043f304ab7a4f0a2ade9f5b (diff) | |
download | sdl_ios-852c621a40670ec149fdeb99ad2051203b15f222.tar.gz |
Fix updating menu every time you leave the menu
-rw-r--r-- | SmartDeviceLink/SDLMenuManager.m | 104 |
1 files changed, 51 insertions, 53 deletions
diff --git a/SmartDeviceLink/SDLMenuManager.m b/SmartDeviceLink/SDLMenuManager.m index a77df488e..de75ce96d 100644 --- a/SmartDeviceLink/SDLMenuManager.m +++ b/SmartDeviceLink/SDLMenuManager.m @@ -52,10 +52,10 @@ NS_ASSUME_NONNULL_BEGIN @property (strong, nonatomic, nullable) NSArray<SDLRPCRequest *> *inProgressUpdate; @property (assign, nonatomic) BOOL hasQueuedUpdate; @property (assign, nonatomic) BOOL waitingOnHMIUpdate; +@property (copy, nonatomic) NSArray<SDLMenuCell *> *waitingUpdateMenuCells; @property (assign, nonatomic) UInt32 lastMenuId; @property (copy, nonatomic) NSArray<SDLMenuCell *> *oldMenuCells; -@property (copy, nonatomic) NSArray<SDLMenuCell *> *waitingUpdateMenuCells; @end @@ -90,10 +90,58 @@ UInt32 const MenuCellIdMin = 1; return self; } +#pragma mark - Setters + +- (void)setMenuCells:(NSArray<SDLMenuCell *> *)menuCells { + if (self.currentHMILevel == nil + || [self.currentHMILevel isEqualToEnum:SDLHMILevelNone] + || [self.currentSystemContext isEqualToEnum:SDLSystemContextMenu]) { + self.waitingOnHMIUpdate = YES; + self.waitingUpdateMenuCells = menuCells; + return; + } + + self.waitingOnHMIUpdate = NO; + + // Check for duplicate titles + NSMutableSet *titleCheckSet = [NSMutableSet set]; + for (SDLMenuCell *cell in menuCells) { + [titleCheckSet addObject:cell.title]; + } + if (titleCheckSet.count != menuCells.count) { + SDLLogE(@"Not all cell titles are unique. The menu will not be set."); + return; + } + + // Set the ids + self.lastMenuId = MenuCellIdMin; + [self sdl_updateIdsOnMenuCells:menuCells parentId:ParentIdNotFound]; + + _oldMenuCells = _menuCells; + _menuCells = menuCells; + + // Upload the artworks + NSArray<SDLArtwork *> *artworksToBeUploaded = [self sdl_findAllArtworksToBeUploadedFromCells:self.menuCells]; + if (artworksToBeUploaded.count > 0) { + [self.fileManager uploadArtworks:artworksToBeUploaded completionHandler:^(NSArray<NSString *> * _Nonnull artworkNames, NSError * _Nullable error) { + if (error != nil) { + SDLLogE(@"Error uploading menu artworks: %@", error); + } + + SDLLogD(@"Menu artworks uploaded"); + [self sdl_updateWithCompletionHandler:nil]; + }]; + } + + [self sdl_updateWithCompletionHandler:nil]; +} + #pragma mark - Updating System - (void)sdl_updateWithCompletionHandler:(nullable SDLMenuUpdateCompletionHandler)completionHandler { - if (self.currentHMILevel == nil || [self.currentHMILevel isEqualToEnum:SDLHMILevelNone] || [self.currentSystemContext isEqualToEnum:SDLSystemContextMenu]) { + if (self.currentHMILevel == nil + || [self.currentHMILevel isEqualToEnum:SDLHMILevelNone] + || [self.currentSystemContext isEqualToEnum:SDLSystemContextMenu]) { self.waitingOnHMIUpdate = YES; self.waitingUpdateMenuCells = self.menuCells; return; @@ -132,7 +180,6 @@ UInt32 const MenuCellIdMin = 1; NSArray<SDLRPCRequest *> *deleteMenuCommands = [self sdl_deleteCommandsForCells:self.oldMenuCells]; self.oldMenuCells = @[]; - [self.connectionManager sendRequests:deleteMenuCommands progressHandler:nil completionHandler:^(BOOL success) { if (!success) { SDLLogW(@"Unable to delete all old menu commands"); @@ -178,12 +225,10 @@ UInt32 const MenuCellIdMin = 1; if (!success) { SDLLogE(@"Failed to send main menu commands: %@", errors); completionHandler([NSError sdl_menuManager_failedToUpdateWithDictionary:errors]); - return; } weakSelf.oldMenuCells = weakSelf.menuCells; - [weakSelf.connectionManager sendRequests:subMenuCommands progressHandler:^(__kindof SDLRPCRequest * _Nonnull request, __kindof SDLRPCResponse * _Nullable response, NSError * _Nullable error, float percentComplete) { if (error != nil) { errors[request] = error; @@ -192,7 +237,6 @@ UInt32 const MenuCellIdMin = 1; if (!success) { SDLLogE(@"Failed to send sub menu commands: %@", errors); completionHandler([NSError sdl_menuManager_failedToUpdateWithDictionary:errors]); - return; } @@ -202,52 +246,6 @@ UInt32 const MenuCellIdMin = 1; }]; } -#pragma mark - Setters - -- (void)setMenuCells:(NSArray<SDLMenuCell *> *)menuCells { - if (self.currentHMILevel == nil - || [self.currentHMILevel isEqualToEnum:SDLHMILevelNone] - || [self.currentSystemContext isEqualToEnum:SDLSystemContextMenu]) { - self.waitingOnHMIUpdate = YES; - self.waitingUpdateMenuCells = menuCells; - return; - } - - self.waitingOnHMIUpdate = NO; - - // Check for duplicate titles - NSMutableSet *titleCheckSet = [NSMutableSet set]; - for (SDLMenuCell *cell in menuCells) { - [titleCheckSet addObject:cell.title]; - } - if (titleCheckSet.count != menuCells.count) { - SDLLogE(@"Not all cell titles are unique. The menu will not be set."); - return; - } - - // Set the ids - self.lastMenuId = MenuCellIdMin; - [self sdl_updateIdsOnMenuCells:menuCells parentId:ParentIdNotFound]; - - _oldMenuCells = _menuCells; - _menuCells = menuCells; - - // Upload the artworks - NSArray<SDLArtwork *> *artworksToBeUploaded = [self sdl_findAllArtworksToBeUploadedFromCells:self.menuCells]; - if (artworksToBeUploaded.count > 0) { - [self.fileManager uploadArtworks:artworksToBeUploaded completionHandler:^(NSArray<NSString *> * _Nonnull artworkNames, NSError * _Nullable error) { - if (error != nil) { - SDLLogE(@"Error uploading menu artworks: %@", error); - } - - SDLLogD(@"Menu artworks uploaded"); - [self sdl_updateWithCompletionHandler:nil]; - }]; - } - - [self sdl_updateWithCompletionHandler:nil]; -} - #pragma mark - Helpers #pragma mark Artworks @@ -388,7 +386,6 @@ UInt32 const MenuCellIdMin = 1; - (void)sdl_hmiStatusNotification:(SDLRPCNotificationNotification *)notification { SDLOnHMIStatus *hmiStatus = (SDLOnHMIStatus *)notification.notification; - SDLHMILevel oldHMILevel = self.currentHMILevel; self.currentHMILevel = hmiStatus.hmiLevel; @@ -408,6 +405,7 @@ UInt32 const MenuCellIdMin = 1; if ([oldSystemContext isEqualToEnum:SDLSystemContextMenu] && ![self.currentSystemContext isEqualToEnum:SDLSystemContextMenu]) { if (self.waitingOnHMIUpdate) { [self setMenuCells:self.waitingUpdateMenuCells]; + self.waitingUpdateMenuCells = @[]; } } } |