CCDetail.m 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. //
  2. // CCDetail.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 16/01/15.
  6. // Copyright (c) 2017 Marino Faggiana. 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. #import "NCUchardet.h"
  27. #import "NCBridgeSwift.h"
  28. #import <KTVHTTPCache/KTVHTTPCache.h>
  29. #import "NCBridgeSwift.h"
  30. #define TOOLBAR_HEIGHT 49.0f
  31. #define alertRequestPasswordPDF 1
  32. @interface CCDetail () <NCTextDelegate, UIDocumentInteractionControllerDelegate>
  33. {
  34. AppDelegate *appDelegate;
  35. UIDocumentInteractionController *docController;
  36. UIBarButtonItem *buttonModifyTxt;
  37. UIBarButtonItem *buttonShare;
  38. UIBarButtonItem *buttonDelete;
  39. NSInteger indexNowVisible;
  40. NSString *fileIDNowVisible;
  41. NSMutableOrderedSet *dataSourceDirectoryID;
  42. NSString *fileNameExtension;
  43. }
  44. @end
  45. @implementation CCDetail
  46. #pragma --------------------------------------------------------------------------------------------
  47. #pragma mark ===== init =====
  48. #pragma --------------------------------------------------------------------------------------------
  49. - (id)initWithCoder:(NSCoder *)aDecoder
  50. {
  51. if (self = [super initWithCoder:aDecoder]) {
  52. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  54. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  55. self.metadataDetail = [[tableMetadata alloc] init];
  56. self.photos = [[NSMutableArray alloc] init];
  57. self.photoDataSource = [NSMutableArray new];
  58. dataSourceDirectoryID = [[NSMutableOrderedSet alloc] init];
  59. indexNowVisible = -1;
  60. fileIDNowVisible = nil;
  61. appDelegate.activeDetail = self;
  62. }
  63. return self;
  64. }
  65. #pragma --------------------------------------------------------------------------------------------
  66. #pragma mark ===== View =====
  67. #pragma --------------------------------------------------------------------------------------------
  68. - (void)viewDidLoad
  69. {
  70. [super viewDidLoad];
  71. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  72. self.imageBackground.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"logo"] multiplier:2 color:[[[NCBrandColor sharedInstance] brand] colorWithAlphaComponent:0.4]];
  73. // Change bar bottom line shadow and remove title back button <"title"
  74. self.navigationController.navigationBar.shadowImage = [CCGraphics generateSinglePixelImageWithColor:[NCBrandColor sharedInstance].brand];
  75. self.navigationController.navigationBar.topItem.title = @"";
  76. // Color Navigation Controller
  77. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  78. // TabBar
  79. self.tabBarController.tabBar.hidden = YES;
  80. self.tabBarController.tabBar.translucent = YES;
  81. // Open View
  82. if ([self.metadataDetail.fileNameView length] > 0 || [self.metadataDetail.directoryID length] > 0 || [self.metadataDetail.fileID length] > 0) {
  83. // open view
  84. [self viewFile];
  85. }
  86. }
  87. - (void)viewWillAppear:(BOOL)animated
  88. {
  89. [super viewWillAppear:animated];
  90. self.tabBarController.tabBar.hidden = YES;
  91. self.tabBarController.tabBar.translucent = YES;
  92. }
  93. - (void)viewDidDisappear:(BOOL)animated
  94. {
  95. [super viewDidDisappear:animated];
  96. // If AVPlayer in play -> Stop
  97. if (appDelegate.player != nil && appDelegate.player.rate != 0) {
  98. [appDelegate.player pause];
  99. }
  100. // remove Observer AVPlayer
  101. if (self.isMediaObserver) {
  102. self.isMediaObserver = NO;
  103. @try{
  104. [[NCViewerMedia sharedInstance] removeObserver];
  105. }@catch(id anException) { }
  106. }
  107. }
  108. - (void)changeTheming
  109. {
  110. [appDelegate changeTheming:self];
  111. if (self.toolbar) {
  112. self.toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  113. self.toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
  114. }
  115. }
  116. - (void)changeToDisplayMode
  117. {
  118. if (_readerPDFViewController)
  119. [self.readerPDFViewController updateContentViews];
  120. }
  121. #pragma --------------------------------------------------------------------------------------------
  122. #pragma mark ===== View File =====
  123. #pragma --------------------------------------------------------------------------------------------
  124. - (void)viewFile
  125. {
  126. // Remove all subview except ..
  127. //for (UIView *view in self.view.superview.subviews) {
  128. // NSInteger tag = view.tag;
  129. //}
  130. // Title
  131. self.navigationController.navigationBar.topItem.title = _metadataDetail.fileNameView;
  132. // verifico se esiste l'icona e se la posso creare
  133. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView]] == NO) {
  134. [CCGraphics createNewImageFrom:self.metadataDetail.fileNameView fileID:self.metadataDetail.fileID extension:[self.metadataDetail.fileNameView pathExtension] filterGrayScale:NO typeFile:self.metadataDetail.typeFile writeImage:YES];
  135. }
  136. // remove Observer AVPlayer
  137. if (self.isMediaObserver) {
  138. self.isMediaObserver = NO;
  139. [[NCViewerMedia sharedInstance] removeObserver];
  140. }
  141. // IMAGE
  142. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image]) {
  143. self.edgesForExtendedLayout = UIRectEdgeAll;
  144. [self viewImage];
  145. }
  146. // AUDIO VIDEO
  147. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  148. self.edgesForExtendedLayout = UIRectEdgeAll;
  149. [self createToolbar];
  150. [[NCViewerMedia sharedInstance] viewMedia:self.metadataDetail detail:self];
  151. }
  152. // DOCUMENT
  153. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  154. fileNameExtension = [[self.metadataDetail.fileNameView pathExtension] uppercaseString];
  155. if ([fileNameExtension isEqualToString:@"PDF"]) {
  156. self.edgesForExtendedLayout = UIRectEdgeBottom;
  157. [self createToolbar];
  158. [self viewPDF:@""];
  159. return;
  160. }
  161. // RichDocument
  162. if ([[NCViewerRichdocument sharedInstance] isRichDocument:self.metadataDetail]) {
  163. [[NCUtility sharedInstance] startActivityIndicatorWithView:self.view];
  164. if ([self.metadataDetail.url isEqualToString:@""]) {
  165. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
  166. [ocNetworking createLinkRichdocumentsWithFileID:self.metadataDetail.fileID success:^(NSString *link) {
  167. [[NCViewerRichdocument sharedInstance] viewRichDocumentAt:link detail:self];
  168. } failure:^(NSString *message, NSInteger errorCode) {
  169. [[NCUtility sharedInstance] stopActivityIndicator];
  170. [appDelegate messageNotification:@"_error_" description:message visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  171. [self.navigationController popViewControllerAnimated:YES];
  172. }];
  173. } else {
  174. [[NCViewerRichdocument sharedInstance] viewRichDocumentAt:self.metadataDetail.url detail:self];
  175. }
  176. return;
  177. }
  178. self.edgesForExtendedLayout = UIRectEdgeBottom;
  179. [self createToolbar];
  180. [[NCViewerDocumentWeb sharedInstance] viewDocumentWebAt:self.metadataDetail detail:self];
  181. }
  182. }
  183. #pragma --------------------------------------------------------------------------------------------
  184. #pragma mark ===== Toolbar =====
  185. #pragma --------------------------------------------------------------------------------------------
  186. - (void)createToolbar
  187. {
  188. CGFloat safeAreaBottom = 0;
  189. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadataDetail.directoryID];
  190. if (!serverUrl)
  191. return;
  192. if (@available(iOS 11, *)) {
  193. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  194. }
  195. self.toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  196. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  197. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  198. fixedSpaceMini.width = 25;
  199. buttonModifyTxt = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetModify"] style:UIBarButtonItemStylePlain target:self action:@selector(modifyTxtButtonPressed:)];
  200. if (![NCBrandOptions sharedInstance].disable_openin_file) {
  201. self.buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"openFile"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  202. }
  203. buttonShare = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"share"] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  204. buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
  205. if ([CCUtility isDocumentModifiableExtension:fileNameExtension]) {
  206. if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) // E2EE
  207. [self.toolbar setItems:[NSArray arrayWithObjects: buttonModifyTxt, flexible, buttonDelete, fixedSpaceMini, self.buttonAction, nil]];
  208. else
  209. [self.toolbar setItems:[NSArray arrayWithObjects: buttonModifyTxt, flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, self.buttonAction, nil]];
  210. } else {
  211. if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) // E2EE
  212. [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, self.buttonAction, nil]];
  213. else
  214. [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, self.buttonAction, nil]];
  215. }
  216. [self.toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  217. self.toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  218. self.toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
  219. [self.view addSubview:self.toolbar];
  220. }
  221. #pragma --------------------------------------------------------------------------------------------
  222. #pragma mark ===== View Image =====
  223. #pragma --------------------------------------------------------------------------------------------
  224. - (void)viewImage
  225. {
  226. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  227. indexNowVisible = -1;
  228. fileIDNowVisible = nil;
  229. [self.photos removeAllObjects];
  230. [dataSourceDirectoryID removeAllObjects];
  231. // if not images, exit
  232. if ([self.photoDataSource count] == 0)
  233. return;
  234. // test
  235. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadataDetail.directoryID];
  236. if (!serverUrl)
  237. return;
  238. NSUInteger index = 0;
  239. for (tableMetadata *metadata in self.photoDataSource) {
  240. // start from here ?
  241. if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
  242. [self.photoBrowser setCurrentPhotoIndex:index];
  243. [self.photos addObject:[MWPhoto photoWithImage:nil]];
  244. // add directory
  245. [dataSourceDirectoryID addObject:metadata.directoryID];
  246. index++;
  247. }
  248. // PhotoBrowser
  249. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  250. self.photoBrowser.displayActionButton = NO;
  251. } else {
  252. self.photoBrowser.displayActionButton = YES;
  253. }
  254. self.photoBrowser.displayDeleteButton = YES;
  255. if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) // E2EE
  256. self.photoBrowser.displayShareButton = NO;
  257. else
  258. self.photoBrowser.displayShareButton = YES;
  259. self.photoBrowser.displayNavArrows = YES;
  260. self.photoBrowser.displaySelectionButtons = NO;
  261. self.photoBrowser.alwaysShowControls = NO;
  262. self.photoBrowser.zoomPhotosToFill = NO;
  263. self.photoBrowser.autoPlayOnAppear = NO;
  264. self.photoBrowser.delayToHideElements = 15;
  265. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
  266. self.photoBrowser.enableSwipeToDismiss = NO;
  267. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  268. [self addChildViewController:self.photoBrowser];
  269. [self.view addSubview:self.photoBrowser.view];
  270. [self.photoBrowser didMoveToParentViewController:self];
  271. } else {
  272. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  273. }
  274. }
  275. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  276. {
  277. return [self.photoDataSource count];
  278. }
  279. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  280. {
  281. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  282. NSString *titleDir = metadata.fileNameView;
  283. self.title = titleDir;
  284. return titleDir;
  285. }
  286. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  287. {
  288. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  289. indexNowVisible = index;
  290. fileIDNowVisible = metadata.fileID;
  291. photoBrowser.toolbar.hidden = NO;
  292. // Download image ?
  293. if (metadata) {
  294. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  295. NSInteger status;
  296. tableMetadata *metadataDB = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
  297. if (metadataDB) {
  298. status = metadataDB.status;
  299. } else {
  300. status = k_metadataStatusNormal;
  301. }
  302. if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView] == NO && status == k_metadataStatusNormal) {
  303. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]] == NO) {
  304. [CCGraphics addImageToTitle:NSLocalizedString(@"_...loading..._", nil) colorTitle:[NCBrandColor sharedInstance].brandText imageTitle:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"load"] multiplier:2 color:[NCBrandColor sharedInstance].brandText] imageRight:NO navigationItem:self.navigationItem];
  305. CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
  306. CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
  307. OCnetworking *ocNetworking = [[OCnetworking alloc] initWithDelegate:nil metadataNet:nil withUser:appDelegate.activeUser withUserID:appDelegate.activeUserID withPassword:appDelegate.activePassword withUrl:appDelegate.activeUrl];
  308. [ocNetworking downloadPreviewWithMetadata:metadata serverUrl:serverUrl withWidth:width andHeight:height completion:^(NSString *message, NSInteger errorCode) {
  309. self.navigationItem.titleView = nil;
  310. self.title = metadata.fileNameView;
  311. [self.photoBrowser reloadData];
  312. }];
  313. } else {
  314. [self downloadPhotoBrowser:metadata serverUrl:serverUrl];
  315. }
  316. }
  317. }
  318. // Title
  319. if (metadata)
  320. self.title = metadata.fileNameView;
  321. }
  322. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  323. {
  324. UIImage *image;
  325. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  326. if (index < self.photos.count) {
  327. if (metadata.fileID) {
  328. UIImage *imagePreview = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  329. // if (!imagePreview) imagePreview = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"file_photo"] multiplier:3 color:[[NCBrandColor sharedInstance] icon]];
  330. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  331. NSString *fileImage = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView];
  332. NSString *ext = [CCUtility getExtension:metadata.fileNameView];
  333. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  334. else image = [UIImage imageWithContentsOfFile:fileImage];
  335. if (image) {
  336. MWPhoto *photo = [MWPhoto photoWithImage:image];
  337. // Location ??
  338. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  339. [self.photos replaceObjectAtIndex:index withObject:photo];
  340. } else {
  341. if (metadata.status == k_metadataStatusDownloadError) {
  342. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  343. } else {
  344. if (imagePreview)
  345. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  346. }
  347. }
  348. }
  349. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  350. if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
  351. NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  352. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  353. video.videoURL = url;
  354. [self.photos replaceObjectAtIndex:index withObject:video];
  355. } else {
  356. if (metadata.status == k_metadataStatusDownloadError) {
  357. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  358. } else {
  359. if (imagePreview)
  360. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  361. }
  362. }
  363. }
  364. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  365. if ([CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView]) {
  366. MWPhoto *audio;
  367. UIImage *audioImage;
  368. NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  369. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]]) {
  370. audioImage = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  371. } else {
  372. audioImage = [UIImage imageNamed:@"notaMusic"]; //[CCGraphics scaleImage:[UIImage imageNamed:@"notaMusic"] toSize:CGSizeMake(200, 200) isAspectRation:YES];
  373. }
  374. audio = [MWPhoto photoWithImage:audioImage];
  375. audio.videoURL = url;
  376. [self.photos replaceObjectAtIndex:index withObject:audio];
  377. } else {
  378. if (metadata.status == k_metadataStatusDownloadError) {
  379. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  380. } else {
  381. if (imagePreview)
  382. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  383. }
  384. }
  385. }
  386. }
  387. // energy saving memory
  388. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  389. int iPrev = (int)index - 2;
  390. if (iPrev >= 0) {
  391. if ([self.photos objectAtIndex:iPrev] != nil)
  392. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  393. }
  394. int iNext = (int)index + 2;
  395. if (iNext < _photos.count) {
  396. if ([self.photos objectAtIndex:iNext] != nil)
  397. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  398. }
  399. });
  400. return [self.photos objectAtIndex:index];
  401. }
  402. return nil;
  403. }
  404. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  405. {
  406. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  407. if (metadata == nil) return;
  408. docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileNameView:metadata.fileNameView]]];
  409. docController.delegate = self;
  410. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  411. [docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  412. [docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  413. }
  414. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  415. {
  416. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  417. [appDelegate.activeMain openWindowShare:metadata];
  418. }
  419. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  420. {
  421. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  422. if (metadata == nil || [CCUtility fileProviderStorageExists:metadata.fileID fileNameView:metadata.fileNameView] == NO) {
  423. [appDelegate messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  424. return;
  425. }
  426. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  427. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  428. style:UIAlertActionStyleDestructive
  429. handler:^(UIAlertAction *action) {
  430. [self deleteFile:metadata];
  431. }]];
  432. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  433. style:UIAlertActionStyleCancel
  434. handler:^(UIAlertAction *action) {
  435. }]];
  436. alertController.popoverPresentationController.barButtonItem = deleteButton;
  437. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  438. [alertController.view layoutIfNeeded];
  439. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  440. }
  441. - (void)photoBrowserDidFinishPresentation:(MWPhotoBrowser *)photoBrowser
  442. {
  443. [self.navigationController popViewControllerAnimated:YES];
  444. }
  445. - (void)triggerProgressTask:(NSNotification *)notification
  446. {
  447. /*
  448. NSDictionary *dict = notification.userInfo;
  449. NSString *fileID = [dict valueForKey:@"fileID"];
  450. //NSString *serverUrl = [dict valueForKey:@"serverUrl"];
  451. //long status = [[dict valueForKey:@"status"] longValue];
  452. float progress = [[dict valueForKey:@"progress"] floatValue];
  453. //long long totalBytes = [[dict valueForKey:@"totalBytes"] longLongValue];
  454. //long long totalBytesExpected = [[dict valueForKey:@"totalBytesExpected"] longLongValue];
  455. if ([fileID isEqualToString:_fileIDNowVisible])
  456. [_hud progress:progress];
  457. */
  458. }
  459. - (void)downloadPhotoBrowserSuccessFailure:(tableMetadata *)metadata selector:(NSString *)selector errorCode:(NSInteger)errorCode
  460. {
  461. // if a message for a directory of these
  462. if (![metadata.fileID isEqualToString:fileIDNowVisible])
  463. return;
  464. // Title
  465. self.navigationItem.titleView = nil;
  466. self.title = metadata.fileNameView;
  467. if (errorCode == 0) {
  468. // verifico se esiste l'icona e se la posso creare
  469. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]] == NO) {
  470. [CCGraphics createNewImageFrom:metadata.fileNameView fileID:metadata.fileID extension:[metadata.fileNameView pathExtension] filterGrayScale:NO typeFile:metadata.typeFile writeImage:YES];
  471. }
  472. [self.photoBrowser reloadData];
  473. } else {
  474. [appDelegate messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  475. [self.navigationController popViewControllerAnimated:YES];
  476. }
  477. }
  478. - (void)downloadPhotoBrowser:(tableMetadata *)metadata serverUrl:(NSString *)serverUrl
  479. {
  480. tableMetadata *metadataForDownload = [[NCManageDatabase sharedInstance] initNewMetadata:metadata];
  481. metadataForDownload.session = k_download_session;
  482. metadataForDownload.sessionError = @"";
  483. metadataForDownload.sessionSelector = selectorLoadViewImage;
  484. metadataForDownload.status = k_metadataStatusWaitDownload;
  485. // Add Metadata for Download
  486. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForDownload];
  487. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  488. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:metadataForDownload.fileID action:k_action_MOD];
  489. [CCGraphics addImageToTitle:NSLocalizedString(@"_...loading..._", nil) colorTitle:[NCBrandColor sharedInstance].brandText imageTitle:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"load"] multiplier:2 color:[NCBrandColor sharedInstance].brandText] imageRight:NO navigationItem:self.navigationItem];
  490. }
  491. - (void)insertGeocoderLocation:(NSNotification *)notification
  492. {
  493. if (notification.userInfo.count == 0)
  494. return;
  495. NSString *fileID = [[notification.userInfo allKeys] objectAtIndex:0];
  496. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  497. // test [Chrash V 1.14,15]
  498. if (indexNowVisible >= [self.photos count])
  499. return;
  500. if ([fileID isEqualToString:fileIDNowVisible]) {
  501. MWPhoto *photo = [self.photos objectAtIndex:indexNowVisible];
  502. [self setLocationCaptionPhoto:photo fileID:fileID];
  503. [self.photoBrowser reloadData];
  504. }
  505. }
  506. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  507. {
  508. tableLocalFile *localFile;
  509. // read Geocoder
  510. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
  511. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  512. // Fix BUG Geo latitude & longitude
  513. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  514. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
  515. if (metadata) {
  516. [[CCExifGeo sharedInstance] setExifLocalTableEtag:metadata];
  517. }
  518. }
  519. [[CCExifGeo sharedInstance] setGeocoderEtag:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  520. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", fileID]];
  521. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  522. NSString *location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  523. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  524. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  525. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  526. }
  527. }
  528. }
  529. }
  530. #pragma --------------------------------------------------------------------------------------------
  531. #pragma mark ===== View PDF =====
  532. #pragma --------------------------------------------------------------------------------------------
  533. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  534. {
  535. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  536. [[alertView textFieldAtIndex:0] resignFirstResponder];
  537. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  538. }
  539. - (void)viewPDF:(NSString *)password
  540. {
  541. // remove cache PDF
  542. NSString *filePlistReader = [NSString stringWithFormat:@"%@/%@.plist", [CCUtility getDirectoryReaderMetadata], self.metadataDetail.fileNameView.stringByDeletingPathExtension];
  543. [CCUtility removeFileAtPath:filePlistReader];
  544. NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView];
  545. if ([CCUtility fileProviderStorageExists:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView] == NO) {
  546. // read file error
  547. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  548. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  549. [alertController addAction:okAction];
  550. [self presentViewController:alertController animated:YES completion:nil];
  551. }
  552. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileNamePath]);
  553. if (pdf) {
  554. // Encrypted
  555. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  556. // Try a blank password first, per Apple's Quartz PDF example
  557. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  558. // blank password
  559. [self readerPDF:fileNamePath password:@""];
  560. } else {
  561. if ([password length] == 0) {
  562. // password request
  563. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  564. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  565. alertView.tag = alertRequestPasswordPDF;
  566. [alertView show];
  567. } else {
  568. const char *key = [password UTF8String];
  569. // failure
  570. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  571. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  572. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  573. [alertController addAction:okAction];
  574. [self presentViewController:alertController animated:YES completion:nil];
  575. } else {
  576. // pdf with password
  577. [self readerPDF:fileNamePath password:password];
  578. }
  579. }
  580. }
  581. } else{
  582. // No password
  583. [self readerPDF:fileNamePath password:@""];
  584. }
  585. } else {
  586. // read file error
  587. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  588. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  589. [alertController addAction:okAction];
  590. [self presentViewController:alertController animated:YES completion:nil];
  591. }
  592. }
  593. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  594. {
  595. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  596. CGFloat safeAreaBottom = 0;
  597. if (@available(iOS 11, *)) {
  598. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  599. }
  600. if (documentPDF != nil) {
  601. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  602. self.readerPDFViewController.delegate = self;
  603. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  604. [self.readerPDFViewController updateContentViews];
  605. [self addChildViewController:self.readerPDFViewController];
  606. [self.view addSubview:self.readerPDFViewController.view];
  607. [self.readerPDFViewController didMoveToParentViewController:self];
  608. } else {
  609. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  610. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  611. [alertController addAction:okAction];
  612. [self presentViewController:alertController animated:YES completion:nil];
  613. }
  614. }
  615. - (void)handleSingleTapReader
  616. {
  617. UILayoutGuide *layoutGuide;
  618. CGFloat safeAreaTop = 0;
  619. CGFloat safeAreaBottom = 0;
  620. if (@available(iOS 11, *)) {
  621. layoutGuide = [UIApplication sharedApplication].delegate.window.safeAreaLayoutGuide;
  622. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  623. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  624. }
  625. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  626. self.toolbar.hidden = !self.toolbar.isHidden;
  627. if (self.toolbar.isHidden) {
  628. self.readerPDFViewController.view.frame = CGRectMake(0, safeAreaTop, self.view.bounds.size.width, self.view.bounds.size.height - safeAreaTop - safeAreaBottom);
  629. } else {
  630. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  631. }
  632. [self.readerPDFViewController updateContentViews];
  633. }
  634. - (void)handleSwipeUpDown
  635. {
  636. // REMOVE IT'S UNUSABLE
  637. /*
  638. self.navigationController.navigationBarHidden = false; // iOS App is unusable after swipe up or down with PDF in fullscreen #526
  639. [self removeAllView];
  640. [self.navigationController popViewControllerAnimated:YES];
  641. */
  642. }
  643. #pragma --------------------------------------------------------------------------------------------
  644. #pragma mark ===== Delete =====
  645. #pragma --------------------------------------------------------------------------------------------
  646. - (void)deleteFile:(tableMetadata *)metadata
  647. {
  648. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  649. tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND e2eEncrypted == 1 AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
  650. [[NCMainCommon sharedInstance ] deleteFileWithMetadatas:[[NSArray alloc] initWithObjects:metadata, nil] e2ee:tableDirectory.e2eEncrypted serverUrl:serverUrl folderFileID:tableDirectory.fileID completion:^(NSInteger errorCode, NSString *message) {
  651. if (errorCode == 0) {
  652. // reload data source
  653. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:serverUrl fileID:metadata.fileID action:k_action_DEL];
  654. // Not image
  655. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] == NO) {
  656. // exit
  657. [self.navigationController popViewControllerAnimated:YES];
  658. } else {
  659. for (NSUInteger index=0; index < [self.photoDataSource count] && _photoBrowser; index++ ) {
  660. tableMetadata *metadataTemp = [self.photoDataSource objectAtIndex:index];
  661. if ([metadata isInvalidated] || [metadataTemp.fileID isEqualToString:metadata.fileID]) {
  662. [self.photoDataSource removeObjectAtIndex:index];
  663. [self.photos removeObjectAtIndex:index];
  664. [self.photoBrowser reloadData];
  665. // exit
  666. if ([self.photoDataSource count] == 0) {
  667. [self.navigationController popViewControllerAnimated:YES];
  668. }
  669. }
  670. }
  671. }
  672. } else {
  673. NSLog(@"[LOG] DeleteFileOrFolder failure error %d, %@", (int)errorCode, message);
  674. }
  675. }];
  676. }
  677. #pragma --------------------------------------------------------------------------------------------
  678. #pragma mark ===== ButtonPressed =====
  679. #pragma --------------------------------------------------------------------------------------------
  680. - (void)dismissTextView
  681. {
  682. if (self.webView) {
  683. NSString *fileNamePath = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNameView];
  684. [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
  685. [[NSFileManager defaultManager] linkItemAtPath:[CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView] toPath:fileNamePath error:nil];
  686. [self.webView reload];
  687. }
  688. }
  689. - (void)modifyTxtButtonPressed:(UIBarButtonItem *)sender
  690. {
  691. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", self.metadataDetail.fileID]];
  692. if (metadata) {
  693. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
  694. NCText *viewController = (NCText *)navigationController.topViewController;
  695. viewController.metadata = metadata;
  696. viewController.delegate = self;
  697. navigationController.modalPresentationStyle = UIModalPresentationPageSheet;
  698. navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  699. [self presentViewController:navigationController animated:YES completion:nil];
  700. }
  701. }
  702. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  703. {
  704. if ([self.metadataDetail.fileNameView length] == 0) return;
  705. NSString *filePath = [CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView];
  706. docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  707. docController.delegate = self;
  708. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  709. [docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  710. [docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  711. }
  712. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  713. {
  714. [appDelegate.activeMain openWindowShare:self.metadataDetail];
  715. }
  716. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  717. {
  718. if ([self.metadataDetail.fileNameView length] == 0) return;
  719. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  720. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  721. style:UIAlertActionStyleDestructive
  722. handler:^(UIAlertAction *action) {
  723. [self deleteFile:self.metadataDetail];
  724. }]];
  725. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  726. style:UIAlertActionStyleCancel
  727. handler:^(UIAlertAction *action) {
  728. [alertController dismissViewControllerAnimated:YES completion:nil];
  729. }]];
  730. alertController.popoverPresentationController.barButtonItem = buttonDelete;
  731. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  732. [alertController.view layoutIfNeeded];
  733. [self presentViewController:alertController animated:YES completion:NULL];
  734. }
  735. @end