From 9713cc6b1e55738a2d39032d64761245621bc1de Mon Sep 17 00:00:00 2001 From: NicoleYarroch Date: Fri, 8 Sep 2017 18:20:07 -0400 Subject: Fixed delete file bug - Delete file method tried to delete file from Core even if it knew there was no such file on Core. - Added example for clearing soft button images and main graphics Signed-off-by: NicoleYarroch --- SmartDeviceLink/SDLFileManager.m | 1 + SmartDeviceLink_Example/Classes/ProxyManager.m | 190 ++++++++++++++------- .../circle_softbutton_icon.imageset/Contents.json | 21 --- .../circle_black_softbutton_icon.png | Bin 647 -> 0 bytes 4 files changed, 129 insertions(+), 83 deletions(-) delete mode 100644 SmartDeviceLink_Example/Images.xcassets/circle_softbutton_icon.imageset/Contents.json delete mode 100644 SmartDeviceLink_Example/Images.xcassets/circle_softbutton_icon.imageset/circle_black_softbutton_icon.png diff --git a/SmartDeviceLink/SDLFileManager.m b/SmartDeviceLink/SDLFileManager.m index a74faf046..0296bffb6 100644 --- a/SmartDeviceLink/SDLFileManager.m +++ b/SmartDeviceLink/SDLFileManager.m @@ -196,6 +196,7 @@ SDLFileManagerState *const SDLFileManagerStateStartupError = @"StartupError"; - (void)deleteRemoteFileWithName:(SDLFileName *)name completionHandler:(nullable SDLFileManagerDeleteCompletionHandler)handler { if ((![self.remoteFileNames containsObject:name]) && (handler != nil)) { handler(NO, self.bytesAvailable, [NSError sdl_fileManager_noKnownFileError]); + return; } __weak typeof(self) weakSelf = self; diff --git a/SmartDeviceLink_Example/Classes/ProxyManager.m b/SmartDeviceLink_Example/Classes/ProxyManager.m index 742c1250f..4ac1216c7 100644 --- a/SmartDeviceLink_Example/Classes/ProxyManager.m +++ b/SmartDeviceLink_Example/Classes/ProxyManager.m @@ -12,10 +12,10 @@ NSString *const SDLAppName = @"SDL Example App"; NSString *const SDLAppId = @"9999"; -NSString *const CircleSoftButtonArtworkName = @"CircleSoftButtonIcon"; NSString *const HexagonOffSoftButtonArtworkName = @"HexagonOffSoftButtonIcon"; NSString *const HexagonOnSoftButtonArtworkName = @"HexagonOnSoftButtonIcon"; NSString *const MainGraphicArtworkName = @"MainArtwork"; +NSString *const MainGraphicBlankArtworkName = @"MainBlankArtwork"; NSString *const StarSoftButtonArtworkName = @"StarSoftButtonIcon"; BOOL const ShouldRestartOnDisconnect = NO; @@ -77,7 +77,7 @@ NS_ASSUME_NONNULL_BEGIN if (self.sdlManager) { return; } SDLLifecycleConfiguration *lifecycleConfig = [self.class sdlex_setLifecycleConfigurationPropertiesOnConfiguration:[SDLLifecycleConfiguration defaultConfigurationWithAppName:SDLAppName appId:SDLAppId]]; - SDLConfiguration *config = [SDLConfiguration configurationWithLifecycle:lifecycleConfig lockScreen:[SDLLockScreenConfiguration enabledConfiguration]]; + SDLConfiguration *config = [SDLConfiguration configurationWithLifecycle:lifecycleConfig lockScreen:[SDLLockScreenConfiguration enabledConfiguration] logging:[SDLLogConfiguration defaultConfiguration]]; self.sdlManager = [[SDLManager alloc] initWithConfiguration:config delegate:self]; [self startManager]; @@ -88,7 +88,11 @@ NS_ASSUME_NONNULL_BEGIN // Check for previous instance of sdlManager if (self.sdlManager) { return; } SDLLifecycleConfiguration *lifecycleConfig = [self.class sdlex_setLifecycleConfigurationPropertiesOnConfiguration:[SDLLifecycleConfiguration debugConfigurationWithAppName:SDLAppName appId:SDLAppId ipAddress:[Preferences sharedPreferences].ipAddress port:[Preferences sharedPreferences].port]]; - SDLConfiguration *config = [SDLConfiguration configurationWithLifecycle:lifecycleConfig lockScreen:[SDLLockScreenConfiguration enabledConfiguration]]; + + SDLLogConfiguration *logConfiguration = [SDLLogConfiguration defaultConfiguration]; + logConfiguration.formatType = SDLLogFormatTypeSimple; + + SDLConfiguration *config = [SDLConfiguration configurationWithLifecycle:lifecycleConfig lockScreen:[SDLLockScreenConfiguration enabledConfiguration] logging:[SDLLogConfiguration defaultConfiguration]]; self.sdlManager = [[SDLManager alloc] initWithConfiguration:config delegate:self]; [self startManager]; @@ -142,17 +146,20 @@ NS_ASSUME_NONNULL_BEGIN } - (void)sdlex_showWithManager:(SDLManager *)manager { - SDLShow* show = [[SDLShow alloc] initWithMainField1:@"SDL" mainField2:@"Test App" alignment:SDLTextAlignmentCenter]; + NSString *mainField1Text = isTextOn ? @"Smart Device Link" : @""; + NSString *mainField2Text = isTextOn ? @"Example App" : @""; + SDLShow* show = [[SDLShow alloc] initWithMainField1:mainField1Text mainField2:mainField2Text alignment:SDLTextAlignmentCenter]; show.softButtons = [self sdlex_softButtons]; - show.graphic = [self.class sdlex_mainGraphicImage]; + show.graphic = areImagesVisible ? [self.class sdlex_mainGraphicImage] : [self.class sdlex_mainGraphicImage]; [manager sendRequest:show]; } - (NSArray *)sdlex_softButtons { SDLSoftButton *starSoftButton = [self.class sdlex_softButton1WithManager:self.sdlManager]; SDLSoftButton *hexagonSoftButton = [self sdlex_softButton2WithManager:self.sdlManager]; - SDLSoftButton *circleSoftButton = [self.class sdlex_softButton3WithManager:self.sdlManager]; - return [@[starSoftButton, hexagonSoftButton, circleSoftButton] mutableCopy]; + SDLSoftButton *textSoftButton = [self sdlex_softButton3WithManager:self.sdlManager]; + SDLSoftButton *imageSoftButton = [self sdlex_softButton4WithManager:self.sdlManager]; + return @[starSoftButton, hexagonSoftButton, textSoftButton, imageSoftButton]; } - (void)sdlex_setupPermissionsCallbacks { @@ -191,7 +198,7 @@ NS_ASSUME_NONNULL_BEGIN } + (SDLLogConfiguration *)sdlex_logConfiguration { - SDLLogConfiguration *logConfig = [SDLLogConfiguration debugConfiguration]; + SDLLogConfiguration *logConfig = [SDLLogConfiguration defaultConfiguration]; SDLLogFileModule *sdlExampleModule = [SDLLogFileModule moduleWithName:@"SDL Example" files:[NSSet setWithArray:@[@"ProxyManager"]]]; logConfig.modules = [logConfig.modules setByAddingObject:sdlExampleModule]; logConfig.targets = [logConfig.targets setByAddingObject:[SDLLogTargetFile logger]]; @@ -331,20 +338,25 @@ NS_ASSUME_NONNULL_BEGIN return; } - SDLLogD(@"Pointing finger soft button press fired"); SDLAlert* alert = [[SDLAlert alloc] init]; alert.alertText1 = @"You pushed the soft button!"; [manager sendRequest:alert]; + + SDLLogD(@"Star icon soft button press fired"); }]; softButton.text = @"Press"; softButton.softButtonID = @100; - softButton.type = SDLSoftButtonTypeBoth; - - SDLImage* image = [[SDLImage alloc] init]; - image.imageType = SDLImageTypeDynamic; - image.value = StarSoftButtonArtworkName; - softButton.image = image; - + + if (areImagesVisible) { + softButton.type = SDLSoftButtonTypeBoth; + SDLImage* image = [[SDLImage alloc] init]; + image.imageType = SDLImageTypeDynamic; + image.value = StarSoftButtonArtworkName; + softButton.image = image; + } else { + softButton.type = SDLSoftButtonTypeText; + } + return softButton; } @@ -358,50 +370,81 @@ static Boolean isHexagonOn = true; isHexagonOn = !isHexagonOn; [self sdlex_showWithManager:manager]; - SDLLogD(@"Hexagon button press fired %d", isHexagonOn); + SDLLogD(@"Hexagon icon button press fired %d", isHexagonOn); }]; softButton.softButtonID = @200; - softButton.type = SDLSoftButtonTypeImage; - SDLImage* image = [[SDLImage alloc] init]; - if (isHexagonOn) { - image.value = HexagonOnSoftButtonArtworkName; + if (areImagesVisible) { + softButton.type = SDLSoftButtonTypeImage; + SDLImage* image = [[SDLImage alloc] init]; + image.value = isHexagonOn ? HexagonOnSoftButtonArtworkName : HexagonOffSoftButtonArtworkName; + image.imageType = SDLImageTypeDynamic; + softButton.image = image; } else { - image.value = HexagonOffSoftButtonArtworkName; + softButton.text = isHexagonOn ? @"➖Hex" : @"➕Hex"; + softButton.type = SDLSoftButtonTypeText; } - image.imageType = SDLImageTypeDynamic; - softButton.image = image; return softButton; } -+ (SDLSoftButton *)sdlex_softButton3WithManager:(SDLManager *)manager { +static Boolean isTextOn = true; +- (SDLSoftButton *)sdlex_softButton3WithManager:(SDLManager *)manager { SDLSoftButton* softButton = [[SDLSoftButton alloc] initWithHandler:^(SDLOnButtonPress * _Nullable buttonPressNotification, SDLOnButtonEvent * _Nullable buttonEventNotification) { if (buttonPressNotification == nil) { return; } - SDLLogD(@"Circle soft button press fired"); - SDLAlert* alert = [[SDLAlert alloc] init]; - alert.alertText1 = @"You pushed the soft button!"; - [manager sendRequest:alert]; + isTextOn = !isTextOn; + [self sdlex_showWithManager:manager]; + + SDLLogD(@"Text visibility soft button press fired"); }]; - softButton.text = @"Check"; softButton.softButtonID = @300; - softButton.type = SDLSoftButtonTypeBoth; + softButton.text = isTextOn ? @"➖Text" : @"➕Text"; + softButton.type = SDLSoftButtonTypeText; - SDLImage* image = [[SDLImage alloc] init]; - image.imageType = SDLImageTypeDynamic; - image.value = CircleSoftButtonArtworkName; - softButton.image = image; + return softButton; +} + +static Boolean areImagesVisible = true; +- (SDLSoftButton *)sdlex_softButton4WithManager:(SDLManager *)manager { + SDLSoftButton* softButton = [[SDLSoftButton alloc] initWithHandler:^(SDLOnButtonPress * _Nullable buttonPressNotification, SDLOnButtonEvent * _Nullable buttonEventNotification) { + if (buttonPressNotification == nil) { return; } + + if (areImagesVisible) { + [self sdlex_deleteFiles:[self.class sdlex_allArtFileNames] completionHandler:^(BOOL success) { + if (!success) { return; } + [self sdlex_showWithManager:manager]; + }]; + } else { + [self sdlex_uploadFilesWithProgressHandler:[self.class sdlex_allArt] completionHandler:^(BOOL success) { + if (!success) { return; } + [self sdlex_showWithManager:manager]; + }]; + } + + areImagesVisible = !areImagesVisible; + + SDLLogD(@"Image visibility soft button press fired %d", isHexagonOn); + }]; + + softButton.text = areImagesVisible ? @"➖Icons" : @"➕Icons"; + softButton.softButtonID = @400; + softButton.type = SDLSoftButtonTypeText; return softButton; } + (SDLImage *)sdlex_mainGraphicImage { SDLImage* image = [[SDLImage alloc] init]; - image.imageType = SDLImageTypeDynamic; - image.value = MainGraphicArtworkName; + if (areImagesVisible) { + image.imageType = SDLImageTypeDynamic; + image.value = MainGraphicArtworkName; + } else { + image.imageType = SDLImageTypeDynamic; + image.value = MainGraphicBlankArtworkName; + } return image; } @@ -414,9 +457,42 @@ static Boolean isHexagonOn = true; }]; } - #pragma mark - Files / Artwork ++ (NSArray *)sdlex_allArtAndBlankPlaceholderArt { + NSMutableArray *art = [NSMutableArray array]; + [art addObjectsFromArray:[self.class sdlex_allArt]]; + [art addObject:[self.class sdlex_mainGraphicBlank]]; + return art; +} + ++ (NSArray *)sdlex_allArt { + NSMutableArray *art = [NSMutableArray array]; + [art addObjectsFromArray:[self.class sdlex_softButtonArt]]; + [art addObject:[self.class sdlex_mainGraphicArtwork]]; + return art; +} + ++ (NSArray *)sdlex_allArtFileNames { + NSMutableArray *fileNames = [NSMutableArray array]; + for (SDLArtwork *art in [self.class sdlex_allArt]) { + [fileNames addObject:art.name]; + } + return fileNames; +} + ++ (NSArray *)sdlex_softButtonArt { + return [[NSArray alloc] initWithObjects:[self.class sdlex_softButton1Artwork], [self.class sdlex_softButton2OnArtwork], [self.class sdlex_softButton2OffArtwork], nil]; +} + ++ (NSArray *)sdlex_softButtonArtFileNames { + NSMutableArray *fileNames = [NSMutableArray array]; + for (SDLArtwork *art in [self.class sdlex_softButtonArt]) { + [fileNames addObject:art.name]; + } + return fileNames; +} + + (SDLArtwork *)sdlex_softButton1Artwork { return [SDLArtwork artworkWithImage:[UIImage imageNamed:@"star_softbutton_icon"] name:StarSoftButtonArtworkName asImageFormat:SDLArtworkImageFormatPNG]; } @@ -429,20 +505,24 @@ static Boolean isHexagonOn = true; return [SDLArtwork artworkWithImage:[UIImage imageNamed:@"hexagon_off_softbutton_icon"] name:HexagonOffSoftButtonArtworkName asImageFormat:SDLArtworkImageFormatPNG]; } -+ (SDLArtwork *)sdlex_softButton3Artwork { - return [SDLArtwork artworkWithImage:[UIImage imageNamed:@"circle_softbutton_icon"] name:CircleSoftButtonArtworkName asImageFormat:SDLArtworkImageFormatPNG]; -} - + (SDLArtwork *)sdlex_mainGraphicArtwork { return [SDLArtwork artworkWithImage:[UIImage imageNamed:@"sdl_logo_green"] name:MainGraphicArtworkName asImageFormat:SDLArtworkImageFormatPNG]; } ++ (SDLArtwork *)sdlex_mainGraphicBlank { + UIGraphicsBeginImageContextWithOptions(CGSizeMake(5, 5), NO, 0.0); + UIImage *blankImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + SDLArtwork *mainGraphicBlank = [SDLArtwork artworkWithImage:blankImage name:MainGraphicBlankArtworkName asImageFormat:SDLArtworkImageFormatPNG]; + return mainGraphicBlank; +} + - (void)sdlex_uploadFiles:(NSArray *)files completionHandler:(void (^)(BOOL success))completionHandler { [self.sdlManager.fileManager uploadFiles:files completionHandler:^(NSError * _Nullable error) { if(!error) { return completionHandler(true); } else { - SDLLogW(@"The files that were not uploaded successfully: %@", error.userInfo); + SDLLogD(@"Failed file uploads: %@", error.userInfo); return completionHandler(false); } }]; @@ -451,7 +531,7 @@ static Boolean isHexagonOn = true; - (void)sdlex_uploadFilesWithProgressHandler:(NSArray *)files completionHandler:(void (^)(BOOL success))completionHandler { [self.sdlManager.fileManager uploadFiles:files progressHandler:^BOOL(SDLFileName * _Nonnull fileName, float uploadPercentage, NSError * _Nullable error) { if (error) { - SDLLogW(@"The file did not upload: %@", error); + SDLLogD(@"The file did not upload: %@", error); // You may want to cancel all future file uploads if the last file failed during the upload process return NO; } @@ -463,7 +543,7 @@ static Boolean isHexagonOn = true; if(!error) { return completionHandler(true); } else { - SDLLogW(@"The files that were not uploaded successfully: %@", error.userInfo); + SDLLogD(@"Failed file uploads: %@", error.userInfo); return completionHandler(false); } }]; @@ -474,7 +554,7 @@ static Boolean isHexagonOn = true; if(!error) { return completionHandler(true); } else { - SDLLogW(@"The files that were not deleted successfully: %@", error.userInfo); + SDLLogD(@"Failed file deletes: %@", error.userInfo); return completionHandler(false); } }]; @@ -487,25 +567,11 @@ static Boolean isHexagonOn = true; dispatch_group_t dataDispatchGroup = dispatch_group_create(); dispatch_group_enter(dataDispatchGroup); - - dispatch_group_enter(dataDispatchGroup); - [self.sdlManager.fileManager uploadFile:[self.class sdlex_mainGraphicArtwork] completionHandler:^(BOOL success, NSUInteger bytesAvailable, NSError * _Nullable error) { - dispatch_group_leave(dataDispatchGroup); - - if (success == NO) { - SDLLogW(@"Something went wrong, image could not upload: %@", error); - return; - } - }]; dispatch_group_enter(dataDispatchGroup); - NSArray *softButtonArtworks = [[NSArray alloc] initWithObjects:[self.class sdlex_softButton1Artwork], [self.class sdlex_softButton2OnArtwork], [self.class sdlex_softButton2OffArtwork], [self.class sdlex_softButton3Artwork], nil]; - [self sdlex_uploadFiles:softButtonArtworks completionHandler:^(BOOL success) { + [self sdlex_uploadFiles:[self.class sdlex_allArtAndBlankPlaceholderArt] completionHandler:^(BOOL success) { dispatch_group_leave(dataDispatchGroup); - - if (success == NO) { - return; - } + if (!success) { return; } }]; dispatch_group_enter(dataDispatchGroup); diff --git a/SmartDeviceLink_Example/Images.xcassets/circle_softbutton_icon.imageset/Contents.json b/SmartDeviceLink_Example/Images.xcassets/circle_softbutton_icon.imageset/Contents.json deleted file mode 100644 index 42e7ce165..000000000 --- a/SmartDeviceLink_Example/Images.xcassets/circle_softbutton_icon.imageset/Contents.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "images" : [ - { - "idiom" : "universal", - "filename" : "circle_black_softbutton_icon.png", - "scale" : "1x" - }, - { - "idiom" : "universal", - "scale" : "2x" - }, - { - "idiom" : "universal", - "scale" : "3x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/SmartDeviceLink_Example/Images.xcassets/circle_softbutton_icon.imageset/circle_black_softbutton_icon.png b/SmartDeviceLink_Example/Images.xcassets/circle_softbutton_icon.imageset/circle_black_softbutton_icon.png deleted file mode 100644 index 94ba9380c..000000000 Binary files a/SmartDeviceLink_Example/Images.xcassets/circle_softbutton_icon.imageset/circle_black_softbutton_icon.png and /dev/null differ -- cgit v1.2.1