CCDetail.m 46 KB

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