CCDetail.m 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153
  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. appDelegate.player.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  223. appDelegate.player.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  224. appDelegate.player.nextButton.hidden = true;
  225. appDelegate.player.previousButton.hidden = true;
  226. appDelegate.player.fullscreenButton_.hidden = true;
  227. LMMediaItem *item = [[LMMediaItem alloc] initWithInfo:@{LMMediaItemInfoURLKey:[NSURL fileURLWithPath:fileName], LMMediaItemInfoContentTypeKey:@(LMMediaItemContentTypeVideo)}];
  228. item.title = self.metadataDetail.fileNamePrint;
  229. item.artist = [NCBrandOptions sharedInstance].brand;
  230. [appDelegate.player.mediaPlayer removeAllMediaInQueue];
  231. [appDelegate.player.mediaPlayer addMedia:item];
  232. [appDelegate.player.mediaPlayer play];
  233. // Info
  234. NSMutableDictionary *songInfo = [[NSMutableDictionary alloc] init];
  235. [songInfo setObject:app.player.mediaPlayer.nowPlayingItem.title forKey:MPMediaItemPropertyTitle];
  236. [songInfo setObject:app.player.mediaPlayer.nowPlayingItem.artist forKey:MPMediaItemPropertyArtist];
  237. [[MPNowPlayingInfoCenter defaultCenter] setNowPlayingInfo:songInfo];
  238. [self.view addSubview:appDelegate.player];
  239. }
  240. #pragma --------------------------------------------------------------------------------------------
  241. #pragma mark ===== View Document =====
  242. #pragma --------------------------------------------------------------------------------------------
  243. - (void)viewDocument
  244. {
  245. NSString *fileName;
  246. if (_sourceDirectoryLocal) {
  247. fileName = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  248. } else {
  249. fileName = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNamePrint];
  250. [[NSFileManager defaultManager] removeItemAtPath:fileName error:nil];
  251. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, self.metadataDetail.fileID] toPath:fileName error:nil];
  252. }
  253. NSURL *url = [NSURL fileURLWithPath:fileName];
  254. WKPreferences *wkPreferences = [[WKPreferences alloc] init];
  255. wkPreferences.javaScriptEnabled = false;
  256. WKWebViewConfiguration *wkConfig = [[WKWebViewConfiguration alloc] init];
  257. wkConfig.preferences = wkPreferences;
  258. self.webView = [[WKWebView alloc] initWithFrame:(CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT)) configuration:wkConfig];
  259. self.webView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
  260. [self.webView setBackgroundColor:[UIColor whiteColor]];
  261. [self.webView setOpaque:NO];
  262. if ( [_fileNameExtension isEqualToString:@"CSS"] || [_fileNameExtension isEqualToString:@"PY"] || [_fileNameExtension isEqualToString:@"XML"] || [_fileNameExtension isEqualToString:@"JS"] ) {
  263. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:[NSURL fileURLWithPath:fileName]];
  264. [headRequest setHTTPMethod:@"HEAD"];
  265. NSHTTPURLResponse *headResponse;
  266. NSError *error = nil;
  267. [NSURLConnection sendSynchronousRequest:headRequest returningResponse:&headResponse error:&error];
  268. if (error != nil) {
  269. NSLog(@"[LOG] loadURLWithString %@",[error localizedDescription]);
  270. }
  271. NSString *dataFile = [[NSString alloc] initWithData:[NSData dataWithContentsOfURL:url] encoding:NSASCIIStringEncoding];
  272. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
  273. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"40",@"Sans-Serif",dataFile] baseURL:nil];
  274. }else{
  275. [self.webView loadHTMLString:[NSString stringWithFormat:@"<div style='font-size:%@;font-family:%@;'><pre>%@",@"20",@"Sans-Serif",dataFile] baseURL:nil];
  276. }
  277. } else if ([_fileNameExtension isEqualToString:@"TXT"]) {
  278. NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  279. NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:nil delegateQueue:nil];
  280. NSMutableURLRequest *headRequest = [NSMutableURLRequest requestWithURL:url];
  281. [headRequest setHTTPMethod:@"HEAD"];
  282. NSURLSessionDataTask *task = [session dataTaskWithRequest:headRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
  283. [self.webView loadData:[NSData dataWithContentsOfURL: url] MIMEType:response.MIMEType characterEncodingName:@"utf-8" baseURL:url];
  284. }];
  285. [task resume];
  286. } else {
  287. [self.webView loadRequest:[NSMutableURLRequest requestWithURL:url]];
  288. }
  289. [self.view addSubview:self.webView];
  290. }
  291. #pragma --------------------------------------------------------------------------------------------
  292. #pragma mark ===== View Image =====
  293. #pragma --------------------------------------------------------------------------------------------
  294. - (void)viewImage
  295. {
  296. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  297. _reload = NO;
  298. _indexNowVisible = -1;
  299. _fileIDNowVisible = nil;
  300. [self.photos removeAllObjects];
  301. [self.thumbs removeAllObjects];
  302. [_dataSourceDirectoryID removeAllObjects];
  303. // if not images, exit
  304. if ([self.dataSourceImagesVideos count] == 0) return;
  305. NSUInteger index = 0;
  306. for (tableMetadata *metadata in self.dataSourceImagesVideos) {
  307. // start from here ?
  308. if (self.metadataDetail.fileID && [metadata.fileID isEqualToString:self.metadataDetail.fileID])
  309. [self.photoBrowser setCurrentPhotoIndex:index];
  310. if (metadata.cryptated) {
  311. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownloadCrypto"]]];
  312. [self.thumbs addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownloadCrypto"]]];
  313. } else {
  314. [self.photos addObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownload"]]];
  315. MWPhoto *thumb = [MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewDownload"]];
  316. if ([metadata.typeFile isEqualToString: k_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. self.photoBrowser.displayDeleteButton = YES;
  326. self.photoBrowser.displayNavArrows = YES;
  327. self.photoBrowser.displaySelectionButtons = NO;
  328. self.photoBrowser.alwaysShowControls = NO;
  329. self.photoBrowser.zoomPhotosToFill = NO;
  330. self.photoBrowser.startOnGrid = NO;
  331. self.photoBrowser.autoPlayOnAppear = NO;
  332. self.photoBrowser.delayToHideElements = 15;
  333. self.photoBrowser.enableGrid = YES;
  334. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  335. [self addChildViewController:self.photoBrowser];
  336. [self.view addSubview:self.photoBrowser.view];
  337. [self.photoBrowser didMoveToParentViewController:self];
  338. } else {
  339. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  340. }
  341. }
  342. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  343. {
  344. return [self.dataSourceImagesVideos count];
  345. }
  346. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  347. {
  348. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  349. NSString *titleDir = metadata.fileNamePrint;
  350. self.title = titleDir;
  351. return titleDir;
  352. }
  353. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  354. {
  355. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  356. NSString *directory;
  357. _indexNowVisible = index;
  358. _fileIDNowVisible = metadata.fileID;
  359. photoBrowser.toolbar.hidden = NO;
  360. if (_sourceDirectoryLocal)
  361. directory = self.metadataDetail.directoryID;
  362. else
  363. directory = app.directoryUser;
  364. // Download image ?
  365. if (metadata) {
  366. tableMetadata *metadataDB = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", metadata.fileID]];
  367. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]] == NO && [metadataDB.session length] == 0)
  368. [self downloadPhotoBrowser:metadata];
  369. }
  370. // Title
  371. if (metadata && !photoBrowser.isGridController)
  372. self.title = metadata.fileNamePrint;
  373. if (_reload) {
  374. [self.photoBrowser performSelector:@selector(reloadData) withObject:nil];
  375. _reload = NO;
  376. }
  377. }
  378. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  379. {
  380. NSString *directory;
  381. UIImage *image;
  382. if (_sourceDirectoryLocal)
  383. directory = self.metadataDetail.directoryID;
  384. else
  385. directory = app.directoryUser;
  386. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  387. if (index < self.photos.count) {
  388. if (metadata.fileID) {
  389. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  390. NSString *fileImage = [NSString stringWithFormat:@"%@/%@", directory, metadata.fileID];
  391. NSString *ext = [CCUtility getExtension:metadata.fileNamePrint];
  392. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  393. else image = [UIImage imageWithContentsOfFile:fileImage];
  394. if (image) {
  395. MWPhoto *photo = [MWPhoto photoWithImage:image];
  396. // Location ??
  397. [self setLocationCaptionPhoto:photo fileID:metadata.fileID];
  398. [self.photos replaceObjectAtIndex:index withObject:photo];
  399. } else {
  400. if ([metadata.sessionError length] > 0 ) {
  401. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  402. } else {
  403. image = [CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50];
  404. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:image]];
  405. }
  406. }
  407. }
  408. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  409. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID]]) {
  410. // remove and make the simbolic link in temp
  411. NSString *toPath = [NSTemporaryDirectory() stringByAppendingString:metadata.fileNamePrint];
  412. [[NSFileManager defaultManager] removeItemAtPath:toPath error:nil];
  413. [[NSFileManager defaultManager] linkItemAtPath:[NSString stringWithFormat:@"%@/%@", directory, metadata.fileID] toPath:toPath error:nil];
  414. NSURL *url = [NSURL fileURLWithPath:toPath];
  415. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  416. video.videoURL = url;
  417. [self.photos replaceObjectAtIndex:index withObject:video];
  418. } else {
  419. if ([metadata.sessionError length] > 0 ) {
  420. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  421. } else {
  422. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[CCGraphics drawText:[NSLocalizedString(@"_loading_", nil) stringByAppendingString:@"..."] inImage:[UIImage imageNamed:@"button1000x200"] colorText:[UIColor darkGrayColor] sizeOfFont:50]]];
  423. }
  424. }
  425. }
  426. }
  427. // energy saving memory
  428. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  429. int iPrev = (int)index - 2;
  430. if (iPrev >= 0) {
  431. if ([self.photos objectAtIndex:iPrev] != nil)
  432. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  433. }
  434. int iNext = (int)index + 2;
  435. if (iNext < _photos.count) {
  436. if ([self.photos objectAtIndex:iNext] != nil)
  437. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  438. }
  439. });
  440. return [self.photos objectAtIndex:index];
  441. }
  442. return nil;
  443. }
  444. - (void)gridWillAppear:(MWPhotoBrowser *)photoBrowser
  445. {
  446. // reload [BUG]
  447. [self.photoBrowser reloadData];
  448. // in grid clear all MWPhoto : energy saving memory
  449. if (self.photos.count > 1 && [self.dataSourceImagesVideos count] > 0) {
  450. for(int index=0; index < self.photos.count; index++)
  451. [_photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:nil]];
  452. }
  453. self.title = [NSString stringWithFormat:@"Album %lu %@", (unsigned long)_photos.count, NSLocalizedString(@"photos", nil)];
  454. }
  455. - (void)gridWillDisappear:(MWPhotoBrowser *)photoBrowser
  456. {
  457. //
  458. photoBrowser.toolbar.hidden = NO;
  459. }
  460. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index
  461. {
  462. NSString *directory;
  463. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  464. if (_sourceDirectoryLocal)
  465. directory = self.metadataDetail.directoryID;
  466. else
  467. directory = app.directoryUser;
  468. if (index < self.thumbs.count) {
  469. if (metadata.fileID) {
  470. UIImage *image;
  471. if (_sourceDirectoryLocal) {
  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: k_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. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  491. if (metadata == nil) return;
  492. if (_sourceDirectoryLocal) {
  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)
  502. [self.docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  503. [self.docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  504. }
  505. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  506. {
  507. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  508. [app.activeMain openWindowShare:metadata];
  509. }
  510. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  511. {
  512. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  513. if (metadata == nil || [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@", app.directoryUser, metadata.fileID]] == NO) {
  514. [app messageNotification:@"_info_" description:@"_file_not_found_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeInfo errorCode:0];
  515. return;
  516. }
  517. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  518. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  519. style:UIAlertActionStyleDestructive
  520. handler:^(UIAlertAction *action) {
  521. [[CCActions sharedInstance] deleteFileOrFolder:metadata delegate:self];
  522. }]];
  523. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  524. style:UIAlertActionStyleCancel
  525. handler:^(UIAlertAction *action) {
  526. [alertController dismissViewControllerAnimated:YES completion:nil];
  527. }]];
  528. alertController.popoverPresentationController.barButtonItem = deleteButton;
  529. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  530. [alertController.view layoutIfNeeded];
  531. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  532. }
  533. - (void)triggerProgressTask:(NSNotification *)notification
  534. {
  535. NSDictionary *dict = notification.userInfo;
  536. float progress = [[dict valueForKey:@"progress"] floatValue];
  537. if (progress == 0)
  538. [self.navigationController cancelCCProgress];
  539. else
  540. [self.navigationController setCCProgressPercentage:progress*100 andTintColor:[NCBrandColor sharedInstance].navigationBarProgress];
  541. }
  542. - (void)downloadPhotoBrowserFailure:(NSInteger)errorCode
  543. {
  544. [app messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:errorCode];
  545. [self.photoBrowser reloadData];
  546. }
  547. - (void)downloadPhotoBrowserSuccess:(tableMetadata *)metadataVar selector:(NSString *)selector
  548. {
  549. NSUInteger index = 0;
  550. // if a message for a directory of these
  551. if (![_dataSourceDirectoryID containsObject:metadataVar.directoryID])
  552. return;
  553. for (NSUInteger i=0; i < [self.dataSourceImagesVideos count]; i++ ) {
  554. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:i];
  555. // search index
  556. if ([metadataVar.fileID isEqualToString:metadata.fileID]) {
  557. index = i;
  558. break;
  559. }
  560. }
  561. // do not reload is Video on air
  562. if (_photoBrowser.currentVideoPlayerViewController.isViewLoaded && _photoBrowser.currentVideoPlayerViewController.view.window) return;
  563. if ([metadataVar.fileID isEqualToString:_fileIDNowVisible] || [self.photoBrowser isGridReload:index]) {
  564. [self.photoBrowser reloadData];
  565. _reload = NO;
  566. } else {
  567. _reload = YES;
  568. }
  569. }
  570. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  571. {
  572. NSString *serverUrl = [[NCManageDatabase sharedInstance] getServerUrl:metadata.directoryID];
  573. if (serverUrl)
  574. [[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];
  575. }
  576. - (void)insertGeocoderLocation:(NSNotification *)notification
  577. {
  578. if (notification.userInfo.count == 0)
  579. return;
  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 (_indexNowVisible >= [self.photos count])
  584. return;
  585. if ([fileID isEqualToString:_fileIDNowVisible]) {
  586. MWPhoto *photo = [self.photos objectAtIndex:_indexNowVisible];
  587. [self setLocationCaptionPhoto:photo fileID:fileID];
  588. if (![self.photoBrowser isGridController]) {
  589. //[self.photoBrowser hideControls];
  590. //[self.photoBrowser showControls];
  591. }
  592. }
  593. }
  594. - (void)setLocationCaptionPhoto:(MWPhoto *)photo fileID:(NSString *)fileID
  595. {
  596. tableLocalFile *localFile;
  597. // read Geocoder
  598. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  599. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  600. // Fix BUG Geo latitude & longitude
  601. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  602. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  603. if (metadata) {
  604. [[CCExifGeo sharedInstance] setExifLocalTableEtag:metadata directoryUser:app.directoryUser activeAccount:app.activeAccount];
  605. }
  606. }
  607. [[CCExifGeo sharedInstance] setGeocoderEtag:fileID exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  608. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"fileID = %@", fileID]];
  609. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  610. NSString *location = [[NCManageDatabase sharedInstance] 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 (_sourceDirectoryLocal) {
  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.delegate = self;
  685. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  686. [self.readerPDFViewController updateContentViews];
  687. [self addChildViewController:self.readerPDFViewController];
  688. [self.view addSubview:self.readerPDFViewController.view];
  689. [self.readerPDFViewController didMoveToParentViewController:self];
  690. } else {
  691. UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) delegate:nil cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  692. [alertView show];
  693. }
  694. }
  695. - (void)handleSingleTapReader
  696. {
  697. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  698. _toolbar.hidden = !_toolbar.isHidden;
  699. if (_toolbar.isHidden) {
  700. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
  701. } else {
  702. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT);
  703. }
  704. [self.readerPDFViewController updateContentViews];
  705. }
  706. #pragma --------------------------------------------------------------------------------------------
  707. #pragma mark ===== Delete =====
  708. #pragma --------------------------------------------------------------------------------------------
  709. - (void)deleteFileOrFolderFailure:(CCMetadataNet *)metadataNet message:(NSString *)message errorCode:(NSInteger)errorCode
  710. {
  711. NSLog(@"[LOG] delete failure");
  712. }
  713. - (void)deleteFileOrFolderSuccess:(CCMetadataNet *)metadataNet
  714. {
  715. // reload Main
  716. [app.activeMain reloadDatasource];
  717. // If removed document (web) or PDF close
  718. if (_webView || _readerPDFViewController)
  719. [self removeAllView];
  720. // if a message for a directory of these
  721. if (![_dataSourceDirectoryID containsObject:metadataNet.directoryID])
  722. return;
  723. // if we are not in browserPhoto and it's removed photo/video in preview then "< Back"
  724. if (!self.photoBrowser && [self.metadataDetail.fileID isEqualToString:metadataNet.fileID]) {
  725. [app.player.mediaPlayer stop];
  726. NSArray *viewsToRemove = [self.view subviews];
  727. for (id element in viewsToRemove) {
  728. if ([element isMemberOfClass:[UIView class]] || [element isMemberOfClass:[UIToolbar class]] || [element isMemberOfClass:[LMMediaPlayerView class]])
  729. [element removeFromSuperview];
  730. }
  731. self.title = @"";
  732. [self.navigationController popViewControllerAnimated:YES];
  733. } else {
  734. // only photoBrowser if exists
  735. for (NSUInteger index=0; index < [self.dataSourceImagesVideos count] && _photoBrowser; index++ ) {
  736. tableMetadata *metadata = [self.dataSourceImagesVideos objectAtIndex:index];
  737. // ricerca index
  738. if ([metadata.fileID isEqualToString:metadataNet.fileID]) {
  739. [self.dataSourceImagesVideos removeObjectAtIndex:index];
  740. [self.photos removeObjectAtIndex:index];
  741. [self.thumbs removeObjectAtIndex:index];
  742. [self.photoBrowser reloadData];
  743. // Title
  744. if ([self.dataSourceImagesVideos count] == 0) {
  745. self.title = @"";
  746. [self.navigationController popViewControllerAnimated:YES];
  747. }
  748. break;
  749. }
  750. }
  751. }
  752. }
  753. #pragma --------------------------------------------------------------------------------------------
  754. #pragma mark ===== ButtonPressed =====
  755. #pragma --------------------------------------------------------------------------------------------
  756. - (void)modifyTxtButtonPressed:(UIBarButtonItem *)sender
  757. {
  758. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
  759. NCText *viewController = (NCText *)navigationController.topViewController;
  760. viewController.metadata = self.metadataDetail;
  761. /*
  762. typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {
  763. UIModalTransitionStyleCoverVertical = 0,
  764. UIModalTransitionStyleFlipHorizontal __TVOS_PROHIBITED,
  765. UIModalTransitionStyleCrossDissolve,
  766. UIModalTransitionStylePartialCurl NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
  767. };
  768. typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {
  769. UIModalPresentationFullScreen = 0,
  770. UIModalPresentationPageSheet NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
  771. UIModalPresentationFormSheet NS_ENUM_AVAILABLE_IOS(3_2) __TVOS_PROHIBITED,
  772. UIModalPresentationCurrentContext NS_ENUM_AVAILABLE_IOS(3_2),
  773. UIModalPresentationCustom NS_ENUM_AVAILABLE_IOS(7_0),
  774. UIModalPresentationOverFullScreen NS_ENUM_AVAILABLE_IOS(8_0),
  775. UIModalPresentationOverCurrentContext NS_ENUM_AVAILABLE_IOS(8_0),
  776. UIModalPresentationPopover NS_ENUM_AVAILABLE_IOS(8_0) __TVOS_PROHIBITED,
  777. UIModalPresentationNone NS_ENUM_AVAILABLE_IOS(7_0) = -1,
  778. };
  779. */
  780. navigationController.modalPresentationStyle = UIModalPresentationPageSheet;
  781. navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  782. [self presentViewController:navigationController animated:YES completion:nil];
  783. }
  784. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  785. {
  786. NSString *filePath;
  787. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  788. if (_sourceDirectoryLocal) {
  789. filePath = [NSString stringWithFormat:@"%@/%@", self.metadataDetail.directoryID, self.metadataDetail.fileNamePrint];
  790. } else {
  791. filePath = [NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), self.metadataDetail.fileNamePrint];
  792. }
  793. self.docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  794. self.docController.delegate = self;
  795. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  796. [self.docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  797. [self.docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  798. }
  799. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  800. {
  801. [app.activeMain openWindowShare:self.metadataDetail];
  802. }
  803. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  804. {
  805. if ([self.metadataDetail.fileNamePrint length] == 0) return;
  806. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  807. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  808. style:UIAlertActionStyleDestructive
  809. handler:^(UIAlertAction *action) {
  810. [[CCActions sharedInstance] deleteFileOrFolder:self.metadataDetail delegate:self];
  811. }]];
  812. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  813. style:UIAlertActionStyleCancel
  814. handler:^(UIAlertAction *action) {
  815. [alertController dismissViewControllerAnimated:YES completion:nil];
  816. }]];
  817. alertController.popoverPresentationController.barButtonItem = _buttonDelete;
  818. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  819. [alertController.view layoutIfNeeded];
  820. [self presentViewController:alertController animated:YES completion:NULL];
  821. }
  822. @end