CCDetail.m 44 KB

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