CCDetail.m 46 KB

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