Skip to content

Commit

Permalink
ChoiceSetManager supports static icon artwork
Browse files Browse the repository at this point in the history
  • Loading branch information
joeljfischer committed Oct 16, 2018
1 parent d139c14 commit e8fc233
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 23 deletions.
7 changes: 7 additions & 0 deletions SmartDeviceLink/SDLArtwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import "SDLFile.h"
#import "SDLStaticIconName.h"

@class SDLImage;

typedef NS_ENUM(NSUInteger, SDLArtworkImageFormat) {
SDLArtworkImageFormatPNG,
SDLArtworkImageFormatJPG
Expand All @@ -27,6 +29,11 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (assign, nonatomic, readonly) BOOL isTemplate;

/**
The Image RPC representing this artwork. Generally for use internally, you should instead pass an artwork to a Screen Manager method.
*/
@property (strong, nonatomic, readonly) SDLImage *imageRPC;

/**
* Convenience helper to create an ephemeral artwork from an image.
*
Expand Down
33 changes: 26 additions & 7 deletions SmartDeviceLink/SDLArtwork.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@
// Copyright © 2015 smartdevicelink. All rights reserved.
//

#import <CommonCrypto/CommonDigest.h>

#import "SDLArtwork.h"
#import "SDLFileType.h"
#import <CommonCrypto/CommonDigest.h>
#import "SDLImage.h"

NS_ASSUME_NONNULL_BEGIN

@interface SDLFile ()

@property (assign, nonatomic, readwrite) BOOL isStaticIcon;

@end

@interface SDLArtwork ()

@property (strong, nonatomic) UIImage *image;
@property (assign, nonatomic, readwrite) BOOL isTemplate;
@property (assign, nonatomic, readwrite) BOOL isStaticIcon;

@end


@implementation SDLArtwork

- (void)setImage:(UIImage *)image {
_image = image;
_isTemplate = (image.renderingMode == UIImageRenderingModeAlwaysTemplate);
}

#pragma mark - Lifecycle

+ (instancetype)artworkWithImage:(UIImage *)image name:(NSString *)name asImageFormat:(SDLArtworkImageFormat)imageFormat {
Expand Down Expand Up @@ -72,6 +74,23 @@ - (instancetype)initWithStaticIcon:(SDLStaticIconName)staticIcon {
return self;
}

#pragma mark - Setters and Getters

- (void)setImage:(UIImage *)image {
_image = image;
_isTemplate = (image.renderingMode == UIImageRenderingModeAlwaysTemplate);
}

- (SDLImage *)imageRPC {
if (self.isStaticIcon) {
return [[SDLImage alloc] initWithStaticIconName:self.name];
} else {
return [[SDLImage alloc] initWithName:self.name isTemplate:self.isTemplate];
}
}

#pragma mark - Helper Methods

/**
* Returns the JPG or PNG image data for a UIImage.
*
Expand Down
4 changes: 4 additions & 0 deletions SmartDeviceLink/SDLChoiceSet.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ - (NSString *)description {
return [NSString stringWithFormat:@"SDLChoiceSet: \"%@\", layout: %@", _title, (_layout == SDLChoiceSetLayoutList ? @"List" : @"Tiles")];
}

- (NSString *)debugDescription {
return [NSString stringWithFormat:@"SDLChoiceSet: Title: \"%@\", layout: %@, timeout: %@, initial prompt: \"%@\", timeout prompt: \"%@\", help prompt: \"%@\", help list: %@, choices: %@", _title, (_layout == SDLChoiceSetLayoutList ? @"List" : @"Tiles"), @(_timeout), _initialPrompt, _timeoutPrompt, _helpPrompt, _helpList, _choices];
}

@end

NS_ASSUME_NONNULL_END
8 changes: 6 additions & 2 deletions SmartDeviceLink/SDLChoiceSetManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#import "SDLError.h"
#import "SDLFileManager.h"
#import "SDLHMILevel.h"
#import "SDLImage.h"
#import "SDLKeyboardProperties.h"
#import "SDLLogMacros.h"
#import "SDLOnHMIStatus.h"
Expand Down Expand Up @@ -280,7 +279,12 @@ - (void)presentChoiceSet:(SDLChoiceSet *)choiceSet mode:(SDLInteractionMode)mode
}

self.pendingPresentationSet = choiceSet;
[self preloadChoices:self.pendingPresentationSet.choices withCompletionHandler:nil];
[self preloadChoices:self.pendingPresentationSet.choices withCompletionHandler:^(NSError * _Nullable error) {
if (error != nil) {
[choiceSet.delegate choiceSet:choiceSet didReceiveError:error];
return;
}
}];

[self sdl_findIdsOnChoiceSet:self.pendingPresentationSet];

Expand Down
20 changes: 13 additions & 7 deletions SmartDeviceLink/SDLPreloadChoicesOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ - (void)sdl_preloadCellArtworksWithCompletionHandler:(void(^)(NSError *_Nullable

NSMutableArray<SDLArtwork *> *artworksToUpload = [NSMutableArray arrayWithCapacity:self.cellsToUpload.count];
for (SDLChoiceCell *cell in self.cellsToUpload) {
if ([self.displayCapabilities hasImageFieldOfName:SDLImageFieldNameChoiceImage]) {
cell.artwork != nil ? [artworksToUpload addObject:cell.artwork] : nil;
if ([self.displayCapabilities hasImageFieldOfName:SDLImageFieldNameChoiceImage]
&& ![self sdl_artworkNeedsUpload:cell.artwork]) {
[artworksToUpload addObject:cell.artwork];
}
if ([self.displayCapabilities hasImageFieldOfName:SDLImageFieldNameChoiceSecondaryImage]) {
cell.secondaryArtwork != nil ? [artworksToUpload addObject:cell.secondaryArtwork] : nil;
if ([self.displayCapabilities hasImageFieldOfName:SDLImageFieldNameChoiceSecondaryImage]
&& ![self sdl_artworkNeedsUpload:cell.artwork]) {
[artworksToUpload addObject:cell.secondaryArtwork];
}
}

Expand All @@ -107,6 +109,10 @@ - (void)sdl_preloadCellArtworksWithCompletionHandler:(void(^)(NSError *_Nullable
}];
}

- (BOOL)sdl_artworkNeedsUpload:(SDLArtwork *)artwork {
return (!artwork || [self.fileManager hasUploadedFile:artwork] || artwork.isStaticIcon);
}

- (void)sdl_preloadCells {
_currentState = SDLPreloadChoicesOperationStatePreloadingChoices;

Expand All @@ -123,7 +129,7 @@ - (void)sdl_preloadCells {
}
} completionHandler:^(BOOL success) {
if (!success) {
SDLLogW(@"Error preloading choice cells: %@", errors);
SDLLogE(@"Error preloading choice cells: %@", errors);
weakSelf.internalError = [NSError sdl_choiceSetManager_choiceUploadFailed:errors];
}

Expand All @@ -147,8 +153,8 @@ - (SDLCreateInteractionChoiceSet *)sdl_choiceFromCell:(SDLChoiceCell *)cell {
NSString *secondaryText = [self.displayCapabilities hasTextFieldOfName:SDLTextFieldNameSecondaryText] ? cell.secondaryText : nil;
NSString *tertiaryText = [self.displayCapabilities hasTextFieldOfName:SDLTextFieldNameTertiaryText] ? cell.tertiaryText : nil;

SDLImage *image = ([self.displayCapabilities hasImageFieldOfName:SDLImageFieldNameChoiceImage] && cell.artwork != nil) ? [[SDLImage alloc] initWithName:cell.artwork.name isTemplate:cell.artwork.isTemplate] : nil;
SDLImage *secondaryImage = ([self.displayCapabilities hasImageFieldOfName:SDLImageFieldNameChoiceSecondaryImage] && cell.secondaryArtwork != nil) ? [[SDLImage alloc] initWithName:cell.secondaryArtwork.name isTemplate:cell.secondaryArtwork.isTemplate] : nil;
SDLImage *image = ([self.displayCapabilities hasImageFieldOfName:SDLImageFieldNameChoiceImage] && cell.artwork != nil) ? cell.artwork.imageRPC : nil;
SDLImage *secondaryImage = ([self.displayCapabilities hasImageFieldOfName:SDLImageFieldNameChoiceSecondaryImage] && cell.secondaryArtwork != nil) ? cell.secondaryArtwork.imageRPC : nil;

SDLChoice *choice = [[SDLChoice alloc] initWithId:cell.choiceId menuName:(NSString *_Nonnull)menuName vrCommands:(NSArray<NSString *> * _Nonnull)vrCommands image:image secondaryText:secondaryText secondaryImage:secondaryImage tertiaryText:tertiaryText];

Expand Down
6 changes: 3 additions & 3 deletions SmartDeviceLink/SDLSoftButtonManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ - (void)sdl_uploadInitialStateImages {
NSMutableArray<SDLArtwork *> *initialStatesToBeUploaded = [NSMutableArray array];
// Upload all soft button images, the initial state images first, then the other states. We need to send updates when the initial state is ready.
for (SDLSoftButtonObject *object in self.softButtonObjects) {
if (![self sdl_isArtworkUploadedOrNonExistent:object.currentState.artwork]) {
if (![self sdl_artworkNeedsUpload:object.currentState.artwork]) {
[initialStatesToBeUploaded addObject:object.currentState.artwork];
}
}
Expand All @@ -293,7 +293,7 @@ - (void)sdl_uploadOtherStateImages {
for (SDLSoftButtonObject *object in self.softButtonObjects) {
for (SDLSoftButtonState *state in object.states) {
if ([state.name isEqualToString:object.currentState.name]) { continue; }
if (![self sdl_isArtworkUploadedOrNonExistent:object.currentState.artwork]) {
if (![self sdl_artworkNeedsUpload:object.currentState.artwork]) {
[otherStatesToBeUploaded addObject:state.artwork];
}
}
Expand All @@ -313,7 +313,7 @@ - (void)sdl_uploadOtherStateImages {
}
}

- (BOOL)sdl_isArtworkUploadedOrNonExistent:(SDLArtwork *)artwork {
- (BOOL)sdl_artworkNeedsUpload:(SDLArtwork *)artwork {
return (!artwork || [self.fileManager hasUploadedFile:artwork] || artwork.isStaticIcon);
}

Expand Down
8 changes: 4 additions & 4 deletions SmartDeviceLink/SDLTextAndGraphicManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ - (void)sdl_updateWithCompletionHandler:(nullable SDLTextAndGraphicUpdateComplet
SDLLogV(@"No images to send, sending text");
// If there are no images to update, just send the text
self.inProgressUpdate = [self sdl_extractTextFromShow:fullShow];
} else if ([self sdl_isArtworkUploadedOrNonExistent:self.primaryGraphic] && [self sdl_isArtworkUploadedOrNonExistent:self.secondaryGraphic]) {
} else if ([self sdl_artworkNeedsUpload:self.primaryGraphic] && [self sdl_artworkNeedsUpload:self.secondaryGraphic]) {
SDLLogV(@"Images already uploaded, sending full update");
// The files to be updated are already uploaded, send the full show immediately
self.inProgressUpdate = fullShow;
Expand Down Expand Up @@ -471,8 +471,8 @@ - (SDLShow *)sdl_extractImageFromShow:(SDLShow *)show {

- (nullable SDLShow *)sdl_createImageOnlyShowWithPrimaryArtwork:(nullable SDLArtwork *)primaryArtwork secondaryArtwork:(nullable SDLArtwork *)secondaryArtwork {
SDLShow *newShow = [[SDLShow alloc] init];
newShow.graphic = [self sdl_isArtworkUploadedOrNonExistent:primaryArtwork] ? [self sdl_imageFromArtwork:primaryArtwork] : nil;
newShow.secondaryGraphic = [self sdl_isArtworkUploadedOrNonExistent:secondaryArtwork] ? [self sdl_imageFromArtwork:secondaryArtwork] : nil;
newShow.graphic = [self sdl_artworkNeedsUpload:primaryArtwork] ? [self sdl_imageFromArtwork:primaryArtwork] : nil;
newShow.secondaryGraphic = [self sdl_artworkNeedsUpload:secondaryArtwork] ? [self sdl_imageFromArtwork:secondaryArtwork] : nil;

if (newShow.graphic == nil && newShow.secondaryGraphic == nil) {
SDLLogV(@"No graphics to upload");
Expand Down Expand Up @@ -503,7 +503,7 @@ - (void)sdl_updateCurrentScreenDataFromShow:(SDLShow *)show {
* @param artwork The artwork to be uploaded to Core
* @return True if the artwork does not need to be uploaded to Core; false if artwork stills needs to be sent to Core.
*/
- (BOOL)sdl_isArtworkUploadedOrNonExistent:(SDLArtwork *)artwork {
- (BOOL)sdl_artworkNeedsUpload:(SDLArtwork *)artwork {
return (!artwork || [self.fileManager hasUploadedFile:artwork] || artwork.isStaticIcon);
}

Expand Down

0 comments on commit e8fc233

Please sign in to comment.