CCDetail.m 44 KB

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