From f7e7477f541e1b9c2db3997bf2f38b6668952977 Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 12 Nov 2018 10:44:39 -0500 Subject: [PATCH] Add sharing scenarios to Debug UI. --- .../src/ViewControllers/DebugUI/DebugUIMisc.m | 76 ++++++++++++++++++- .../attachments/AttachmentSharing.h | 2 + .../attachments/AttachmentSharing.m | 14 +++- 3 files changed, 87 insertions(+), 5 deletions(-) diff --git a/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m b/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m index f39486aa4..934695bc7 100644 --- a/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m +++ b/Signal/src/ViewControllers/DebugUI/DebugUIMisc.m @@ -20,6 +20,7 @@ #import #import #import +#import "DebugUIMessagesAssetLoader.h" NS_ASSUME_NONNULL_BEGIN @@ -113,14 +114,25 @@ NS_ASSUME_NONNULL_BEGIN [OWS2FAManager.sharedManager setDefaultRepetitionInterval]; }]]; - #ifdef DEBUG [items addObject:[OWSTableItem subPageItemWithText:@"Share UIImage" actionBlock:^(UIViewController *viewController) { UIImage *image = - [UIImage imageWithColor:UIColor.redColor size:CGSizeMake(1.f, 1.f)]; + [UIImage imageWithColor:UIColor.redColor size:CGSizeMake(1.f, 1.f)]; [AttachmentSharing showShareUIForUIImage:image]; }]]; + [items addObject:[OWSTableItem subPageItemWithText:@"Share 2 Images" + actionBlock:^(UIViewController *viewController) { + [DebugUIMisc shareImages:2]; + }]]; + [items addObject:[OWSTableItem subPageItemWithText:@"Share 2 Videos" + actionBlock:^(UIViewController *viewController) { + [DebugUIMisc shareVideos:2]; + }]]; + [items addObject:[OWSTableItem subPageItemWithText:@"Share 2 PDFs" + actionBlock:^(UIViewController *viewController) { + [DebugUIMisc sharePDFs:2]; + }]]; #endif [items @@ -265,6 +277,66 @@ NS_ASSUME_NONNULL_BEGIN [ThreadUtil enqueueMessageWithAttachment:attachment inThread:thread quotedReplyModel:nil]; } +#ifdef DEBUG + ++ (void)shareAssets:(NSUInteger)count + fromAssetLoaders:(NSArray *)assetLoaders +{ + [DebugUIMessagesAssetLoader prepareAssetLoaders:assetLoaders + success:^{ + [self shareAssets:count + fromPreparedAssetLoaders:assetLoaders]; + } + failure:^{ + OWSLogError(@"Could not prepare asset loaders."); + }]; +} + ++ (void)shareAssets:(NSUInteger)count + fromPreparedAssetLoaders:(NSArray *)assetLoaders +{ + __block NSMutableArray *urls = [NSMutableArray new]; + for (NSUInteger i = 0;i < count;i++) { + DebugUIMessagesAssetLoader *assetLoader = assetLoaders[arc4random_uniform((uint32_t) assetLoaders.count)]; + NSString *filePath = [OWSFileSystem temporaryFilePathWithFileExtension:assetLoader.filePath.pathExtension]; + NSError *error; + [[NSFileManager defaultManager] copyItemAtPath:assetLoader.filePath toPath:filePath error:&error]; + OWSAssertDebug(!error); + [urls addObject:[NSURL fileURLWithPath:filePath]]; + } + OWSLogVerbose(@"urls: %@", urls); + [AttachmentSharing showShareUIForURLs:urls completion:^{ + urls = nil; + }]; +} + ++ (void)shareImages:(NSUInteger)count +{ + [self shareAssets:count + fromAssetLoaders:@[ + [DebugUIMessagesAssetLoader jpegInstance], + [DebugUIMessagesAssetLoader tinyPngInstance], + ]]; +} + ++ (void)shareVideos:(NSUInteger)count +{ + [self shareAssets:count + fromAssetLoaders:@[ + [DebugUIMessagesAssetLoader mp4Instance], + ]]; +} + ++ (void)sharePDFs:(NSUInteger)count +{ + [self shareAssets:count + fromAssetLoaders:@[ + [DebugUIMessagesAssetLoader tinyPdfInstance], + ]]; +} + +#endif + @end NS_ASSUME_NONNULL_END diff --git a/SignalMessaging/attachments/AttachmentSharing.h b/SignalMessaging/attachments/AttachmentSharing.h index cda17d667..0be5d3194 100644 --- a/SignalMessaging/attachments/AttachmentSharing.h +++ b/SignalMessaging/attachments/AttachmentSharing.h @@ -19,6 +19,8 @@ typedef void (^AttachmentSharingCompletion)(void); + (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion; ++ (void)showShareUIForURLs:(NSArray *)urls completion:(nullable AttachmentSharingCompletion)completion; + + (void)showShareUIForText:(NSString *)text; + (void)showShareUIForText:(NSString *)text completion:(nullable AttachmentSharingCompletion)completion; diff --git a/SignalMessaging/attachments/AttachmentSharing.m b/SignalMessaging/attachments/AttachmentSharing.m index 7420ac919..10c005a54 100644 --- a/SignalMessaging/attachments/AttachmentSharing.m +++ b/SignalMessaging/attachments/AttachmentSharing.m @@ -40,10 +40,18 @@ NS_ASSUME_NONNULL_BEGIN + (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion { OWSAssertDebug(url); - + [AttachmentSharing showShareUIForActivityItems:@[ - url, - ] + url, + ] + completion:completion]; +} + ++ (void)showShareUIForURLs:(NSArray *)urls completion:(nullable AttachmentSharingCompletion)completion +{ + OWSAssertDebug(urls.count > 0); + + [AttachmentSharing showShareUIForActivityItems:urls completion:completion]; }