6565import com .smartdevicelink .proxy .rpc .enums .PredefinedWindows ;
6666import com .smartdevicelink .proxy .rpc .enums .SystemCapabilityType ;
6767import com .smartdevicelink .proxy .rpc .enums .SystemContext ;
68+ import com .smartdevicelink .proxy .rpc .enums .TextFieldName ;
6869import com .smartdevicelink .proxy .rpc .listeners .OnMultipleRequestListener ;
6970import com .smartdevicelink .proxy .rpc .listeners .OnRPCNotificationListener ;
7071import 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
0 commit comments