Skip to content
Prev Previous commit
Next Next commit
Added updatePendingOperationsWithFailedScreenState method.
  • Loading branch information
ChloeMJM committed Sep 13, 2022
commit 636bf1a97820e81bbb13c46e7c46be4360553d8b
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ abstract class BaseTextAndGraphicManager extends BaseSubManager {
Queue transactionQueue;

//Constructors

BaseTextAndGraphicManager(@NonNull ISdl internalInterface, @NonNull FileManager fileManager, @NonNull SoftButtonManager softButtonManager) {
// set class vars
super(internalInterface);
Expand Down Expand Up @@ -167,7 +166,6 @@ private void updateTransactionQueueSuspended() {
}

// Upload / Send

protected void update(CompletionListener listener) {
// check if is batch update
if (batchingUpdates) {
Expand All @@ -182,27 +180,6 @@ protected void update(CompletionListener listener) {
}

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;

Expand All @@ -217,9 +194,10 @@ public void onUpdate(TextAndGraphicState newScreenData) {
}

@Override
public void onError() {
public void onError(TextAndGraphicState errorState) {
// Invalidate data that's different from our current screen data
resetFieldsToCurrentScreenData();
updatePendingOperationsWithFailedScreenState(errorState);
}
};

Expand Down Expand Up @@ -257,10 +235,20 @@ void updatePendingOperationsWithNewScreenData() {
}
}

void updatePendingOperationsWithFailedScreenState(TextAndGraphicState errorState) {
for (Task task : transactionQueue.getTasksAsList()) {
if (!(task instanceof TextAndGraphicUpdateOperation)) {
continue;
}
((TextAndGraphicUpdateOperation) task).setCurrentScreenData(currentScreenData);
}
updateOperation.updateTargetStateWithErrorState(errorState);
}

interface CurrentScreenDataUpdatedListener {
void onUpdate(TextAndGraphicState newState);

void onError();
void onError(TextAndGraphicState errorState);
}


Expand Down Expand Up @@ -305,14 +293,12 @@ Boolean hasData() {


// Convert to State

TextAndGraphicState currentState() {
return new TextAndGraphicState(textField1, textField2, textField3, textField4, mediaTrackTextField,
title, primaryGraphic, secondaryGraphic, textAlignment, textField1Type, textField2Type, textField3Type, textField4Type, templateConfiguration);
}

// Getters / Setters

void setTextAlignment(TextAlignment textAlignment) {
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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.smartdevicelink.managers.screen;

import android.util.Log;

import com.livio.taskmaster.Task;
import com.smartdevicelink.managers.CompletionListener;
import com.smartdevicelink.managers.ISdl;
Expand All @@ -26,7 +24,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;


/**
* Created by Julian Kast on 8/23/20.
Expand All @@ -43,8 +41,6 @@ class TextAndGraphicUpdateOperation extends Task {
private final CompletionListener listener;
private Show fullShow;

private boolean errorState;

TextAndGraphicUpdateOperation(ISdl internalInterface, FileManager fileManager, WindowCapability currentCapabilities,
TextAndGraphicState currentScreenData, TextAndGraphicState newState, CompletionListener listener, TextAndGraphicManager.CurrentScreenDataUpdatedListener currentScreenDataUpdateListener) {
super("TextAndGraphicUpdateOperation");
Expand Down