Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu Manager Refactor and Updating Implementation #1901

Merged
merged 120 commits into from
Sep 24, 2021
Merged
Show file tree
Hide file tree
Changes from 116 commits
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
a30ce6e
First round of updates for the menu manager
joeljfischer Jan 21, 2021
a7aa504
Consolidate some opening menu code
joeljfischer Jan 22, 2021
3a17e6a
Warning cleanup
joeljfischer Jan 22, 2021
7332f5e
A ton of work on the menu replace operations
joeljfischer Jan 22, 2021
3a83a1c
Move a method into dynamic operation
joeljfischer Jan 25, 2021
e6ce6ea
Fixes for menu manager
joeljfischer Jan 25, 2021
1b9caee
Update static operation with finishOperation calls
joeljfischer Jan 25, 2021
52961d7
Minor updates
joeljfischer Jan 25, 2021
e7d5bb1
Update menu replace utility to check window capability
joeljfischer Jan 26, 2021
9385fb4
Menu operation updates
joeljfischer Jan 27, 2021
d67ed41
Fix checking if image needs upload
joeljfischer Jan 27, 2021
2cb4ccb
Add removing deleted cells from static operation
joeljfischer Jan 27, 2021
e9a1abf
Fixes
joeljfischer Jan 27, 2021
8a6389d
Working on adding cells to current menu list
joeljfischer Jan 27, 2021
2a3fd2b
Merge branch 'develop' into feature/issue-1898-menu-manager-refactor
joeljfischer Jan 29, 2021
92516dc
Finish untested setup of static operation
joeljfischer Jan 29, 2021
b05c7a7
Simplify static operation code duplication
joeljfischer Jan 29, 2021
0387d10
Add some comments, fix some comments, stub a test class
joeljfischer Jan 29, 2021
2c7c99b
Fix not building
joeljfischer Jan 29, 2021
12d413c
Fix still not compiling code
joeljfischer Jan 29, 2021
a118ee5
Working on menu replace utils tests
joeljfischer Jan 29, 2021
c5e1989
Start shifting menu operation stuff all to dynamic
joeljfischer Feb 2, 2021
befec52
Merge branch 'develop' into feature/issue-1898-menu-manager-refactor
joeljfischer Feb 3, 2021
6326a49
Continue to work on updating menu replace operation
joeljfischer Feb 3, 2021
79c12a9
Update rpc_spec
joeljfischer Feb 5, 2021
d1662e7
Finish removing static operation
joeljfischer Feb 5, 2021
0960312
Update window capability properly
joeljfischer Feb 8, 2021
3ae329f
Update replace ops with new menu configuration
joeljfischer Feb 8, 2021
7074a35
In progress alignment
joeljfischer Feb 8, 2021
364ccfa
Merge branch 'develop' into feature/issue-1898-menu-manager-refactor
joeljfischer Feb 10, 2021
09cb1c9
Update RPC spec
joeljfischer Feb 10, 2021
c54f565
Merge branch 'develop' into feature/issue-1898-menu-manager-refactor
joeljfischer Feb 10, 2021
7b41774
Alignment and fixes
joeljfischer Feb 10, 2021
6215d29
Remove unneeded private property
joeljfischer Feb 10, 2021
5ce749e
Fixing crashers in menu tests
joeljfischer Feb 10, 2021
cc15977
Merge branch 'develop' into feature/issue-1898-menu-manager-refactor
joeljfischer Feb 16, 2021
c0c734f
Working on unit test refactor
joeljfischer Feb 16, 2021
974e308
Fix not properly checking setting equality in menu manager
joeljfischer Feb 16, 2021
3514057
Fix menu configuration update op to return an error in more situations
joeljfischer Feb 17, 2021
cedee38
Fix add menu item with id returning early
joeljfischer Feb 17, 2021
150dc20
Add additional tests
joeljfischer Feb 17, 2021
7398e3f
Add tests for menu show operation
joeljfischer Feb 17, 2021
053dc3b
Moving test code around
joeljfischer Feb 17, 2021
c311761
Working on tests
joeljfischer Feb 18, 2021
d575aaf
Lots of little bug fixes
joeljfischer Feb 18, 2021
34d82e0
Remove a few additional items
joeljfischer Feb 18, 2021
317e270
Additional test work
joeljfischer Feb 18, 2021
535c872
Slight change to test
joeljfischer Feb 19, 2021
cb4e3db
Fix some spelling and a menu operation bug
joeljfischer Feb 19, 2021
38f8f4b
Fix menu bug and updating unit tests
joeljfischer Feb 19, 2021
44a7bf8
Continuing to add tests
joeljfischer Feb 24, 2021
745e6df
Update menu replace op callback to pass back error too
joeljfischer Feb 25, 2021
2ecf74d
Additional menu manager tests
joeljfischer Feb 25, 2021
3e238f0
New tests and fixes
joeljfischer Feb 25, 2021
4d7d271
Merge branch 'develop' into feature/issue-1898-menu-manager-refactor
joeljfischer Jul 28, 2021
5a76523
Starting updates of menu refactor
joeljfischer Jul 28, 2021
d50d1a9
Fix menu show completion block
joeljfischer Jul 29, 2021
6716b98
Continued updating to menu manager
joeljfischer Jul 29, 2021
23b0aea
Dynamic run score now compares unique titles
joeljfischer Jul 30, 2021
f884416
Add SDLMenuCell equivalency method including unique titles
joeljfischer Jul 30, 2021
82d3ba6
Remove unneeded private import
joeljfischer Jul 30, 2021
66a09c3
Fixes to menu replace operation for previous changes
joeljfischer Jul 30, 2021
6b20df4
Refactoring uploading menu artworks
joeljfischer Jul 30, 2021
f9dd47a
Merge branch 'develop' into feature/issue-1898-menu-manager-refactor
joeljfischer Aug 3, 2021
271ce1a
Fix missing semicolon
joeljfischer Aug 4, 2021
16e9a67
Fix replace operation to properly finish various tasks
joeljfischer Aug 4, 2021
35fafa8
Fix missing files from log module map
joeljfischer Aug 4, 2021
637f3e5
Fix missing completion handler call
joeljfischer Aug 4, 2021
cf9b0d9
Fix menu not using unique titles
joeljfischer Aug 4, 2021
5cb8098
Change some debug logs to verbose
joeljfischer Aug 4, 2021
04cb08b
Fix dynamic update algorithm failing in many cases
joeljfischer Aug 5, 2021
a551716
Update menu config update op
joeljfischer Aug 5, 2021
e13e060
Fix menu replace operation warning
joeljfischer Aug 5, 2021
aa04b9c
Update tests for changes
joeljfischer Aug 5, 2021
c84b402
More test fixes
joeljfischer Aug 5, 2021
51b020d
Current state of tests pass
joeljfischer Aug 5, 2021
bc30d80
Fix menu config not calling back in some cases
joeljfischer Aug 5, 2021
4127a5b
Fix menu config operation callback
joeljfischer Aug 5, 2021
b66bc00
Menu show operation test updates
joeljfischer Aug 5, 2021
ad941f2
Fix #1923 Empty string bug in menu cell texts
joeljfischer Aug 6, 2021
7031f68
Menu submenu cell conditions update
joeljfischer Aug 6, 2021
f25932a
Add test for cell equality with subcells empty vs nil
joeljfischer Aug 6, 2021
6ea3b36
Add more to menu replace utilities spec
joeljfischer Aug 6, 2021
b5bc553
Fix creating wrong RPCs for cell
joeljfischer Aug 6, 2021
e37c26f
Stubbing out additional tests
joeljfischer Aug 9, 2021
f7f5aad
In progress test updates
joeljfischer Aug 9, 2021
bff7993
Test fixes
joeljfischer Aug 9, 2021
b0c4e8a
Fix not finding secondary artworks to upload
joeljfischer Aug 10, 2021
63e70a9
Fix tests
joeljfischer Aug 10, 2021
df856a4
Finish menu replace tests
joeljfischer Aug 10, 2021
8d24f02
Work on replace operation spec
joeljfischer Aug 10, 2021
24905c8
Fix not using the stripped menu
joeljfischer Aug 11, 2021
d0ddd9a
Menu manager fixes
joeljfischer Aug 11, 2021
2a86bb3
Fix unit tests
joeljfischer Aug 12, 2021
c312e17
Compatibility mode needs unique cells
joeljfischer Aug 12, 2021
57b3e14
Lots of additional menu replace operation tests
joeljfischer Aug 12, 2021
d0c1531
Added more tests to replace operation spec
joeljfischer Aug 12, 2021
540f082
No need to apply unique names on current menu
joeljfischer Aug 13, 2021
1da1b9d
Update menu manager spec
joeljfischer Aug 13, 2021
9cdf9c2
Temporarily remove things that may not be necessary
joeljfischer Aug 13, 2021
9afd201
Revert "Temporarily remove things that may not be necessary"
joeljfischer Aug 13, 2021
5f0c618
Revert "Revert "Temporarily remove things that may not be necessary""
joeljfischer Aug 13, 2021
f59205a
Let the menu algorithm determine equality
joeljfischer Aug 17, 2021
f49850b
In progress menu test
joeljfischer Aug 17, 2021
61dd2f7
Lots of menu subcell update fixes
joeljfischer Aug 23, 2021
1797fe4
Menu replace operation fixes
joeljfischer Aug 23, 2021
9ff204a
Add a log
joeljfischer Aug 23, 2021
fd0c9c5
Transfer menu cell handlers from new cells to old
joeljfischer Aug 24, 2021
829513c
Fix build issues
joeljfischer Aug 24, 2021
1e2a7fc
Menu fixes
joeljfischer Aug 24, 2021
7053b9d
Update spec helper to remove commented out code
joeljfischer Aug 24, 2021
c776099
Add menu replace utility tests
joeljfischer Aug 24, 2021
f8834d1
Fix menu manager tests
joeljfischer Aug 24, 2021
5ff6811
Fixes to menu replace operation
joeljfischer Aug 24, 2021
cae62c6
Fix some more menu replace tests
joeljfischer Aug 25, 2021
61a48af
Add test for transferring handlers
joeljfischer Aug 25, 2021
7aacb05
Update from review
joeljfischer Sep 8, 2021
e3d8ab0
Fix still setting menu configuration if it fails
joeljfischer Sep 9, 2021
7ef29cc
Fix using wrong menu configuration pass through to menu operation
joeljfischer Sep 21, 2021
6010452
Merge branch 'develop' into feature/issue-1898-menu-manager-refactor
joeljfischer Sep 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cartfile.private
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
github "Quick/Quick" ~> 3.0
github "Quick/Nimble" ~> 9.0.0
github "Quick/Nimble" ~> 9.0
github "erikdoe/ocmock" ~> 3.7
154 changes: 122 additions & 32 deletions SmartDeviceLink-iOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1250"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8829567D207CF68800EF056C"
BuildableName = "SDL Example Swift.app"
BlueprintName = "SmartDeviceLink-Example-Swift"
ReferencedContainer = "container:SmartDeviceLink-iOS.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8829567D207CF68800EF056C"
BuildableName = "SDL Example Swift.app"
BlueprintName = "SmartDeviceLink-Example-Swift"
ReferencedContainer = "container:SmartDeviceLink-iOS.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "8829567D207CF68800EF056C"
BuildableName = "SDL Example Swift.app"
BlueprintName = "SmartDeviceLink-Example-Swift"
ReferencedContainer = "container:SmartDeviceLink-iOS.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
19 changes: 18 additions & 1 deletion SmartDeviceLink/private/SDLDynamicMenuUpdateAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,24 @@

@class SDLDynamicMenuUpdateRunScore;
@class SDLMenuCell;
@class SDLWindowCapability;

NS_ASSUME_NONNULL_BEGIN

/// Menu cell state
///
/// Cell state that tells the menu manager what it should do with a given SDLMenuCell
typedef NS_ENUM(NSUInteger, SDLMenuCellUpdateState) {
/// Marks the cell to be deleted
SDLMenuCellUpdateStateDelete = 0,

/// Marks the cell to be added
SDLMenuCellUpdateStateAdd,

/// Marks the cell to be kept
SDLMenuCellUpdateStateKeep
};

@interface SDLDynamicMenuUpdateAlgorithm : NSObject

/**
Expand All @@ -21,7 +36,9 @@ NS_ASSUME_NONNULL_BEGIN
@param oldMenuCells The old menu array
@param updatedMenuCells The new menu array
*/
+ (nullable SDLDynamicMenuUpdateRunScore *)compareOldMenuCells:(NSArray<SDLMenuCell *> *)oldMenuCells updatedMenuCells:(NSArray<SDLMenuCell *> *)updatedMenuCells;
+ (SDLDynamicMenuUpdateRunScore *)dynamicRunScoreOldMenuCells:(NSArray<SDLMenuCell *> *)oldMenuCells updatedMenuCells:(NSArray<SDLMenuCell *> *)updatedMenuCells;

+ (SDLDynamicMenuUpdateRunScore *)compatibilityRunScoreWithOldMenuCells:(NSArray<SDLMenuCell *> *)oldMenuCells updatedMenuCells:(NSArray<SDLMenuCell *> *)updatedMenuCells;

@end

Expand Down
55 changes: 32 additions & 23 deletions SmartDeviceLink/private/SDLDynamicMenuUpdateAlgorithm.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,50 @@
#import "SDLDynamicMenuUpdateRunScore.h"
#import "SDLMenuCell.h"
#import "SDLLogMacros.h"
#import "SDLMenuManagerConstants.h"
#import "SDLWindowCapability.h"

NS_ASSUME_NONNULL_BEGIN

@implementation SDLDynamicMenuUpdateAlgorithm

#pragma mark - Update Menu Cells
+ (nullable SDLDynamicMenuUpdateRunScore *)compareOldMenuCells:(NSArray<SDLMenuCell *> *)oldMenuCells updatedMenuCells:(NSArray<SDLMenuCell *> *)updatedMenuCells{
#pragma mark Compatibility Menu Run Score

+ (SDLDynamicMenuUpdateRunScore *)compatibilityRunScoreWithOldMenuCells:(NSArray<SDLMenuCell *> *)oldMenuCells updatedMenuCells:(NSArray<SDLMenuCell *> *)updatedMenuCells {
return [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:[self sdl_buildAllDeleteStatusesForMenu:oldMenuCells] updatedStatus:[self sdl_buildAllAddStatusesForMenu:updatedMenuCells] score:updatedMenuCells.count];
}

#pragma mark - Dynamic Menu Run Score

+ (SDLDynamicMenuUpdateRunScore *)dynamicRunScoreOldMenuCells:(NSArray<SDLMenuCell *> *)oldMenuCells updatedMenuCells:(NSArray<SDLMenuCell *> *)updatedMenuCells {
if (oldMenuCells.count > 0 && updatedMenuCells.count == 0) {
return [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:[SDLDynamicMenuUpdateAlgorithm sdl_buildAllDeleteStatusesforMenu:oldMenuCells] updatedStatus:@[] score:0];
// Deleting all cells
return [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:[SDLDynamicMenuUpdateAlgorithm sdl_buildAllDeleteStatusesForMenu:oldMenuCells] updatedStatus:@[] score:0];
}else if (oldMenuCells.count == 0 && updatedMenuCells.count > 0) {
// No cells to delete
return [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:@[] updatedStatus:[SDLDynamicMenuUpdateAlgorithm sdl_buildAllAddStatusesForMenu:updatedMenuCells] score:updatedMenuCells.count];
} else if (oldMenuCells.count == 0 && updatedMenuCells.count == 0) {
return nil;
// Empty menu to empty menu
return [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:@[] updatedStatus:@[] score:0];
}

return [SDLDynamicMenuUpdateAlgorithm sdl_startCompareAtRun:0 oldMenuCells:oldMenuCells updatedMenuCells:updatedMenuCells];
}

+ (nullable SDLDynamicMenuUpdateRunScore *)sdl_startCompareAtRun:(NSUInteger)startRun oldMenuCells:(NSArray<SDLMenuCell *> *)oldMenuCells updatedMenuCells:(NSArray<SDLMenuCell *> *)updatedMenuCells {
SDLDynamicMenuUpdateRunScore *bestScore = nil;
+ (SDLDynamicMenuUpdateRunScore *)sdl_startCompareAtRun:(NSUInteger)startRun oldMenuCells:(NSArray<SDLMenuCell *> *)oldMenuCells updatedMenuCells:(NSArray<SDLMenuCell *> *)updatedMenuCells {
SDLDynamicMenuUpdateRunScore *bestScore = [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:@[] updatedStatus:@[] score:0];

for (NSUInteger run = startRun; run < oldMenuCells.count; run++) {
// Set the menu status as a 1-1 array, start off will oldMenus = all Deletes, newMenu = all Adds
NSMutableArray<NSNumber *> *oldMenuStatus = [SDLDynamicMenuUpdateAlgorithm sdl_buildAllDeleteStatusesforMenu:oldMenuCells];
NSMutableArray<NSNumber *> *oldMenuStatus = [SDLDynamicMenuUpdateAlgorithm sdl_buildAllDeleteStatusesForMenu:oldMenuCells];
NSMutableArray<NSNumber *> *newMenuStatus = [SDLDynamicMenuUpdateAlgorithm sdl_buildAllAddStatusesForMenu:updatedMenuCells];

NSUInteger startIndex = 0;
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]]) {
oldMenuStatus[oldCellIndex] = @(MenuCellStateKeep);
newMenuStatus[newCellIndex] = @(MenuCellStateKeep);
if ([oldMenuCells[oldCellIndex] isEqualToCellWithUniqueTitle:updatedMenuCells[newCellIndex]]) {
oldMenuStatus[oldCellIndex] = @(SDLMenuCellUpdateStateKeep);
newMenuStatus[newCellIndex] = @(SDLMenuCellUpdateStateKeep);
startIndex = newCellIndex + 1;
break;
}
Expand All @@ -54,18 +64,17 @@ + (nullable SDLDynamicMenuUpdateRunScore *)sdl_startCompareAtRun:(NSUInteger)sta
NSUInteger numberOfAdds = 0;
for (NSUInteger status = 0; status < newMenuStatus.count; status++) {
// 0 = Delete 1 = Add 2 = Keep
if (newMenuStatus[status].integerValue == MenuCellStateAdd) {
if (newMenuStatus[status].integerValue == SDLMenuCellUpdateStateAdd) {
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) {
bestScore = [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:oldMenuStatus updatedStatus:newMenuStatus score:numberOfAdds];
return bestScore;
return [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:oldMenuStatus updatedStatus:newMenuStatus score:numberOfAdds];
}
// 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 we haven't create the bestScore object or if the current score beats the old score then we will create a new bestScore
if (bestScore.isEmpty || numberOfAdds < bestScore.score) {
bestScore = [[SDLDynamicMenuUpdateRunScore alloc] initWithOldStatus:oldMenuStatus updatedStatus:newMenuStatus score:numberOfAdds];
}
}
Expand All @@ -78,12 +87,12 @@ + (nullable SDLDynamicMenuUpdateRunScore *)sdl_startCompareAtRun:(NSUInteger)sta

@param oldMenu The old menu array
*/
+ (NSMutableArray<NSNumber *> *)sdl_buildAllDeleteStatusesforMenu:(NSArray<SDLMenuCell *> *)oldMenu {
NSMutableArray<NSNumber *> *oldMenuStatus = [[NSMutableArray alloc] init];
+ (NSMutableArray<NSNumber *> *)sdl_buildAllDeleteStatusesForMenu:(NSArray<SDLMenuCell *> *)oldMenu {
NSMutableArray<NSNumber *> *oldMenuStatus = [[NSMutableArray alloc] initWithCapacity:oldMenu.count];
for (NSUInteger index = 0; index < oldMenu.count; index++) {
[oldMenuStatus addObject:@(MenuCellStateDelete)];
[oldMenuStatus addObject:@(SDLMenuCellUpdateStateDelete)];
}
return [oldMenuStatus mutableCopy];
return oldMenuStatus;
}

/**
Expand All @@ -92,11 +101,11 @@ + (nullable SDLDynamicMenuUpdateRunScore *)sdl_startCompareAtRun:(NSUInteger)sta
@param newMenu The new menu array
*/
+ (NSMutableArray<NSNumber *> *)sdl_buildAllAddStatusesForMenu:(NSArray<SDLMenuCell *> *)newMenu {
NSMutableArray<NSNumber *> *newMenuStatus = [[NSMutableArray alloc] init];
NSMutableArray<NSNumber *> *newMenuStatus = [[NSMutableArray alloc] initWithCapacity:newMenu.count];
for (NSUInteger index = 0; index < newMenu.count; index++) {
[newMenuStatus addObject:@(MenuCellStateAdd)];
[newMenuStatus addObject:@(SDLMenuCellUpdateStateAdd)];
}
return [newMenuStatus mutableCopy];
return newMenuStatus;
}

@end
Expand Down
7 changes: 5 additions & 2 deletions SmartDeviceLink/private/SDLDynamicMenuUpdateRunScore.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ NS_ASSUME_NONNULL_BEGIN
@interface SDLDynamicMenuUpdateRunScore : NSObject

/**
Will contain all the Deletes and Keeps
Will contain all the Deletes and Keeps. Contains SDLMenuState.
*/
@property (copy, nonatomic, readonly) NSArray<NSNumber *> *oldStatus;

/**
Will contain all the Adds and Keeps
Will contain all the Adds and Keeps. Contains SDLMenuState.
*/
@property (copy, nonatomic, readonly) NSArray<NSNumber *> *updatedStatus;

Expand All @@ -27,6 +27,9 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (assign, nonatomic, readonly) NSUInteger score;

/// Contains no old score, new score, or score
@property (assign, nonatomic, readonly) BOOL isEmpty;

- (instancetype)initWithOldStatus:(NSArray<NSNumber *> *)oldStatus updatedStatus:(NSArray<NSNumber *> *)updatedStatus score:(NSUInteger)score;

@end
Expand Down
25 changes: 25 additions & 0 deletions SmartDeviceLink/private/SDLDynamicMenuUpdateRunScore.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "SDLDynamicMenuUpdateRunScore.h"

#import "SDLDynamicMenuUpdateAlgorithm.h"

NS_ASSUME_NONNULL_BEGIN

@implementation SDLDynamicMenuUpdateRunScore
Expand All @@ -23,6 +25,29 @@ - (instancetype)initWithOldStatus:(NSArray<NSNumber *> *)oldStatus updatedStatus
return self;
}

- (NSString *)description {
return [NSString stringWithFormat:@"Run Score: %ld, old status: %@, updated status: %@", (long)self.score, [self sdl_stringArrayForCellUpdateStatuses:self.oldStatus], [self sdl_stringArrayForCellUpdateStatuses:self.updatedStatus]];
}

- (NSArray<NSString *> *)sdl_stringArrayForCellUpdateStatuses:(NSArray<NSNumber *> *)statuses {
NSMutableArray<NSString *> *mutableStringArray = [NSMutableArray arrayWithCapacity:statuses.count];
for (NSNumber *status in statuses) {
if (status.unsignedIntegerValue == SDLMenuCellUpdateStateDelete) {
[mutableStringArray addObject:@"DELETE"];
} else if (status.unsignedIntegerValue == SDLMenuCellUpdateStateAdd) {
[mutableStringArray addObject:@"ADD"];
} else if (status.unsignedIntegerValue == SDLMenuCellUpdateStateKeep) {
[mutableStringArray addObject:@"KEEP"];
}
}

return [mutableStringArray copy];
}

- (BOOL)isEmpty {
return (self.oldStatus.count == 0 && self.updatedStatus.count == 0 && self.score == 0);
}

@end

NS_ASSUME_NONNULL_END
9 changes: 9 additions & 0 deletions SmartDeviceLink/private/SDLError.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#import "SDLErrorConstants.h"
#import "SDLResult.h"

@class SDLMenuCell;
@class SDLMenuConfiguration;


NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -55,7 +58,13 @@ NS_ASSUME_NONNULL_BEGIN

#pragma mark Menu Manager

+ (NSError *)sdl_menuManager_configurationOperationLayoutsNotSupported;
+ (NSError *)sdl_menuManager_configurationOperationFailed:(SDLMenuConfiguration *)failedConfiguration;
+ (NSError *)sdl_menuManager_openMenuOperationCancelled;
+ (NSError *)sdl_menuManager_openMenuOperationFailed:(nullable SDLMenuCell *)menuCell;
+ (NSError *)sdl_menuManager_replaceOperationCancelled;
+ (NSError *)sdl_menuManager_failedToUpdateWithDictionary:(NSDictionary *)userInfo;

+ (NSError *)sdl_voiceCommandManager_pendingUpdateSuperseded;

#pragma mark Choice Set Manager
Expand Down
49 changes: 49 additions & 0 deletions SmartDeviceLink/private/SDLError.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "SDLError.h"

#import "SDLChoiceSetManager.h"
#import "SDLMenuConfiguration.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -270,6 +271,54 @@ + (NSError *)sdl_subscribeButtonManager_notSubscribed {

#pragma mark Menu Manager

+ (NSError *)sdl_menuManager_configurationOperationLayoutsNotSupported {
return [NSError errorWithDomain:SDLErrorDomainMenuManager code:SDLMenuManagerErrorConfigurationUpdateLayoutNotSupported userInfo:@{
NSLocalizedDescriptionKey: @"Menu Manager - Configuration Update Failed",
NSLocalizedFailureReasonErrorKey: @"One or more of the configuration layouts is not supported by the module",
NSLocalizedRecoverySuggestionErrorKey: @"Compare SDLManager.systemCapabilityManager.defaultWindowCapability.menuLayoutsAvailable to what you attempted to set"
}];
}

+ (NSError *)sdl_menuManager_configurationOperationFailed:(SDLMenuConfiguration *)failedConfiguration {
return [NSError errorWithDomain:SDLErrorDomainMenuManager code:SDLMenuManagerErrorConfigurationUpdateFailed userInfo:@{
@"Failed Configuration": failedConfiguration,
NSLocalizedDescriptionKey: @"Menu Manager - Configuration Update Failed",
NSLocalizedFailureReasonErrorKey: @"The configuration may not be supported by the connected head unit",
NSLocalizedRecoverySuggestionErrorKey: @"Check SystemCapabilityManager.defaultWindowCapability.menuLayouts to ensure the set configuration is supported"
}];
}

+ (NSError *)sdl_menuManager_openMenuOperationCancelled {
return [NSError errorWithDomain:SDLErrorDomainMenuManager code:SDLMenuManagerErrorOperationCancelled userInfo:@{
NSLocalizedDescriptionKey: @"Menu Manager - Open Menu Cancelled",
NSLocalizedFailureReasonErrorKey: @"The menu manager was probably stopped or opening another menu item was requested.",
NSLocalizedRecoverySuggestionErrorKey: @"This error probably does not need recovery."
}];
}

+ (NSError *)sdl_menuManager_openMenuOperationFailed:(nullable SDLMenuCell *)menuCell {
NSString *failureReason = nil;
if (menuCell != nil) {
failureReason = @"Something went wrong attempting to open the menu.";
} else {
failureReason = [NSString stringWithFormat:@"Something went wrong attempting to open the menu to the given subcell: %@", menuCell];
}

return [NSError errorWithDomain:SDLErrorDomainMenuManager code:SDLMenuManagerErrorOpenMenuFailed userInfo:@{
NSLocalizedDescriptionKey: @"Menu Manager - Open Menu Failed",
NSLocalizedFailureReasonErrorKey: failureReason,
NSLocalizedRecoverySuggestionErrorKey: @"Check the error logs for more information on the RPC failure."
}];
}

+ (NSError *)sdl_menuManager_replaceOperationCancelled {
return [NSError errorWithDomain:SDLErrorDomainMenuManager code:SDLMenuManagerErrorOperationCancelled userInfo:@{
NSLocalizedDescriptionKey: @"Menu Manager - Menu Replace Cancelled",
NSLocalizedFailureReasonErrorKey: @"The menu manager was probably stopped or another menu update was requested.",
NSLocalizedRecoverySuggestionErrorKey: @"This error probably does not need recovery."
}];
}

+ (NSError *)sdl_menuManager_failedToUpdateWithDictionary:(NSDictionary *)userInfo {
return [NSError errorWithDomain:SDLErrorDomainMenuManager code:SDLMenuManagerErrorRPCsFailed userInfo:userInfo];
}
Expand Down
Loading