summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrettyWhite <geekman3454@protonmail.com>2019-06-06 11:02:54 -0400
committerBrettyWhite <geekman3454@protonmail.com>2019-06-06 11:02:54 -0400
commit46ee6d15b65cc9ebea24420ab73855f44b6e8325 (patch)
treeee3187abcbbcf5eff43a3a3f5154ca010ca90f70
parent098d2cbb59e3ee7b00f1539b9289d2b8f3fcf34c (diff)
downloadsdl_android-46ee6d15b65cc9ebea24420ab73855f44b6e8325.tar.gz
delete operation
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java48
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCell.java2
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperation.java59
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PreloadChoicesOperation.java12
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentChoiceSetOperation.java4
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentKeyboardOperation.java4
6 files changed, 116 insertions, 13 deletions
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java
index c3f01cd63..e50c82732 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java
@@ -40,6 +40,8 @@ import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.managers.file.FileManager;
import com.smartdevicelink.managers.screen.choiceset.operations.CheckChoiceVROptionalInterface;
import com.smartdevicelink.managers.screen.choiceset.operations.CheckChoiceVROptionalOperation;
+import com.smartdevicelink.managers.screen.choiceset.operations.DeleteChoicesOperation;
+import com.smartdevicelink.managers.screen.choiceset.operations.PreloadChoicesOperation;
import com.smartdevicelink.protocol.enums.FunctionID;
import com.smartdevicelink.proxy.RPCNotification;
import com.smartdevicelink.proxy.interfaces.ISdl;
@@ -91,6 +93,7 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
// We will pass operations into this to be completed
private PausableThreadPoolExecutor pausableThreadPoolExecutor;
private LinkedBlockingQueue<Runnable> operationQueue;
+ private boolean pendingPresentOperation;
private int nextChoiceId;
private int choiceCellIdMin = 1;
@@ -98,20 +101,21 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
BaseChoiceSetManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager) {
super(internalInterface);
+ // capabilities
+ currentSystemContext = SystemContext.SYSCTXT_MAIN;
+ currentHMILevel = HMILevel.HMI_NONE;
+ addListeners();
+
+ // setting/instantiating class vars
this.fileManager = new WeakReference<>(fileManager);
preloadedMutableChoices = new HashSet<>();
pendingMutablePreloadChoices = new HashSet<>();
nextChoiceId = choiceCellIdMin;
isVROptional = false;
keyboardConfiguration = defaultKeyboardConfiguration();
- currentSystemContext = SystemContext.SYSCTXT_MAIN;
- currentHMILevel = HMILevel.HMI_NONE;
- // create the new executor service
operationQueue = new LinkedBlockingQueue<>();
- // set maxPoolSize to number of processors
pausableThreadPoolExecutor = new PausableThreadPoolExecutor(1, Runtime.getRuntime().availableProcessors(), 10, TimeUnit.SECONDS, operationQueue);
pausableThreadPoolExecutor.pause(); // pause until HMI ready
- addListeners();
}
@Override
@@ -188,15 +192,43 @@ abstract class BaseChoiceSetManager extends BaseSubManager {
if (!isReady()){ return; }
// Find cells to be deleted that are already uploaded or are pending upload
- HashSet<ChoiceCell> cellsToDelete = choicesToBeDeletedWithArray(choices);
+ final HashSet<ChoiceCell> cellsToBeDeleted = choicesToBeDeletedWithArray(choices);
HashSet<ChoiceCell> cellsToBeRemovedFromPending = choicesToBeRemovedFromPendingWithArray(choices);
// If choices are deleted that are already uploaded or pending and are used by a pending presentation, cancel it and send an error
- if (pendingPresentationSet != null && pendingPresentationSet.getChoices() != null) {
- HashSet<ChoiceCell> pendingPresentationChoices = new HashSet<>(pendingPresentationSet.getChoices());
+ HashSet<ChoiceCell> pendingPresentationChoices = new HashSet<>(pendingPresentationSet.getChoices());
+
+ if (!pendingPresentOperation && (cellsToBeDeleted.retainAll(pendingPresentationChoices) || cellsToBeRemovedFromPending.retainAll(pendingPresentationChoices))){
+ DebugTool.logError("Attempting to delete choice cells while there is a pending presentation operation");
+ return;
+ }
+
+ // Remove cells from pending and delete choices
+ pendingPresentationChoices.removeAll(cellsToBeRemovedFromPending);
+ for (Runnable operation : operationQueue){
+ if (!(operation instanceof PreloadChoicesOperation)){ continue; }
+
+ ((PreloadChoicesOperation) operation).removeChoicesFromUpload(cellsToBeRemovedFromPending);
}
+ // Find Choices to delete
+ if (cellsToBeDeleted.size() == 0){ return; }
+
+ findIdsOnChoices(cellsToBeDeleted);
+
+ DeleteChoicesOperation deleteChoicesOperation = new DeleteChoicesOperation(internalInterface, cellsToBeDeleted, new CompletionListener() {
+ @Override
+ public void onComplete(boolean success) {
+ if (!success){
+ DebugTool.logError("Failed to delete choices");
+ return;
+ }
+ preloadedMutableChoices.removeAll(cellsToBeDeleted);
+ }
+ });
+
+ pausableThreadPoolExecutor.execute(deleteChoicesOperation);
}
public void presentChoiceSet(final ChoiceSet choiceSet, InteractionMode mode, KeyboardListener listener){
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCell.java
index 136ee0741..bbba4debb 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCell.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/ChoiceCell.java
@@ -214,7 +214,7 @@ public class ChoiceCell {
* Get the choiceId
* @return the choiceId for this Choice Cell
*/
- int getChoiceId() {
+ public int getChoiceId() {
return choiceId;
}
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperation.java
index 42176e55a..faf0b909d 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/DeleteChoicesOperation.java
@@ -32,9 +32,66 @@
package com.smartdevicelink.managers.screen.choiceset.operations;
-class DeleteChoicesOperation implements Runnable {
+import com.smartdevicelink.managers.CompletionListener;
+import com.smartdevicelink.managers.screen.choiceset.ChoiceCell;
+import com.smartdevicelink.proxy.RPCResponse;
+import com.smartdevicelink.proxy.interfaces.ISdl;
+import com.smartdevicelink.proxy.rpc.DeleteInteractionChoiceSet;
+import com.smartdevicelink.proxy.rpc.enums.Result;
+import com.smartdevicelink.proxy.rpc.listeners.OnMultipleRequestListener;
+
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+
+public class DeleteChoicesOperation implements Runnable {
+
+ private WeakReference<ISdl> internalInterface;
+ private HashSet<ChoiceCell> cellsToDelete;
+ private CompletionListener completionListener;
+
+ public DeleteChoicesOperation(ISdl internalInterface, HashSet<ChoiceCell> cellsToDelete, CompletionListener completionListener){
+ this.internalInterface = new WeakReference<>(internalInterface);
+ this.cellsToDelete = cellsToDelete;
+ this.completionListener = completionListener;
+ }
@Override
public void run() {
+ sendDeletions();
+ }
+
+ private void sendDeletions(){
+
+ List<DeleteInteractionChoiceSet> deleteChoices = new ArrayList<>(cellsToDelete.size());
+ for (ChoiceCell cell : cellsToDelete){
+ deleteChoices.add(new DeleteInteractionChoiceSet(cell.getChoiceId()));
+ }
+
+ if (internalInterface.get() != null){
+ internalInterface.get().sendRequests(deleteChoices, new OnMultipleRequestListener() {
+ @Override
+ public void onUpdate(int remainingRequests) {}
+
+ @Override
+ public void onFinished() {
+ if (completionListener != null){
+ completionListener.onComplete(true);
+ }
+ }
+
+ @Override
+ public void onError(int correlationId, Result resultCode, String info) {
+ if (completionListener != null){
+ completionListener.onComplete(false);
+ }
+ }
+
+ @Override
+ public void onResponse(int correlationId, RPCResponse response) {}
+ });
+ }
+
}
}
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PreloadChoicesOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PreloadChoicesOperation.java
index 2f26d904b..a47ae3669 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PreloadChoicesOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PreloadChoicesOperation.java
@@ -32,9 +32,19 @@
package com.smartdevicelink.managers.screen.choiceset.operations;
-class PreloadChoicesOperation implements Runnable {
+import com.smartdevicelink.managers.screen.choiceset.ChoiceCell;
+
+import java.util.HashSet;
+
+public class PreloadChoicesOperation implements Runnable {
+
+ public PreloadChoicesOperation(){}
@Override
public void run() {
}
+
+ public void removeChoicesFromUpload(HashSet<ChoiceCell> choices){
+
+ }
} \ No newline at end of file
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentChoiceSetOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentChoiceSetOperation.java
index aaf9f4329..2d993d671 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentChoiceSetOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentChoiceSetOperation.java
@@ -32,7 +32,9 @@
package com.smartdevicelink.managers.screen.choiceset.operations;
-class PresentChoiceSetOperation implements Runnable {
+public class PresentChoiceSetOperation implements Runnable {
+
+ public PresentChoiceSetOperation(){}
@Override
public void run() {
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentKeyboardOperation.java b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentKeyboardOperation.java
index c8eed9028..eb4e74d49 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentKeyboardOperation.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/choiceset/operations/PresentKeyboardOperation.java
@@ -32,7 +32,9 @@
package com.smartdevicelink.managers.screen.choiceset.operations;
-class PresentKeyboardOperation implements Runnable {
+public class PresentKeyboardOperation implements Runnable {
+
+ public PresentKeyboardOperation(){}
@Override
public void run() {