Skip to content

Commit a140e49

Browse files
Robert HeniganHenigan
andauthored
Notify ChoiceSetManager of failed preloads (#1716)
* Notify ChoiceSetManager of failed preloads * Move Completion Listener to the BaseCSManager Co-authored-by: Henigan <rheniga1@MGC12Z921DLVCG.fbpld77.ford.com>
1 parent c3553b7 commit a140e49

2 files changed

Lines changed: 31 additions & 8 deletions

File tree

base/src/main/java/com/smartdevicelink/managers/screen/choiceset/BaseChoiceSetManager.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ public void preloadChoices(@NonNull List<ChoiceCell> choices, @Nullable final Co
223223
pendingPreloadChoices.addAll(choicesToUpload);
224224

225225
if (fileManager.get() != null) {
226-
PreloadChoicesOperation preloadChoicesOperation = new PreloadChoicesOperation(internalInterface, fileManager.get(), displayName, defaultMainWindowCapability, isVROptional, choicesToUpload, new CompletionListener() {
226+
PreloadChoicesOperation preloadChoicesOperation = new PreloadChoicesOperation(internalInterface, fileManager.get(), displayName, defaultMainWindowCapability, isVROptional, choicesToUpload, new BaseChoiceSetManager.ChoiceSetCompletionListener() {
227227
@Override
228-
public void onComplete(boolean success) {
228+
public void onComplete(boolean success, HashSet<ChoiceCell> failedChoiceCells) {
229229
if (success) {
230230
preloadedChoices.addAll(choicesToUpload);
231231
pendingPreloadChoices.removeAll(choicesToUpload);
@@ -234,6 +234,9 @@ public void onComplete(boolean success) {
234234
}
235235
} else {
236236
DebugTool.logError(TAG, "There was an error pre loading choice cells");
237+
choicesToUpload.removeAll(failedChoiceCells);
238+
preloadedChoices.addAll(choicesToUpload);
239+
pendingPreloadChoices.removeAll(choicesToUpload);
237240
if (listener != null) {
238241
listener.onComplete(false);
239242
}
@@ -671,6 +674,14 @@ ChoiceCell findIfPresent(ChoiceCell cell, HashSet<ChoiceCell> set) {
671674
return null;
672675
}
673676

677+
/**
678+
* Interface that sends a list of ChoiceCells that failed to preload, to allow BaseChoioceSetManager
679+
* to stop keeping track of them for their onButtonEventListener
680+
*/
681+
interface ChoiceSetCompletionListener {
682+
void onComplete(boolean success, HashSet<ChoiceCell> failedChoiceCells);
683+
}
684+
674685
// LISTENERS
675686

676687
private void addListeners() {

base/src/main/java/com/smartdevicelink/managers/screen/choiceset/PreloadChoicesOperation.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ class PreloadChoicesOperation extends Task {
7070
private final WindowCapability defaultMainWindowCapability;
7171
private final String displayName;
7272
private final HashSet<ChoiceCell> cellsToUpload;
73-
private final CompletionListener completionListener;
73+
private final BaseChoiceSetManager.ChoiceSetCompletionListener completionListener;
7474
private boolean isRunning;
7575
private final boolean isVROptional;
7676
private boolean choiceError = false;
7777

7878
PreloadChoicesOperation(ISdl internalInterface, FileManager fileManager, String displayName, WindowCapability defaultMainWindowCapability,
79-
Boolean isVROptional, LinkedHashSet<ChoiceCell> cellsToPreload, CompletionListener listener) {
79+
Boolean isVROptional, LinkedHashSet<ChoiceCell> cellsToPreload, BaseChoiceSetManager.ChoiceSetCompletionListener listener) {
8080
super("PreloadChoicesOperation");
8181
this.internalInterface = new WeakReference<>(internalInterface);
8282
this.fileManager = new WeakReference<>(fileManager);
@@ -141,7 +141,7 @@ public void onComplete(Map<String, String> errors) {
141141

142142
private void preloadCells() {
143143
isRunning = true;
144-
List<CreateInteractionChoiceSet> choiceRPCs = new ArrayList<>(cellsToUpload.size());
144+
final List<CreateInteractionChoiceSet> choiceRPCs = new ArrayList<>(cellsToUpload.size());
145145
for (ChoiceCell cell : cellsToUpload) {
146146
CreateInteractionChoiceSet csCell = choiceFromCell(cell);
147147
if (csCell != null) {
@@ -151,13 +151,15 @@ private void preloadCells() {
151151

152152
if (choiceRPCs.size() == 0) {
153153
DebugTool.logError(TAG, " All Choice cells to send are null, so the choice set will not be shown");
154-
completionListener.onComplete(true);
154+
completionListener.onComplete(true, null);
155155
isRunning = false;
156156
return;
157157
}
158158

159159
if (internalInterface.get() != null) {
160160
internalInterface.get().sendRPCs(choiceRPCs, new OnMultipleRequestListener() {
161+
final HashSet<ChoiceCell> failedChoiceCells = new HashSet<>();
162+
161163
@Override
162164
public void onUpdate(int remainingRequests) {
163165

@@ -167,7 +169,7 @@ public void onUpdate(int remainingRequests) {
167169
public void onFinished() {
168170
isRunning = false;
169171
DebugTool.logInfo(TAG, "Finished pre loading choice cells");
170-
completionListener.onComplete(!choiceError);
172+
completionListener.onComplete(!choiceError, !choiceError ? null : failedChoiceCells);
171173
choiceError = false;
172174
PreloadChoicesOperation.super.onFinished();
173175
}
@@ -177,13 +179,23 @@ public void onResponse(int correlationId, RPCResponse response) {
177179
if (!response.getSuccess()) {
178180
DebugTool.logError(TAG, "There was an error uploading a choice cell: " + response.getInfo() + " resultCode: " + response.getResultCode());
179181
choiceError = true;
182+
for (CreateInteractionChoiceSet choiceSet : choiceRPCs) {
183+
if (choiceSet.getCorrelationID() == correlationId) {
184+
int choiceId = choiceSet.getChoiceSet().get(0).getChoiceID();
185+
for (ChoiceCell cell : cellsToUpload) {
186+
if (cell.getChoiceId() == choiceId) {
187+
failedChoiceCells.add(cell);
188+
}
189+
}
190+
}
191+
}
180192
}
181193
}
182194
});
183195
} else {
184196
DebugTool.logError(TAG, "Internal Interface null in preload choice operation");
185197
isRunning = false;
186-
completionListener.onComplete(false);
198+
completionListener.onComplete(false, cellsToUpload);
187199
}
188200
}
189201

0 commit comments

Comments
 (0)