@@ -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