summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Elias <francois.elias@livio.io>2020-11-16 11:18:25 -0500
committerFrank Elias <francois.elias@livio.io>2020-11-16 11:18:25 -0500
commit504a8f4273bdfa903bd3491da6965f825463e93c (patch)
treefff876ebf5b461b6e5c67cc52145335f32a8f21b
parent1c2a043b620ff16e7ca84bd7e51f325bf10e8603 (diff)
downloadsdl_ios-504a8f4273bdfa903bd3491da6965f825463e93c.tar.gz
Fix for overwriting SDLArtwork
-rw-r--r--SmartDeviceLink/private/SDLMenuManager.m31
-rw-r--r--SmartDeviceLink/private/SDLPreloadChoicesOperation.m9
-rw-r--r--SmartDeviceLink/private/SDLSoftButtonReplaceOperation.m9
-rw-r--r--SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m32
4 files changed, 69 insertions, 12 deletions
diff --git a/SmartDeviceLink/private/SDLMenuManager.m b/SmartDeviceLink/private/SDLMenuManager.m
index af91dc3a1..bf5b59290 100644
--- a/SmartDeviceLink/private/SDLMenuManager.m
+++ b/SmartDeviceLink/private/SDLMenuManager.m
@@ -472,7 +472,7 @@ UInt32 const MenuCellIdMin = 1;
NSArray<SDLRPCRequest *> *mainMenuCommands = nil;
NSArray<SDLRPCRequest *> *subMenuCommands = nil;
- if ([self sdl_findAllArtworksToBeUploadedFromCells:self.menuCells].count > 0 || ![self.windowCapability hasImageFieldOfName:SDLImageFieldNameCommandIcon]) {
+ if ([self sdl_allArtworksUploaded:self.menuCells] || ![self.windowCapability hasImageFieldOfName:SDLImageFieldNameCommandIcon]) {
// Send artwork-less menu
mainMenuCommands = [self sdl_mainMenuCommandsForCells:updatedMenu withArtwork:NO usingIndexesFrom:menu];
subMenuCommands = [self sdl_subMenuCommandsForCells:updatedMenu withArtwork:NO];
@@ -552,7 +552,34 @@ UInt32 const MenuCellIdMin = 1;
}
- (BOOL)sdl_artworkNeedsUpload:(SDLArtwork *)artwork {
- return (artwork != nil && ![self.fileManager hasUploadedFile:artwork] && !artwork.isStaticIcon);
+ if (artwork != nil) {
+ if (artwork.isStaticIcon) {
+ return false;
+ } else {
+ return artwork.overwrite || (self.fileManager != nil && ![self.fileManager hasUploadedFile:artwork]);
+ }
+ }
+ return false;
+}
+
+- (BOOL) sdl_allArtworksUploaded:(NSArray<SDLMenuCell *> *)cells {
+ for (SDLMenuCell *cell in cells) {
+ if (![self sdl_artworkUploaded:cell.icon]) {
+ return false;
+ }
+ if (cell.subCells != nil && [cell.subCells count]> 0) {
+ return [self sdl_allArtworksUploaded:cell.subCells];
+ }
+ }
+
+ return true;
+}
+
+- (BOOL) sdl_artworkUploaded:(SDLArtwork *)artwork {
+ if (artwork != nil) {
+ return artwork.isStaticIcon || (self.fileManager != nil && [self.fileManager hasUploadedFile:artwork]);
+ }
+ return true;
}
#pragma mark IDs
diff --git a/SmartDeviceLink/private/SDLPreloadChoicesOperation.m b/SmartDeviceLink/private/SDLPreloadChoicesOperation.m
index 82f7435ff..8dd0e9704 100644
--- a/SmartDeviceLink/private/SDLPreloadChoicesOperation.m
+++ b/SmartDeviceLink/private/SDLPreloadChoicesOperation.m
@@ -114,7 +114,14 @@ NS_ASSUME_NONNULL_BEGIN
}
- (BOOL)sdl_artworkNeedsUpload:(SDLArtwork *)artwork {
- return (artwork != nil && ![self.fileManager hasUploadedFile:artwork] && !artwork.isStaticIcon);
+ if (artwork != nil) {
+ if (artwork.isStaticIcon) {
+ return false;
+ } else {
+ return artwork.overwrite || (self.fileManager != nil && ![self.fileManager hasUploadedFile:artwork]);
+ }
+ }
+ return false;
}
- (void)sdl_preloadCells {
diff --git a/SmartDeviceLink/private/SDLSoftButtonReplaceOperation.m b/SmartDeviceLink/private/SDLSoftButtonReplaceOperation.m
index d3a68735c..12d17c5f2 100644
--- a/SmartDeviceLink/private/SDLSoftButtonReplaceOperation.m
+++ b/SmartDeviceLink/private/SDLSoftButtonReplaceOperation.m
@@ -228,7 +228,14 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Images
- (BOOL)sdl_artworkNeedsUpload:(SDLArtwork *)artwork {
- return (artwork != nil && ![self.fileManager hasUploadedFile:artwork] && self.softButtonCapabilities.imageSupported.boolValue && !artwork.isStaticIcon);
+ if (artwork != nil && self.softButtonCapabilities.imageSupported) {
+ if (artwork.isStaticIcon) {
+ return false;
+ } else {
+ return artwork.overwrite || (self.fileManager != nil && ![self.fileManager hasUploadedFile:artwork]);
+ }
+ }
+ return false;
}
/// Checks all the button states for images that need to be uploaded.
diff --git a/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m b/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m
index 990df13f2..9ac06fded 100644
--- a/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m
+++ b/SmartDeviceLink/private/SDLTextAndGraphicUpdateOperation.m
@@ -263,8 +263,8 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable SDLShow *)sdl_createImageOnlyShowWithPrimaryArtwork:(nullable SDLArtwork *)primaryArtwork secondaryArtwork:(nullable SDLArtwork *)secondaryArtwork {
SDLShow *newShow = [[SDLShow alloc] init];
- newShow.graphic = ![self sdl_artworkNeedsUpload:primaryArtwork] ? primaryArtwork.imageRPC : nil;
- newShow.secondaryGraphic = ![self sdl_artworkNeedsUpload:secondaryArtwork] ? secondaryArtwork.imageRPC : nil;
+ newShow.graphic = [self sdl_artworkUploaded:primaryArtwork] ? primaryArtwork.imageRPC : nil;
+ newShow.secondaryGraphic = [self sdl_artworkUploaded:secondaryArtwork] ? secondaryArtwork.imageRPC : nil;
if (newShow.graphic == nil && newShow.secondaryGraphic == nil) {
SDLLogV(@"No graphics to upload");
@@ -516,29 +516,45 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Should Update
- (BOOL)sdl_artworkNeedsUpload:(SDLArtwork *)artwork {
- return (artwork != nil && ![self.fileManager hasUploadedFile:artwork] && !artwork.isStaticIcon);
+ if (artwork != nil) {
+ if (artwork.isStaticIcon) {
+ return false;
+ } else {
+ return (artwork.overwrite || (![self.fileManager hasUploadedFile:artwork]));
+ }
+ }
+ return true;
+}
+
+- (BOOL) sdl_artworkUploaded:(SDLArtwork *)artwork {
+ if (artwork != nil) {
+ return artwork.isStaticIcon || (self.fileManager != nil && [self.fileManager hasUploadedFile:artwork]);
+ }
+ return true;
}
- (BOOL)sdl_shouldUpdatePrimaryImage {
// If the template is updating, we don't yet know it's capabilities. Just assume the template supports the primary image.
BOOL templateSupportsPrimaryArtwork = [self.currentCapabilities hasImageFieldOfName:SDLImageFieldNameGraphic] || [self sdl_shouldUpdateTemplateConfig];
- BOOL graphicMatchesExisting = [self.currentScreenData.primaryGraphic.name isEqualToString:self.updatedState.primaryGraphic.name];
+ BOOL graphicNameMatchesExisting = [self.currentScreenData.primaryGraphic.name isEqualToString:self.updatedState.primaryGraphic.name];
+ BOOL shouldOverwriteGraphic = self.updatedState.primaryGraphic != nil && self.updatedState.primaryGraphic.overwrite;
BOOL graphicExists = (self.updatedState.primaryGraphic != nil);
- return (templateSupportsPrimaryArtwork && !graphicMatchesExisting && graphicExists);
+ return (templateSupportsPrimaryArtwork && (shouldOverwriteGraphic || !graphicNameMatchesExisting) && graphicExists);
}
- (BOOL)sdl_shouldUpdateSecondaryImage {
// If the template is updating, we don't yet know it's capabilities. Just assume the template supports the secondary image.
BOOL templateSupportsSecondaryArtwork = [self.currentCapabilities hasImageFieldOfName:SDLImageFieldNameSecondaryGraphic] || [self sdl_shouldUpdateTemplateConfig];
- BOOL graphicMatchesExisting = [self.currentScreenData.secondaryGraphic.name isEqualToString:self.updatedState.secondaryGraphic.name];
+ BOOL graphicNameMatchesExisting = [self.currentScreenData.secondaryGraphic.name isEqualToString:self.updatedState.secondaryGraphic.name];
+ BOOL shouldOverwriteGraphic = self.updatedState.secondaryGraphic != nil && self.updatedState.secondaryGraphic.overwrite;
BOOL graphicExists = (self.updatedState.secondaryGraphic != nil);
// Cannot detect if there is a secondary image below v5.0, so we'll just try to detect if the primary image is allowed and allow the secondary image if it is.
if ([[SDLGlobals sharedGlobals].rpcVersion isGreaterThanOrEqualToVersion:[SDLVersion versionWithMajor:5 minor:0 patch:0]]) {
- return (templateSupportsSecondaryArtwork && !graphicMatchesExisting && graphicExists);
+ return (templateSupportsSecondaryArtwork && (shouldOverwriteGraphic || !graphicNameMatchesExisting) && graphicExists);
} else {
- return ([self.currentCapabilities hasImageFieldOfName:SDLImageFieldNameGraphic] && !graphicMatchesExisting && graphicExists);
+ return ([self.currentCapabilities hasImageFieldOfName:SDLImageFieldNameGraphic] && (shouldOverwriteGraphic || !graphicNameMatchesExisting) && graphicExists);
}
}