CCDetail.m 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. //
  2. // CCDetail.m
  3. // Crypto Cloud Technology Nextcloud
  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 "NCBridgeSwift.h"
  27. #define TOOLBAR_HEIGHT 49.0f
  28. #define alertRequestPasswordPDF 1
  29. @interface CCDetail () <CCActionsDeleteDelegate>
  30. {
  31. AppDelegate *appDelegate;
  32. UIToolbar *_toolbar;
  33. UIBarButtonItem *_buttonAction;
  34. UIBarButtonItem *_buttonShare;
  35. UIBarButtonItem *_buttonDelete;
  36. NSInteger _indexNowVisible;
  37. NSString *_fileIDNowVisible;
  38. BOOL _reload;
  39. NSMutableOrderedSet *_dataSourceDirectoryID;
  40. }
  41. @end
  42. @implementation CCDetail
  43. #pragma --------------------------------------------------------------------------------------------
  44. #pragma mark ===== init =====
  45. #pragma --------------------------------------------------------------------------------------------
  46. - (id)initWithCoder:(NSCoder *)aDecoder
  47. {
  48. if (self = [super initWithCoder:aDecoder]) {
  49. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(triggerProgressTask:) name:@"NotificationProgressTask" object:nil];
  50. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  51. self.metadataDetail = [[tableMetadata alloc] init];
  52. self.photos = [[NSMutableArray alloc] init];
  53. self.thumbs = [[NSMutableArray alloc] init];
  54. self.dataSourceImagesVideos = [[NSMutableArray alloc] init];
  55. _dataSourceDirectoryID = [[NSMutableOrderedSet alloc] init];
  56. _indexNowVisible = -1;
  57. _fileIDNowVisible = nil;
  58. app.activeDetail = self;
  59. }
  60. return self;
  61. }
  62. #pragma --------------------------------------------------------------------------------------------
  63. #pragma mark ===== View =====
  64. #pragma --------------------------------------------------------------------------------------------
  65. - (void)viewDidLoad
  66. {
  67. [super viewDidLoad];
  68. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  69. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  70. self.imageBackground.image = [UIImage imageNamed:@"backgroundDetail"];
  71. if ([self.metadataDetail.fileName length] > 0 || [self.metadataDetail.directoryID length] > 0 || [self.metadataDetail.fileID length] > 0) {
  72. // open view
  73. [self viewFile];
  74. }
  75. }
  76. // Apparirà
  77. - (void)viewWillAppear:(BOOL)animated
  78. {
  79. [super viewWillAppear:animated];
  80. if (self.splitViewController.isCollapsed) {
  81. self.tabBarController.tabBar.hidden = YES;
  82. self.tabBarController.tabBar.translucent = YES;
  83. }
  84. if (self.splitViewController.isCollapsed)
  85. [app plusButtonVisibile:false];
  86. }
  87. // E' scomparso
  88. - (void)viewDidDisappear:(BOOL)animated
  89. {
  90. [super viewDidDisappear:animated];
  91. // remove all
  92. if (self.isMovingFromParentViewController)
  93. [self removeAllView];
  94. }
  95. - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
  96. {
  97. [coordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
  98. }];
  99. [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
  100. }
  101. // remove all view
  102. - (void)removeAllView
  103. {
  104. // Audio
  105. if (appDelegate.player)
  106. [appDelegate.player removeFromSuperview];
  107. // Document
  108. if (_webView) {
  109. [_webView removeFromSuperview];
  110. _webView = nil;
  111. }
  112. // PDF
  113. if (_readerPDFViewController) {
  114. [_readerPDFViewController.view removeFromSuperview];
  115. _readerPDFViewController.delegate = nil;
  116. _readerPDFViewController = nil;
  117. }
  118. // Photo-Video
  119. if (_photoBrowser) {
  120. [_photos removeAllObjects];
  121. [_thumbs removeAllObjects];
  122. _photoBrowser.delegate = nil;
  123. _photoBrowser = nil;
  124. }
  125. [self.navigationController popToRootViewControllerAnimated:NO];
  126. self.navigationController.navigationBarHidden = YES;
  127. }
  128. - (void)changeToDisplayMode
  129. {
  130. if (_readerPDFViewController)
  131. [self.readerPDFViewController updateContentViews];
  132. }
  133. - (void)createToolbar
  134. {
  135. _toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  136. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  137. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  138. fixedSpaceMini.width = 25;
  139. _buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetOpenIn"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  140. _buttonShare = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetShare"] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  141. _buttonDelete = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed:)];
  142. [_toolbar setItems:[NSArray arrayWithObjects: flexible, _buttonDelete, fixedSpaceMini, _buttonShare, fixedSpaceMini, _buttonAction, nil]];
  143. [_toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  144. _toolbar.barTintColor = [NCBrandColor sharedInstance].tabBar;
  145. [self.view addSubview:_toolbar];
  146. }
  147. - (void)changeTheming
  148. {
  149. if (self.isViewLoaded && self.view.window)
  150. [app changeTheming:self];
  151. }
  152. #pragma --------------------------------------------------------------------------------------------
  153. #pragma mark ===== View File =====
  154. #pragma --------------------------------------------------------------------------------------------
  155. - (void)viewFile
  156. {
  157. // verifico se esiste l'icona e se la posso creare
  158. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, self.metadataDetail.fileID]] == NO) {
  159. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{
  160. [CCGraphics createNewImageFrom:self.metadataDetail.fileID directoryUser:app.directoryUser fileNameTo:self.metadataDetail.fileID fileNamePrint:self.metadataDetail.fileNamePrint size:@"m" imageForUpload:NO typeFile:self.metadataDetail.typeFile writePreview:YES optimizedFileName:[CCUtility getOptimizedPhoto]];
  161. });
  162. }
  163. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video]) {
  164. self.edgesForExtendedLayout = UIRectEdgeAll;
  165. [self viewImage];
  166. }
  167. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  168. self.edgesForExtendedLayout = UIRectEdgeBottom;
  169. [self viewAudio];
  170. [self createToolbar];
  171. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  172. }
  173. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  174. NSString *ext = [[self.metadataDetail.fileNamePrint pathExtension] lowercaseString];
  175. if ([ext isEqualToString:@"pdf"]) {
  176. self.edgesForExtendedLayout = UIRectEdgeBottom;
  177. [self viewPDF:@""];
  178. [self createToolbar];
  179. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  180. } else {
  181. self.edgesForExtendedLayout = UIRectEdgeBottom;
  182. [self viewDocument];
  183. [self createToolbar];
  184. [app aspectNavigationControllerBar:self.navigationController.navigationBar encrypted:NO online:[app.reachability isReachable] hidden:NO];
  185. }
  186. }
  187. }
  188. #pragma --------------------------------------------------------------------------------------------
  189. #pragma mark ===== View Audio =====
  190. #pragma --------------------------------------------------------------------------------------------
  191. - (void)viewAudio
  192. {
  193. NSString *fileName;
  194. if (_sourceDirectoryLocal) {
  195. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  196. } else {
  197. fileName = [NSString stringWithFormat:@"%@/%@", [CCUtility getDirectoryAudio], self.metadataDetail.fileNamePrint];
  198. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  199. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  200. }
  201. appDelegate.player.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  202. appDelegate.player.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  203. appDelegate.player.nextButton.hidden = true;
  204. appDelegate.player.previousButton.hidden = true;
  205. appDelegate.player.fullscreenButton_.hidden = true;
  206. LMMediaItem *item = [[LMMediaItem alloc] initWithInfo:@{LMMediaItemInfoURLKey:[NSURL fileURLWithPath:fileName], LMMediaItemInfoContentTypeKey:@(LMMediaItemContentTypeVideo)}];
  207. item.title = self.metadataDetail.fileNamePrint;
  208. item.artist = [NCBrandOptions sharedInstance].brand;
  209. [appDelegate.player.mediaPlayer removeAllMediaInQueue];
  210. [appDelegate.player.mediaPlayer addMedia:item];
  211. [appDelegate.player.mediaPlayer play];
  212. // Info
  213. NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
  214. [songInfo setObject:app.player.mediaPlayer.nowPlayingItem.title forKey:MPMediaItemPropertyTitle];
  215. [songInfo setObject:app.player.mediaPlayer.nowPlayingItem.artist forKey:MPMediaItemPropertyArtist];
  216. [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
  217. [self.view addSubview:appDelegate.player];
  218. }
  219. #pragma --------------------------------------------------------------------------------------------
  220. #pragma mark ===== View Document =====
  221. #pragma --------------------------------------------------------------------------------------------
  222. - (void)viewDocument
  223. {
  224. NSString *fileName;
  225. if (_sourceDirectoryLocal) {
  226. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  227. } else {
  228. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNamePrint];
  229. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  230. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  231. }
  232. NSString *ext=@"";
  233. ext = [CCUtility getExtension:self.metadataDetail.fileNamePrint];
  234. WKPreferences *wkPreferences = [[WKPreferences alloc] init];
  235. wkPreferences.javaScriptEnabled = false;
  236. WKWebViewConfiguration *wkConfig = [[WKWebViewConfiguration alloc] init];
  237. wkConfig.preferences = wkPreferences;
  238. self.webView = [[WKWebView alloc] initWithFrame:(CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT)) configuration:wkConfig];
  239. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  240. [self.webView setBackgroundColor:[UIColor whiteColor]];
  241. [self.webView setOpaque:NO];
  242. if ( [ext isEqualToString:@"CSS"] || [ext isEqualToString:@"PY"] || [ext isEqualToString:@"XML"] || [ext isEqualToString:@"JS"] ) {
  243. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]];
  244. [headRequest setHTTPMethod:@"HEAD"];
  245. NSHTTPURLResponse *headResponse;
  246. NSError *error = nil;
  247. [NSURLConnection sendSynchronousRequest:headRequest returningResponse:&headResponse error:&error];
  248. if (error != nil) {
  249. NSLog(@"[LOG] loadURLWithString %@",[error localizedDescription]);
  250. }
  251. NSString *dataFile = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:fileName]] encoding:NSASCIIStringEncoding];
  252. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  253. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"40",@"Sans-Serif",dataFile] baseURL:nil];
  254. }else{
  255. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"20",@"Sans-Serif",dataFile] baseURL:nil];
  256. }
  257. } else if ([ext isEqualToString:@"TXT"] ) {
  258. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]];
  259. [headRequest setHTTPMethod:@"HEAD"];
  260. NSHTTPURLResponse *headResponse;
  261. NSError *error = nil;
  262. [NSURLConnection sendSynchronousRequest:headRequest returningResponse:&headResponse error:&error];
  263. if (error != nil) {
  264. NSLog(@"[LOG] loadURLWithString %@",[error localizedDescription]);
  265. }
  266. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]]];
  267. } else {
  268. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]]];
  269. }
  270. [self.view addSubview:self.webView];
  271. }
  272. #pragma --------------------------------------------------------------------------------------------
  273. #pragma mark ===== View Image =====
  274. #pragma --------------------------------------------------------------------------------------------
  275. - (void)viewImage
  276. {
  277. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  278. _reload = NO;
  279. _indexNowVisible = -1;
  280. _fileIDNowVisible = nil;
  281. [self.photos removeAllObjects];
  282. [self.thumbs removeAllObjects];
  283. [_dataSourceDirectoryID removeAllObjects];
  284. // if not images, exit
  285. if ([self.dataSourceImagesVideos count] == 0) return;
  286. NSUInteger index = 0;
  287. for (tableMetadata *metadata in self.dataSourceImagesVideos) {
  288. // start from here ?
  289. if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
  290. [self.photoBrowser setCurrentPhotoIndex:index];
  291. if (metadata.cryptated) {
  292. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownloadCrypto"]]];
  293. [self.thumbs addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownloadCrypto"]]];
  294. } else {
  295. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownload"]]];
  296. MWPhoto *thumb = [MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownload"]];
  297. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  298. [self.thumbs addObject:thumb];
  299. }
  300. // add directory
  301. [_dataSourceDirectoryID addObject:metadata.directoryID];
  302. index++;
  303. }
  304. // PhotoBrowser
  305. self.photoBrowser.displayActionButton = YES;
  306. self.photoBrowser.displayDeleteButton = YES;
  307. self.photoBrowser.displayNavArrows = YES;
  308. self.photoBrowser.displaySelectionButtons = NO;
  309. self.photoBrowser.alwaysShowControls = NO;
  310. self.photoBrowser.zoomPhotosToFill = NO;
  311. self.photoBrowser.startOnGrid = NO;
  312. self.photoBrowser.autoPlayOnAppear = NO;
  313. self.photoBrowser.delayToHideElements = 15;
  314. self.photoBrowser.enableGrid = YES;
  315. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  316. [self addChildViewController:self.photoBrowser];
  317. [self.view addSubview:self.photoBrowser.view];
  318. [self.photoBrowser didMoveToParentViewController:self];
  319. } else {
  320. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  321. }
  322. }
  323. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  324. {
  325. return [self.dataSourceImagesVideos count];
  326. }
  327. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  328. {
  329. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  330. NSString *titleDir = metadata.fileNamePrint;
  331. self.title = titleDir;
  332. return titleDir;
  333. }
  334. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  335. {
  336. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  337. NSString *directory;
  338. _indexNowVisible = index;
  339. _fileIDNowVisible = metadata.fileID;
  340. photoBrowser.toolbar.hidden = NO;
  341. if (_sourceDirectoryLocal)
  342. directory = self.metadataDetail.directoryID;
  343. else
  344. directory = app.directoryUser;
  345. // Download
  346. if (metadata && [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]] == NO && [metadata.session length] == 0)
  347. [self performSelector:@selector(downloadPhotoBrowser:) withObject:metadata];
  348. // Title
  349. if (metadata && !photoBrowser.isGridController)
  350. self.title = metadata.fileNamePrint;
  351. if (_reload) {
  352. [self.photoBrowser performSelector:@selector(reloadData) withObject:nil];
  353. _reload = NO;
  354. }
  355. }
  356. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  357. {
  358. NSString *directory;
  359. UIImage *image;
  360. if (_sourceDirectoryLocal)
  361. directory = self.metadataDetail.directoryID;
  362. else
  363. directory = app.directoryUser;
  364. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  365. if (index < self.photos.count) {
  366. if (metadata.fileID) {
  367. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  368. NSString *fileImage = [NSString stringWithFormat:@"%@/%@", directory, metadata.fileID];
  369. NSString *ext = [CCUtility getExtension:metadata.fileNamePrint];
  370. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  371. else image = [UIImage imageWithContentsOfFile:fileImage];
  372. if (image) {
  373. MWPhoto *photo = [MWPhoto photoWithImage:image];
  374. // Location ??
  375. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  376. [self.photos replaceObjectAtIndex:index withObject:photo];
  377. } else {
  378. if ([metadata.sessionError length] > 0 ) {
  379. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  380. } else {
  381. image = [CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50];
  382. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:image]];
  383. }
  384. }
  385. }
  386. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  387. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]]) {
  388. // remove and make the simbolic link in temp
  389. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint];
  390. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  391. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID] toPath:toPath error:nil];
  392. NSURL *url = [NSURL fileURLWithPath:toPath];
  393. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  394. video.videoURL = url;
  395. [self.photos replaceObjectAtIndex:index withObject:video];
  396. } else {
  397. if ([metadata.sessionError length] > 0 ) {
  398. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  399. } else {
  400. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50]]];
  401. }
  402. }
  403. }
  404. }
  405. // energy saving memory
  406. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  407. int iPrev = (int)index - 2;
  408. if (iPrev >= 0) {
  409. if ([self.photos objectAtIndex:iPrev] != nil)
  410. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  411. }
  412. int iNext = (int)index + 2;
  413. if (iNext < _photos.count) {
  414. if ([self.photos objectAtIndex:iNext] != nil)
  415. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  416. }
  417. });
  418. return [self.photos objectAtIndex:index];
  419. }
  420. return nil;
  421. }
  422. - (void)gridWillAppear:(MWPhotoBrowser *)photoBrowser
  423. {
  424. // reload [BUG]
  425. [self.photoBrowser reloadData];
  426. // in grid clear all MWPhoto : energy saving memory
  427. if (self.photos.count > 1 && [self.dataSourceImagesVideos count] > 0) {
  428. for(int index=0; index < self.photos.count; index++)
  429. [_photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:nil]];
  430. }
  431. self.title = [NSString stringWithFormat:@"Album %lu %@", (unsigned long)_photos.count, NSLocalizedString(@"photos", nil)];
  432. }
  433. - (void)gridWillDisappear:(MWPhotoBrowser *)photoBrowser
  434. {
  435. //
  436. photoBrowser.toolbar.hidden = NO;
  437. }
  438. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index
  439. {
  440. NSString *directory;
  441. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  442. if (_sourceDirectoryLocal)
  443. directory = self.metadataDetail.directoryID;
  444. else
  445. directory = app.directoryUser;
  446. if (index < self.thumbs.count) {
  447. if (metadata.fileID) {
  448. UIImage *image;
  449. if (_sourceDirectoryLocal) {
  450. image = [CCGraphics createNewImageFrom:metadata.fileID directoryUser:directory fileNameTo:metadata.fileID fileNamePrint:metadata.fileNamePrint size:@"m" imageForUpload:NO typeFile:metadata.typeFile writePreview:NO optimizedFileName:[CCUtility getOptimizedPhoto]];
  451. } else {
  452. NSString *fileImage = [NSString stringWithFormat:@"%@/%@.ico", directory, metadata.fileID];
  453. image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  454. }
  455. if (image) {
  456. MWPhoto *thumb = [MWPhoto photoWithImage:image];
  457. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  458. [self.thumbs replaceObjectAtIndex:index withObject:thumb];
  459. }
  460. }
  461. return [self.thumbs objectAtIndex:index];
  462. }
  463. return nil;
  464. }
  465. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  466. {
  467. NSString *filePath;
  468. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  469. if (metadata == nil) return;
  470. if (_sourceDirectoryLocal) {
  471. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  472. } else {
  473. filePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  474. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  475. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:filePath error:nil];
  476. }
  477. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  478. self.docController.delegate = self;
  479. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  480. [self.docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  481. [self.docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  482. }
  483. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  484. {
  485. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  486. [app.activeMain openWindowShare:metadata];
  487. }
  488. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  489. {
  490. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  491. if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]] == NO) {
  492. [app messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  493. return;
  494. }
  495. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  496. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  497. style:UIAlertActionStyleDestructive
  498. handler:^(UIAlertAction *action) {
  499. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  500. }]];
  501. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  502. style:UIAlertActionStyleCancel
  503. handler:^(UIAlertAction *action) {
  504. [alertController dismissViewControllerAnimated:YES completion:nil];
  505. }]];
  506. alertController.popoverPresentationController.barButtonItem = deleteButton;
  507. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  508. [alertController.view layoutIfNeeded];
  509. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  510. }
  511. - (void)triggerProgressTask:(NSNotification *)notification
  512. {
  513. NSDictionary *dict = notification.userInfo;
  514. float progress = [[dict valueForKey:@"progress"] floatValue];
  515. if (progress == 0)
  516. [self.navigationController cancelCCProgress];
  517. else
  518. [self.navigationController setCCProgressPercentage:progress*100 andTintColor:[NCBrandColor sharedInstance].navigationBarProgress];
  519. }
  520. - (void)downloadPhotoBrowserFailure:(NSInteger)errorCode
  521. {
  522. [app messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  523. [self.photoBrowser reloadData];
  524. }
  525. - (void)downloadPhotoBrowserSuccess:(tableMetadata *)metadataVar selector:(NSString *)selector
  526. {
  527. NSUInteger index = 0;
  528. // if a message for a directory of these
  529. if (![_dataSourceDirectoryID containsObject:metadataVar.directoryID])
  530. return;
  531. for (NSUInteger i=0; i < [self.dataSourceImagesVideos count]; i++ ) {
  532. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:i];
  533. // search index
  534. if ([metadataVar.fileID isEqualToString:metadata.fileID]) {
  535. index = i;
  536. break;
  537. }
  538. }
  539. // do not reload is Video on air
  540. if (_photoBrowser.currentVideoPlayerViewController.isViewLoaded && _photoBrowser.currentVideoPlayerViewController.view.window) return;
  541. //NSLog(@"[LOG] Add Download Photo Browser");
  542. if ([metadataVar.fileID isEqualToString:_fileIDNowVisible] || [self.photoBrowser isGridReload:index]) {
  543. [self.photoBrowser reloadData];
  544. _reload = NO;
  545. } else {
  546. _reload = YES;
  547. }
  548. }
  549. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  550. {
  551. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  552. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadViewImage selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:nil];
  553. }
  554. - (void)insertGeocoderLocation:(NSNotification *)notification
  555. {
  556. if (notification.userInfo.count == 0)
  557. return;
  558. NSString *fileID = [[notification.userInfo allKeys] objectAtIndex:0];
  559. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  560. // test [Chrash V 1.14,15]
  561. if (_indexNowVisible >= [self.photos count])
  562. return;
  563. if ([fileID isEqualToString:_fileIDNowVisible]) {
  564. MWPhoto *photo = [self.photos objectAtIndex:_indexNowVisible];
  565. [self setLocationCaptionPhoto:photo fileID:fileID];
  566. if (![self.photoBrowser isGridController]) {
  567. //[self.photoBrowser hideControls];
  568. //[self.photoBrowser showControls];
  569. }
  570. }
  571. }
  572. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  573. {
  574. tableLocalFile *localFile;
  575. // read Geocoder
  576. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  577. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  578. // Fix BUG Geo latitude & longitude
  579. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  580. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  581. if (metadata) {
  582. [[CCExifGeo sharedInstance] setExifLocalTableEtag:metadata directoryUser:app.directoryUser activeAccount:app.activeAccount];
  583. }
  584. }
  585. [[CCExifGeo sharedInstance] setGeocoderEtag:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  586. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  587. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  588. NSString *location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  589. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  590. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  591. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  592. }
  593. }
  594. }
  595. }
  596. #pragma --------------------------------------------------------------------------------------------
  597. #pragma mark ===== View PDF =====
  598. #pragma --------------------------------------------------------------------------------------------
  599. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  600. {
  601. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  602. [[alertView textFieldAtIndex:0] resignFirstResponder];
  603. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  604. }
  605. - (void)viewPDF:(NSString *)password
  606. {
  607. NSString *fileName;
  608. if (_sourceDirectoryLocal) {
  609. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  610. } else {
  611. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNamePrint];
  612. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  613. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  614. }
  615. if ([[NSFileManager defaultManager] fileExistsAtPath:fileName isDirectory:nil] == NO) {
  616. // read file error
  617. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  618. [alertView show];
  619. }
  620. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileName]);
  621. if (pdf) {
  622. // Encrypted
  623. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  624. // Try a blank password first, per Apple's Quartz PDF example
  625. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  626. // blank password
  627. [self readerPDF:fileName password:@""];
  628. } else {
  629. if ([password length] == 0) {
  630. // password request
  631. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  632. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  633. alertView.tag = alertRequestPasswordPDF;
  634. [alertView show];
  635. } else {
  636. const char *key = [password UTF8String];
  637. // failure
  638. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  639. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  640. [alertView show];
  641. } else {
  642. // pdf with password
  643. [self readerPDF:fileName password:password];
  644. }
  645. }
  646. }
  647. } else{
  648. // No password
  649. [self readerPDF:fileName password:@""];
  650. }
  651. } else {
  652. // read file error
  653. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  654. [alertView show];
  655. }
  656. }
  657. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  658. {
  659. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  660. if (documentPDF != nil) {
  661. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  662. self.readerPDFViewController.delegate = self;
  663. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  664. [self.readerPDFViewController updateContentViews];
  665. [self addChildViewController:self.readerPDFViewController];
  666. [self.view addSubview:self.readerPDFViewController.view];
  667. [self.readerPDFViewController didMoveToParentViewController:self];
  668. } else {
  669. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  670. [alertView show];
  671. }
  672. }
  673. - (void)handleSingleTapReader
  674. {
  675. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  676. _toolbar.hidden = !_toolbar.isHidden;
  677. if (_toolbar.isHidden) {
  678. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
  679. } else {
  680. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  681. }
  682. [self.readerPDFViewController updateContentViews];
  683. }
  684. #pragma --------------------------------------------------------------------------------------------
  685. #pragma mark ===== Delete =====
  686. #pragma --------------------------------------------------------------------------------------------
  687. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  688. {
  689. NSLog(@"[LOG] delete failure");
  690. }
  691. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  692. {
  693. // reload Main
  694. [app.activeMain reloadDatasource];
  695. // If removed document (web) or PDF close
  696. if (_webView || _readerPDFViewController)
  697. [self removeAllView];
  698. // if a message for a directory of these
  699. if (![_dataSourceDirectoryID containsObject:metadataNet.directoryID])
  700. return;
  701. // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
  702. if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadataNet.fileID]) {
  703. [app.player.mediaPlayer stop];
  704. NSArray *viewsToRemove = [self.view subviews];
  705. for (id element in viewsToRemove) {
  706. if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]] || [element isMemberOfClass:[LMMediaPlayerView class]])
  707. [element removeFromSuperview];
  708. }
  709. self.title = @"";
  710. [self.navigationController popViewControllerAnimated:YES];
  711. } else {
  712. // only photoBrowser if exists
  713. for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
  714. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  715. // ricerca index
  716. if ([metadata.fileID isEqualToString:metadataNet.fileID]) {
  717. [self.dataSourceImagesVideos removeObjectAtIndex:index];
  718. [self.photos removeObjectAtIndex:index];
  719. [self.thumbs removeObjectAtIndex:index];
  720. [self.photoBrowser reloadData];
  721. // Title
  722. if ([self.dataSourceImagesVideos count] == 0) {
  723. self.title = @"";
  724. [self.navigationController popViewControllerAnimated:YES];
  725. }
  726. break;
  727. }
  728. }
  729. }
  730. }
  731. #pragma --------------------------------------------------------------------------------------------
  732. #pragma mark ===== ButtonPressed =====
  733. #pragma --------------------------------------------------------------------------------------------
  734. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  735. {
  736. NSString *filePath;
  737. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  738. if (_sourceDirectoryLocal) {
  739. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  740. } else {
  741. filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.metadataDetail.fileNamePrint];
  742. }
  743. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  744. self.docController.delegate = self;
  745. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  746. [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  747. [self.docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  748. }
  749. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  750. {
  751. [app.activeMain openWindowShare:self.metadataDetail];
  752. }
  753. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  754. {
  755. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  756. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  757. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  758. style:UIAlertActionStyleDestructive
  759. handler:^(UIAlertAction *action) {
  760. [[CCActions sharedInstance] deleteFileOrFolder:self.metadataDetail delegate:self];
  761. }]];
  762. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  763. style:UIAlertActionStyleCancel
  764. handler:^(UIAlertAction *action) {
  765. [alertController dismissViewControllerAnimated:YES completion:nil];
  766. }]];
  767. alertController.popoverPresentationController.barButtonItem = _buttonDelete;
  768. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  769. [alertController.view layoutIfNeeded];
  770. [self presentViewController:alertController animated:YES completion:NULL];
  771. }
  772. @end