CCQuickActions.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // CCQuickActions.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 30/06/16.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCQuickActions.h"
  24. #import "CCHud.h"
  25. #import "AppDelegate.h"
  26. #import "CCMain.h"
  27. #import "NCBridgeSwift.h"
  28. @interface CCQuickActions ()
  29. {
  30. AppDelegate *appDelegate;
  31. CCMove *_move;
  32. CCMain *_mainVC;
  33. NSMutableArray *_assets;
  34. }
  35. @end
  36. @implementation CCQuickActions
  37. + (instancetype)quickActionsManager
  38. {
  39. static dispatch_once_t once;
  40. static CCQuickActions *__quickActionsManager;
  41. dispatch_once(&once, ^{
  42. __quickActionsManager = [[CCQuickActions alloc] init];
  43. __quickActionsManager->appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  44. });
  45. return __quickActionsManager;
  46. }
  47. - (instancetype)init
  48. {
  49. if (self = [super init]) {
  50. }
  51. return self;
  52. }
  53. - (void)startQuickActionsViewController:(UIViewController *)viewController
  54. {
  55. _mainVC = (CCMain *)viewController;
  56. [self openAssetsPickerController];
  57. }
  58. - (void)closeAll
  59. {
  60. if (_move)
  61. [_move dismissViewControllerAnimated:NO completion:nil];
  62. _move = nil;
  63. _assets = nil;
  64. }
  65. #pragma --------------------------------------------------------------------------------------------
  66. #pragma mark ===== Assets Picker =====
  67. #pragma --------------------------------------------------------------------------------------------
  68. - (void)openAssetsPickerController
  69. {
  70. [[NCMainCommon sharedInstance] openPhotosPickerViewController:_mainVC phAssets:^(NSArray<PHAsset *> * _Nonnull assets) {
  71. if (assets.count > 0) {
  72. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
  73. _assets = [[NSMutableArray alloc] initWithArray:assets];
  74. if ([assets count] > 0)
  75. [self moveOpenWindow:nil];
  76. });
  77. }
  78. }];
  79. }
  80. /*
  81. - (void)openAssetsPickerController
  82. {
  83. CTAssetCheckmark *checkmark = [CTAssetCheckmark appearance];
  84. checkmark.tintColor = [NCBrandColor sharedInstance].brandElement;
  85. [checkmark setMargin:0.0 forVerticalEdge:NSLayoutAttributeRight horizontalEdge:NSLayoutAttributeTop];
  86. UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:[CTAssetsPickerController class], nil];
  87. [appDelegate aspectNavigationControllerBar:navBar online:YES hidden:NO];
  88. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  89. dispatch_async(dispatch_get_main_queue(), ^{
  90. CTAssetCheckmark *checkmark = [CTAssetCheckmark appearance];
  91. [checkmark setMargin:0.0 forVerticalEdge:NSLayoutAttributeRight horizontalEdge:NSLayoutAttributeBottom];
  92. // init picker
  93. _picker = [CTAssetsPickerController new];
  94. // set delegate
  95. _picker.delegate = self;
  96. // to present picker as a form sheet in iPad
  97. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  98. _picker.modalPresentationStyle = UIModalPresentationFormSheet;
  99. // present picker
  100. [_mainVC presentViewController:_picker animated:YES completion:nil];
  101. });
  102. }];
  103. }
  104. */
  105. #pragma --------------------------------------------------------------------------------------------
  106. #pragma mark ===== Move =====
  107. #pragma --------------------------------------------------------------------------------------------
  108. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title type:(NSString *)type
  109. {
  110. [_mainVC uploadFileAsset:_assets serverUrl:serverUrlTo useSubFolder:NO session:k_upload_session];
  111. }
  112. - (void)moveOpenWindow:(NSArray *)indexPaths
  113. {
  114. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  115. _move = (CCMove *)navigationController.topViewController;
  116. _move.move.title = NSLocalizedString(@"_upload_file_", nil);
  117. _move.delegate = self;
  118. _move.tintColor = [NCBrandColor sharedInstance].brandText;
  119. _move.barTintColor = [NCBrandColor sharedInstance].brand;
  120. _move.tintColorTitle = [NCBrandColor sharedInstance].brandText;
  121. _move.networkingOperationQueue = appDelegate.netQueue;
  122. // E2EE
  123. _move.includeDirectoryE2EEncryption = NO;
  124. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  125. [_mainVC presentViewController:navigationController animated:YES completion:nil];
  126. }
  127. @end