Skip to content

Commit 44ec539

Browse files
author
Julian Kast
committed
Fix to avoid deleting and setting identical voice commands, Updates in BaseVoiceCommandManger and VoiceCommandUpdateOperation
1 parent d8c09da commit 44ec539

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private void updatePendingOperations(List<VoiceCommand> newCurrentVoiceCommands)
182182
continue;
183183
}
184184
VoiceCommandUpdateOperation vcOperation = (VoiceCommandUpdateOperation) operation;
185-
vcOperation.oldVoiceCommands = newCurrentVoiceCommands;
185+
vcOperation.setOldVoiceCommands(newCurrentVoiceCommands);
186186
}
187187
}
188188

@@ -217,8 +217,8 @@ public void onNotified(RPCNotification notification) {
217217
@Override
218218
public void onNotified(RPCNotification notification) {
219219
OnCommand onCommand = (OnCommand) notification;
220-
if (voiceCommands != null && voiceCommands.size() > 0) {
221-
for (VoiceCommand command : voiceCommands) {
220+
if (currentVoiceCommands != null && currentVoiceCommands.size() > 0) {
221+
for (VoiceCommand command : currentVoiceCommands) {
222222
if (onCommand.getCmdID() == command.getCommandId()) {
223223
if (command.getVoiceCommandSelectionListener() != null) {
224224
command.getVoiceCommandSelectionListener().onVoiceCommandSelected();

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,23 @@ public void onComplete(boolean success2) {
8282

8383
private void sendDeleteCurrentVoiceCommands(final CompletionListener listener) {
8484

85-
if (oldVoiceCommands == null || oldVoiceCommands.isEmpty()) {
85+
if (oldVoiceCommands == null || oldVoiceCommands.size() == 0) {
8686
if (listener != null) {
8787
listener.onComplete(true);
8888
}
8989
return;
9090
}
9191

92-
deleteVoiceCommands = deleteCommandsForVoiceCommands(oldVoiceCommands);
92+
List<VoiceCommand> voiceCommandsToDelete = voiceCommandsInListNotInSecondList(oldVoiceCommands, pendingVoiceCommands);
93+
94+
if (voiceCommandsToDelete.size() == 0) {
95+
if (listener != null) {
96+
listener.onComplete(true);
97+
}
98+
return;
99+
}
100+
101+
deleteVoiceCommands = deleteCommandsForVoiceCommands(voiceCommandsToDelete);
93102

94103
internalInterface.get().sendRPCs(deleteVoiceCommands, new OnMultipleRequestListener() {
95104
@Override
@@ -156,14 +165,16 @@ private void removeCurrentVoiceCommand(Integer commandId) {
156165

157166
private void sendCurrentVoiceCommands(final CompletionListener listener) {
158167

159-
if (pendingVoiceCommands == null || pendingVoiceCommands.size() == 0) {
168+
List<VoiceCommand> voiceCommandsToAdd = voiceCommandsInListNotInSecondList(pendingVoiceCommands, oldVoiceCommands);
169+
170+
if (voiceCommandsToAdd.size() == 0) {
160171
if (listener != null) {
161172
listener.onComplete(true); // no voice commands to send doesnt mean that its an error
162173
}
163174
return;
164175
}
165176

166-
addCommandsToSend = addCommandsForVoiceCommands(pendingVoiceCommands);
177+
addCommandsToSend = addCommandsForVoiceCommands(voiceCommandsToAdd);
167178

168179
internalInterface.get().sendRPCs(addCommandsToSend, new OnMultipleRequestListener() {
169180
@Override
@@ -207,6 +218,20 @@ public void onResponse(int correlationId, RPCResponse response) {
207218
});
208219
}
209220

221+
List<VoiceCommand> voiceCommandsInListNotInSecondList(List<VoiceCommand> firstList, List<VoiceCommand> secondList) {
222+
if (secondList == null || secondList.size() == 0) {
223+
return firstList;
224+
}
225+
List<VoiceCommand> differencesList = new ArrayList<>(firstList);
226+
differencesList.removeAll(secondList);
227+
return differencesList;
228+
}
229+
230+
public void setOldVoiceCommands(List<VoiceCommand> oldVoiceCommands) {
231+
this.oldVoiceCommands = oldVoiceCommands;
232+
this.currentVoiceCommands = new ArrayList<>(oldVoiceCommands);
233+
}
234+
210235
// Create AddCommand List
211236

212237
List<AddCommand> addCommandsForVoiceCommands(List<VoiceCommand> voiceCommands) {

0 commit comments

Comments
 (0)