CCDetail.m 45 KB

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