Add sharing scenarios to Debug UI.

pull/1/head
Matthew Chen 7 years ago
parent 860eb44edc
commit f7e7477f54

@ -20,6 +20,7 @@
#import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h> #import <SignalServiceKit/TSInvalidIdentityKeyReceivingErrorMessage.h>
#import <SignalServiceKit/TSThread.h> #import <SignalServiceKit/TSThread.h>
#import <SignalServiceKit/UIImage+OWS.h> #import <SignalServiceKit/UIImage+OWS.h>
#import "DebugUIMessagesAssetLoader.h"
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@ -113,14 +114,25 @@ NS_ASSUME_NONNULL_BEGIN
[OWS2FAManager.sharedManager setDefaultRepetitionInterval]; [OWS2FAManager.sharedManager setDefaultRepetitionInterval];
}]]; }]];
#ifdef DEBUG #ifdef DEBUG
[items addObject:[OWSTableItem subPageItemWithText:@"Share UIImage" [items addObject:[OWSTableItem subPageItemWithText:@"Share UIImage"
actionBlock:^(UIViewController *viewController) { actionBlock:^(UIViewController *viewController) {
UIImage *image = 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]; [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 #endif
[items [items
@ -265,6 +277,66 @@ NS_ASSUME_NONNULL_BEGIN
[ThreadUtil enqueueMessageWithAttachment:attachment inThread:thread quotedReplyModel:nil]; [ThreadUtil enqueueMessageWithAttachment:attachment inThread:thread quotedReplyModel:nil];
} }
#ifdef DEBUG
+ (void)shareAssets:(NSUInteger)count
fromAssetLoaders:(NSArray<DebugUIMessagesAssetLoader *> *)assetLoaders
{
[DebugUIMessagesAssetLoader prepareAssetLoaders:assetLoaders
success:^{
[self shareAssets:count
fromPreparedAssetLoaders:assetLoaders];
}
failure:^{
OWSLogError(@"Could not prepare asset loaders.");
}];
}
+ (void)shareAssets:(NSUInteger)count
fromPreparedAssetLoaders:(NSArray<DebugUIMessagesAssetLoader *> *)assetLoaders
{
__block NSMutableArray<NSURL *> *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 @end
NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_END

@ -19,6 +19,8 @@ typedef void (^AttachmentSharingCompletion)(void);
+ (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion; + (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion;
+ (void)showShareUIForURLs:(NSArray<NSURL *> *)urls completion:(nullable AttachmentSharingCompletion)completion;
+ (void)showShareUIForText:(NSString *)text; + (void)showShareUIForText:(NSString *)text;
+ (void)showShareUIForText:(NSString *)text completion:(nullable AttachmentSharingCompletion)completion; + (void)showShareUIForText:(NSString *)text completion:(nullable AttachmentSharingCompletion)completion;

@ -40,10 +40,18 @@ NS_ASSUME_NONNULL_BEGIN
+ (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion + (void)showShareUIForURL:(NSURL *)url completion:(nullable AttachmentSharingCompletion)completion
{ {
OWSAssertDebug(url); OWSAssertDebug(url);
[AttachmentSharing showShareUIForActivityItems:@[ [AttachmentSharing showShareUIForActivityItems:@[
url, url,
] ]
completion:completion];
}
+ (void)showShareUIForURLs:(NSArray<NSURL *> *)urls completion:(nullable AttachmentSharingCompletion)completion
{
OWSAssertDebug(urls.count > 0);
[AttachmentSharing showShareUIForActivityItems:urls
completion:completion]; completion:completion];
} }

Loading…
Cancel
Save