summaryrefslogtreecommitdiff
path: root/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java')
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java77
1 files changed, 33 insertions, 44 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 0a201fc22..92bc82817 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/BaseTextAndGraphicManager.java
@@ -87,7 +87,6 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
private MetadataType textField1Type, textField2Type, textField3Type, textField4Type;
private TemplateConfiguration templateConfiguration;
TextAndGraphicUpdateOperation updateOperation;
- private CompletionListener currentOperationListener;
Queue transactionQueue;
//Constructors
@@ -175,36 +174,13 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
if (isDirty) {
isDirty = false;
- sdlUpdate(true, listener);
+ sdlUpdate(listener);
} else if (listener != null) {
listener.onComplete(true);
}
}
- private synchronized void sdlUpdate(Boolean supersedePreviousOperations, final CompletionListener listener) {
- if (this.transactionQueue.getTasksAsList().size() > 0 && supersedePreviousOperations) {
- // Transactions already in queue, we need to clear it out
- transactionQueue.clear();
- updateOperation = null;
- if (currentOperationListener != null) {
- currentOperationListener.onComplete(false);
- }
- }
-
- // 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 && supersedePreviousOperations) {
- updateOperation.cancelTask();
- if (currentOperationListener != null) {
- currentOperationListener.onComplete(false);
- }
- }
-
- // If Task is IN_PROGRESS, it’s not on the queue, we need to mark it as cancelled. The task will return at some point when it checks its status and call the listener back
- if (updateOperation != null && updateOperation.getState() == Task.IN_PROGRESS && supersedePreviousOperations) {
- updateOperation.cancelTask();
- }
-
- currentOperationListener = listener;
+ private synchronized void sdlUpdate(final CompletionListener listener) {
CurrentScreenDataUpdatedListener currentScreenDataUpdateListener = new CurrentScreenDataUpdatedListener() {
@Override
@@ -217,13 +193,16 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
@Override
- public void onError() {
+ public void onError(TextAndGraphicState errorState) {
// Invalidate data that's different from our current screen data
resetFieldsToCurrentScreenData();
+ if (errorState != null) {
+ updatePendingOperationsWithFailedScreenState(errorState);
+ }
}
};
- updateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager.get(), defaultMainWindowCapability, currentScreenData, currentState(), currentOperationListener, currentScreenDataUpdateListener);
+ updateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager.get(), defaultMainWindowCapability, currentScreenData, currentState(), listener, currentScreenDataUpdateListener);
transactionQueue.add(updateOperation, false);
}
@@ -257,10 +236,20 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
}
}
+ void updatePendingOperationsWithFailedScreenState(TextAndGraphicState errorState) {
+ for (Task task : transactionQueue.getTasksAsList()) {
+ if (!(task instanceof TextAndGraphicUpdateOperation)) {
+ continue;
+ }
+ ((TextAndGraphicUpdateOperation) task).setCurrentScreenData(currentScreenData);
+ ((TextAndGraphicUpdateOperation) task).updateTargetStateWithErrorState(errorState);
+ }
+ }
+
interface CurrentScreenDataUpdatedListener {
void onUpdate(TextAndGraphicState newState);
- void onError();
+ void onError(TextAndGraphicState errorState);
}
@@ -317,7 +306,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
this.textAlignment = textAlignment;
// If we aren't batching, send the update immediately, if we are, set ourselves as dirty (so we know we should send an update after the batch ends)
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -330,7 +319,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setMediaTrackTextField(String mediaTrackTextField) {
this.mediaTrackTextField = mediaTrackTextField;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -343,7 +332,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField1(String textField1) {
this.textField1 = textField1;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -356,7 +345,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField2(String textField2) {
this.textField2 = textField2;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -369,7 +358,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField3(String textField3) {
this.textField3 = textField3;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -382,7 +371,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField4(String textField4) {
this.textField4 = textField4;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -395,7 +384,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField1Type(MetadataType textField1Type) {
this.textField1Type = textField1Type;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -408,7 +397,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField2Type(MetadataType textField2Type) {
this.textField2Type = textField2Type;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -421,7 +410,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField3Type(MetadataType textField3Type) {
this.textField3Type = textField3Type;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -434,7 +423,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTextField4Type(MetadataType textField4Type) {
this.textField4Type = textField4Type;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -447,7 +436,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setTitle(String title) {
this.title = title;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -460,7 +449,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setPrimaryGraphic(SdlArtwork primaryGraphic) {
this.primaryGraphic = primaryGraphic;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -473,7 +462,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void setSecondaryGraphic(SdlArtwork secondaryGraphic) {
this.secondaryGraphic = secondaryGraphic;
if (!batchingUpdates) {
- sdlUpdate(true, null);
+ sdlUpdate(null);
} else {
isDirty = true;
}
@@ -491,7 +480,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
void changeLayout(TemplateConfiguration templateConfiguration, CompletionListener listener) {
setTemplateConfiguration(templateConfiguration);
if (!batchingUpdates) {
- sdlUpdate(true, listener);
+ sdlUpdate(listener);
} else {
isDirty = true;
}
@@ -554,7 +543,7 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
updateTransactionQueueSuspended();
if (hasData()) {
// HAX: Capability updates cannot supersede earlier updates because of the case where a developer batched a `changeLayout` call w/ T&G changes on < 6.0 systems could cause this to come in before the operation completes. That would cause the operation to report a "failure" (because it was superseded by this call) when in fact the operation didn't fail at all and is just being adjusted.
- sdlUpdate(false, null);
+ sdlUpdate(null);
}
}