CCDetail.m 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  1. //
  2. // CCDetail.m
  3. // Nextcloud iOS
  4. //
  5. // Created by Marino Faggiana on 16/01/15.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCDetail.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "NCUchardet.h"
  27. #import "NCBridgeSwift.h"
  28. #define TOOLBAR_HEIGHT 49.0f
  29. #define alertRequestPasswordPDF 1
  30. @interface CCDetail ()
  31. {
  32. AppDelegate *appDelegate;
  33. UIToolbar *_toolbar;
  34. UIBarButtonItem *_buttonModifyTxt;
  35. UIBarButtonItem *_buttonAction;
  36. UIBarButtonItem *_buttonShare;
  37. UIBarButtonItem *_buttonDelete;
  38. NSInteger _indexNowVisible;
  39. NSString *_fileIDNowVisible;
  40. NSMutableOrderedSet *_dataSourceDirectoryID;
  41. NSString *_fileNameExtension;
  42. }
  43. @end
  44. @implementation CCDetail
  45. #pragma --------------------------------------------------------------------------------------------
  46. #pragma mark ===== init =====
  47. #pragma --------------------------------------------------------------------------------------------
  48. - (id)initWithCoder:(NSCoder *)aDecoder
  49. {
  50. if (self = [super initWithCoder:aDecoder]) {
  51. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  52. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  53. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  54. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(backNavigationController) name:@"detailBack" object:nil];
  55. self.metadataDetail = [[tableMetadata alloc] init];
  56. self.photos = [[NSMutableArray alloc] init];
  57. self.dataSourceImagesVideos = [[NSMutableArray alloc] init];
  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
  74. self.navigationController.navigationBar.shadowImage = [CCGraphics generateSinglePixelImageWithColor:[NCBrandColor sharedInstance].brand];
  75. if ([self.metadataDetail.fileNameView length] > 0 || [self.metadataDetail.directoryID length] > 0 || [self.metadataDetail.fileID length] > 0) {
  76. // open view
  77. [self viewFile];
  78. }
  79. }
  80. // Apparirà
  81. - (void)viewWillAppear:(BOOL)animated
  82. {
  83. [super viewWillAppear:animated];
  84. if (self.splitViewController.isCollapsed) {
  85. self.tabBarController.tabBar.hidden = YES;
  86. self.tabBarController.tabBar.translucent = YES;
  87. }
  88. if (self.splitViewController.isCollapsed)
  89. [appDelegate plusButtonVisibile:false];
  90. }
  91. // E' scomparso
  92. - (void)viewDidDisappear:(BOOL)animated
  93. {
  94. [super viewDidDisappear:animated];
  95. // remove all
  96. if (self.isMovingFromParentViewController)
  97. [self removeAllView];
  98. }
  99. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  100. {
  101. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  102. }];
  103. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  104. }
  105. // remove all view
  106. - (void)removeAllView
  107. {
  108. // Document
  109. if (_webView) {
  110. [_webView removeFromSuperview];
  111. _webView = nil;
  112. }
  113. // PDF
  114. if (_readerPDFViewController) {
  115. [_readerPDFViewController.view removeFromSuperview];
  116. _readerPDFViewController.delegate = nil;
  117. _readerPDFViewController = nil;
  118. }
  119. // Photo-Video-Audio
  120. if (_photoBrowser) {
  121. [_photos removeAllObjects];
  122. _photoBrowser.delegate = nil;
  123. _photoBrowser = nil;
  124. }
  125. // ToolBar
  126. if (_toolbar) {
  127. [_toolbar removeFromSuperview];
  128. _toolbar = nil;
  129. }
  130. // Title
  131. self.title = nil;
  132. }
  133. - (void)backNavigationController
  134. {
  135. [self removeAllView];
  136. [self.navigationController popViewControllerAnimated:NO];
  137. }
  138. - (void)changeToDisplayMode
  139. {
  140. if (_readerPDFViewController)
  141. [self.readerPDFViewController updateContentViews];
  142. }
  143. - (void)createToolbar
  144. {
  145. CGFloat safeAreaBottom = 0;
  146. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadataDetail.directoryID];
  147. if (!serverUrl)
  148. return;
  149. if (@available(iOS 11, *)) {
  150. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  151. }
  152. _toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  153. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  154. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  155. fixedSpaceMini.width = 25;
  156. _buttonModifyTxt = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetModify"] style:UIBarButtonItemStylePlain target:self action:@selector(modifyTxtButtonPressed:)];
  157. _buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"openFile"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  158. _buttonShare = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"share"] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  159. _buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
  160. if ([CCUtility isDocumentModifiableExtension:_fileNameExtension]) {
  161. if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) // E2EE
  162. [_toolbar setItems:[NSArray arrayWithObjects: _buttonModifyTxt, flexible, _buttonDelete, fixedSpaceMini, _buttonAction, nil]];
  163. else
  164. [_toolbar setItems:[NSArray arrayWithObjects: _buttonModifyTxt, flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  165. } else {
  166. if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) // E2EE
  167. [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonAction, nil]];
  168. else
  169. [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  170. }
  171. [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  172. _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  173. _toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
  174. [self.view addSubview:_toolbar];
  175. }
  176. - (void)changeTheming
  177. {
  178. [appDelegate changeTheming:self];
  179. if (_toolbar) {
  180. _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  181. _toolbar.tintColor = [NCBrandColor sharedInstance].brandElement;
  182. }
  183. }
  184. #pragma --------------------------------------------------------------------------------------------
  185. #pragma mark ===== View File =====
  186. #pragma --------------------------------------------------------------------------------------------
  187. - (void)viewFile
  188. {
  189. // verifico se esiste l'icona e se la posso creare
  190. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:self.metadataDetail.fileID fileNameView:self.metadataDetail.fileNameView]] == NO) {
  191. [CCGraphics createNewImageFrom:self.metadataDetail.fileNameView fileID:self.metadataDetail.fileID extension:[self.metadataDetail.fileNameView pathExtension] size:@"m" imageForUpload:NO typeFile:self.metadataDetail.typeFile writeImage:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
  192. }
  193. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  194. self.edgesForExtendedLayout = UIRectEdgeAll;
  195. [self viewImageVideoAudio];
  196. }
  197. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  198. _fileNameExtension = [[self.metadataDetail.fileNameView pathExtension] uppercaseString];
  199. if ([_fileNameExtension isEqualToString:@"PDF"]) {
  200. self.edgesForExtendedLayout = UIRectEdgeBottom;
  201. [self viewPDF:@""];
  202. [self createToolbar];
  203. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  204. } else {
  205. self.edgesForExtendedLayout = UIRectEdgeBottom;
  206. [self viewDocument];
  207. [self createToolbar];
  208. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  209. }
  210. }
  211. }
  212. #pragma --------------------------------------------------------------------------------------------
  213. #pragma mark ===== View Document =====
  214. #pragma --------------------------------------------------------------------------------------------
  215. - (void)viewDocument
  216. {
  217. CGFloat safeAreaBottom = 0;
  218. if (@available(iOS 11, *)) {
  219. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  220. }
  221. if ([CCUtility fileProviderStorageExists:self.metadataDetail.fileID fileName:self.metadataDetail.fileNameView] == NO) {
  222. [self backNavigationController];
  223. return;
  224. }
  225. NSString *fileNamePath = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNameView];
  226. [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
  227. [[NSFileManager defaultManager] linkItemAtPath:[CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileName:self.metadataDetail.fileNameView] toPath:fileNamePath error:nil];
  228. NSURL *url = [NSURL fileURLWithPath:fileNamePath];
  229. WKPreferences *wkPreferences = [[WKPreferences alloc] init];
  230. wkPreferences.javaScriptEnabled = true;
  231. WKWebViewConfiguration *wkConfig = [[WKWebViewConfiguration alloc] init];
  232. wkConfig.preferences = wkPreferences;
  233. self.webView = [[WKWebView alloc] initWithFrame:(CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom)) configuration:wkConfig];
  234. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  235. [self.webView setBackgroundColor:[NCBrandColor sharedInstance].backgroundView];
  236. [self.webView setOpaque:NO];
  237. if ( [_fileNameExtension isEqualToString:@"CSS"] || [_fileNameExtension isEqualToString:@"PY"] || [_fileNameExtension isEqualToString:@"XML"] || [_fileNameExtension isEqualToString:@"JS"] ) {
  238. NSString *dataFile = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:url] encoding:NSASCIIStringEncoding];
  239. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  240. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"40",@"Sans-Serif",dataFile] baseURL:nil];
  241. }else{
  242. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"20",@"Sans-Serif",dataFile] baseURL:nil];
  243. }
  244. } else if ([CCUtility isDocumentModifiableExtension:_fileNameExtension]) {
  245. NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  246. NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
  247. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:url];
  248. [headRequest setHTTPMethod:@"HEAD"];
  249. NSURLSessionDataTask *task = [session dataTaskWithRequest:headRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  250. dispatch_async(dispatch_get_main_queue(), ^{
  251. NSString *encodingName = [[NCUchardet sharedNUCharDet] encodingStringDetectWithData:data];
  252. [self.webView loadData:[NSData dataWithContentsOfURL: url] MIMEType:response.MIMEType characterEncodingName:encodingName baseURL:url];
  253. });
  254. }];
  255. [task resume];
  256. } else {
  257. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:url]];
  258. }
  259. [self.view addSubview:self.webView];
  260. }
  261. #pragma --------------------------------------------------------------------------------------------
  262. #pragma mark ===== View Image =====
  263. #pragma --------------------------------------------------------------------------------------------
  264. - (void)viewImageVideoAudio
  265. {
  266. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  267. _indexNowVisible = -1;
  268. _fileIDNowVisible = nil;
  269. [self.photos removeAllObjects];
  270. [_dataSourceDirectoryID removeAllObjects];
  271. // if not images, exit
  272. if ([self.dataSourceImagesVideos count] == 0)
  273. return;
  274. // test
  275. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:_metadataDetail.directoryID];
  276. if (!serverUrl)
  277. return;
  278. NSUInteger index = 0;
  279. for (tableMetadata *metadata in self.dataSourceImagesVideos) {
  280. // start from here ?
  281. if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
  282. [self.photoBrowser setCurrentPhotoIndex:index];
  283. [self.photos addObject:[MWPhoto photoWithImage:nil]];
  284. // add directory
  285. [_dataSourceDirectoryID addObject:metadata.directoryID];
  286. index++;
  287. }
  288. // PhotoBrowser
  289. self.photoBrowser.displayActionButton = YES;
  290. self.photoBrowser.displayDeleteButton = YES;
  291. if ([CCUtility isFolderEncrypted:serverUrl account:appDelegate.activeAccount]) // E2EE
  292. self.photoBrowser.displayShareButton = NO;
  293. else
  294. self.photoBrowser.displayShareButton = YES;
  295. self.photoBrowser.displayNavArrows = YES;
  296. self.photoBrowser.displaySelectionButtons = NO;
  297. self.photoBrowser.alwaysShowControls = NO;
  298. self.photoBrowser.zoomPhotosToFill = NO;
  299. self.photoBrowser.autoPlayOnAppear = NO;
  300. self.photoBrowser.delayToHideElements = 15;
  301. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
  302. self.photoBrowser.enableSwipeToDismiss = NO;
  303. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  304. [self addChildViewController:self.photoBrowser];
  305. [self.view addSubview:self.photoBrowser.view];
  306. [self.photoBrowser didMoveToParentViewController:self];
  307. } else {
  308. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  309. }
  310. }
  311. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  312. {
  313. return [self.dataSourceImagesVideos count];
  314. }
  315. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  316. {
  317. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  318. NSString *titleDir = metadata.fileNameView;
  319. self.title = titleDir;
  320. return titleDir;
  321. }
  322. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  323. {
  324. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  325. _indexNowVisible = index;
  326. _fileIDNowVisible = metadata.fileID;
  327. photoBrowser.toolbar.hidden = NO;
  328. // Download image ?
  329. if (metadata) {
  330. tableMetadata *metadataDB = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID == %@", metadata.fileID]];
  331. if ([CCUtility fileProviderStorageExists:metadata.fileID fileName:metadata.fileNameView] == NO && metadataDB.status == k_metadataStatusNormal) {
  332. [self downloadPhotoBrowser:metadata];
  333. }
  334. }
  335. // Title
  336. if (metadata)
  337. self.title = metadata.fileNameView;
  338. }
  339. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  340. {
  341. UIImage *image;
  342. // UIImage *loadingGIF = [UIImage animatedImageWithAnimatedGIFURL:[[NSBundle mainBundle] URLForResource:@"loading" withExtension:@"gif"]];
  343. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  344. if (index < self.photos.count) {
  345. if (metadata.fileID) {
  346. UIImage *imagePreview = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  347. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  348. if (!imagePreview) imagePreview = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"file_photo"] multiplier:3 color:[[NCBrandColor sharedInstance] icon]];
  349. NSString *fileImage = [CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileName:metadata.fileNameView];
  350. NSString *ext = [CCUtility getExtension:metadata.fileNameView];
  351. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  352. else image = [UIImage imageWithContentsOfFile:fileImage];
  353. if (image) {
  354. MWPhoto *photo = [MWPhoto photoWithImage:image];
  355. // Location ??
  356. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  357. [self.photos replaceObjectAtIndex:index withObject:photo];
  358. } else {
  359. if (metadata.status == k_metadataStatusDownloadError) {
  360. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  361. } else {
  362. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  363. }
  364. }
  365. }
  366. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  367. if (!imagePreview) imagePreview = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"file_photo"] multiplier:3 color:[[NCBrandColor sharedInstance] icon]];
  368. if ([CCUtility fileProviderStorageExists:metadata.fileID fileName:metadata.fileNameView]) {
  369. NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileName:metadata.fileNameView]];
  370. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  371. video.videoURL = url;
  372. [self.photos replaceObjectAtIndex:index withObject:video];
  373. } else {
  374. if (metadata.status == k_metadataStatusDownloadError) {
  375. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  376. } else {
  377. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  378. }
  379. }
  380. }
  381. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  382. if (!imagePreview) imagePreview = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"file_audio"] multiplier:3 color:[[NCBrandColor sharedInstance] icon]];
  383. if ([CCUtility fileProviderStorageExists:metadata.fileID fileName:metadata.fileNameView]) {
  384. MWPhoto *audio;
  385. UIImage *audioImage;
  386. NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileName:metadata.fileNameView]];
  387. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]]) {
  388. audioImage = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]];
  389. } else {
  390. audioImage = [UIImage imageNamed:@"notaMusic"]; //[CCGraphics scaleImage:[UIImage imageNamed:@"notaMusic"] toSize:CGSizeMake(200, 200) isAspectRation:YES];
  391. }
  392. audio = [MWPhoto photoWithImage:audioImage];
  393. audio.videoURL = url;
  394. [self.photos replaceObjectAtIndex:index withObject:audio];
  395. } else {
  396. if (metadata.status == k_metadataStatusDownloadError) {
  397. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  398. } else {
  399. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  400. }
  401. }
  402. }
  403. }
  404. // energy saving memory
  405. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  406. int iPrev = (int)index - 2;
  407. if (iPrev >= 0) {
  408. if ([self.photos objectAtIndex:iPrev] != nil)
  409. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  410. }
  411. int iNext = (int)index + 2;
  412. if (iNext < _photos.count) {
  413. if ([self.photos objectAtIndex:iNext] != nil)
  414. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  415. }
  416. });
  417. return [self.photos objectAtIndex:index];
  418. }
  419. return nil;
  420. }
  421. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  422. {
  423. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  424. if (metadata == nil) return;
  425. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageFileID:metadata.fileID fileName:metadata.fileNameView]]];
  426. self.docController.delegate = self;
  427. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  428. [self.docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  429. [self.docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  430. }
  431. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  432. {
  433. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  434. [appDelegate.activeMain openWindowShare:metadata];
  435. }
  436. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  437. {
  438. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  439. if (metadata == nil || [CCUtility fileProviderStorageExists:metadata.fileID fileName:metadata.fileNameView] == NO) {
  440. [appDelegate messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  441. return;
  442. }
  443. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  444. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  445. style:UIAlertActionStyleDestructive
  446. handler:^(UIAlertAction *action) {
  447. [self deleteFile:metadata];
  448. }]];
  449. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  450. style:UIAlertActionStyleCancel
  451. handler:^(UIAlertAction *action) {
  452. }]];
  453. alertController.popoverPresentationController.barButtonItem = deleteButton;
  454. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  455. [alertController.view layoutIfNeeded];
  456. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  457. }
  458. - (void)photoBrowserDidFinishPresentation:(MWPhotoBrowser *)photoBrowser
  459. {
  460. [self removeAllView];
  461. [self.navigationController popViewControllerAnimated:YES];
  462. }
  463. - (void)triggerProgressTask:(NSNotification *)notification
  464. {
  465. NSDictionary *dict = notification.userInfo;
  466. NSString *fileID = [dict valueForKey:@"fileID"];
  467. //NSString *serverUrl = [dict valueForKey:@"serverUrl"];
  468. //long status = [[dict valueForKey:@"status"] longValue];
  469. float progress = [[dict valueForKey:@"progress"] floatValue];
  470. //long long totalBytes = [[dict valueForKey:@"totalBytes"] longLongValue];
  471. //long long totalBytesExpected = [[dict valueForKey:@"totalBytesExpected"] longLongValue];
  472. // if ([fileID isEqualToString:_fileIDNowVisible])
  473. // [_hud progress:progress];
  474. }
  475. - (void)downloadPhotoBrowserSuccessFailure:(tableMetadata *)metadata selector:(NSString *)selector errorCode:(NSInteger)errorCode
  476. {
  477. // if a message for a directory of these
  478. if (![metadata.fileID isEqualToString:_fileIDNowVisible])
  479. return;
  480. if (errorCode == 0) {
  481. // verifico se esiste l'icona e se la posso creare
  482. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconFileID:metadata.fileID fileNameView:metadata.fileNameView]] == NO)
  483. [CCGraphics createNewImageFrom:metadata.fileNameView fileID:metadata.fileID extension:[metadata.fileNameView pathExtension] size:@"m" imageForUpload:NO typeFile:metadata.typeFile writeImage:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
  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 backNavigationController];
  488. }
  489. }
  490. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  491. {
  492. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  493. if (serverUrl) {
  494. metadata.session = k_download_session;
  495. metadata.sessionError = @"";
  496. metadata.sessionSelector = selectorLoadViewImage;
  497. metadata.status = k_metadataStatusWaitDownload;
  498. // Add Metadata for Download
  499. (void)[[NCManageDatabase sharedInstance] addMetadata:metadata];
  500. [appDelegate performSelectorOnMainThread:@selector(loadAutoDownloadUpload) withObject:nil waitUntilDone:YES];
  501. }
  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. NSString *fileNamePath = [CCUtility getDirectoryProviderStorageFileID:self.metadataDetail.fileID fileName:self.metadataDetail.fileNameView];
  554. if ([CCUtility fileProviderStorageExists:self.metadataDetail.fileID fileName:self.metadataDetail.fileNameView] == NO) {
  555. // read file error
  556. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  557. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  558. [alertController addAction:okAction];
  559. [self presentViewController:alertController animated:YES completion:nil];
  560. }
  561. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileNamePath]);
  562. if (pdf) {
  563. // Encrypted
  564. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  565. // Try a blank password first, per Apple's Quartz PDF example
  566. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  567. // blank password
  568. [self readerPDF:fileNamePath password:@""];
  569. } else {
  570. if ([password length] == 0) {
  571. // password request
  572. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  573. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  574. alertView.tag = alertRequestPasswordPDF;
  575. [alertView show];
  576. } else {
  577. const char *key = [password UTF8String];
  578. // failure
  579. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  580. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  581. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  582. [alertController addAction:okAction];
  583. [self presentViewController:alertController animated:YES completion:nil];
  584. } else {
  585. // pdf with password
  586. [self readerPDF:fileNamePath password:password];
  587. }
  588. }
  589. }
  590. } else{
  591. // No password
  592. [self readerPDF:fileNamePath password:@""];
  593. }
  594. } else {
  595. // read file error
  596. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  597. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  598. [alertController addAction:okAction];
  599. [self presentViewController:alertController animated:YES completion:nil];
  600. }
  601. }
  602. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  603. {
  604. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  605. CGFloat safeAreaBottom = 0;
  606. if (@available(iOS 11, *)) {
  607. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  608. }
  609. if (documentPDF != nil) {
  610. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  611. self.readerPDFViewController.delegate = self;
  612. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  613. [self.readerPDFViewController updateContentViews];
  614. [self addChildViewController:self.readerPDFViewController];
  615. [self.view addSubview:self.readerPDFViewController.view];
  616. [self.readerPDFViewController didMoveToParentViewController:self];
  617. } else {
  618. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  619. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  620. [alertController addAction:okAction];
  621. [self presentViewController:alertController animated:YES completion:nil];
  622. }
  623. }
  624. - (void)handleSingleTapReader
  625. {
  626. UILayoutGuide *layoutGuide;
  627. CGFloat safeAreaTop = 0;
  628. CGFloat safeAreaBottom = 0;
  629. if (@available(iOS 11, *)) {
  630. layoutGuide = [UIApplication sharedApplication].delegate.window.safeAreaLayoutGuide;
  631. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  632. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  633. }
  634. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  635. _toolbar.hidden = !_toolbar.isHidden;
  636. if (_toolbar.isHidden) {
  637. self.readerPDFViewController.view.frame = CGRectMake(0, safeAreaTop, self.view.bounds.size.width, self.view.bounds.size.height - safeAreaTop - safeAreaBottom);
  638. } else {
  639. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  640. }
  641. [self.readerPDFViewController updateContentViews];
  642. }
  643. - (void)handleSwipeUpDown
  644. {
  645. // REMOVE IT'S UNUSABLE
  646. /*
  647. self.navigationController.navigationBarHidden = false; // iOS App is unusable after swipe up or down with PDF in fullscreen #526
  648. [self removeAllView];
  649. [self.navigationController popViewControllerAnimated:YES];
  650. */
  651. }
  652. #pragma --------------------------------------------------------------------------------------------
  653. #pragma mark ===== Delete =====
  654. #pragma --------------------------------------------------------------------------------------------
  655. - (void)deleteFile:(tableMetadata *)metadata
  656. {
  657. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  658. tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND e2eEncrypted == 1 AND serverUrl == %@", appDelegate.activeAccount, serverUrl]];
  659. [[NCMainCommon sharedInstance ] deleteFileWithMetadatas:[[NSArray alloc] initWithObjects:metadata, nil] e2ee:tableDirectory.e2eEncrypted serverUrl:serverUrl folderFileID:tableDirectory.fileID completion:^(NSInteger errorCode, NSString *message) {
  660. if (errorCode == 0) {
  661. // reload Main
  662. [appDelegate.activeMain reloadDatasource];
  663. // If removed document (web) or PDF close
  664. if (_webView || _readerPDFViewController)
  665. [self removeAllView];
  666. // if a message for a directory of these
  667. if (![_dataSourceDirectoryID containsObject:metadata.directoryID])
  668. return;
  669. // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
  670. if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadata.fileID]) {
  671. NSArray *viewsToRemove = [self.view subviews];
  672. for (id element in viewsToRemove) {
  673. if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]])
  674. [element removeFromSuperview];
  675. }
  676. self.title = @"";
  677. [self.navigationController popViewControllerAnimated:YES];
  678. } else {
  679. // only photoBrowser if exists
  680. for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
  681. tableMetadata *metadataTemp = [self.dataSourceImagesVideos objectAtIndex:index];
  682. if ([metadata isInvalidated] || [metadataTemp.fileID isEqualToString:metadata.fileID]) {
  683. [self.dataSourceImagesVideos removeObjectAtIndex:index];
  684. [self.photos removeObjectAtIndex:index];
  685. [self.photoBrowser reloadData];
  686. // Title
  687. if ([self.dataSourceImagesVideos count] == 0) {
  688. self.title = @"";
  689. [self.navigationController popViewControllerAnimated:YES];
  690. }
  691. }
  692. }
  693. }
  694. } else {
  695. NSLog(@"[LOG] DeleteFileOrFolder failure error %d, %@", (int)errorCode, message);
  696. }
  697. }];
  698. }
  699. #pragma --------------------------------------------------------------------------------------------
  700. #pragma mark ===== ButtonPressed =====
  701. #pragma --------------------------------------------------------------------------------------------
  702. - (void)modifyTxtButtonPressed:(UIBarButtonItem *)sender
  703. {
  704. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
  705. NCText *viewController = (NCText *)navigationController.topViewController;
  706. viewController.metadata = self.metadataDetail;
  707. navigationController.modalPresentationStyle = UIModalPresentationPageSheet;
  708. navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  709. [self presentViewController:navigationController animated:YES completion:nil];
  710. }
  711. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  712. {
  713. if ([self.metadataDetail.fileNameView length] == 0) return;
  714. NSString *filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.metadataDetail.fileNameView];
  715. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  716. self.docController.delegate = self;
  717. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  718. [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  719. [self.docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  720. }
  721. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  722. {
  723. [appDelegate.activeMain openWindowShare:self.metadataDetail];
  724. }
  725. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  726. {
  727. if ([self.metadataDetail.fileNameView length] == 0) return;
  728. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  729. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  730. style:UIAlertActionStyleDestructive
  731. handler:^(UIAlertAction *action) {
  732. [self deleteFile:self.metadataDetail];
  733. }]];
  734. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  735. style:UIAlertActionStyleCancel
  736. handler:^(UIAlertAction *action) {
  737. [alertController dismissViewControllerAnimated:YES completion:nil];
  738. }]];
  739. alertController.popoverPresentationController.barButtonItem = _buttonDelete;
  740. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  741. [alertController.view layoutIfNeeded];
  742. [self presentViewController:alertController animated:YES completion:NULL];
  743. }
  744. @end