FLEXImageShortcuts.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // FLEXImageShortcuts.m
  3. // FLEX
  4. //
  5. // Created by Tanner Bennett on 8/29/19.
  6. // Copyright © 2019 Flipboard. All rights reserved.
  7. //
  8. #import "FLEXImageShortcuts.h"
  9. #import "FLEXImagePreviewViewController.h"
  10. #import "FLEXShortcut.h"
  11. #import "FLEXAlert.h"
  12. @interface UIAlertController (FLEXImageShortcuts)
  13. - (void)flex_image:(UIImage *)image disSaveWithError:(NSError *)error :(void *)context;
  14. @end
  15. @implementation FLEXImageShortcuts
  16. #pragma mark - Overrides
  17. + (instancetype)forObject:(UIImage *)image {
  18. // These additional rows will appear at the beginning of the shortcuts section.
  19. // The methods below are written in such a way that they will not interfere
  20. // with properties/etc being registered alongside these
  21. return [self forObject:image additionalRows:@[
  22. [FLEXActionShortcut title:@"View Image" subtitle:nil
  23. viewer:^UIViewController *(id image) {
  24. return [FLEXImagePreviewViewController forImage:image];
  25. }
  26. accessoryType:^UITableViewCellAccessoryType(id image) {
  27. return UITableViewCellAccessoryDisclosureIndicator;
  28. }
  29. ],
  30. [FLEXActionShortcut title:@"Save Image" subtitle:nil
  31. selectionHandler:^(UIViewController *host, id image) {
  32. // Present modal alerting user about saving
  33. UIAlertController *alert = [FLEXAlert makeAlert:^(FLEXAlert *make) {
  34. make.title(@"Saving Image…");
  35. }];
  36. [host presentViewController:alert animated:YES completion:nil];
  37. // Save the image
  38. UIImageWriteToSavedPhotosAlbum(
  39. image, alert, @selector(flex_image:disSaveWithError::), nil
  40. );
  41. }
  42. accessoryType:^UITableViewCellAccessoryType(id image) {
  43. return UITableViewCellAccessoryDisclosureIndicator;
  44. }
  45. ]
  46. ]];
  47. }
  48. @end
  49. @implementation UIAlertController (FLEXImageShortcuts)
  50. - (void)flex_image:(UIImage *)image disSaveWithError:(NSError *)error :(void *)context {
  51. self.title = @"Image Saved";
  52. flex_dispatch_after(1, dispatch_get_main_queue(), ^{
  53. [self dismissViewControllerAnimated:YES completion:nil];
  54. });
  55. }
  56. @end