12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292 |
- #import "CCPhotosCameraUpload.h"
- #import "AppDelegate.h"
- #ifdef CUSTOM_BUILD
- #import "Custom.h"
- #else
- #import "Nextcloud-Swift.h"
- #endif
- @interface CCPhotosCameraUpload () <CCActionsDeleteDelegate, CCActionsDownloadThumbnailDelegate>
- {
- CCMetadata *_metadata;
- BOOL _cellEditing;
- NSMutableArray *_queueMetadatas;
- NSMutableArray *_selectedMetadatas;
- NSUInteger _numSelectedMetadatas;
-
-
- CCSectionDataSourceMetadata *_sectionDataSource;
-
- CCHud *_hud;
- }
- @end
- @implementation CCPhotosCameraUpload
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Init =====
- #pragma --------------------------------------------------------------------------------------------
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- if (self = [super initWithCoder:aDecoder]) {
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initStateCameraUpload:) name:@"initStateCameraUpload" object:nil];
-
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setupCameraUploadFull) name:@"setupCameraUploadFull" object:nil];
-
- app.activePhotosCameraUpload = self;
- }
-
- return self;
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== View =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- _queueMetadatas = [[NSMutableArray alloc] init];
- _selectedMetadatas = [[NSMutableArray alloc] init];
- _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
-
-
- self.collectionView.emptyDataSetDelegate = self;
- self.collectionView.emptyDataSetSource = self;
- }
- - (void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
-
-
- [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
- [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
-
-
- [app plusButtonVisibile:true];
-
- [self reloadDatasource];
- }
- - (void)viewDidAppear:(BOOL)animated
- {
- [super viewDidAppear:animated];
-
- [self.navigationController cancelCCProgress];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
-
-
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ====== Photos ======
- #pragma --------------------------------------------------------------------------------------------
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Gestione Grafica Window =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)setUINavigationBarDefault
- {
- [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
-
-
- UIImage *icon = [UIImage imageNamed:image_seleziona];
- UIBarButtonItem *buttonSelect = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(collectionSelectYES)];
-
- if ([_sectionDataSource.allRecordsDataSource count] > 0) buttonSelect.enabled = true;
- else buttonSelect.enabled = false;
-
- self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonSelect, nil];
- self.navigationItem.leftBarButtonItem = nil;
-
-
- self.navigationItem.title = NSLocalizedString(@"_photo_camera_", nil);
- }
- - (void)setUINavigationBarSelected
- {
- UIImage *icon;
-
- icon = [UIImage imageNamed:image_deleteSelectedFiles];
- UIBarButtonItem *buttonDelete = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(deleteSelectedFiles)];
-
- icon = [UIImage imageNamed:image_openSelectedFiles];
- UIBarButtonItem *buttonOpenWith = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(openSelectedFiles)];
-
- UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIBarButtonItemStylePlain target:self action:@selector(reloadCollection)];
-
- self.navigationItem.leftBarButtonItem = leftButton;
- self.navigationItem.rightBarButtonItems = [[NSArray alloc] initWithObjects:buttonDelete, buttonOpenWith, nil];
-
-
- self.navigationItem.title = [NSString stringWithFormat:@"%@ : %lu / %lu", NSLocalizedString(@"_selected_", nil), (unsigned long)[_selectedMetadatas count], (unsigned long)[_sectionDataSource.allRecordsDataSource count]];
- }
- - (void)collectionSelect:(BOOL)edit
- {
- [self.collectionView setAllowsMultipleSelection:edit];
-
- _cellEditing = edit;
-
- if (edit)
- [self setUINavigationBarSelected];
- else
- [self setUINavigationBarDefault];
- }
- - (void)collectionSelectYES
- {
- [self collectionSelect:YES];
- }
- - (void)cellSelect:(BOOL)select indexPath:(NSIndexPath *)indexPath metadata:(CCMetadata *)metadata
- {
- UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
- UIVisualEffectView *effect = [cell viewWithTag:200];
- UIImageView *checked = [cell viewWithTag:300];
-
- if (select) {
- effect.hidden = NO;
- effect.alpha = 0.4;
- checked.hidden = NO;
- [_selectedMetadatas addObject:metadata];
-
- } else {
- effect.hidden = YES;
- checked.hidden = YES;
- [_selectedMetadatas removeObject:metadata];
- }
-
-
- self.navigationItem.title = [NSString stringWithFormat:@"%@ : %lu / %lu", NSLocalizedString(@"_selected_", nil), (unsigned long)[_selectedMetadatas count], (unsigned long)[_sectionDataSource.allRecordsDataSource count]];
- }
- - (void)scrollToTop
- {
- [self.collectionView setContentOffset:CGPointMake(0, - self.collectionView.contentInset.top) animated:NO];
- }
- - (void)getGeoLocationForSection:(NSInteger)section
- {
- NSString *addLocation = @"";
-
- NSArray *fileIDsForKey = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]];
-
- for (NSString *fileID in fileIDsForKey) {
-
- TableLocalFile *localFile = [CCCoreData getLocalFileWithFileID:fileID activeAccount:app.activeAccount];
-
- if ([localFile.exifLatitude floatValue] > 0 || [localFile.exifLongitude floatValue] > 0) {
-
- NSString *location = [CCCoreData getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
-
- addLocation = [NSString stringWithFormat:@"%@, %@", addLocation, location];
-
- }
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Photo Library Change Observer ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)photoLibraryDidChange:(PHChange *)changeInfo
- {
-
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== DZNEmptyDataSetSource Methods ====
- #pragma --------------------------------------------------------------------------------------------
- - (BOOL)emptyDataSetShouldDisplay:(UIScrollView *)scrollView
- {
- return YES;
- }
- - (CGFloat)spaceHeightForEmptyDataSet:(UIScrollView *)scrollView
- {
- return 0.0f;
- }
- - (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
- {
- return - self.navigationController.navigationBar.frame.size.height;
- }
- - (UIColor *)backgroundColorForEmptyDataSet:(UIScrollView *)scrollView
- {
- return [UIColor whiteColor];
- }
- - (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView
- {
- return [UIImage imageNamed:image_brandBackgroundLite];
- }
- - (NSAttributedString *)titleForEmptyDataSet:(UIScrollView *)scrollView
- {
- NSString *text = [NSString stringWithFormat:@"%@", @""];
-
- NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:20.0f], NSForegroundColorAttributeName:COLOR_BRAND};
-
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- - (NSAttributedString *)descriptionForEmptyDataSet:(UIScrollView *)scrollView
- {
- NSMutableParagraphStyle *paragraph = [NSMutableParagraphStyle new];
- paragraph.lineBreakMode = NSLineBreakByWordWrapping;
- paragraph.alignment = NSTextAlignmentCenter;
- NSString *text;
-
- if ([CCCoreData getCameraUploadActiveAccount:app.activeAccount])
- text = [NSString stringWithFormat:@"\n%@", NSLocalizedString(@"_tutorial_photo_view_", nil)];
- else
- text = [NSString stringWithFormat:@"\n%@\n", NSLocalizedString(@"_tutorial_camera_upload_view_", nil)];
-
- NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSParagraphStyleAttributeName: paragraph};
- return [[NSAttributedString alloc] initWithString:text attributes:attributes];
- }
- - (UIImage *)buttonImageForEmptyDataSet:(UIScrollView *)scrollView forState:(UIControlState)state
- {
- if ([CCCoreData getCameraUploadActiveAccount:app.activeAccount] == NO) {
-
-
- UIImage *imageButton = [UIImage imageNamed:image_activeCameraUpload];
- UIImage *image = [CCUtility drawText:NSLocalizedString(@"_activate_camera_upload_", nil) inImage:imageButton];
-
- return image;
-
- } else return nil;
- }
- - (void)emptyDataSetDidTapButton:(UIScrollView *)scrollView
- {
- CCManageCameraUpload *viewController = [[CCManageCameraUpload alloc] initWithNibName:nil bundle:nil];
- UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
-
- [navigationController setModalPresentationStyle:UIModalPresentationFullScreen];
- [self presentViewController:navigationController animated:YES completion:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== openSelectedFiles =====
- #pragma--------------------------------------------------------------------------------------------
- - (void)openSelectedFiles
- {
- NSMutableArray *dataToShare = [[NSMutableArray alloc] init];
-
- for (CCMetadata *metadata in _selectedMetadatas) {
-
- NSString *fileNamePath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint];
-
- [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:fileNamePath error:nil];
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:fileNamePath]) {
-
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
-
- NSData *data = [NSData dataWithData:UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:fileNamePath], 0.9)];
- [dataToShare addObject:data];
- }
-
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
-
- [dataToShare addObject:[NSURL fileURLWithPath:fileNamePath]];
- }
- }
- }
-
- if ([dataToShare count] > 0) {
-
- UIActivityViewController* activityViewController = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
-
-
- activityViewController.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItems.lastObject;
-
- self.navigationItem.leftBarButtonItem.enabled = NO;
- self.navigationItem.rightBarButtonItem.enabled = NO;
-
- [self presentViewController:activityViewController animated:YES completion:^{
-
- [activityViewController setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
-
- self.navigationItem.leftBarButtonItem.enabled = YES;
- self.navigationItem.rightBarButtonItem.enabled = YES;
-
- if (completed) {
-
- [dataToShare enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
-
- if ([obj isKindOfClass:[UIImage class]])
- [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
-
- if ([obj isKindOfClass:[NSURL class]])
- [CCCoreData setCameraUploadDateVideo:[NSDate date]];
- }];
-
- [self performSelector:@selector(reloadCollection) withObject:nil];
- }
- }];
- }];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Download =====
- #pragma--------------------------------------------------------------------------------------------
- - (void)downloadFileFailure:(NSInteger)errorCode
- {
- [app messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
- }
- - (void)downloadFileSuccess:(CCMetadata *)metadata
- {
- NSIndexPath *indexPath;
- BOOL existsIcon = NO;
-
- if (metadata.fileID) {
- existsIcon = [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
- indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadata.fileID];
- }
-
- if (indexPath && existsIcon) {
-
- UICollectionViewCell *cell = [self.collectionView cellForItemAtIndexPath:indexPath];
-
- if (cell) {
- UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
- UIVisualEffectView *effect = [cell viewWithTag:200];
- UIImageView *checked = [cell viewWithTag:300];
-
- imageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
- effect.hidden = YES;
- checked.hidden = YES;
-
- [app.icoImagesCache setObject:imageView.image forKey:metadata.fileID];
- }
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Delete =====
- #pragma--------------------------------------------------------------------------------------------
- - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
- {
- [self deleteFileOrFolderSuccess:metadataNet];
- }
- - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
- {
- [_queueMetadatas removeObject:metadataNet.selector];
-
- if ([_queueMetadatas count] == 0) {
-
- [_hud hideHud];
- if ([_selectedMetadatas count] > 0) {
-
- [_selectedMetadatas removeObjectAtIndex:0];
-
- if ([_selectedMetadatas count] > 0) {
-
- [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
-
- } else {
-
- [self reloadDatasource];
- }
-
- } else {
-
- [self reloadDatasource];
- }
- }
- }
- - (void)deleteFileOrFolder:(CCMetadata *)metadata numFile:(NSInteger)numFile ofFile:(NSInteger)ofFile
- {
-
- if (metadata.cryptated) {
- [_queueMetadatas addObject:selectorDeleteCrypto];
- [_queueMetadatas addObject:selectorDeletePlist];
- } else {
- [_queueMetadatas addObject:selectorDelete];
- }
-
- [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
- [_hud visibleHudTitle:[NSString stringWithFormat:NSLocalizedString(@"_delete_file_n_", nil), ofFile - numFile + 1, ofFile] mode:MBProgressHUDModeIndeterminate color:nil];
- }
- - (void)deleteSelectedFiles
- {
- [_queueMetadatas removeAllObjects];
-
- _numSelectedMetadatas = [_selectedMetadatas count];
-
- if ([_selectedMetadatas count] == 0)
- return;
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
- style:UIAlertActionStyleDestructive
- handler:^(UIAlertAction *action) {
- [self deleteFileOrFolder:[_selectedMetadatas objectAtIndex:0] numFile:[_selectedMetadatas count] ofFile:_numSelectedMetadatas];
- }]];
-
- [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
- style:UIAlertActionStyleCancel
- handler:^(UIAlertAction *action) {
- [alertController dismissViewControllerAnimated:YES completion:nil];
- }]];
-
- alertController.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItems.firstObject;
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
- [alertController.view layoutIfNeeded];
-
- [self presentViewController:alertController animated:YES completion:NULL];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Download Thumbnail Delegate ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)downloadThumbnailSuccess:(CCMetadataNet *)metadataNet
- {
- NSIndexPath *indexPath = [_sectionDataSource.fileIDIndexPath objectForKey:metadataNet.fileID];
-
- if (indexPath && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadataNet.fileID]])
- [self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ==== Collection ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)reloadDatasourceForced
- {
- [CCSectionMetadata removeAllObjectsSectionDataSource:_sectionDataSource];
- [self reloadDatasource];
- }
- - (void)reloadDatasource
- {
-
- if (app.activeAccount.length == 0)
- return;
-
- NSString *serverUrl = [CCCoreData getCameraUploadFolderNamePathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
- if (_sectionDataSource) {
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
-
- _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:[CCCoreData getRecordsTableMetadataPhotosCameraUpload:serverUrl activeAccount:app.activeAccount] listProgressMetadata:nil groupByField:@"date" replaceDateToExifDate:YES activeAccount:app.activeAccount];
-
- dispatch_async(dispatch_get_main_queue(), ^{
- [self reloadCollection];
- });
- });
- } else {
-
- _sectionDataSource = [CCSectionMetadata creataDataSourseSectionMetadata:[CCCoreData getRecordsTableMetadataPhotosCameraUpload:serverUrl activeAccount:app.activeAccount] listProgressMetadata:nil groupByField:@"date" replaceDateToExifDate:YES activeAccount:app.activeAccount];
- [self reloadCollection];
- }
- }
- - (void)reloadCollection
- {
- [self.collectionView reloadData];
-
- [_selectedMetadatas removeAllObjects];
- [self collectionSelect:NO];
- }
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
- {
- return [[_sectionDataSource.sectionArrayRow allKeys] count];
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return [[_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:section]] count];
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- UIInterfaceOrientation orientationOnLunch = [[UIApplication sharedApplication] statusBarOrientation];
-
- if (orientationOnLunch == UIInterfaceOrientationPortrait)
- return CGSizeMake(collectionView.frame.size.width / 5.3f, collectionView.frame.size.width / 5.3f);
- else
- return CGSizeMake(collectionView.frame.size.width / 7.3f, collectionView.frame.size.width / 7.3f);
- }
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
- {
- if ([_sectionDataSource.sections count] - 1 == section)
- return CGSizeMake(collectionView.frame.size.width, 50);
-
- return CGSizeZero;
- }
- - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
- {
- if (kind == UICollectionElementKindSectionHeader) {
-
- UICollectionReusableView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"header" forIndexPath:indexPath];
-
-
-
- [self getGeoLocationForSection:indexPath.section];
-
- UILabel *titleLabel = (UILabel *)[headerView viewWithTag:100];
- titleLabel.textColor = COLOR_TEXT_ANTHRACITE;
- titleLabel.text = [CCUtility getTitleSectionDate:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
- return headerView;
- }
-
- if (kind == UICollectionElementKindSectionFooter) {
-
- UICollectionReusableView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"footer" forIndexPath:indexPath];
-
- UILabel *titleLabel = (UILabel *)[footerView viewWithTag:100];
- titleLabel.textColor = [UIColor grayColor];
- titleLabel.text = [NSString stringWithFormat:@"%lu %@, %lu %@", (long)_sectionDataSource.image, NSLocalizedString(@"photo", nil), (long)_sectionDataSource.video, NSLocalizedString(@"_video_", nil)];
-
- return footerView;
- }
-
- return nil;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
- UIImageView *imageView = (UIImageView *)[cell viewWithTag:100];
- UIVisualEffectView *effect = [cell viewWithTag:200];
- UIImageView *checked = [cell viewWithTag:300];
- checked.image = [UIImage imageNamed:image_checked];
- NSArray *metadatasForKey = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
- NSString *fileID = [metadatasForKey objectAtIndex:indexPath.row];
- CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
-
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]]) {
-
- imageView.image = [app.icoImagesCache objectForKey:metadata.fileID];
-
- if (imageView.image == nil) {
-
-
- UIImage *image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, metadata.fileID]];
- imageView.image = image;
- [app.icoImagesCache setObject:image forKey:metadata.fileID];
- }
-
- } else {
-
-
- imageView.image = [UIImage imageNamed:image_photosDownload];
-
- if (metadata.thumbnailExists)
- [[CCActions sharedInstance] downloadTumbnail:metadata delegate:self];
- }
-
-
- if (cell.selected) {
- checked.hidden = NO;
- effect.hidden = NO;
- effect.alpha = 0.4;
- } else {
- checked.hidden = YES;
- effect.hidden = YES;
- }
-
- return cell;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- NSArray *metadatasForKey = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
- NSString *fileID = [metadatasForKey objectAtIndex:indexPath.row];
- _metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
-
-
-
- if (_cellEditing) {
-
- [self cellSelect:YES indexPath:indexPath metadata:_metadata];
-
- } else {
-
- if ([self shouldPerformSegue])
- [self performSegueWithIdentifier:@"segueDetail" sender:self];
- }
- }
- - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath
- {
- if (_cellEditing == NO)
- return;
-
-
-
- NSArray *metadatasForKey = [_sectionDataSource.sectionArrayRow objectForKey:[_sectionDataSource.sections objectAtIndex:indexPath.section]];
- NSString *fileID = [metadatasForKey objectAtIndex:indexPath.row];
- _metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
-
- [self cellSelect:NO indexPath:indexPath metadata:_metadata];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Navigation ====
- #pragma --------------------------------------------------------------------------------------------
- - (BOOL)shouldPerformSegue
- {
-
-
-
- if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground)
- return NO;
-
-
- if (self.view.window == NO)
- return NO;
-
-
- if (self.splitViewController.isCollapsed)
- if (self.detailViewController.isViewLoaded && self.detailViewController.view.window)
- return NO;
-
-
- if (self.detailViewController.photoBrowser.currentVideoPlayerViewController.isViewLoaded && self.detailViewController.photoBrowser.currentVideoPlayerViewController.view.window)
- return NO;
-
-
- return YES;
- }
- -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
- {
- id controller = segue.destinationViewController;
-
- if ([controller isKindOfClass:[UINavigationController class]]) {
- UINavigationController *navigationController = controller;
- self.detailViewController = (CCDetail *)navigationController.topViewController;
- } else {
- self.detailViewController = segue.destinationViewController;
- }
-
- NSMutableArray *allRecordsDataSourceImagesVideos = [[NSMutableArray alloc] init];
- for (NSString *fileID in _sectionDataSource.allFileID) {
- CCMetadata *metadata = [_sectionDataSource.allRecordsDataSource objectForKey:fileID];
- if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image] || [metadata.typeFile isEqualToString: k_metadataTypeFile_video])
- [allRecordsDataSourceImagesVideos addObject:metadata];
- }
-
- self.detailViewController.dataSourceImagesVideos = allRecordsDataSourceImagesVideos;
- self.detailViewController.metadataDetail = _metadata;
- self.detailViewController.dateFilterQuery = _metadata.date;
- self.detailViewController.isCameraUpload = YES;
-
- [self.detailViewController setTitle:_metadata.fileNamePrint];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ====== --- Camera Upload --- ======
- #pragma --------------------------------------------------------------------------------------------
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark === initStateCameraUpload ===
- #pragma --------------------------------------------------------------------------------------------
- - (void)initStateCameraUpload:(NSNotification *)notification
- {
- int afterDelay = 0;
-
- if (notification.object)
- afterDelay = [[notification.object objectForKey:@"afterDelay"] intValue];
-
- [self performSelector:@selector(initStateCameraUpload) withObject:nil afterDelay:afterDelay];
- }
- - (void)initStateCameraUpload
- {
-
-
-
- if([CCCoreData getCameraUploadActiveAccount:app.activeAccount]) {
-
- [self setupCameraUpload];
-
- if([CCCoreData getCameraUploadBackgroundActiveAccount:app.activeAccount])
- [self checkIfLocationIsEnabled];
-
- } else {
-
- [CCCoreData setCameraUpload:NO activeAccount:app.activeAccount];
-
- [PHPhotoLibrary.sharedPhotoLibrary unregisterChangeObserver:self];
-
- [[CCManageLocation sharedSingleton] stopSignificantChangeUpdates];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark === Camera Upload & Full ===
- #pragma --------------------------------------------------------------------------------------------
- - (void)setupCameraUpload
- {
- if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized) {
-
- self.assetsFetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum | PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
-
- [PHPhotoLibrary.sharedPhotoLibrary registerChangeObserver:self];
-
- [self uploadNewAssets];
-
- } else {
-
- [CCCoreData setCameraUpload:NO activeAccount:app.activeAccount];
-
- [PHPhotoLibrary.sharedPhotoLibrary unregisterChangeObserver:self];
-
- [[CCManageLocation sharedSingleton] stopSignificantChangeUpdates];
-
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil)
- message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil)
- delegate:nil
- cancelButtonTitle:NSLocalizedString(@"_ok_", nil)
- otherButtonTitles:nil];
- [alert show];
- }
- }
- - (void)setupCameraUploadFull
- {
- if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized) {
-
- self.assetsFetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum | PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
-
- [PHPhotoLibrary.sharedPhotoLibrary registerChangeObserver:self];
-
- [self uploadFullAssets];
-
- } else {
-
- [CCCoreData setCameraUpload:NO activeAccount:app.activeAccount];
-
- [PHPhotoLibrary.sharedPhotoLibrary unregisterChangeObserver:self];
-
- [[CCManageLocation sharedSingleton] stopSignificantChangeUpdates];
-
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil)
- message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil)
- delegate:nil
- cancelButtonTitle:NSLocalizedString(@"_ok_", nil)
- otherButtonTitles:nil];
- [alert show];
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark === Location ===
- #pragma --------------------------------------------------------------------------------------------
- - (BOOL)checkIfLocationIsEnabled
- {
- [CCManageLocation sharedSingleton].delegate = self;
-
- if ([CLLocationManager locationServicesEnabled]) {
-
- NSLog(@"[LOG] checkIfLocationIsEnabled : authorizationStatus: %d", [CLLocationManager authorizationStatus]);
-
- if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways) {
-
- if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined ) {
-
- NSLog(@"[LOG] checkIfLocationIsEnabled : Location services not determined");
- [[CCManageLocation sharedSingleton] startSignificantChangeUpdates];
-
- } else {
-
- if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized) {
-
- [CCCoreData setCameraUploadBackground:NO activeAccount:app.activeAccount];
-
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_location_not_enabled_", nil)
- message:NSLocalizedString(@"_location_not_enabled_msg_", nil)
- delegate:nil
- cancelButtonTitle:NSLocalizedString(@"_ok_", nil)
- otherButtonTitles:nil];
- [alert show];
-
- } else {
-
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil)
- message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil)
- delegate:nil
- cancelButtonTitle:NSLocalizedString(@"_ok_", nil)
- otherButtonTitles:nil];
- [alert show];
- }
- }
-
- } else {
-
- if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized) {
-
- [CCCoreData setCameraUploadBackground:YES activeAccount:app.activeAccount];
- [[CCManageLocation sharedSingleton] startSignificantChangeUpdates];
-
- } else {
-
- [CCCoreData setCameraUploadBackground:NO activeAccount:app.activeAccount];
- [[CCManageLocation sharedSingleton] stopSignificantChangeUpdates];
-
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil)
- message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil)
- delegate:nil
- cancelButtonTitle:NSLocalizedString(@"_ok_", nil)
- otherButtonTitles:nil];
- [alert show];
- }
- }
-
- } else {
-
- [CCCoreData setCameraUploadBackground:NO activeAccount:app.activeAccount];
- [[CCManageLocation sharedSingleton] stopSignificantChangeUpdates];
-
- if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized) {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_location_not_enabled_", nil)
- message:NSLocalizedString(@"_location_not_enabled_msg_", nil)
- delegate:nil
- cancelButtonTitle:NSLocalizedString(@"_ok_", nil)
- otherButtonTitles:nil];
- [alert show];
-
- } else {
-
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_access_photo_location_not_enabled_", nil)
- message:NSLocalizedString(@"_access_photo_location_not_enabled_msg_", nil)
- delegate:nil
- cancelButtonTitle:NSLocalizedString(@"_ok_", nil)
- otherButtonTitles:nil];
- [alert show];
- }
- }
-
- return [CCCoreData getCameraUploadBackgroundActiveAccount:app.activeAccount];
- }
- - (void)statusAuthorizationLocationChanged
- {
- if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusNotDetermined){
-
- if (![CCManageLocation sharedSingleton].firstChangeAuthorizationDone) {
-
- ALAssetsLibrary *assetLibrary = [CCUtility defaultAssetsLibrary];
-
- [assetLibrary enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos
- usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
-
- } failureBlock:^(NSError *error) {
-
- }];
- }
-
- if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
-
- if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized) {
-
- if ([CCManageLocation sharedSingleton].firstChangeAuthorizationDone) {
-
- [CCCoreData setCameraUploadBackground:NO activeAccount:app.activeAccount];
- [[CCManageLocation sharedSingleton] stopSignificantChangeUpdates];
- }
-
- } else {
-
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_access_photo_not_enabled_", nil)
- message:NSLocalizedString(@"_access_photo_not_enabled_msg_", nil)
- delegate:nil
- cancelButtonTitle:NSLocalizedString(@"_ok_", nil)
- otherButtonTitles:nil];
- [alert show];
- }
-
- } else if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusNotDetermined){
-
- if ([CCCoreData getCameraUploadBackgroundActiveAccount:app.activeAccount]) {
-
- [CCCoreData setCameraUploadBackground:NO activeAccount:app.activeAccount];
- [[CCManageLocation sharedSingleton] stopSignificantChangeUpdates];
-
- if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized) {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_location_not_enabled_", nil)
- message:NSLocalizedString(@"_location_not_enabled_msg_", nil)
- delegate:nil
- cancelButtonTitle:NSLocalizedString(@"_ok_", nil)
- otherButtonTitles:nil];
- [alert show];
-
- } else {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_access_photo_location_not_enabled_", nil)
- message:NSLocalizedString(@"_access_photo_location_not_enabled_msg_", nil)
- delegate:nil
- cancelButtonTitle:NSLocalizedString(@"_ok_", nil)
- otherButtonTitles:nil];
- [alert show];
- }
- }
- }
-
- if (![CCManageLocation sharedSingleton].firstChangeAuthorizationDone) {
-
- [CCManageLocation sharedSingleton].firstChangeAuthorizationDone = YES;
- }
- }
- }
- - (void)changedLocation
- {
-
- [[CCNetworking sharedNetworking] automaticDownloadInError];
- [[CCNetworking sharedNetworking] automaticUploadInError];
-
-
- if([CCCoreData getCameraUploadActiveAccount:app.activeAccount] && [CCCoreData getCameraUploadBackgroundActiveAccount:app.activeAccount ] && [[UIApplication sharedApplication] applicationState] == UIApplicationStateBackground) {
-
- if ([ALAssetsLibrary authorizationStatus] == ALAuthorizationStatusAuthorized) {
-
-
- if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways) {
-
- NSLog(@"[LOG] Changed Location call uploadNewAssets");
- [self uploadNewAssets];
- }
-
- } else {
-
- [CCCoreData setCameraUpload:NO activeAccount:app.activeAccount];
-
- [CCCoreData setCameraUploadBackground:NO activeAccount:app.activeAccount];
-
- [[CCManageLocation sharedSingleton] stopSignificantChangeUpdates];
- [PHPhotoLibrary.sharedPhotoLibrary unregisterChangeObserver:self];
- }
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Upload Assets : NEW & FULL ====
- #pragma --------------------------------------------------------------------------------------------
- - (void)uploadNewAssets
- {
- [self uploadAssetsNewAndFull:NO];
- }
- - (void)uploadFullAssets
- {
- [self uploadAssetsNewAndFull:YES];
- }
- - (void)uploadAssetsNewAndFull:(BOOL)assetsFull
- {
- CCManageAsset *manageAsset = [[CCManageAsset alloc] init];
- NSMutableArray *newItemsToUpload;
-
-
- if (assetsFull) {
-
- newItemsToUpload = [manageAsset getCameraRollNewItemsWithDatePhoto:[NSDate distantPast] dateVideo:[NSDate distantPast]];
-
- } else {
-
- NSDate *databaseDateVideo = [CCCoreData getCameraUploadDateVideoActiveAccount:app.activeAccount];
- NSDate *databaseDatePhoto = [CCCoreData getCameraUploadDatePhotoActiveAccount:app.activeAccount];
-
- newItemsToUpload = [manageAsset getCameraRollNewItemsWithDatePhoto:databaseDatePhoto dateVideo:databaseDateVideo];
- }
-
-
- if ([newItemsToUpload count] == 0)
- return;
-
-
-
-
-
- [[UIApplication sharedApplication] setIdleTimerDisabled: YES];
-
- if (!_hud) _hud = [[CCHud alloc] initWithView:[[[UIApplication sharedApplication] delegate] window]];
-
- if (assetsFull)
- [_hud visibleHudTitle:NSLocalizedString(@"_create_full_upload_", nil) mode:MBProgressHUDModeIndeterminate color:nil];
- else
- [_hud visibleHudTitle:nil mode:MBProgressHUDModeIndeterminate color:nil];
-
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
-
- if (assetsFull)
- [self performSelectorOnMainThread:@selector(uploadFullAssetsToNetwork:) withObject:newItemsToUpload waitUntilDone:NO];
- else
- [self performSelectorOnMainThread:@selector(uploadNewAssetsToNetwork:) withObject:newItemsToUpload waitUntilDone:NO];
- });
- }
- - (void)uploadNewAssetsToNetwork:(NSMutableArray *)newItemsToUpload
- {
- [self uploadAssetsToNetwork:newItemsToUpload assetsFull:NO];
- }
- - (void)uploadFullAssetsToNetwork:(NSMutableArray *)newItemsToUpload
- {
- [self uploadAssetsToNetwork:newItemsToUpload assetsFull:YES];
- }
- - (void)uploadAssetsToNetwork:(NSMutableArray *)newItemsToUpload assetsFull:(BOOL)assetsFull
- {
- NSMutableArray *newItemsPHAssetToUpload = [[NSMutableArray alloc] init];
-
- NSString *folderPhotos = [CCCoreData getCameraUploadFolderNamePathActiveAccount:app.activeAccount activeUrl:app.activeUrl];
- BOOL createSubfolders = [CCCoreData getCameraUploadCreateSubfolderActiveAccount:app.activeAccount];
-
-
- for (ALAsset *asset in newItemsToUpload) {
-
- NSURL *url = [asset valueForProperty:@"ALAssetPropertyAssetURL"];
- PHFetchResult *fetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
- PHAsset *asset = [fetchResult firstObject];
- [newItemsPHAssetToUpload addObject:asset];
- }
-
-
- if(![self automaticCreateFolder:folderPhotos]) {
-
-
- if (assetsFull)
- [app messageNotification:@"_error_" description:NSLocalizedStringFromTable(@"_not_possible_create_folder_", @"Error", nil) visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
-
-
-
-
- return;
- }
-
-
- if (createSubfolders) {
-
- for (NSString *dateSubFolder in [CCUtility createNameSubFolder:newItemsPHAssetToUpload]) {
-
- if (![self automaticCreateFolder:[NSString stringWithFormat:@"%@/%@", folderPhotos, dateSubFolder]]) {
-
- [self endLoadingAssets];
-
- if (assetsFull)
- [app messageNotification:@"_error_" description:@"_error_createsubfolders_upload_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
-
- return;
- }
- }
- }
-
- for (PHAsset *asset in newItemsPHAssetToUpload) {
-
- NSString *serverUrl;
- NSDate *assetDate = asset.creationDate;
- PHAssetMediaType assetMediaType = asset.mediaType;
- NSString *session;
- NSString *fileName = [CCUtility createFileNameFromAsset:asset key:nil];
-
-
-
- if (assetMediaType == PHAssetMediaTypeImage && [CCCoreData getCameraUploadWWanPhotoActiveAccount:app.activeAccount] == NO) session = k_upload_session;
- if (assetMediaType == PHAssetMediaTypeVideo && [CCCoreData getCameraUploadWWanVideoActiveAccount:app.activeAccount] == NO) session = k_upload_session;
- if (assetMediaType == PHAssetMediaTypeImage && [CCCoreData getCameraUploadWWanPhotoActiveAccount:app.activeAccount]) session = k_upload_session_wwan;
- if (assetMediaType == PHAssetMediaTypeVideo && [CCCoreData getCameraUploadWWanVideoActiveAccount:app.activeAccount]) session = k_upload_session_wwan;
- NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
-
- [formatter setDateFormat:@"yyyy"];
- NSString *yearString = [formatter stringFromDate:assetDate];
-
- [formatter setDateFormat:@"MM"];
- NSString *monthString = [formatter stringFromDate:assetDate];
- if (createSubfolders)
- serverUrl = [NSString stringWithFormat:@"%@/%@/%@", folderPhotos, yearString, monthString];
- else
- serverUrl = folderPhotos;
-
- CCMetadataNet *metadataNet = [[CCMetadataNet alloc] initWithAccount:app.activeAccount];
-
- metadataNet.action = actionUploadAsset;
- metadataNet.identifier = asset.localIdentifier;
- if (assetsFull) {
- metadataNet.selector = selectorUploadAutomaticAll;
- metadataNet.selectorPost = selectorUploadRemovePhoto;
- metadataNet.priority = NSOperationQueuePriorityLow;
- } else {
- metadataNet.selector = selectorUploadAutomatic;
- metadataNet.selectorPost = nil;
- metadataNet.priority = NSOperationQueuePriorityNormal;
- }
- metadataNet.fileName = fileName;
- metadataNet.serverUrl = serverUrl;
- metadataNet.session = session;
- metadataNet.taskStatus = k_taskStatusResume;
-
- [CCCoreData addTableAutomaticUpload:metadataNet account:app.activeAccount context:nil];
-
-
- if ([metadataNet.selector isEqualToString:selectorUploadAutomatic])
- [CCCoreData setCameraUploadDateAssetType:assetMediaType assetDate:assetDate activeAccount:app.activeAccount];
- }
-
-
- if (assetsFull)
- [app loadTableAutomaticUploadForSelector:selectorUploadAutomaticAll];
- else
- [app loadTableAutomaticUploadForSelector:selectorUploadAutomatic];
-
- [self endLoadingAssets];
-
-
- [app updateApplicationIconBadgeNumber];
- }
- - (BOOL)automaticCreateFolder:(NSString *)folderPathName
- {
- OCCommunication *communication = [CCNetworking sharedNetworking].sharedOCCommunication;
- __block BOOL noError = YES;
-
- dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
-
- [communication setCredentialsWithUser:app.activeUser andPassword:app.activePassword];
- [communication setUserAgent:[CCUtility getUserAgent]];
-
- [communication readFile:folderPathName onCommunication:communication successRequest:^(NSHTTPURLResponse *response, NSArray *items, NSString *redirectedServer) {
-
- dispatch_semaphore_signal(semaphore);
-
- } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
-
- [communication createFolder:folderPathName onCommunication:communication withForbiddenCharactersSupported:app.hasServerForbiddenCharactersSupport successRequest:^(NSHTTPURLResponse *response, NSString *redirectedServer) {
-
- [CCCoreData clearDateReadAccount:app.activeAccount serverUrl:[CCUtility deletingLastPathComponentFromServerUrl:folderPathName] directoryID:nil];
-
- dispatch_semaphore_signal(semaphore);
-
- } failureRequest:^(NSHTTPURLResponse *response, NSError *error, NSString *redirectedServer) {
-
- noError = NO;
-
- dispatch_semaphore_signal(semaphore);
-
- } errorBeforeRequest:^(NSError *error) {
-
- noError = NO;
- dispatch_semaphore_signal(semaphore);
- }];
- }];
-
- while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW))
- [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:k_timeout_webdav]];
-
- return noError;
- }
- -(void)endLoadingAssets
- {
- [_hud hideHud];
-
-
-
-
-
- [[UIApplication sharedApplication] setIdleTimerDisabled:NO];
- }
- @end
|