diff options
author | Julian Kast <julian@livio.com> | 2020-08-26 19:01:18 -0400 |
---|---|---|
committer | Julian Kast <julian@livio.com> | 2020-08-26 19:01:18 -0400 |
commit | cdadb3bf31051787bf48bcb14a0e7da1d4300706 (patch) | |
tree | 0b3d205f63f7537f44dcad193177db957489bbca | |
parent | 8d445a8cb181722c74172dae9266458563692c0a (diff) | |
download | sdl_android-cdadb3bf31051787bf48bcb14a0e7da1d4300706.tar.gz |
Fixed queue management
-rw-r--r-- | base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java index a06b72179..7dba7853e 100644 --- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java +++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java @@ -86,6 +86,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { private String textField1, textField2, textField3, textField4, mediaTrackTextField, title; private MetadataType textField1Type, textField2Type, textField3Type, textField4Type; private TextAndGraphicUpdateOperation updateOperation; + private CompletionListener currentOperationListener; Queue transactionQueue; //Constructors @@ -178,19 +179,30 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { } private synchronized void sdlUpdate(final CompletionListener listener) { - if (transactionQueue.getTasksAsList().size() > 0) { - //Transactions already exist, cancelling them - for (Task task : transactionQueue.getTasksAsList()) { - if (task instanceof TextAndGraphicUpdateOperation) { - ((TextAndGraphicUpdateOperation) task).setTaskIsCanceled(true); - } + if (this.transactionQueue.getTasksAsList().size() > 0) { + // Transactions already in queue, we need to clear it out + transactionQueue.clear(); + updateOperation = null; + if (currentOperationListener != null) { + currentOperationListener.onComplete(false); } } - // transactionQueue.getTaskAsList() will not return a task in progress, so we need to check + + // Task can be READY, about to start and popped of the queue, so we have to cancel it, to prevent it from starting + if (updateOperation != null && updateOperation.getState() == Task.READY) { + updateOperation.cancelTask(); + if (currentOperationListener != null) { + currentOperationListener.onComplete(false); + } + } + + // If Task is IN_PROGRESS it's not on the queue, we need to cancel it, operation will take care of stopping it. if (updateOperation != null && updateOperation.getState() == Task.IN_PROGRESS) { - updateOperation.setTaskIsCanceled(true); + updateOperation.cancelTask(); } + currentOperationListener = listener; + CurrentScreenDataUpdatedListener currentScreenDataUpdateListener = new CurrentScreenDataUpdatedListener() { @Override public void onUpdate(Show show) { @@ -198,16 +210,8 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager { currentScreenData = show; } }; - CompletionListener updateOperationListener = new CompletionListener() { - @Override - public void onComplete(boolean success) { - if (listener != null) { - listener.onComplete(success); - } - } - }; - updateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager.get(), defaultMainWindowCapability, currentScreenData, currentState(), updateOperationListener, currentScreenDataUpdateListener); + updateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager.get(), defaultMainWindowCapability, currentScreenData, currentState(), currentOperationListener, currentScreenDataUpdateListener); transactionQueue.add(updateOperation, false); } |