CCDetail.m 47 KB

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