CCDetail.m 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082
  1. //
  2. // CCDetail.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 16/01/15.
  6. // Copyright (c) 2014 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 "CCDetail.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #ifdef CUSTOM_BUILD
  27. #import "CustomSwift.h"
  28. #else
  29. #import "Nextcloud-Swift.h"
  30. #endif
  31. #define TOOLBAR_HEIGHT 49.0f
  32. #define alertRequestPasswordPDF 1
  33. @interface CCDetail () <CCActionsDeleteDelegate>
  34. {
  35. UIToolbar *_toolbar;
  36. UIBarButtonItem *_buttonAction;
  37. UIBarButtonItem *_buttonShare;
  38. UIBarButtonItem *_buttonDelete;
  39. BOOL _reload;
  40. NSMutableOrderedSet *_dataSourceDirectoryID;
  41. }
  42. @end
  43. @implementation CCDetail
  44. #pragma --------------------------------------------------------------------------------------------
  45. #pragma mark ===== init =====
  46. #pragma --------------------------------------------------------------------------------------------
  47. - (id)initWithCoder:(NSCoder *)aDecoder
  48. {
  49. if (self = [super initWithCoder:aDecoder]) {
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  51. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  52. self.metadataDetail = [[CCMetadata alloc] init];
  53. self.photos = [[NSMutableArray alloc] init];
  54. self.thumbs = [[NSMutableArray alloc] init];
  55. self.dataSourceImagesVideos = [[NSMutableArray alloc] init];
  56. _dataSourceDirectoryID = [[NSMutableOrderedSet alloc] init];
  57. self.indexNowVisible = 0;
  58. self.fileIDNowVisible = nil;
  59. app.activeDetail = self;
  60. }
  61. return self;
  62. }
  63. #pragma --------------------------------------------------------------------------------------------
  64. #pragma mark ===== View =====
  65. #pragma --------------------------------------------------------------------------------------------
  66. - (void)viewDidLoad
  67. {
  68. [super viewDidLoad];
  69. self.imageBackground.image = [UIImage imageNamed:image_brandBackgroundLite];
  70. if ([self.metadataDetail.fileName length] > 0 || [self.metadataDetail.directoryID length] > 0 || [self.metadataDetail.fileID length] > 0) {
  71. // open view
  72. [self viewFile];
  73. }
  74. }
  75. // Apparirà
  76. - (void)viewWillAppear:(BOOL)animated
  77. {
  78. [super viewWillAppear:animated];
  79. if (self.splitViewController.isCollapsed) {
  80. self.tabBarController.tabBar.hidden = YES;
  81. self.tabBarController.tabBar.translucent = YES;
  82. }
  83. if (self.splitViewController.isCollapsed)
  84. [app plusButtonVisibile:false];
  85. }
  86. - (void)viewDidAppear:(BOOL)animated
  87. {
  88. [super viewDidAppear:animated];
  89. }
  90. // E' scomparso
  91. - (void)viewDidDisappear:(BOOL)animated
  92. {
  93. [super viewDidDisappear:animated];
  94. // remove all
  95. if (self.isMovingFromParentViewController)
  96. [self removeAllView];
  97. }
  98. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  99. {
  100. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  101. }];
  102. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  103. }
  104. // remove all view
  105. - (void)removeAllView
  106. {
  107. // Audio
  108. if (app.player)
  109. [app.player removeFromSuperview];
  110. // Document
  111. if (_webView) {
  112. [_webView removeFromSuperview];
  113. _webView = nil;
  114. }
  115. // PDF
  116. if (_readerPDFViewController) {
  117. [_readerPDFViewController.view removeFromSuperview];
  118. _readerPDFViewController.delegate = nil;
  119. _readerPDFViewController = nil;
  120. }
  121. // Photo-Video
  122. if (_photoBrowser) {
  123. [_photos removeAllObjects];
  124. [_thumbs removeAllObjects];
  125. _photoBrowser.delegate = nil;
  126. _photoBrowser = nil;
  127. }
  128. [self.navigationController popToRootViewControllerAnimated:NO];
  129. self.navigationController.navigationBarHidden = YES;
  130. }
  131. - (void)changeToDisplayMode
  132. {
  133. if (_readerPDFViewController)
  134. [self.readerPDFViewController updateContentViews];
  135. }
  136. - (void)createToolbar
  137. {
  138. _toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  139. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  140. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  141. fixedSpaceMini.width = 25;
  142. _buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:image_actionSheetOpenIn] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  143. _buttonShare = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:image_actionSheetShare] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  144. _buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
  145. [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  146. [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  147. _toolbar.barTintColor = COLOR_TABBAR;
  148. [self.view addSubview:_toolbar];
  149. }
  150. #pragma --------------------------------------------------------------------------------------------
  151. #pragma mark ===== UIDocumentInteractionControllerDelegate =====
  152. #pragma --------------------------------------------------------------------------------------------
  153. - (void)documentInteractionControllerDidDismissOptionsMenu:(UIDocumentInteractionController *)controller
  154. {
  155. // evitiamo il rimando della eventuale photo e/o video
  156. if ([CCCoreData getCameraUploadActiveAccount:app.activeAccount]) {
  157. [CCCoreData setCameraUploadDatePhoto:[NSDate date]];
  158. [CCCoreData setCameraUploadDateVideo:[NSDate date]];
  159. }
  160. }
  161. #pragma --------------------------------------------------------------------------------------------
  162. #pragma mark ===== View File =====
  163. #pragma --------------------------------------------------------------------------------------------
  164. - (void)viewFile
  165. {
  166. // verifico se esiste l'icona e se la posso creare
  167. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, self.metadataDetail.fileID]] == NO) {
  168. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{
  169. [CCGraphics createNewImageFrom:self.metadataDetail.fileID directoryUser:app.directoryUser fileNameTo:self.metadataDetail.fileID fileNamePrint:self.metadataDetail.fileNamePrint size:@"m" imageForUpload:NO typeFile:self.metadataDetail.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
  170. });
  171. }
  172. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video]) {
  173. self.edgesForExtendedLayout = UIRectEdgeAll;
  174. [self viewImage];
  175. }
  176. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  177. self.edgesForExtendedLayout = UIRectEdgeBottom;
  178. [self viewAudio];
  179. [self createToolbar];
  180. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  181. }
  182. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  183. NSString *ext = [[self.metadataDetail.fileNamePrint pathExtension] lowercaseString];
  184. if ([ext isEqualToString:@"pdf"]) {
  185. self.edgesForExtendedLayout = UIRectEdgeBottom;
  186. [self viewPDF:@""];
  187. [self createToolbar];
  188. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  189. } else {
  190. self.edgesForExtendedLayout = UIRectEdgeBottom;
  191. [self viewDocument];
  192. [self createToolbar];
  193. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  194. }
  195. }
  196. }
  197. #pragma --------------------------------------------------------------------------------------------
  198. #pragma mark ===== View Audio =====
  199. #pragma --------------------------------------------------------------------------------------------
  200. - (void)viewAudio
  201. {
  202. NSString *fileName;
  203. if (_sourceDirectoryLocal) {
  204. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  205. } else {
  206. fileName = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryAudio], self.metadataDetail.fileNamePrint];
  207. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  208. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  209. }
  210. app.player.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  211. app.player.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  212. app.player.nextButton.hidden = true;
  213. app.player.previousButton.hidden = true;
  214. app.player.fullscreenButton_.hidden = true;
  215. LMMediaItem *item = [[LMMediaItem alloc] initWithInfo:@{LMMediaItemInfoURLKey:[NSURL fileURLWithPath:fileName], LMMediaItemInfoContentTypeKey:@(LMMediaItemContentTypeVideo)}];
  216. item.title = self.metadataDetail.fileNamePrint;
  217. item.artist = k_brand;
  218. [app.player.mediaPlayer removeAllMediaInQueue];
  219. [app.player.mediaPlayer addMedia:item];
  220. [app.player.mediaPlayer play];
  221. // Info
  222. NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
  223. [songInfo setObject:app.player.mediaPlayer.nowPlayingItem.title forKey:MPMediaItemPropertyTitle];
  224. [songInfo setObject:app.player.mediaPlayer.nowPlayingItem.artist forKey:MPMediaItemPropertyArtist];
  225. [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
  226. [self.view addSubview:app.player];
  227. }
  228. #pragma --------------------------------------------------------------------------------------------
  229. #pragma mark ===== View Document =====
  230. #pragma --------------------------------------------------------------------------------------------
  231. - (void)viewDocument
  232. {
  233. NSString *fileName;
  234. if (_sourceDirectoryLocal) {
  235. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  236. } else {
  237. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNamePrint];
  238. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  239. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  240. }
  241. NSString *ext=@"";
  242. ext = [CCUtility getExtension:self.metadataDetail.fileNamePrint];
  243. WKPreferences *wkPreferences = [[WKPreferences alloc] init];
  244. wkPreferences.javaScriptEnabled = false;
  245. WKWebViewConfiguration *wkConfig = [[WKWebViewConfiguration alloc] init];
  246. wkConfig.preferences = wkPreferences;
  247. self.webView = [[WKWebView alloc] initWithFrame:(CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT)) configuration:wkConfig];
  248. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  249. [self.webView setBackgroundColor:[UIColor whiteColor]];
  250. [self.webView setOpaque:NO];
  251. if ( [ext isEqualToString:@"CSS"] || [ext isEqualToString:@"PY"] || [ext isEqualToString:@"XML"] || [ext isEqualToString:@"JS"] ) {
  252. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]];
  253. [headRequest setHTTPMethod:@"HEAD"];
  254. NSHTTPURLResponse *headResponse;
  255. NSError *error = nil;
  256. [NSURLConnection sendSynchronousRequest:headRequest returningResponse:&headResponse error:&error];
  257. if (error != nil) {
  258. NSLog(@"[LOG] loadURLWithString %@",[error localizedDescription]);
  259. }
  260. NSString *dataFile = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:fileName]] encoding:NSASCIIStringEncoding];
  261. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  262. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"40",@"Sans-Serif",dataFile] baseURL:nil];
  263. }else{
  264. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"20",@"Sans-Serif",dataFile] baseURL:nil];
  265. }
  266. } else if ([ext isEqualToString:@"TXT"] ) {
  267. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]];
  268. [headRequest setHTTPMethod:@"HEAD"];
  269. NSHTTPURLResponse *headResponse;
  270. NSError *error = nil;
  271. [NSURLConnection sendSynchronousRequest:headRequest returningResponse:&headResponse error:&error];
  272. if (error != nil) {
  273. NSLog(@"[LOG] loadURLWithString %@",[error localizedDescription]);
  274. }
  275. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]]];
  276. } else {
  277. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]]];
  278. }
  279. [self.view addSubview:self.webView];
  280. }
  281. #pragma --------------------------------------------------------------------------------------------
  282. #pragma mark ===== View Image =====
  283. #pragma --------------------------------------------------------------------------------------------
  284. - (void)viewImage
  285. {
  286. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  287. _reload = NO;
  288. [self.photos removeAllObjects];
  289. [self.thumbs removeAllObjects];
  290. [_dataSourceDirectoryID removeAllObjects];
  291. // if not images, exit
  292. if ([self.dataSourceImagesVideos count] == 0) return;
  293. NSUInteger index = 0;
  294. for (CCMetadata *metadata in self.dataSourceImagesVideos) {
  295. // start from here ?
  296. if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
  297. [self.photoBrowser setCurrentPhotoIndex:index];
  298. if (metadata.cryptated) {
  299. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewDownloadCrypto]]];
  300. [self.thumbs addObject:[MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewDownloadCrypto]]];
  301. } else {
  302. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewDownload]]];
  303. MWPhoto *thumb = [MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewDownload]];
  304. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  305. [self.thumbs addObject:thumb];
  306. }
  307. // add directory
  308. [_dataSourceDirectoryID addObject:metadata.directoryID];
  309. index++;
  310. }
  311. // PhotoBrowser
  312. self.photoBrowser.displayActionButton = YES;
  313. self.photoBrowser.displayDeleteButton = YES;
  314. self.photoBrowser.displayNavArrows = YES;
  315. self.photoBrowser.displaySelectionButtons = NO;
  316. self.photoBrowser.alwaysShowControls = NO;
  317. self.photoBrowser.zoomPhotosToFill = NO;
  318. self.photoBrowser.startOnGrid = NO;
  319. self.photoBrowser.autoPlayOnAppear = NO;
  320. self.photoBrowser.delayToHideElements = 15;
  321. self.photoBrowser.enableGrid = YES;
  322. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  323. [self addChildViewController:self.photoBrowser];
  324. [self.view addSubview:self.photoBrowser.view];
  325. [self.photoBrowser didMoveToParentViewController:self];
  326. } else {
  327. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  328. }
  329. }
  330. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  331. {
  332. return [self.dataSourceImagesVideos count];
  333. }
  334. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  335. {
  336. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  337. NSString *titleDir = metadata.fileNamePrint; //[NSString stringWithFormat:@"%lu %@ %lu", (unsigned long)index+1, NSLocalizedString(@"of", nil), (unsigned long)self.photos.count];
  338. self.title = titleDir;
  339. return titleDir;
  340. }
  341. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  342. {
  343. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  344. NSString *directory;
  345. self.indexNowVisible = index;
  346. self.fileIDNowVisible = metadata.fileID;
  347. photoBrowser.toolbar.hidden = NO;
  348. if (_reload) {
  349. [self.photoBrowser performSelector:@selector(reloadData) withObject:nil afterDelay:0.1];
  350. _reload = NO;
  351. }
  352. if (_sourceDirectoryLocal)
  353. directory = self.metadataDetail.directoryID;
  354. else
  355. directory = app.directoryUser;
  356. // Download
  357. if (metadata && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]] == NO && [metadata.session length] == 0)
  358. [self performSelector:@selector(downloadPhotoBrowser:) withObject:metadata afterDelay:0.1];
  359. // Title
  360. if (metadata && !photoBrowser.isGridController)
  361. self.title = metadata.fileNamePrint;
  362. }
  363. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  364. {
  365. NSString *directory;
  366. UIImage *image;
  367. if (_sourceDirectoryLocal)
  368. directory = self.metadataDetail.directoryID;
  369. else
  370. directory = app.directoryUser;
  371. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  372. //NSLog(@"[LOG] photoBrowser: photoAtIndex : %lu ---- di totali photo : %lu", (unsigned long)index, (unsigned long)_photos.count);
  373. if (index < self.photos.count) {
  374. if (metadata.fileID) {
  375. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  376. NSString *fileImage = [NSString stringWithFormat:@"%@/%@", directory, metadata.fileID];
  377. NSString *ext = [CCUtility getExtension:metadata.fileNamePrint];
  378. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  379. else image = [UIImage imageWithContentsOfFile:fileImage];
  380. if (image) {
  381. MWPhoto *photo = [MWPhoto photoWithImage:image];
  382. // Location ??
  383. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  384. if (!photo.caption) {
  385. // Remove title foto caption
  386. //photo.caption = metadata.fileNamePrint;
  387. }
  388. [self.photos replaceObjectAtIndex:index withObject:photo];
  389. } else {
  390. if ([metadata.sessionError length] > 0 ) {
  391. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewError]]];
  392. } else {
  393. NSURL *url = [[NSBundle mainBundle] URLForResource:@"loading" withExtension:@"gif"];
  394. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage animatedImageWithAnimatedGIFURL:url]]];
  395. }
  396. }
  397. }
  398. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  399. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]]) {
  400. // remove and make the simbolic link in temp
  401. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint];
  402. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  403. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID] toPath:toPath error:nil];
  404. NSURL *url = [NSURL fileURLWithPath:toPath];
  405. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  406. video.caption = metadata.fileNamePrint;
  407. video.videoURL = url;
  408. [self.photos replaceObjectAtIndex:index withObject:video];
  409. } else {
  410. if ([metadata.sessionError length] > 0 ) {
  411. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:image_filePreviewError]]];
  412. } else {
  413. NSURL *url = [[NSBundle mainBundle] URLForResource:@"loading" withExtension:@"gif"];
  414. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage animatedImageWithAnimatedGIFURL:url]]];
  415. }
  416. }
  417. }
  418. }
  419. // energy saving memory
  420. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  421. int iPrev = (int)index - 2;
  422. if (iPrev >= 0) {
  423. if ([self.photos objectAtIndex:iPrev] != nil)
  424. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  425. }
  426. int iNext = (int)index + 2;
  427. if (iNext < _photos.count) {
  428. if ([self.photos objectAtIndex:iNext] != nil)
  429. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  430. }
  431. });
  432. return [self.photos objectAtIndex:index];
  433. }
  434. return nil;
  435. }
  436. - (void)gridWillAppear:(MWPhotoBrowser *)photoBrowser
  437. {
  438. // reload [BUG]
  439. [self.photoBrowser reloadData];
  440. // in grid clear all MWPhoto : energy saving memory
  441. if (self.photos.count > 1 && [self.dataSourceImagesVideos count] > 0) {
  442. for(int index=0; index < self.photos.count; index++)
  443. [_photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:nil]];
  444. }
  445. self.title = [NSString stringWithFormat:@"Album %lu %@", (unsigned long)_photos.count, NSLocalizedString(@"photos", nil)];
  446. }
  447. - (void)gridWillDisappear:(MWPhotoBrowser *)photoBrowser
  448. {
  449. //
  450. photoBrowser.toolbar.hidden = NO;
  451. }
  452. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index
  453. {
  454. NSString *directory;
  455. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  456. if (_sourceDirectoryLocal)
  457. directory = self.metadataDetail.directoryID;
  458. else
  459. directory = app.directoryUser;
  460. if (index < self.thumbs.count) {
  461. if (metadata.fileID) {
  462. UIImage *image;
  463. if (_sourceDirectoryLocal) {
  464. image = [CCGraphics createNewImageFrom:metadata.fileID directoryUser:directory fileNameTo:metadata.fileID fileNamePrint:metadata.fileNamePrint size:@"m" imageForUpload:NO typeFile:metadata.typeFile writePreview:NO optimizedFileName:[CCUtility getOptimizedPhoto]];
  465. } else {
  466. NSString *fileImage = [NSString stringWithFormat:@"%@/%@.ico", directory, metadata.fileID];
  467. image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  468. }
  469. if (image) {
  470. MWPhoto *thumb = [MWPhoto photoWithImage:image];
  471. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  472. [self.thumbs replaceObjectAtIndex:index withObject:thumb];
  473. }
  474. }
  475. return [self.thumbs objectAtIndex:index];
  476. }
  477. return nil;
  478. }
  479. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  480. {
  481. NSString *filePath;
  482. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  483. if (metadata == nil) return;
  484. if (_sourceDirectoryLocal) {
  485. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  486. } else {
  487. filePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  488. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  489. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:filePath error:nil];
  490. }
  491. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  492. self.docController.delegate = self;
  493. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) [self.docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  494. [self.docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  495. }
  496. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  497. {
  498. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  499. [app.activeMain openWindowShare:metadata];
  500. }
  501. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  502. {
  503. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  504. if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]] == NO) {
  505. [app messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo];
  506. return;
  507. }
  508. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  509. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  510. style:UIAlertActionStyleDestructive
  511. handler:^(UIAlertAction *action) {
  512. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  513. }]];
  514. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  515. style:UIAlertActionStyleCancel
  516. handler:^(UIAlertAction *action) {
  517. [alertController dismissViewControllerAnimated:YES completion:nil];
  518. }]];
  519. alertController.popoverPresentationController.barButtonItem = deleteButton;
  520. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  521. [alertController.view layoutIfNeeded];
  522. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  523. }
  524. - (void)triggerProgressTask:(NSNotification *)notification
  525. {
  526. NSDictionary *dict = notification.userInfo;
  527. float progress = [[dict valueForKey:@"progress"] floatValue];
  528. if (progress == 0)
  529. [self.navigationController cancelCCProgress];
  530. else
  531. [self.navigationController setCCProgressPercentage:progress*100 andTintColor:COLOR_NAVIGATIONBAR_PROGRESS];
  532. }
  533. - (void)downloadPhotoBrowserFailure:(NSInteger)errorCode
  534. {
  535. [app messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError];
  536. [self.photoBrowser reloadData];
  537. }
  538. - (void)downloadPhotoBrowserSuccess:(CCMetadata *)metadataVar selector:(NSString *)selector
  539. {
  540. NSUInteger index = 0;
  541. // if a message for a directory of these
  542. if (![_dataSourceDirectoryID containsObject:metadataVar.directoryID])
  543. return;
  544. for (NSUInteger i=0; i < [self.dataSourceImagesVideos count]; i++ ) {
  545. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:i];
  546. // search index
  547. if ([metadataVar.fileID isEqualToString:metadata.fileID]) {
  548. index = i;
  549. break;
  550. }
  551. }
  552. // do not reload is Video on air
  553. if (_photoBrowser.currentVideoPlayerViewController.isViewLoaded && _photoBrowser.currentVideoPlayerViewController.view.window) return;
  554. //NSLog(@"[LOG] Add Download Photo Browser");
  555. if ([metadataVar.fileID isEqualToString:self.fileIDNowVisible] || [self.photoBrowser isGridReload:index]) {
  556. [self.photoBrowser reloadData];
  557. _reload = NO;
  558. } else {
  559. _reload = YES;
  560. }
  561. }
  562. - (void)downloadPhotoBrowser:(CCMetadata *)metadata
  563. {
  564. NSString *serverUrl = [CCCoreData getServerUrlFromDirectoryID:metadata.directoryID activeAccount:metadata.account];
  565. [[CCNetworking sharedNetworking] downloadFile:metadata serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadViewImage selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:nil];
  566. }
  567. - (void)insertGeocoderLocation:(NSNotification *)notification
  568. {
  569. NSString *fileID = [[notification.userInfo allKeys] objectAtIndex:0];
  570. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  571. // test [Chrash V 1.14,15]
  572. if (self.indexNowVisible >= [self.photos count])
  573. return;
  574. dispatch_async(dispatch_get_main_queue(), ^{
  575. if ([fileID isEqualToString:self.fileIDNowVisible]) {
  576. MWPhoto *photo = [self.photos objectAtIndex:self.indexNowVisible];
  577. [self setLocationCaptionPhoto:photo fileID:fileID];
  578. if (![self.photoBrowser isGridController]) {
  579. [self.photoBrowser hideControls];
  580. [self.photoBrowser showControls];
  581. }
  582. }
  583. });
  584. }
  585. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  586. {
  587. TableLocalFile *localFile;
  588. // read Geocoder
  589. localFile = [CCCoreData getLocalFileWithFileID:fileID activeAccount:app.activeAccount];
  590. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  591. // Fix BUG Geo latitude & longitude
  592. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  593. CCMetadata *metadata = [CCCoreData getMetadataWithPreficate:[NSPredicate predicateWithFormat:@"(fileID == %@) AND (account == %@)", fileID, app.activeAccount] context:nil];
  594. [CCExifGeo setExifLocalTableFileID:metadata directoryUser:app.directoryUser activeAccount:app.activeAccount];
  595. }
  596. [CCExifGeo setGeocoderFileID:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  597. localFile = [CCCoreData getLocalFileWithFileID:fileID activeAccount:app.activeAccount];
  598. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  599. NSString *location = [CCCoreData getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  600. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  601. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  602. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  603. }
  604. }
  605. }
  606. }
  607. #pragma --------------------------------------------------------------------------------------------
  608. #pragma mark ===== View PDF =====
  609. #pragma --------------------------------------------------------------------------------------------
  610. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  611. {
  612. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  613. [[alertView textFieldAtIndex:0] resignFirstResponder];
  614. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  615. }
  616. - (void)viewPDF:(NSString *)password
  617. {
  618. NSString *fileName;
  619. if (_sourceDirectoryLocal) {
  620. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  621. } else {
  622. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNamePrint];
  623. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  624. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  625. }
  626. if ([[NSFileManager defaultManager] fileExistsAtPath:fileName isDirectory:nil] == NO) {
  627. // read file error
  628. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  629. [alertView show];
  630. }
  631. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileName]);
  632. if (pdf) {
  633. // Encrypted
  634. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  635. // Try a blank password first, per Apple's Quartz PDF example
  636. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  637. // blank password
  638. [self readerPDF:fileName password:@""];
  639. } else {
  640. if ([password length] == 0) {
  641. // password request
  642. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  643. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  644. alertView.tag = alertRequestPasswordPDF;
  645. [alertView show];
  646. } else {
  647. const char *key = [password UTF8String];
  648. // failure
  649. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  650. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  651. [alertView show];
  652. } else {
  653. // pdf with password
  654. [self readerPDF:fileName password:password];
  655. }
  656. }
  657. }
  658. } else{
  659. // No password
  660. [self readerPDF:fileName password:@""];
  661. }
  662. } else {
  663. // read file error
  664. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  665. [alertView show];
  666. }
  667. }
  668. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  669. {
  670. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  671. if (documentPDF != nil) {
  672. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  673. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  674. [self.readerPDFViewController updateContentViews];
  675. [self addChildViewController:self.readerPDFViewController];
  676. [self.view addSubview:self.readerPDFViewController.view];
  677. [self.readerPDFViewController didMoveToParentViewController:self];
  678. } else {
  679. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  680. [alertView show];
  681. }
  682. }
  683. #pragma --------------------------------------------------------------------------------------------
  684. #pragma mark ===== Delete =====
  685. #pragma --------------------------------------------------------------------------------------------
  686. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  687. {
  688. NSLog(@"[LOG] delete failure");
  689. }
  690. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  691. {
  692. // if a message for a directory of these
  693. if (![_dataSourceDirectoryID containsObject:metadataNet.metadata.directoryID])
  694. return;
  695. // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
  696. if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadataNet.metadata.fileID]) {
  697. if ([metadataNet.metadata.typeFile isEqualToString: k_metadataTypeFile_audio])
  698. [app.player.mediaPlayer stop];
  699. NSArray *viewsToRemove = [self.view subviews];
  700. for (id element in viewsToRemove) {
  701. if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]] || [element isMemberOfClass:[LMMediaPlayerView class]])
  702. [element removeFromSuperview];
  703. }
  704. self.title = @"";
  705. [self.navigationController popViewControllerAnimated:YES];
  706. } else {
  707. // only photoBrowser if exists
  708. for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
  709. CCMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  710. // ricerca index
  711. if ([metadataNet.metadata.fileID isEqualToString:metadata.fileID]) {
  712. [self.dataSourceImagesVideos removeObjectAtIndex:index];
  713. [self.photos removeObjectAtIndex:index];
  714. [self.thumbs removeObjectAtIndex:index];
  715. [self.photoBrowser reloadData];
  716. // Title
  717. if ([self.dataSourceImagesVideos count] == 0) {
  718. self.title = @"";
  719. [self.navigationController popViewControllerAnimated:YES];
  720. }
  721. break;
  722. }
  723. }
  724. }
  725. }
  726. #pragma --------------------------------------------------------------------------------------------
  727. #pragma mark ===== ButtonPressed =====
  728. #pragma --------------------------------------------------------------------------------------------
  729. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  730. {
  731. NSString *filePath;
  732. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  733. if (_sourceDirectoryLocal) {
  734. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  735. } else {
  736. filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.metadataDetail.fileNamePrint];
  737. }
  738. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  739. self.docController.delegate = self;
  740. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  741. [self.docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  742. }
  743. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  744. {
  745. [app.activeMain openWindowShare:self.metadataDetail];
  746. }
  747. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  748. {
  749. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  750. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  751. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  752. style:UIAlertActionStyleDestructive
  753. handler:^(UIAlertAction *action) {
  754. [[CCActions sharedInstance] deleteFileOrFolder:self.metadataDetail delegate:self];
  755. }]];
  756. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  757. style:UIAlertActionStyleCancel
  758. handler:^(UIAlertAction *action) {
  759. [alertController dismissViewControllerAnimated:YES completion:nil];
  760. }]];
  761. alertController.popoverPresentationController.barButtonItem = _buttonDelete;
  762. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  763. [alertController.view layoutIfNeeded];
  764. [self presentViewController:alertController animated:YES completion:NULL];
  765. }
  766. @end