123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #import "CCQuickActions.h"
- #import "CCHud.h"
- #import "AppDelegate.h"
- #import "CCMain.h"
- @interface CCQuickActions ()
- {
- BOOL _cryptated;
-
- long _numTaskUploadInProgress;
- CTAssetsPickerController *_picker;
- CCMove *_move;
- CCMain *_mainVC;
- NSMutableArray *_assets;
- }
- @end
- @implementation CCQuickActions
- + (instancetype)quickActionsManager
- {
- static dispatch_once_t once;
- static CCQuickActions *__quickActionsManager;
-
- dispatch_once(&once, ^{
- __quickActionsManager = [[CCQuickActions alloc] init];
- });
-
- return __quickActionsManager;
- }
- - (instancetype)init
- {
- if (self = [super init]) {
-
- _cryptated = NO;
- _numTaskUploadInProgress = 0;
- }
-
- return self;
- }
- - (void)startQuickActionsEncrypted:(BOOL)cryptated viewController:(UITableViewController *)viewController
- {
- _numTaskUploadInProgress = [[CCCoreData getTableMetadataWithPredicate:[NSPredicate predicateWithFormat:@"(account == %@) AND (session CONTAINS 'upload') AND ((sessionTaskIdentifier >= 0) OR (sessionTaskIdentifierPlist >= 0))", app.activeAccount] context:nil] count];
- _cryptated = cryptated;
- _mainVC = (CCMain *)viewController;
-
- [self openAssetsPickerController];
- }
- - (void)closeAll
- {
- if (_picker)
- [_picker dismissViewControllerAnimated:NO completion:nil];
-
- if (_move)
- [_move dismissViewControllerAnimated:NO completion:nil];
-
- _cryptated = NO;
- _numTaskUploadInProgress = 0;
-
- _picker = nil;
- _move = nil;
- _assets = nil;
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Assets Picker =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)openAssetsPickerController
- {
- CTAssetSelectionLabel *assetSelectionLabel = [CTAssetSelectionLabel appearance];
- assetSelectionLabel.borderWidth = 1.0;
- assetSelectionLabel.borderColor = COLOR_BRAND;
- [assetSelectionLabel setMargin:2.0];
- [assetSelectionLabel setTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:12.0], NSForegroundColorAttributeName : [UIColor whiteColor], NSBackgroundColorAttributeName : COLOR_BRAND}];
-
- [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
- _picker = [[CTAssetsPickerController alloc] init];
-
-
- _picker.delegate = self;
-
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
- _picker.modalPresentationStyle = UIModalPresentationFormSheet;
-
-
- [_mainVC presentViewController:_picker animated:YES completion:nil];
- });
- }];
- }
- - (BOOL)assetsPickerController:(CTAssetsPickerController *)picker shouldSelectAsset:(PHAsset *)asset
- {
- __block float imageSize;
-
- PHImageRequestOptions *option = [PHImageRequestOptions new];
- option.synchronous = YES;
-
-
- [[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
- imageSize = imageData.length;
- }];
-
-
- for (PHAsset *asset in picker.selectedAssets) {
- [[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
- imageSize = imageData.length + imageSize;
- }];
- }
-
- if (imageSize > k_MaxDimensionUpload || (picker.selectedAssets.count >= (k_pickerControllerMax - _numTaskUploadInProgress))) {
-
- [app messageNotification:@"_info_" description:@"_limited_dimension_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
-
- return NO;
- }
-
- return YES;
- }
- - (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
- {
- [picker dismissViewControllerAnimated:YES completion:^{
-
- _assets = [[NSMutableArray alloc] initWithArray:assets];
-
- if ([assets count] > 0)
- [self moveOpenWindow:nil];
- }];
- }
- - (void)assetsPickerControllerDidCancel:(CTAssetsPickerController *)picker
- {
- [picker dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Move =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)moveServerUrlTo:(NSString *)serverUrlTo title:(NSString *)title selectedMetadatas:(NSArray *)selectedMetadatas
- {
- [_mainVC uploadFileAsset:_assets serverUrl:serverUrlTo cryptated:_cryptated useSubFolder:NO session:k_upload_session];
- }
- - (void)moveOpenWindow:(NSArray *)indexPaths
- {
- UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"CCMove" bundle:nil] instantiateViewControllerWithIdentifier:@"CCMove"];
-
- _move = (CCMove *)navigationController.topViewController;
-
- if (_cryptated)
- _move.move.title = NSLocalizedString(@"_upload_encrypted_file_", nil);
- else
- _move.move.title = NSLocalizedString(@"_upload_file_", nil);
- _move.delegate = self;
- _move.selectedMetadatas = nil;
- _move.tintColor = COLOR_BRAND;
- _move.barTintColor = COLOR_NAVIGATIONBAR;
- _move.tintColorTitle = COLOR_GRAY;
- _move.networkingOperationQueue = app.netQueue;
-
- [navigationController setModalPresentationStyle:UIModalPresentationFormSheet];
-
- [_mainVC presentViewController:navigationController animated:YES completion:nil];
- }
- @end
|