CCQuickActions.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // CCQuickActions.m
  3. // Crypto Cloud Technology Nextcloud
  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. BOOL _cryptated;
  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. });
  46. return __quickActionsManager;
  47. }
  48. - (instancetype)init
  49. {
  50. if (self = [super init]) {
  51. _cryptated = NO;
  52. }
  53. return self;
  54. }
  55. - (void)startQuickActionsEncrypted:(BOOL)cryptated viewController:(UITableViewController *)viewController
  56. {
  57. _cryptated = cryptated;
  58. _mainVC = (CCMain *)viewController;
  59. [self openAssetsPickerController];
  60. }
  61. - (void)closeAll
  62. {
  63. if (_picker)
  64. [_picker dismissViewControllerAnimated:NO completion:nil];
  65. if (_move)
  66. [_move dismissViewControllerAnimated:NO completion:nil];
  67. _cryptated = NO;
  68. _picker = nil;
  69. _move = nil;
  70. _assets = nil;
  71. }
  72. #pragma --------------------------------------------------------------------------------------------
  73. #pragma mark ===== Assets Picker =====
  74. #pragma --------------------------------------------------------------------------------------------
  75. - (void)openAssetsPickerController
  76. {
  77. CTAssetCheckmark *checkmark = [CTAssetCheckmark appearance];
  78. checkmark.tintColor = [NCBrandColor sharedInstance].brand;
  79. [checkmark setMargin:0.0 forVerticalEdge:NSLayoutAttributeRight horizontalEdge:NSLayoutAttributeTop];
  80. UINavigationBar *navBar = [UINavigationBar appearanceWhenContainedIn:[CTAssetsPickerController class], nil];
  81. [app aspectNavigationControllerBar:navBar encrypted:NO online:YES hidden:NO];
  82. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  83. dispatch_async(dispatch_get_main_queue(), ^{
  84. CTAssetCheckmark *checkmark = [CTAssetCheckmark appearance];
  85. [checkmark setMargin:0.0 forVerticalEdge:NSLayoutAttributeRight horizontalEdge:NSLayoutAttributeBottom];
  86. // init picker
  87. _picker = [CTAssetsPickerController new];
  88. // set delegate
  89. _picker.delegate = self;
  90. // to present picker as a form sheet in iPad
  91. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  92. _picker.modalPresentationStyle = UIModalPresentationFormSheet;
  93. // present picker
  94. [_mainVC presentViewController:_picker animated:YES completion:nil];
  95. });
  96. }];
  97. }
  98. - (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldSelectAsset:(PHAsset *)asset
  99. {
  100. if (picker.selectedAssets.count > k_pickerControllerMax) {
  101. [app messageNotification:@"_info_" description:@"_limited_dimension_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  102. return NO;
  103. }
  104. return YES;
  105. }
  106. - (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
  107. {
  108. [picker dismissViewControllerAnimated:YES completion:^{
  109. _assets = [[NSMutableArray alloc] initWithArray:assets];
  110. if ([assets count] > 0)
  111. [self moveOpenWindow:nil];
  112. }];
  113. }
  114. - (void)assetsPickerControllerDidCancel:(CTAssetsPickerController *)picker
  115. {
  116. [picker dismissViewControllerAnimated:YES completion:nil];
  117. }
  118. #pragma --------------------------------------------------------------------------------------------
  119. #pragma mark ===== Move =====
  120. #pragma --------------------------------------------------------------------------------------------
  121. - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title
  122. {
  123. [_mainVC uploadFileAsset:_assets serverUrl:serverUrlTo cryptated:_cryptated useSubFolder:NO session:k_upload_session];
  124. }
  125. - (void)moveOpenWindow:(NSArray *)indexPaths
  126. {
  127. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
  128. _move = (CCMove *)navigationController.topViewController;
  129. if (_cryptated)
  130. _move.move.title = NSLocalizedString(@"_upload_encrypted_file_", nil);
  131. else
  132. _move.move.title = NSLocalizedString(@"_upload_file_", nil);
  133. _move.delegate = self;
  134. _move.tintColor = [NCBrandColor sharedInstance].navigationBarText;
  135. _move.barTintColor = [NCBrandColor sharedInstance].brand;
  136. _move.tintColorTitle = [NCBrandColor sharedInstance].navigationBarText;
  137. _move.networkingOperationQueue = app.netQueue;
  138. [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
  139. [_mainVC presentViewController:navigationController animated:YES completion:nil];
  140. }
  141. @end