summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBilal Alsharifi <bilal.alsharifi@gmail.com>2021-08-11 16:51:22 -0400
committerBilal Alsharifi <bilal.alsharifi@gmail.com>2021-08-11 16:51:22 -0400
commit75a07319e608081c3ab2a352dee3d324c137ea67 (patch)
treefd7db7ce4e2a3475190ed648245811c01cfe201f
parent827ecd8d26ceae1010800d5a9173fb976c32aa53 (diff)
downloadsdl_android-75a07319e608081c3ab2a352dee3d324c137ea67.tar.gz
Move cell Id handeling to operation
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java18
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuReplaceOperation.java4
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuReplaceUtilities.java28
3 files changed, 31 insertions, 19 deletions
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java
index 82aafd50f..6497da6ce 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/BaseMenuManager.java
@@ -66,7 +66,6 @@ import java.util.List;
abstract class BaseMenuManager extends BaseSubManager {
private static final String TAG = "BaseMenuManager";
- static final int menuCellIdMin = 1;
static final int parentIdNotFound = 2000000000;
final WeakReference<FileManager> fileManager;
@@ -83,12 +82,10 @@ abstract class BaseMenuManager extends BaseSubManager {
OnSystemCapabilityListener onDisplaysCapabilityListener;
WindowCapability windowCapability;
private Queue transactionQueue;
- int lastMenuId;
BaseMenuManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) {
super(internalInterface);
- this.lastMenuId = menuCellIdMin;
this.menuConfiguration = new MenuConfiguration(null, null);
this.menuCells = new ArrayList<>();
this.currentMenuCells = new ArrayList<>();
@@ -108,7 +105,6 @@ abstract class BaseMenuManager extends BaseSubManager {
@Override
public void dispose() {
- lastMenuId = menuCellIdMin;
menuCells = new ArrayList<>();
currentMenuCells = new ArrayList<>();
currentHMILevel = HMILevel.HMI_NONE;
@@ -184,8 +180,6 @@ abstract class BaseMenuManager extends BaseSubManager {
// Create a deep copy of the list so future changes by developers don't affect the algorithm logic
this.menuCells = cloneMenuCellsList(cells);
- updateIdsOnMenuCells(menuCells, parentIdNotFound);
-
boolean isDynamicMenuUpdateActive = isDynamicMenuUpdateActive(dynamicMenuUpdatesMode, displayType);
Task operation = new MenuReplaceOperation(internalInterface, fileManager.get(), windowCapability, menuConfiguration, currentMenuCells, menuCells, isDynamicMenuUpdateActive, new MenuManagerCompletionListener() {
@Override
@@ -424,18 +418,6 @@ abstract class BaseMenuManager extends BaseSubManager {
return true;
}
- private void updateIdsOnMenuCells(List<MenuCell> menuCells, int parentId) {
- for (MenuCell cell : menuCells) {
- cell.setCellId(lastMenuId++);
- if (parentId != parentIdNotFound) {
- cell.setParentCellId(parentId);
- }
- if (isSubMenuCell(cell) && !cell.getSubCells().isEmpty()) {
- updateIdsOnMenuCells(cell.getSubCells(), cell.getCellId());
- }
- }
- }
-
/**
* Check for cell lists with completely duplicate information, or any duplicate voiceCommands
*
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuReplaceOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuReplaceOperation.java
index 6a15d4d3d..b709e1159 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuReplaceOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuReplaceOperation.java
@@ -2,6 +2,7 @@ package com.smartdevicelink.managers.screen.menu;
import static com.smartdevicelink.managers.ManagerUtility.WindowCapabilityUtility.hasImageFieldOfName;
import static com.smartdevicelink.managers.ManagerUtility.WindowCapabilityUtility.hasTextFieldOfName;
+import static com.smartdevicelink.managers.screen.menu.BaseMenuManager.parentIdNotFound;
import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.addCellWithCellId;
import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.cloneMenuCellsList;
import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.commandIdForRPCRequest;
@@ -13,6 +14,7 @@ import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.posi
import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.removeCellFromList;
import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.sendRPCs;
import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.subMenuCommandsForCells;
+import static com.smartdevicelink.managers.screen.menu.MenuReplaceUtilities.updateIdsOnMenuCells;
import com.livio.taskmaster.Task;
import com.smartdevicelink.managers.CompletionListener;
@@ -84,6 +86,8 @@ class MenuReplaceOperation extends Task {
}
private void updateMenuCells(final CompletionListener listener) {
+ updateIdsOnMenuCells(updatedMenu, parentIdNotFound);
+
DynamicMenuUpdateRunScore runScore;
if (!isDynamicMenuUpdateActive) {
DebugTool.logInfo(TAG, "Dynamic menu update inactive. Forcing the deletion of all old cells and adding all new ones, even if they're the same.");
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuReplaceUtilities.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuReplaceUtilities.java
index cfc91f1c6..c96bbced1 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuReplaceUtilities.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuReplaceUtilities.java
@@ -30,6 +30,33 @@ import java.util.Map;
* Created by Bilal Alsharifi on 1/25/21.
*/
class MenuReplaceUtilities {
+ private static int menuId = 0;
+
+ static void setNextMenuId(int nextMenuId) {
+ menuId = nextMenuId;
+ }
+
+ static int getNextMenuId() {
+ return ++menuId;
+ }
+
+ /**
+ * Assign cell ids on an array of menu cells given a parent id (or no parent id)
+ * @param menuCells The array of menu cells to update
+ * @param parentId The parent id to assign if needed
+ */
+ static void updateIdsOnMenuCells(List<MenuCell> menuCells, int parentId) {
+ for (MenuCell cell : menuCells) {
+ cell.setCellId(getNextMenuId());
+ if (parentId != parentIdNotFound) {
+ cell.setParentCellId(parentId);
+ }
+ if (isSubMenuCell(cell) && !cell.getSubCells().isEmpty()) {
+ updateIdsOnMenuCells(cell.getSubCells(), cell.getCellId());
+ }
+ }
+ }
+
static List<SdlArtwork> findAllArtworksToBeUploadedFromCells(List<MenuCell> cells, FileManager fileManager, WindowCapability windowCapability) {
// Make sure we can use images in the menus
if (!hasImageFieldOfName(windowCapability, ImageFieldName.cmdIcon)) {
@@ -267,7 +294,6 @@ class MenuReplaceUtilities {
insertMenuCell(cell, menuCellList, position);
return true;
}
-
}
private static void insertMenuCell(MenuCell cell, List<MenuCell> cellList, int position) {