CCDetail.m 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094
  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 image ?
  346. if (metadata) {
  347. tableMetadata *metadataDB = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadata.fileID]];
  348. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]] == NO && [metadataDB.session length] == 0)
  349. [self downloadPhotoBrowser:metadata];
  350. }
  351. // Title
  352. if (metadata && !photoBrowser.isGridController)
  353. self.title = metadata.fileNamePrint;
  354. if (_reload) {
  355. [self.photoBrowser performSelector:@selector(reloadData) withObject:nil];
  356. _reload = NO;
  357. }
  358. }
  359. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  360. {
  361. NSString *directory;
  362. UIImage *image;
  363. if (_sourceDirectoryLocal)
  364. directory = self.metadataDetail.directoryID;
  365. else
  366. directory = app.directoryUser;
  367. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  368. if (index < self.photos.count) {
  369. if (metadata.fileID) {
  370. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  371. NSString *fileImage = [NSString stringWithFormat:@"%@/%@", directory, metadata.fileID];
  372. NSString *ext = [CCUtility getExtension:metadata.fileNamePrint];
  373. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  374. else image = [UIImage imageWithContentsOfFile:fileImage];
  375. if (image) {
  376. MWPhoto *photo = [MWPhoto photoWithImage:image];
  377. // Location ??
  378. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  379. [self.photos replaceObjectAtIndex:index withObject:photo];
  380. } else {
  381. if ([metadata.sessionError length] > 0 ) {
  382. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  383. } else {
  384. image = [CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50];
  385. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:image]];
  386. }
  387. }
  388. }
  389. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  390. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]]) {
  391. // remove and make the simbolic link in temp
  392. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint];
  393. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  394. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID] toPath:toPath error:nil];
  395. NSURL *url = [NSURL fileURLWithPath:toPath];
  396. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  397. video.videoURL = url;
  398. [self.photos replaceObjectAtIndex:index withObject:video];
  399. } else {
  400. if ([metadata.sessionError length] > 0 ) {
  401. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  402. } else {
  403. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50]]];
  404. }
  405. }
  406. }
  407. }
  408. // energy saving memory
  409. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  410. int iPrev = (int)index - 2;
  411. if (iPrev >= 0) {
  412. if ([self.photos objectAtIndex:iPrev] != nil)
  413. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  414. }
  415. int iNext = (int)index + 2;
  416. if (iNext < _photos.count) {
  417. if ([self.photos objectAtIndex:iNext] != nil)
  418. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  419. }
  420. });
  421. return [self.photos objectAtIndex:index];
  422. }
  423. return nil;
  424. }
  425. - (void)gridWillAppear:(MWPhotoBrowser *)photoBrowser
  426. {
  427. // reload [BUG]
  428. [self.photoBrowser reloadData];
  429. // in grid clear all MWPhoto : energy saving memory
  430. if (self.photos.count > 1 && [self.dataSourceImagesVideos count] > 0) {
  431. for(int index=0; index < self.photos.count; index++)
  432. [_photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:nil]];
  433. }
  434. self.title = [NSString stringWithFormat:@"Album %lu %@", (unsigned long)_photos.count, NSLocalizedString(@"photos", nil)];
  435. }
  436. - (void)gridWillDisappear:(MWPhotoBrowser *)photoBrowser
  437. {
  438. //
  439. photoBrowser.toolbar.hidden = NO;
  440. }
  441. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index
  442. {
  443. NSString *directory;
  444. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  445. if (_sourceDirectoryLocal)
  446. directory = self.metadataDetail.directoryID;
  447. else
  448. directory = app.directoryUser;
  449. if (index < self.thumbs.count) {
  450. if (metadata.fileID) {
  451. UIImage *image;
  452. if (_sourceDirectoryLocal) {
  453. 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]];
  454. } else {
  455. NSString *fileImage = [NSString stringWithFormat:@"%@/%@.ico", directory, metadata.fileID];
  456. image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  457. }
  458. if (image) {
  459. MWPhoto *thumb = [MWPhoto photoWithImage:image];
  460. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) thumb.isVideo = YES;
  461. [self.thumbs replaceObjectAtIndex:index withObject:thumb];
  462. }
  463. }
  464. return [self.thumbs objectAtIndex:index];
  465. }
  466. return nil;
  467. }
  468. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  469. {
  470. NSString *filePath;
  471. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  472. if (metadata == nil) return;
  473. if (_sourceDirectoryLocal) {
  474. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  475. } else {
  476. filePath = [NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileNamePrint];
  477. [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
  478. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID] toPath:filePath error:nil];
  479. }
  480. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  481. self.docController.delegate = self;
  482. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  483. [self.docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  484. [self.docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  485. }
  486. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  487. {
  488. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  489. [app.activeMain openWindowShare:metadata];
  490. }
  491. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  492. {
  493. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  494. if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]] == NO) {
  495. [app messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  496. return;
  497. }
  498. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  499. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  500. style:UIAlertActionStyleDestructive
  501. handler:^(UIAlertAction *action) {
  502. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  503. }]];
  504. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  505. style:UIAlertActionStyleCancel
  506. handler:^(UIAlertAction *action) {
  507. [alertController dismissViewControllerAnimated:YES completion:nil];
  508. }]];
  509. alertController.popoverPresentationController.barButtonItem = deleteButton;
  510. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  511. [alertController.view layoutIfNeeded];
  512. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  513. }
  514. - (void)triggerProgressTask:(NSNotification *)notification
  515. {
  516. NSDictionary *dict = notification.userInfo;
  517. float progress = [[dict valueForKey:@"progress"] floatValue];
  518. if (progress == 0)
  519. [self.navigationController cancelCCProgress];
  520. else
  521. [self.navigationController setCCProgressPercentage:progress*100 andTintColor:[NCBrandColor sharedInstance].navigationBarProgress];
  522. }
  523. - (void)downloadPhotoBrowserFailure:(NSInteger)errorCode
  524. {
  525. [app messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  526. [self.photoBrowser reloadData];
  527. }
  528. - (void)downloadPhotoBrowserSuccess:(tableMetadata *)metadataVar selector:(NSString *)selector
  529. {
  530. NSUInteger index = 0;
  531. // if a message for a directory of these
  532. if (![_dataSourceDirectoryID containsObject:metadataVar.directoryID])
  533. return;
  534. for (NSUInteger i=0; i < [self.dataSourceImagesVideos count]; i++ ) {
  535. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:i];
  536. // search index
  537. if ([metadataVar.fileID isEqualToString:metadata.fileID]) {
  538. index = i;
  539. break;
  540. }
  541. }
  542. // do not reload is Video on air
  543. if (_photoBrowser.currentVideoPlayerViewController.isViewLoaded && _photoBrowser.currentVideoPlayerViewController.view.window) return;
  544. if ([metadataVar.fileID isEqualToString:_fileIDNowVisible] || [self.photoBrowser isGridReload:index]) {
  545. [self.photoBrowser reloadData];
  546. _reload = NO;
  547. } else {
  548. _reload = YES;
  549. }
  550. }
  551. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  552. {
  553. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  554. if (serverUrl)
  555. [[CCNetworking sharedNetworking] downloadFile:metadata.fileID serverUrl:serverUrl downloadData:YES downloadPlist:NO selector:selectorLoadViewImage selectorPost:nil session:k_download_session taskStatus:k_taskStatusResume delegate:nil];
  556. }
  557. - (void)insertGeocoderLocation:(NSNotification *)notification
  558. {
  559. if (notification.userInfo.count == 0)
  560. return;
  561. NSString *fileID = [[notification.userInfo allKeys] objectAtIndex:0];
  562. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  563. // test [Chrash V 1.14,15]
  564. if (_indexNowVisible >= [self.photos count])
  565. return;
  566. if ([fileID isEqualToString:_fileIDNowVisible]) {
  567. MWPhoto *photo = [self.photos objectAtIndex:_indexNowVisible];
  568. [self setLocationCaptionPhoto:photo fileID:fileID];
  569. if (![self.photoBrowser isGridController]) {
  570. //[self.photoBrowser hideControls];
  571. //[self.photoBrowser showControls];
  572. }
  573. }
  574. }
  575. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  576. {
  577. tableLocalFile *localFile;
  578. // read Geocoder
  579. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  580. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  581. // Fix BUG Geo latitude & longitude
  582. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  583. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  584. if (metadata) {
  585. [[CCExifGeo sharedInstance] setExifLocalTableEtag:metadata directoryUser:app.directoryUser activeAccount:app.activeAccount];
  586. }
  587. }
  588. [[CCExifGeo sharedInstance] setGeocoderEtag:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  589. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  590. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  591. NSString *location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  592. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  593. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  594. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  595. }
  596. }
  597. }
  598. }
  599. #pragma --------------------------------------------------------------------------------------------
  600. #pragma mark ===== View PDF =====
  601. #pragma --------------------------------------------------------------------------------------------
  602. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  603. {
  604. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  605. [[alertView textFieldAtIndex:0] resignFirstResponder];
  606. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  607. }
  608. - (void)viewPDF:(NSString *)password
  609. {
  610. NSString *fileName;
  611. if (_sourceDirectoryLocal) {
  612. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  613. } else {
  614. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNamePrint];
  615. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  616. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  617. }
  618. if ([[NSFileManager defaultManager] fileExistsAtPath:fileName isDirectory:nil] == NO) {
  619. // read file error
  620. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  621. [alertView show];
  622. }
  623. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileName]);
  624. if (pdf) {
  625. // Encrypted
  626. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  627. // Try a blank password first, per Apple's Quartz PDF example
  628. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  629. // blank password
  630. [self readerPDF:fileName password:@""];
  631. } else {
  632. if ([password length] == 0) {
  633. // password request
  634. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  635. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  636. alertView.tag = alertRequestPasswordPDF;
  637. [alertView show];
  638. } else {
  639. const char *key = [password UTF8String];
  640. // failure
  641. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  642. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  643. [alertView show];
  644. } else {
  645. // pdf with password
  646. [self readerPDF:fileName password:password];
  647. }
  648. }
  649. }
  650. } else{
  651. // No password
  652. [self readerPDF:fileName password:@""];
  653. }
  654. } else {
  655. // read file error
  656. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  657. [alertView show];
  658. }
  659. }
  660. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  661. {
  662. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  663. if (documentPDF != nil) {
  664. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  665. self.readerPDFViewController.delegate = self;
  666. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  667. [self.readerPDFViewController updateContentViews];
  668. [self addChildViewController:self.readerPDFViewController];
  669. [self.view addSubview:self.readerPDFViewController.view];
  670. [self.readerPDFViewController didMoveToParentViewController:self];
  671. } else {
  672. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  673. [alertView show];
  674. }
  675. }
  676. - (void)handleSingleTapReader
  677. {
  678. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  679. _toolbar.hidden = !_toolbar.isHidden;
  680. if (_toolbar.isHidden) {
  681. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
  682. } else {
  683. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  684. }
  685. [self.readerPDFViewController updateContentViews];
  686. }
  687. #pragma --------------------------------------------------------------------------------------------
  688. #pragma mark ===== Delete =====
  689. #pragma --------------------------------------------------------------------------------------------
  690. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  691. {
  692. NSLog(@"[LOG] delete failure");
  693. }
  694. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  695. {
  696. // reload Main
  697. [app.activeMain reloadDatasource];
  698. // If removed document (web) or PDF close
  699. if (_webView || _readerPDFViewController)
  700. [self removeAllView];
  701. // if a message for a directory of these
  702. if (![_dataSourceDirectoryID containsObject:metadataNet.directoryID])
  703. return;
  704. // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
  705. if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadataNet.fileID]) {
  706. [app.player.mediaPlayer stop];
  707. NSArray *viewsToRemove = [self.view subviews];
  708. for (id element in viewsToRemove) {
  709. if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]] || [element isMemberOfClass:[LMMediaPlayerView class]])
  710. [element removeFromSuperview];
  711. }
  712. self.title = @"";
  713. [self.navigationController popViewControllerAnimated:YES];
  714. } else {
  715. // only photoBrowser if exists
  716. for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
  717. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  718. // ricerca index
  719. if ([metadata.fileID isEqualToString:metadataNet.fileID]) {
  720. [self.dataSourceImagesVideos removeObjectAtIndex:index];
  721. [self.photos removeObjectAtIndex:index];
  722. [self.thumbs removeObjectAtIndex:index];
  723. [self.photoBrowser reloadData];
  724. // Title
  725. if ([self.dataSourceImagesVideos count] == 0) {
  726. self.title = @"";
  727. [self.navigationController popViewControllerAnimated:YES];
  728. }
  729. break;
  730. }
  731. }
  732. }
  733. }
  734. #pragma --------------------------------------------------------------------------------------------
  735. #pragma mark ===== ButtonPressed =====
  736. #pragma --------------------------------------------------------------------------------------------
  737. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  738. {
  739. NSString *filePath;
  740. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  741. if (_sourceDirectoryLocal) {
  742. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  743. } else {
  744. filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.metadataDetail.fileNamePrint];
  745. }
  746. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  747. self.docController.delegate = self;
  748. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  749. [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  750. [self.docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  751. }
  752. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  753. {
  754. [app.activeMain openWindowShare:self.metadataDetail];
  755. }
  756. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  757. {
  758. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  759. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  760. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  761. style:UIAlertActionStyleDestructive
  762. handler:^(UIAlertAction *action) {
  763. [[CCActions sharedInstance] deleteFileOrFolder:self.metadataDetail delegate:self];
  764. }]];
  765. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  766. style:UIAlertActionStyleCancel
  767. handler:^(UIAlertAction *action) {
  768. [alertController dismissViewControllerAnimated:YES completion:nil];
  769. }]];
  770. alertController.popoverPresentationController.barButtonItem = _buttonDelete;
  771. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  772. [alertController.view layoutIfNeeded];
  773. [self presentViewController:alertController animated:YES completion:NULL];
  774. }
  775. @end