CCQuickActions.m 5.5 KB

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