CCDetail.m 45 KB

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