Skip to content

Commit 82c75e7

Browse files
Robert HeniganHenigan
andauthored
Fix Main Menu UI updates do not take text field name into account (#1629)
* Check for textFieldNames * Review Feedback * Remove empty line seperating doc from method * Update MenuCell Constructors * Update JavaSE MenuCell Constructors Co-authored-by: Henigan <rheniga1@MGC12Z921DLVCG.fbpld77.ford.com>
1 parent 6ace491 commit 82c75e7

3 files changed

Lines changed: 108 additions & 24 deletions

File tree

android/hello_sdl_android/src/main/java/com/sdl/hellosdlandroid/SdlService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,15 @@ private void sendMenus() {
298298
// some voice commands
299299
List<String> voice2 = Collections.singletonList("Cell two");
300300

301-
MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", livio, null, new MenuSelectionListener() {
301+
MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", "Secondary Text", "Tertiary Text", livio, livio, null, new MenuSelectionListener() {
302302
@Override
303303
public void onTriggered(TriggerSource trigger) {
304304
Log.i(TAG, "Test cell 1 triggered. Source: " + trigger.toString());
305305
showTest();
306306
}
307307
});
308308

309-
MenuCell mainCell2 = new MenuCell("Test Cell 2", null, voice2, new MenuSelectionListener() {
309+
MenuCell mainCell2 = new MenuCell("Test Cell 2", "Secondary Text", null, null, null, voice2, new MenuSelectionListener() {
310310
@Override
311311
public void onTriggered(TriggerSource trigger) {
312312
Log.i(TAG, "Test cell 2 triggered. Source: " + trigger.toString());
@@ -315,31 +315,31 @@ public void onTriggered(TriggerSource trigger) {
315315

316316
// SUB MENU
317317

318-
MenuCell subCell1 = new MenuCell("SubCell 1", null, null, new MenuSelectionListener() {
318+
MenuCell subCell1 = new MenuCell("SubCell 1", null, null, null, null, null, new MenuSelectionListener() {
319319
@Override
320320
public void onTriggered(TriggerSource trigger) {
321321
Log.i(TAG, "Sub cell 1 triggered. Source: " + trigger.toString());
322322
}
323323
});
324324

325-
MenuCell subCell2 = new MenuCell("SubCell 2", null, null, new MenuSelectionListener() {
325+
MenuCell subCell2 = new MenuCell("SubCell 2", null, null, null, null, null, new MenuSelectionListener() {
326326
@Override
327327
public void onTriggered(TriggerSource trigger) {
328328
Log.i(TAG, "Sub cell 2 triggered. Source: " + trigger.toString());
329329
}
330330
});
331331

332332
// sub menu parent cell
333-
MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", MenuLayout.LIST, null, Arrays.asList(subCell1, subCell2));
333+
MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", null, null, MenuLayout.LIST, null, null, Arrays.asList(subCell1, subCell2));
334334

335-
MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, new MenuSelectionListener() {
335+
MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, null, null, null, new MenuSelectionListener() {
336336
@Override
337337
public void onTriggered(TriggerSource trigger) {
338338
showPerformInteraction();
339339
}
340340
});
341341

342-
MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, new MenuSelectionListener() {
342+
MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, null,null, null, new MenuSelectionListener() {
343343
@Override
344344
public void onTriggered(TriggerSource trigger) {
345345
Log.i(TAG, "Clearing Menu. Source: " + trigger.toString());

base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java

Lines changed: 94 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.smartdevicelink.proxy.rpc.enums.PredefinedWindows;
6666
import com.smartdevicelink.proxy.rpc.enums.SystemCapabilityType;
6767
import com.smartdevicelink.proxy.rpc.enums.SystemContext;
68+
import com.smartdevicelink.proxy.rpc.enums.TextFieldName;
6869
import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener;
6970
import com.smartdevicelink.proxy.rpc.listeners.OnRPCNotificationListener;
7071
import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener;
@@ -740,6 +741,12 @@ private void setAddStatus(Integer size, List<Integer> newArray) {
740741

741742
// ARTWORKS
742743

744+
/**
745+
* Get an array of artwork that needs to be uploaded from a list of menu cells
746+
*
747+
* @param cells List of MenuCell's to check
748+
* @return List of artwork that needs to be uploaded
749+
*/
743750
private List<SdlArtwork> findAllArtworksToBeUploadedFromCells(List<MenuCell> cells) {
744751
// Make sure we can use images in the menus
745752
if (!hasImageFieldOfName(ImageFieldName.cmdIcon)) {
@@ -770,6 +777,18 @@ private List<SdlArtwork> findAllArtworksToBeUploadedFromCells(List<MenuCell> cel
770777
return artworks;
771778
}
772779

780+
/**
781+
* Determine if cells should or should not be uploaded to the head unit with artworks.
782+
*
783+
* No artworks will be uploaded if:
784+
*
785+
* 1. If any cell has a dynamic artwork that is not uploaded
786+
* 2. If any cell contains a secondary artwork may be used on the head unit, and the cell has a dynamic secondary artwork that is not uploaded
787+
* 3. If any cell's subcells fail check (1) or (2)
788+
*
789+
* @param cells List of MenuCell's to check
790+
* @return True if the cells should be uploaded with artwork, false if they should not
791+
*/
773792
private boolean shouldRPCsIncludeImages(List<MenuCell> cells) {
774793
for (MenuCell cell : cells) {
775794
SdlArtwork artwork = cell.getIcon();
@@ -784,8 +803,8 @@ private boolean shouldRPCsIncludeImages(List<MenuCell> cells) {
784803
if (secondaryArtwork != null && !secondaryArtwork.isStaticIcon() && fileManager.get() != null && !fileManager.get().hasUploadedFile(secondaryArtwork)) {
785804
return false;
786805
}
787-
} else if (cell.getSubCells() != null && cell.getSubCells().size() > 0) {
788-
return shouldRPCsIncludeImages(cell.getSubCells());
806+
} else if (cell.getSubCells() != null && cell.getSubCells().size() > 0 && !shouldRPCsIncludeImages(cell.getSubCells())) {
807+
return false;
789808
}
790809
}
791810
return true;
@@ -795,6 +814,10 @@ private boolean hasImageFieldOfName(ImageFieldName imageFieldName) {
795814
return defaultMainWindowCapability == null || ManagerUtility.WindowCapabilityUtility.hasImageFieldOfName(defaultMainWindowCapability, imageFieldName);
796815
}
797816

817+
private boolean hasTextFieldOfName(TextFieldName textFieldName) {
818+
return defaultMainWindowCapability == null || ManagerUtility.WindowCapabilityUtility.hasTextFieldOfName(defaultMainWindowCapability, textFieldName);
819+
}
820+
798821
// IDs
799822

800823
private void updateIdsOnDynamicCells(List<MenuCell> dynamicCells) {
@@ -841,6 +864,13 @@ private List<MenuCell> updateIdsOnDynamicSubCells(List<MenuCell> oldList, List<M
841864
return null;
842865
}
843866

867+
868+
/**
869+
* Assign cell ids on an array of menu cells given a parent id (or no parent id)
870+
*
871+
* @param cells List of menu cells to update
872+
* @param parentId The parent id to assign if needed
873+
*/
844874
private void updateIdsOnMenuCells(List<MenuCell> cells, int parentId) {
845875
for (MenuCell cell : cells) {
846876
int newId = ++lastMenuId;
@@ -880,6 +910,12 @@ private void transferIdsToKeptSubCells(List<MenuCell> old, List<MenuCell> keeps)
880910

881911
// DELETES
882912

913+
/**
914+
* Create an array of DeleteCommand and DeleteSubMenu RPCs from an ArrayList of menu cells
915+
*
916+
* @param cells List of menu cells to use
917+
* @return List of DeleteCommand and DeletedSubmenu RPCs
918+
*/
883919
private List<RPCRequest> createDeleteRPCsForCells(List<MenuCell> cells) {
884920
List<RPCRequest> deletes = new ArrayList<>();
885921
for (MenuCell cell : cells) {
@@ -896,6 +932,14 @@ private List<RPCRequest> createDeleteRPCsForCells(List<MenuCell> cells) {
896932

897933
// COMMANDS / SUBMENU RPCs
898934

935+
/**
936+
* This method will receive the cells to be added. It will then build an array of add commands using the correct index to position the new items in the correct location.
937+
* e.g. If the new menu array is [A, B, C, D] but only [C, D] are new we need to pass [A, B , C , D] so C and D can be added to index 2 and 3 respectively.
938+
*
939+
* @param cellsToAdd List of MenuCell's that will be added to the menu, this array must contain only cells that are not already in the menu.
940+
* @param shouldHaveArtwork Boolean that indicates whether artwork should be applied to the RPC or not
941+
* @return List of RPCRequest addCommands
942+
*/
899943
private List<RPCRequest> mainMenuCommandsForCells(List<MenuCell> cellsToAdd, boolean shouldHaveArtwork) {
900944
List<RPCRequest> builtCommands = new ArrayList<>();
901945

@@ -917,6 +961,13 @@ private List<RPCRequest> mainMenuCommandsForCells(List<MenuCell> cellsToAdd, boo
917961
return builtCommands;
918962
}
919963

964+
/**
965+
* Creates AddSubMenu RPCs for the passed array of menu cells, AND all of those cells' subcell RPCs, both AddCommands and AddSubMenus
966+
*
967+
* @param cells List of MenuCell's to create RPCs for
968+
* @param shouldHaveArtwork Boolean that indicates whether artwork should be applied to the RPC or not
969+
* @return An List of RPCs of AddSubMenus and their associated subcell RPCs
970+
*/
920971
private List<RPCRequest> subMenuCommandsForCells(List<MenuCell> cells, boolean shouldHaveArtwork) {
921972
List<RPCRequest> builtCommands = new ArrayList<>();
922973
for (MenuCell cell : cells) {
@@ -927,6 +978,13 @@ private List<RPCRequest> subMenuCommandsForCells(List<MenuCell> cells, boolean s
927978
return builtCommands;
928979
}
929980

981+
/**
982+
* Creates AddCommand and AddSubMenu RPCs for a passed array of cells, AND all of those cells' subcell RPCs, both AddCommands and AddSubmenus
983+
*
984+
* @param cells List of MenuCell's to create RPCs for
985+
* @param shouldHaveArtwork Boolean that indicates whether artwork should be applied to the RPC or not
986+
* @return An List of RPCs of AddCommand and AddSubMenus for the array of menu cells and their subcells, recursively
987+
*/
930988
List<RPCRequest> allCommandsForCells(List<MenuCell> cells, boolean shouldHaveArtwork) {
931989
List<RPCRequest> builtCommands = new ArrayList<>();
932990

@@ -959,11 +1017,19 @@ private List<RPCRequest> createCommandsForDynamicSubCells(List<MenuCell> oldMenu
9591017
return builtCommands;
9601018
}
9611019

1020+
/**
1021+
* An individual AddCommand RPC for a given MenuCell
1022+
*
1023+
* @param cell MenuCell to create RPCs for
1024+
* @param shouldHaveArtwork Boolean that indicates whether artwork should be applied to the RPC or not
1025+
* @param position The position the AddCommand RPC should be given
1026+
* @return The AddCommand RPC
1027+
*/
9621028
private AddCommand commandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position) {
9631029

9641030
MenuParams params = new MenuParams(cell.getUniqueTitle());
965-
params.setSecondaryText((cell.getSecondaryText() != null && cell.getSecondaryText().length() == 0) ? null : cell.getSecondaryText());
966-
params.setTertiaryText((cell.getTertiaryText() != null && cell.getTertiaryText().length() == 0) ? null : cell.getTertiaryText());
1031+
params.setSecondaryText((cell.getSecondaryText() != null && cell.getSecondaryText().length() > 0 && hasTextFieldOfName(TextFieldName.menuCommandSecondaryText)) ? cell.getSecondaryText() : null);
1032+
params.setTertiaryText((cell.getTertiaryText() != null && cell.getTertiaryText().length() > 0 && hasTextFieldOfName(TextFieldName.menuCommandTertiaryText)) ? cell.getTertiaryText() : null);
9671033
params.setParentID(cell.getParentCellId() != MAX_ID ? cell.getParentCellId() : null);
9681034
params.setPosition(position);
9691035

@@ -980,10 +1046,18 @@ private AddCommand commandForMenuCell(MenuCell cell, boolean shouldHaveArtwork,
9801046
return command;
9811047
}
9821048

1049+
/**
1050+
* An individual AddSubMenu RPC for a given MenuCell
1051+
*
1052+
* @param cell The cell to create the RPC for
1053+
* @param shouldHaveArtwork Whether artwork should be applied to the RPC
1054+
* @param position The position the AddSubMenu RPC should be given
1055+
* @return The AddSubMenu RPC
1056+
*/
9831057
private AddSubMenu subMenuCommandForMenuCell(MenuCell cell, boolean shouldHaveArtwork, int position) {
9841058
AddSubMenu subMenu = new AddSubMenu(cell.getCellId(), cell.getUniqueTitle());
985-
subMenu.setSecondaryText((cell.getSecondaryText() != null && cell.getSecondaryText().length() == 0) ? null : cell.getSecondaryText());
986-
subMenu.setTertiaryText((cell.getTertiaryText() != null && cell.getTertiaryText().length() == 0) ? null : cell.getTertiaryText());
1059+
subMenu.setSecondaryText((cell.getSecondaryText() != null && cell.getSecondaryText().length() > 0 && hasTextFieldOfName(TextFieldName.menuSubMenuSecondaryText)) ? cell.getSecondaryText() : null);
1060+
subMenu.setTertiaryText((cell.getTertiaryText() != null && cell.getTertiaryText().length() > 0 && hasTextFieldOfName(TextFieldName.menuSubMenuTertiaryText)) ? cell.getTertiaryText() : null);
9871061
subMenu.setPosition(position);
9881062
if (cell.getSubMenuLayout() != null) {
9891063
subMenu.setMenuLayout(cell.getSubMenuLayout());
@@ -997,6 +1071,14 @@ private AddSubMenu subMenuCommandForMenuCell(MenuCell cell, boolean shouldHaveAr
9971071

9981072
// CELL COMMAND HANDLING
9991073

1074+
1075+
/**
1076+
* Call a listener for a currently displayed MenuCell based on the incoming OnCommand notification
1077+
*
1078+
* @param cells List of MenuCell's to check (including their subcells)
1079+
* @param command OnCommand notification retrieved
1080+
* @return True if the handler was found, false if it was not found
1081+
*/
10001082
private boolean callListenerForCells(List<MenuCell> cells, OnCommand command) {
10011083
if (cells != null && cells.size() > 0 && command != null) {
10021084
for (MenuCell cell : cells) {
@@ -1379,11 +1461,13 @@ private void addUniqueNamesToCells(List<MenuCell> cells) {
13791461
}
13801462
}
13811463

1382-
/**
1383-
Check for cell lists with completely duplicate information, or any duplicate voiceCommands
13841464

1385-
@param cells The cells you will be adding
1386-
@return Boolean that indicates whether menuCells are unique or not
1465+
/**
1466+
* Check for cell lists with completely duplicate information, or any duplicate voiceCommands
1467+
*
1468+
* @param cells List of MenuCell's you will be adding
1469+
* @param allVoiceCommands List of String's for VoiceCommands (Used for recursive calls to check voiceCommands of the cells)
1470+
* @return Boolean that indicates whether menuCells are unique or not
13871471
*/
13881472
private boolean menuCellsAreUnique(List<MenuCell> cells, ArrayList<String> allVoiceCommands) {
13891473
//Check all voice commands for identical items and check each list of cells for identical cells

javaSE/hello_sdl_java/src/main/java/com/smartdevicelink/java/SdlService.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ private void sendMenus() {
247247
// some voice commands
248248
List<String> voice2 = Collections.singletonList("Cell two");
249249

250-
MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", livio, null, new MenuSelectionListener() {
250+
MenuCell mainCell1 = new MenuCell("Test Cell 1 (speak)", "Secondary Text", "Tertiary Text", livio, livio, null, new MenuSelectionListener() {
251251
@Override
252252
public void onTriggered(TriggerSource trigger) {
253253
DebugTool.logInfo(TAG, "Test cell 1 triggered. Source: " + trigger.toString());
254254
showTest();
255255
}
256256
});
257257

258-
MenuCell mainCell2 = new MenuCell("Test Cell 2", null, voice2, new MenuSelectionListener() {
258+
MenuCell mainCell2 = new MenuCell("Test Cell 2", "Secondary Text", null, null, null, voice2, new MenuSelectionListener() {
259259
@Override
260260
public void onTriggered(TriggerSource trigger) {
261261
DebugTool.logInfo(TAG, "Test cell 2 triggered. Source: " + trigger.toString());
@@ -264,31 +264,31 @@ public void onTriggered(TriggerSource trigger) {
264264

265265
// SUB MENU
266266

267-
MenuCell subCell1 = new MenuCell("SubCell 1", null, null, new MenuSelectionListener() {
267+
MenuCell subCell1 = new MenuCell("SubCell 1", null, null, null, null, null, new MenuSelectionListener() {
268268
@Override
269269
public void onTriggered(TriggerSource trigger) {
270270
DebugTool.logInfo(TAG, "Sub cell 1 triggered. Source: " + trigger.toString());
271271
}
272272
});
273273

274-
MenuCell subCell2 = new MenuCell("SubCell 2", null, null, new MenuSelectionListener() {
274+
MenuCell subCell2 = new MenuCell("SubCell 2", null, null, null, null, null, new MenuSelectionListener() {
275275
@Override
276276
public void onTriggered(TriggerSource trigger) {
277277
DebugTool.logInfo(TAG, "Sub cell 2 triggered. Source: " + trigger.toString());
278278
}
279279
});
280280

281281
// sub menu parent cell
282-
MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", MenuLayout.LIST, null, Arrays.asList(subCell1, subCell2));
282+
MenuCell mainCell3 = new MenuCell("Test Cell 3 (sub menu)", null, null, MenuLayout.LIST, null, null, Arrays.asList(subCell1, subCell2));
283283

284-
MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, new MenuSelectionListener() {
284+
MenuCell mainCell4 = new MenuCell("Show Perform Interaction", null, null, null, null, null, new MenuSelectionListener() {
285285
@Override
286286
public void onTriggered(TriggerSource trigger) {
287287
showPerformInteraction();
288288
}
289289
});
290290

291-
MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, new MenuSelectionListener() {
291+
MenuCell mainCell5 = new MenuCell("Clear the menu", null, null, null,null, null, new MenuSelectionListener() {
292292
@Override
293293
public void onTriggered(TriggerSource trigger) {
294294
DebugTool.logInfo(TAG, "Clearing Menu. Source: " + trigger.toString());

0 commit comments

Comments
 (0)