CCDetail.m 45 KB

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