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