Skip to content

Commit 445c576

Browse files
Fix issue #1756
1 parent 13a7d2f commit 445c576

2 files changed

Lines changed: 42 additions & 19 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,10 @@ private void sendAddMenuCells(final List<MenuCell> addMenuCells, final List<Menu
373373
MenuLayout defaultSubmenuLayout = menuConfiguration != null ? menuConfiguration.getSubMenuLayout() : null;
374374

375375
// RPCs for cells on the main menu level. They could be AddCommands or AddSubMenus depending on whether the cell has child cells or not.
376-
final List<RPCRequest> mainMenuCommands = mainMenuCommandsForCells(addMenuCells, fileManager.get(), fullMenu, windowCapability, defaultSubmenuLayout);
376+
final List<RPCRequest> mainMenuCommands = mainMenuCommandsForCells(internalInterface.get(), addMenuCells, fileManager.get(), fullMenu, windowCapability, defaultSubmenuLayout);
377377

378378
// RPCs for cells on the second menu level (one level deep). They could be AddCommands or AddSubMenus.
379-
final List<RPCRequest> subMenuCommands = subMenuCommandsForCells(addMenuCells, fileManager.get(), windowCapability, defaultSubmenuLayout);
379+
final List<RPCRequest> subMenuCommands = subMenuCommandsForCells(internalInterface.get(), addMenuCells, fileManager.get(), windowCapability, defaultSubmenuLayout);
380380

381381
sendRPCs(mainMenuCommands, internalInterface.get(), new SendingRPCsCompletionListener() {
382382
@Override

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

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.smartdevicelink.proxy.rpc.enums.MenuLayout;
5353
import com.smartdevicelink.proxy.rpc.enums.TextFieldName;
5454
import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener;
55+
import com.smartdevicelink.util.Version;
5556

5657
import java.util.ArrayList;
5758
import java.util.HashMap;
@@ -141,15 +142,37 @@ static Set<SdlArtwork> findAllArtworksToBeUploadedFromCells(List<MenuCell> cells
141142
return artworks;
142143
}
143144

144-
// If there is an icon and the icon has been uploaded, or if the icon is a static icon, it should include the image
145-
static boolean shouldCellIncludePrimaryImageFromCell(MenuCell cell, FileManager fileManager, WindowCapability windowCapability) {
146-
boolean supportsImage = cell.isSubMenuCell() ? hasImageFieldOfName(windowCapability, ImageFieldName.subMenuIcon) : hasImageFieldOfName(windowCapability, ImageFieldName.cmdIcon);
145+
static boolean windowCapabilitySupportsPrimaryImage(ISdl internalInterface, WindowCapability windowCapability, MenuCell cell) {
146+
boolean supportsImage;
147+
if (cell.isSubMenuCell() && internalInterface != null && internalInterface.getSdlMsgVersion() != null) {
148+
Version headUnitRPCVersion = new Version(internalInterface.getSdlMsgVersion());
149+
Version minRPCVersion = new Version(5, 0, 0);
150+
Version maxRPCVersion = new Version(7, 1, 0);
151+
// If RPC version is >= 5.0 && < 7.1
152+
if (headUnitRPCVersion.isNewerThan(minRPCVersion) == 0 || headUnitRPCVersion.isBetween(minRPCVersion, maxRPCVersion) == 1) {
153+
supportsImage = true;
154+
} else {
155+
supportsImage = hasImageFieldOfName(windowCapability, ImageFieldName.subMenuIcon);
156+
}
157+
} else {
158+
supportsImage = hasImageFieldOfName(windowCapability, ImageFieldName.cmdIcon);
159+
}
160+
return supportsImage;
161+
}
162+
163+
static boolean windowCapabilitySupportsSecondaryImage(WindowCapability windowCapability, MenuCell cell) {
164+
return cell.isSubMenuCell() ? hasImageFieldOfName(windowCapability, ImageFieldName.menuSubMenuSecondaryImage) : hasImageFieldOfName(windowCapability, ImageFieldName.menuCommandSecondaryImage);
165+
}
166+
167+
// If there is an icon and the icon has been uploaded, or if the icon is a static icon, it should include the image
168+
static boolean shouldCellIncludePrimaryImageFromCell(ISdl internalInterface, MenuCell cell, FileManager fileManager, WindowCapability windowCapability) {
169+
boolean supportsImage = windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, cell);
147170
return cell.getIcon() != null && supportsImage && (fileManager.hasUploadedFile(cell.getIcon()) || cell.getIcon().isStaticIcon());
148171
}
149172

150173
// If there is an icon and the icon has been uploaded, or if the icon is a static icon, it should include the image
151174
static boolean shouldCellIncludeSecondaryImageFromCell(MenuCell cell, FileManager fileManager, WindowCapability windowCapability) {
152-
boolean supportsImage = cell.isSubMenuCell() ? hasImageFieldOfName(windowCapability, ImageFieldName.menuSubMenuSecondaryImage) : hasImageFieldOfName(windowCapability, ImageFieldName.menuCommandSecondaryImage);
175+
boolean supportsImage = windowCapabilitySupportsSecondaryImage(windowCapability, cell);
153176
return cell.getSecondaryArtwork() != null && supportsImage && (fileManager.hasUploadedFile(cell.getSecondaryArtwork()) || cell.getSecondaryArtwork().isStaticIcon());
154177
}
155178

@@ -191,7 +214,7 @@ static List<RPCRequest> deleteCommandsForCells(List<MenuCell> cells) {
191214
return deletes;
192215
}
193216

194-
static List<RPCRequest> mainMenuCommandsForCells(List<MenuCell> cells, FileManager fileManager, List<MenuCell> menu, WindowCapability windowCapability, MenuLayout defaultSubmenuLayout) {
217+
static List<RPCRequest> mainMenuCommandsForCells(ISdl internalInterface, List<MenuCell> cells, FileManager fileManager, List<MenuCell> menu, WindowCapability windowCapability, MenuLayout defaultSubmenuLayout) {
195218
List<RPCRequest> commands = new ArrayList<>();
196219

197220
// We need the index to use it as position so we will use this type of loop
@@ -201,9 +224,9 @@ static List<RPCRequest> mainMenuCommandsForCells(List<MenuCell> cells, FileManag
201224
MenuCell addCell = cells.get(updateCellsIndex);
202225
if (mainCell.equals(addCell)) {
203226
if (addCell.isSubMenuCell()) {
204-
commands.add(subMenuCommandForMenuCell(addCell, fileManager, windowCapability, menuInteger, defaultSubmenuLayout));
227+
commands.add(subMenuCommandForMenuCell(internalInterface, addCell, fileManager, windowCapability, menuInteger, defaultSubmenuLayout));
205228
} else {
206-
commands.add(commandForMenuCell(addCell, fileManager, windowCapability, menuInteger));
229+
commands.add(commandForMenuCell(internalInterface, addCell, fileManager, windowCapability, menuInteger));
207230
}
208231
break;
209232
}
@@ -212,36 +235,36 @@ static List<RPCRequest> mainMenuCommandsForCells(List<MenuCell> cells, FileManag
212235
return commands;
213236
}
214237

215-
static List<RPCRequest> subMenuCommandsForCells(List<MenuCell> cells, FileManager fileManager, WindowCapability windowCapability, MenuLayout defaultSubmenuLayout) {
238+
static List<RPCRequest> subMenuCommandsForCells(ISdl internalInterface, List<MenuCell> cells, FileManager fileManager, WindowCapability windowCapability, MenuLayout defaultSubmenuLayout) {
216239
List<RPCRequest> commands = new ArrayList<>();
217240
for (MenuCell cell : cells) {
218241
if (cell.isSubMenuCell() && !cell.getSubCells().isEmpty()) {
219-
commands.addAll(allCommandsForCells(cell.getSubCells(), fileManager, windowCapability, defaultSubmenuLayout));
242+
commands.addAll(allCommandsForCells(internalInterface, cell.getSubCells(), fileManager, windowCapability, defaultSubmenuLayout));
220243
}
221244
}
222245
return commands;
223246
}
224247

225-
static List<RPCRequest> allCommandsForCells(List<MenuCell> cells, FileManager fileManager, WindowCapability windowCapability, MenuLayout defaultSubmenuLayout) {
248+
static List<RPCRequest> allCommandsForCells(ISdl internalInterface, List<MenuCell> cells, FileManager fileManager, WindowCapability windowCapability, MenuLayout defaultSubmenuLayout) {
226249
List<RPCRequest> commands = new ArrayList<>();
227250

228251
for (int cellIndex = 0; cellIndex < cells.size(); cellIndex++) {
229252
MenuCell cell = cells.get(cellIndex);
230253
if (cell.isSubMenuCell()) {
231-
commands.add(subMenuCommandForMenuCell(cell, fileManager, windowCapability, cellIndex, defaultSubmenuLayout));
254+
commands.add(subMenuCommandForMenuCell(internalInterface, cell, fileManager, windowCapability, cellIndex, defaultSubmenuLayout));
232255

233256
// Recursively grab the commands for all the sub cells
234257
if (!cell.getSubCells().isEmpty()) {
235-
commands.addAll(allCommandsForCells(cell.getSubCells(), fileManager, windowCapability, defaultSubmenuLayout));
258+
commands.addAll(allCommandsForCells(internalInterface, cell.getSubCells(), fileManager, windowCapability, defaultSubmenuLayout));
236259
}
237260
} else {
238-
commands.add(commandForMenuCell(cell, fileManager, windowCapability, cellIndex));
261+
commands.add(commandForMenuCell(internalInterface, cell, fileManager, windowCapability, cellIndex));
239262
}
240263
}
241264
return commands;
242265
}
243266

244-
static AddCommand commandForMenuCell(MenuCell cell, FileManager fileManager, WindowCapability windowCapability, int position) {
267+
static AddCommand commandForMenuCell(ISdl internalInterface, MenuCell cell, FileManager fileManager, WindowCapability windowCapability, int position) {
245268
AddCommand command = new AddCommand(cell.getCellId());
246269

247270
MenuParams params = new MenuParams(cell.getUniqueTitle());
@@ -256,7 +279,7 @@ static AddCommand commandForMenuCell(MenuCell cell, FileManager fileManager, Win
256279
} else {
257280
command.setVrCommands(null);
258281
}
259-
boolean shouldCellIncludePrimaryImage = cell.getIcon() != null && shouldCellIncludePrimaryImageFromCell(cell, fileManager, windowCapability);
282+
boolean shouldCellIncludePrimaryImage = cell.getIcon() != null && shouldCellIncludePrimaryImageFromCell(internalInterface, cell, fileManager, windowCapability);
260283
command.setCmdIcon(shouldCellIncludePrimaryImage ? cell.getIcon().getImageRPC() : null);
261284

262285
boolean shouldCellIncludeSecondaryImage = cell.getSecondaryArtwork() != null && shouldCellIncludeSecondaryImageFromCell(cell, fileManager, windowCapability);
@@ -265,8 +288,8 @@ static AddCommand commandForMenuCell(MenuCell cell, FileManager fileManager, Win
265288
return command;
266289
}
267290

268-
static AddSubMenu subMenuCommandForMenuCell(MenuCell cell, FileManager fileManager, WindowCapability windowCapability, int position, MenuLayout defaultSubmenuLayout) {
269-
boolean shouldCellIncludePrimaryImage = cell.getIcon() != null && cell.getIcon().getImageRPC() != null && shouldCellIncludePrimaryImageFromCell(cell, fileManager, windowCapability);
291+
static AddSubMenu subMenuCommandForMenuCell(ISdl internalInterface, MenuCell cell, FileManager fileManager, WindowCapability windowCapability, int position, MenuLayout defaultSubmenuLayout) {
292+
boolean shouldCellIncludePrimaryImage = cell.getIcon() != null && cell.getIcon().getImageRPC() != null && shouldCellIncludePrimaryImageFromCell(internalInterface, cell, fileManager, windowCapability);
270293
Image icon = (shouldCellIncludePrimaryImage ? cell.getIcon().getImageRPC() : null);
271294
boolean shouldCellIncludeSecondaryImage = cell.getSecondaryArtwork() != null && cell.getSecondaryArtwork().getImageRPC() != null && shouldCellIncludeSecondaryImageFromCell(cell, fileManager, windowCapability);
272295
Image secondaryIcon = (shouldCellIncludeSecondaryImage ? cell.getSecondaryArtwork().getImageRPC() : null);

0 commit comments

Comments
 (0)