CCDetail.m 47 KB

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