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

SDL 0180 - Fix to support broaden choice cell uniqueness #1886

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
52dc8b3
uniqueText property added in SDLChoiceCell
FrankElias77 Jan 8, 2021
76eaf29
SDLChoiceSet and SDLChoiceSetManager update
FrankElias77 Jan 8, 2021
f97ef9a
update PreloadChoicesOperation
FrankElias77 Jan 8, 2021
19dfe89
test update for equivalent cell text
FrankElias77 Jan 8, 2021
f87d61d
encapsulation and comment fixes
FrankElias77 Jan 11, 2021
df8f8e9
Function time enhancement
FrankElias77 Jan 12, 2021
163091e
ChoiceSet updates
FrankElias77 Jan 13, 2021
1cc4736
MenuCell updates
FrankElias77 Jan 13, 2021
5af989e
spec file updates
FrankElias77 Jan 13, 2021
94a24ea
Comments review
FrankElias77 Jan 13, 2021
f84eede
menuCell updates
FrankElias77 Jan 14, 2021
b4c28b9
Merge branch 'develop' into feature/issue-1024-sdl-0180-broaden-choic…
joeljfischer Feb 2, 2021
821dfd6
comments review
FrankElias77 Feb 3, 2021
f74c128
Comments review
FrankElias77 Feb 4, 2021
13b66fd
comments review
FrankElias77 Feb 9, 2021
2873483
comments review
FrankElias77 Feb 10, 2021
ebfdd35
Comments review
FrankElias77 Feb 10, 2021
5071953
Update RPC_Spec
joeljfischer Feb 15, 2021
648bfad
comments review
FrankElias77 Feb 18, 2021
1a05fc6
comments review
FrankElias77 Feb 18, 2021
7a17f0d
Merge branch 'develop' into feature/issue-1024-sdl-0180-broaden-choic…
FrankElias77 Feb 19, 2021
0d29e70
Fixing warnings
FrankElias77 Feb 19, 2021
1350438
comments review
FrankElias77 Feb 19, 2021
7112c0a
Fixes for 0180
joeljfischer Feb 22, 2021
1f62149
Fixes to menu manager checks for unique voice commands
joeljfischer Feb 22, 2021
7a762fb
Style and other slight fixes
joeljfischer Feb 22, 2021
a3a6995
Style and other slight fixes
joeljfischer Feb 22, 2021
9c38eae
Choice set fixes
joeljfischer Feb 22, 2021
65f1281
Fix choice set spec
joeljfischer Feb 22, 2021
9d598d0
Clarify a log
joeljfischer Feb 22, 2021
3076f62
Fix crashing tests
joeljfischer Feb 25, 2021
af32086
Fix menu manager not properly uploading menu when there are not dupli…
joeljfischer Feb 25, 2021
61100f1
Add additional comments about uniquing choice cells
joeljfischer Feb 25, 2021
78342fc
Additional documentation
joeljfischer Feb 25, 2021
3561365
Merge branch 'develop' into feature/issue-1024-sdl-0180-broaden-choic…
joeljfischer Mar 4, 2021
35e3168
Fix tests
joeljfischer Mar 4, 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
5 changes: 3 additions & 2 deletions SmartDeviceLink/private/SDLChoiceSetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,9 @@ - (void)dismissKeyboardWithCancelID:(NSNumber<SDLInt> *)cancelID {
/// @return The choices that have not yet been uploaded to the module
- (NSSet<SDLChoiceCell *> *)sdl_choicesToBeUploadedWithArray:(NSArray<SDLChoiceCell *> *)choices {
NSMutableSet<SDLChoiceCell *> *choicesSet = [NSMutableSet setWithArray:choices];
joeljfischer marked this conversation as resolved.
Show resolved Hide resolved
SDLVersion *choiceUniquenessSupportedVersion = [[SDLVersion alloc] initWithMajor:7 minor:1 patch:0];
if ([[SDLGlobals sharedGlobals].rpcVersion isLessThanVersion:choiceUniquenessSupportedVersion]) {

// If we're running on a connection < RPC 7.1, we need to de-duplicate cells because presenting them will fail if we have the same cell primary text.
SDLVersion *choiceUniquenessSupportedVersion = [[SDLVersion alloc] initWithMajor:7 minor:1 patch:0]; if ([[SDLGlobals sharedGlobals].rpcVersion isLessThanVersion:choiceUniquenessSupportedVersion]) {
FrankElias77 marked this conversation as resolved.
Show resolved Hide resolved
[self sdl_addUniqueNamesToCells:choicesSet];
}
[choicesSet minusSet:self.preloadedChoices];
Expand Down
21 changes: 21 additions & 0 deletions SmartDeviceLink/private/SDLMenuManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,34 @@ - (void)setMenuCells:(NSArray<SDLMenuCell *> *)menuCells {
self.waitingOnHMIUpdate = NO;

NSMutableSet<NSString *> *allMenuVoiceCommands = [NSMutableSet set];
NSMutableSet *cellCheckSet = [NSMutableSet set];
FrankElias77 marked this conversation as resolved.
Show resolved Hide resolved
NSUInteger voiceCommandCount = 0;
for (SDLMenuCell *cell in cells) {
[cellCheckSet addObject:cell];
if (cell.subCells.count > 0) {
NSMutableSet *subCellsCheckSet = [NSMutableSet set];
for (SDLMenuCell *subCell in cell.subCells) {
FrankElias77 marked this conversation as resolved.
Show resolved Hide resolved
[subCellsCheckSet addObject:subCell];
if (subCell.voiceCommands == nil) { continue; }
[allMenuVoiceCommands addObjectsFromArray:subCell.voiceCommands];
voiceCommandCount += subCell.voiceCommands.count;
FrankElias77 marked this conversation as resolved.
Show resolved Hide resolved
}

if (subCellsCheckSet.count != cell.subCells.count) {
SDLLogE(@"Not all subCells are unique. The menu will not be set.");
return;
FrankElias77 marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (cell.voiceCommands == nil) { continue; }
[allMenuVoiceCommands addObjectsFromArray:cell.voiceCommands];
voiceCommandCount += cell.voiceCommands.count;
}

if (cellCheckSet.count != cells.count) {
SDLLogE(@"Not all cells are unique. The menu will not be set.");
FrankElias77 marked this conversation as resolved.
Show resolved Hide resolved
return;
}

// Check for duplicate voice recognition commands
if (allMenuVoiceCommands.count != voiceCommandCount) {
SDLLogE(@"Attempted to create a menu with duplicate voice commands. Voice commands must be unique. The menu will not be set.");
Expand Down
7 changes: 7 additions & 0 deletions SmartDeviceLink/public/SDLChoiceSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,23 @@ - (instancetype)initWithTitle:(NSString *)title delegate:(id<SDLChoiceSetDelegat
return nil;
}

NSMutableSet<SDLChoiceCell *> *choicesSet = [NSMutableSet setWithCapacity:choices.count];
NSMutableSet<NSString *> *uniqueVoiceCommands = [NSMutableSet set];
NSUInteger allVoiceCommandsCount = 0;
NSUInteger choiceCellWithVoiceCommandCount = 0;
for (SDLChoiceCell *cell in choices) {
[choicesSet addObject:cell];
if (cell.voiceCommands == nil) { continue; }
FrankElias77 marked this conversation as resolved.
Show resolved Hide resolved
[uniqueVoiceCommands addObjectsFromArray:cell.voiceCommands];
choiceCellWithVoiceCommandCount += 1;
allVoiceCommandsCount += cell.voiceCommands.count;
}

if (choicesSet.count < choices.count) {
SDLLogE(@"Attempted to create a choice set with duplicate cell text. Cell text must be unique. The choice set will not be set.");
return nil;
}
FrankElias77 marked this conversation as resolved.
Show resolved Hide resolved

// All or none of the choices must have VR commands
if ((choiceCellWithVoiceCommandCount > 0 && choiceCellWithVoiceCommandCount < choices.count)) {
SDLLogE(@"If using voice recognition commands, all of the choice set cells must have unique VR commands. There are %lu cells with unique voice commands and %lu total cells. The choice set will not be set.", (unsigned long)choiceCellWithVoiceCommandCount, (unsigned long)choices.count);
Expand Down
4 changes: 2 additions & 2 deletions SmartDeviceLinkTests/DevAPISpecs/SDLChoiceSetSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ @interface SDLChoiceSet()
expect(testChoiceSet).to(beNil());
});

it(@"should not return nil with equivalent cell text", ^{
it(@"should return nil when 2 or more cells are identical", ^{
FrankElias77 marked this conversation as resolved.
Show resolved Hide resolved
// Cell `text` cannot be equal
FrankElias77 marked this conversation as resolved.
Show resolved Hide resolved
SDLChoiceCell *equalCell = [[SDLChoiceCell alloc] initWithText:@"Text"];
SDLChoiceCell *equalCell2 = [[SDLChoiceCell alloc] initWithText:@"Text"];
FrankElias77 marked this conversation as resolved.
Show resolved Hide resolved
testChoiceSet = [[SDLChoiceSet alloc] initWithTitle:testTitle delegate:testDelegate choices:@[equalCell, equalCell2]];
expect(testChoiceSet).toNot(beNil());
expect(testChoiceSet).to(beNil());
});

context(@"With bad VR data", ^{
Expand Down