CCQuickActions.m 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // CCQuickActions.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 30/06/16.
  6. // Copyright (c) 2017 TWS. 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 "CTAssetCheckmark.h"
  25. #import "CCHud.h"
  26. #import "AppDelegate.h"
  27. #import "CCMain.h"
  28. #import "NCBridgeSwift.h"
  29. @interface CCQuickActions ()
  30. {
  31. AppDelegate *appDelegate;
  32. CTAssetsPickerController *_picker;
  33. CCMove *_move;
  34. CCMain *_mainVC;
  35. NSMutableArray *_assets;
  36. }
  37. @end
  38. @implementation CCQuickActions
  39. + (instancetype)quickActionsManager
  40. {
  41. static dispatch_once_t once;
  42. static CCQuickActions *__quickActionsManager;
  43. dispatch_once(&once, ^{
  44. __quickActionsManager = [[CCQuickActions alloc] init];
  45. __quickActionsManager->appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  46. });
  47. return __quickActionsManager;
  48. }
  49. - (instancetype)init
  50. {
  51. if (self = [super init]) {
  52. }
  53. return self;
  54. }
  55. - (void)startQuickActionsViewController:(UIViewController *)viewController
  56. {
  57. _mainVC = (CCMain *)viewController;
  58. [self openAssetsPickerController];
  59. }
  60. - (void)closeAll
  61. {
  62. if (_picker)
  63. [_picker dismissViewControllerAnimated:NO completion:nil];
  64. if (_move)
  65. [_move dismissViewControllerAnimated:NO completion:nil];
  66. _picker = nil;
  67. _move = nil;
  68. _assets = nil;
  69. }
  70. #pragma --------------------------------------------------------------------------------------------
  71. #pragma mark ===== Assets Picker =====
  72. #pragma --------------------------------------------------------------------------------------------
  73. - (void)openAssetsPickerController
  74. {
  75. CTAssetCheckmark *checkmark = [CTAssetCheckmark appearance];
  76. checkmark.tintColor = [NCBrandColor sharedInstance].brandElement;
  77. [checkmark setMargin:0.0 forVerticalEdge:NSLayoutAttributeRight horizontalEdge:NSLayoutAttributeTop];
  78. UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:[CTAssetsPickerController class], nil];
  79. [appDelegate aspectNavigationControllerBar:navBar online:YES hidden:NO];
  80. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  81. dispatch_async(dispatch_get_main_queue(), ^{
  82. CTAssetCheckmark *checkmark = [CTAssetCheckmark appearance];
  83. [checkmark setMargin:0.0 forVerticalEdge:NSLayoutAttributeRight horizontalEdge:NSLayoutAttributeBottom];
  84. // init picker
  85. _picker = [CTAssetsPickerController new];
  86. // set delegate
  87. _picker.delegate = self;
  88. // to present picker as a form sheet in iPad
  89. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  90. _picker.modalPresentationStyle = UIModalPresentationFormSheet;
  91. // present picker
  92. [_mainVC presentViewController:_picker animated:YES completion:nil];
  93. });
  94. }];
  95. }
  96. - (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldSelectAsset:(PHAsset *)asset
  97. {
  98. if (picker.selectedAssets.count > k_pickerControllerMax) {
  99. [appDelegate messageNotification:@"_info_" description:@"_limited_dimension_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  100. return NO;
  101. }
  102. return YES;
  103. }
  104. - (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
  105. {
  106. [picker dismissViewControllerAnimated:YES completion:^{
  107. _assets = [[NSMutableArray alloc] initWithArray:assets];
  108. if ([assets count] > 0)
  109. [self moveOpenWindow:nil];
  110. }];
  111. }
  112. - (void)assetsPickerControllerDidCancel:(CTAssetsPickerController *)picker
  113. {
  114. [picker dismissViewControllerAnimated:YES completion:nil];
  115. }
  116. #pragma --------------------------------------------------------------------------------------------
  117. #pragma mark ===== Move =====
  118. #pragma --------------------------------------------------------------------------------------------
  119. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title
  120. {
  121. [_mainVC uploadFileAsset:_assets serverUrl:serverUrlTo useSubFolder:NO session:k_upload_session];
  122. }
  123. - (void)moveOpenWindow:(NSArray *)indexPaths
  124. {
  125. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  126. _move = (CCMove *)navigationController.topViewController;
  127. _move.move.title = NSLocalizedString(@"_upload_file_", nil);
  128. _move.delegate = self;
  129. _move.tintColor = [NCBrandColor sharedInstance].brandText;
  130. _move.barTintColor = [NCBrandColor sharedInstance].brand;
  131. _move.tintColorTitle = [NCBrandColor sharedInstance].brandText;
  132. _move.networkingOperationQueue = appDelegate.netQueue;
  133. // E2E
  134. _move.includeDirectoryE2EEncryption = NO;
  135. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  136. [_mainVC presentViewController:navigationController animated:YES completion:nil];
  137. }
  138. @end