CCDetail.m 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  1. //
  2. // CCDetail.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 16/01/15.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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. #import "NCBridgeSwift.h"
  29. #define TOOLBAR_HEIGHT 49.0f
  30. #define alertRequestPasswordPDF 1
  31. @interface CCDetail () <NCTextDelegate, UIDocumentInteractionControllerDelegate>
  32. {
  33. AppDelegate *appDelegate;
  34. UIDocumentInteractionController *docController;
  35. UIBarButtonItem *buttonModifyFile;
  36. UIBarButtonItem *buttonShare;
  37. UIBarButtonItem *buttonDelete;
  38. NSInteger indexNowVisible;
  39. NSString *ocIdNowVisible;
  40. NSString *fileNameExtension;
  41. }
  42. @end
  43. @implementation CCDetail
  44. #pragma --------------------------------------------------------------------------------------------
  45. #pragma mark ===== init =====
  46. #pragma --------------------------------------------------------------------------------------------
  47. - (id)initWithCoder:(NSCoder *)aDecoder
  48. {
  49. if (self = [super initWithCoder:aDecoder]) {
  50. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  51. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  52. self.metadataDetail = [[tableMetadata alloc] init];
  53. self.photos = [[NSMutableArray alloc] init];
  54. self.photoDataSource = [NSMutableArray new];
  55. indexNowVisible = -1;
  56. ocIdNowVisible = nil;
  57. appDelegate.activeDetail = self;
  58. }
  59. return self;
  60. }
  61. #pragma --------------------------------------------------------------------------------------------
  62. #pragma mark ===== View =====
  63. #pragma --------------------------------------------------------------------------------------------
  64. - (void)viewDidLoad
  65. {
  66. [super viewDidLoad];
  67. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(insertGeocoderLocation:) name:@"insertGeocoderLocation" object:nil];
  68. [self changeTheming];
  69. // Open View
  70. if ([self.metadataDetail.fileNameView length] > 0 || [self.metadataDetail.serverUrl length] > 0 || [self.metadataDetail.ocId length] > 0) {
  71. [self viewFile];
  72. }
  73. }
  74. - (void)viewWillAppear:(BOOL)animated
  75. {
  76. [super viewWillAppear:animated];
  77. self.tabBarController.tabBar.hidden = YES;
  78. }
  79. - (void)viewWillDisappear:(BOOL)animated
  80. {
  81. [super viewWillDisappear:animated];
  82. self.navigationController.navigationBarHidden = NO;
  83. self.tabBarController.tabBar.hidden = NO;
  84. }
  85. - (void)viewDidDisappear:(BOOL)animated
  86. {
  87. [super viewDidDisappear:animated];
  88. // If AVPlayer in play -> Stop
  89. if (appDelegate.player != nil && appDelegate.player.rate != 0) {
  90. [appDelegate.player pause];
  91. }
  92. // remove Observer AVPlayer
  93. if (self.isMediaObserver) {
  94. self.isMediaObserver = NO;
  95. @try{
  96. [[NCViewerMedia sharedInstance] removeObserver];
  97. }@catch(id anException) { }
  98. }
  99. }
  100. - (void)changeTheming
  101. {
  102. [appDelegate changeTheming:self tableView:nil collectionView:nil form:false];
  103. if (self.toolbar) {
  104. self.toolbar.barTintColor = NCBrandColor.sharedInstance.tabBar;
  105. self.toolbar.tintColor = NCBrandColor.sharedInstance.brandElement;
  106. }
  107. // Logo
  108. self.imageBackground.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"logo"] multiplier:2 color:[NCBrandColor.sharedInstance.brand colorWithAlphaComponent:0.4]];
  109. // reload image
  110. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image]) {
  111. self.edgesForExtendedLayout = UIRectEdgeAll;
  112. [self viewImage];
  113. }
  114. }
  115. - (void)changeToDisplayMode
  116. {
  117. if (_readerPDFViewController) {
  118. [self.readerPDFViewController updateContentViews];
  119. }
  120. }
  121. #pragma --------------------------------------------------------------------------------------------
  122. #pragma mark ===== View File =====
  123. #pragma --------------------------------------------------------------------------------------------
  124. - (void)viewFile
  125. {
  126. // Remove all subview except ..
  127. //for (UIView *view in self.view.superview.subviews) {
  128. // NSInteger tag = view.tag;
  129. //}
  130. // Title
  131. self.navigationController.navigationBar.topItem.title = _metadataDetail.fileNameView;
  132. // verifico se esiste l'icona e se la posso creare
  133. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconOcId:self.metadataDetail.ocId fileNameView:self.metadataDetail.fileNameView]] == NO) {
  134. [CCGraphics createNewImageFrom:self.metadataDetail.fileNameView ocId:self.metadataDetail.ocId extension:[self.metadataDetail.fileNameView pathExtension] filterGrayScale:NO typeFile:self.metadataDetail.typeFile writeImage:YES];
  135. }
  136. // remove Observer AVPlayer
  137. if (self.isMediaObserver) {
  138. self.isMediaObserver = NO;
  139. [[NCViewerMedia sharedInstance] removeObserver];
  140. }
  141. // IMAGE
  142. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image]) {
  143. self.edgesForExtendedLayout = UIRectEdgeAll;
  144. [self viewImage];
  145. }
  146. // AUDIO VIDEO
  147. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_video] || [self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  148. self.edgesForExtendedLayout = UIRectEdgeAll;
  149. [self createToolbar];
  150. [[NCViewerMedia sharedInstance] viewMedia:self.metadataDetail detail:self];
  151. }
  152. // DOCUMENT - INTERNAL VIEWER
  153. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document] && [self.selectorDetail isEqualToString:selectorLoadFileInternalView]) {
  154. self.edgesForExtendedLayout = UIRectEdgeBottom;
  155. [self createToolbar];
  156. [[NCViewerDocumentWeb sharedInstance] viewDocumentWebAt:self.metadataDetail detail:self];
  157. return;
  158. }
  159. // DOCUMENT
  160. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_document]) {
  161. fileNameExtension = [[self.metadataDetail.fileNameView pathExtension] uppercaseString];
  162. if ([fileNameExtension isEqualToString:@"PDF"]) {
  163. self.edgesForExtendedLayout = UIRectEdgeBottom;
  164. [self createToolbar];
  165. [self viewPDF:@""];
  166. return;
  167. }
  168. // Nextcloud Text - RichWorkspace
  169. if ([[NCUtility sharedInstance] isDirectEditing:self.metadataDetail] != nil && appDelegate.reachability.isReachable) {
  170. NSString *editor = [[NCUtility sharedInstance] isDirectEditing:self.metadataDetail];
  171. if ([editor.lowercaseString isEqualToString:@"nextcloud text"]) {
  172. if([self.metadataDetail.url isEqualToString:@""]) {
  173. [[NCUtility sharedInstance] startActivityIndicatorWithView:self.view bottom:0];
  174. NSString *fileNamePath = [CCUtility returnFileNamePathFromFileName:self.metadataDetail.fileName serverUrl:self.metadataDetail.serverUrl activeUrl:appDelegate.activeUrl];
  175. [[NCCommunication sharedInstance] NCTextOpenFileWithUrlString:appDelegate.activeUrl fileNamePath:fileNamePath editor: @"text" account:self.metadataDetail.account completionHandler:^(NSString *account, NSString *url, NSInteger errorCode, NSString *errorMessage) {
  176. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  177. self.nextcloudText = [[NCViewerNextcloudText alloc] initWithFrame:self.view.bounds configuration:[WKWebViewConfiguration new]];
  178. [self.view addSubview:self.nextcloudText];
  179. [self.nextcloudText viewerAt:url detail:self metadata:self.metadataDetail];
  180. } else {
  181. if (errorCode != 0) {
  182. [[NCContentPresenter shared] messageNotification:@"_error_" description:errorMessage delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  183. } else {
  184. NSLog(@"[LOG] It has been changed user during networking process, error.");
  185. }
  186. [self.navigationController popViewControllerAnimated:YES];
  187. }
  188. }];
  189. } else {
  190. self.nextcloudText = [[NCViewerNextcloudText alloc] initWithFrame:self.view.bounds configuration:[WKWebViewConfiguration new]];
  191. [self.view addSubview:self.nextcloudText];
  192. [self.nextcloudText viewerAt:self.metadataDetail.url detail:self metadata:self.metadataDetail];
  193. }
  194. }
  195. return;
  196. }
  197. // RichDocument
  198. if ([[NCUtility sharedInstance] isRichDocument:self.metadataDetail] && appDelegate.reachability.isReachable) {
  199. [[NCUtility sharedInstance] startActivityIndicatorWithView:self.view bottom:0];
  200. if ([self.metadataDetail.url isEqualToString:@""]) {
  201. [[OCNetworking sharedManager] createLinkRichdocumentsWithAccount:appDelegate.activeAccount fileId:self.metadataDetail.fileId completion:^(NSString *account, NSString *link, NSString *message, NSInteger errorCode) {
  202. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  203. self.richDocument = [[NCViewerRichdocument alloc] initWithFrame:self.view.bounds configuration:[WKWebViewConfiguration new]];
  204. [self.view addSubview:self.richDocument];
  205. [self.richDocument viewRichDocumentAt:link detail:self metadata:self.metadataDetail];
  206. } else {
  207. [[NCUtility sharedInstance] stopActivityIndicator];
  208. if (errorCode != 0) {
  209. [[NCContentPresenter shared] messageNotification:@"_error_" description:message delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  210. } else {
  211. NSLog(@"[LOG] It has been changed user during networking process, error.");
  212. }
  213. [self.navigationController popViewControllerAnimated:YES];
  214. }
  215. }];
  216. } else {
  217. self.richDocument = [[NCViewerRichdocument alloc] initWithFrame:self.view.bounds configuration:[WKWebViewConfiguration new]];
  218. [self.view addSubview:self.richDocument];
  219. [self.richDocument viewRichDocumentAt:self.metadataDetail.url detail:self metadata:self.metadataDetail];
  220. }
  221. return;
  222. }
  223. self.edgesForExtendedLayout = UIRectEdgeBottom;
  224. [self createToolbar];
  225. [[NCViewerDocumentWeb sharedInstance] viewDocumentWebAt:self.metadataDetail detail:self];
  226. }
  227. }
  228. #pragma --------------------------------------------------------------------------------------------
  229. #pragma mark ===== Toolbar =====
  230. #pragma --------------------------------------------------------------------------------------------
  231. - (void)createToolbar
  232. {
  233. CGFloat safeAreaBottom = 0;
  234. if (@available(iOS 11, *)) {
  235. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  236. }
  237. self.toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom, self.view.bounds.size.width, TOOLBAR_HEIGHT)];
  238. UIBarButtonItem *flexible = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
  239. UIBarButtonItem *fixedSpaceMini = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
  240. fixedSpaceMini.width = 25;
  241. buttonModifyFile = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"actionSheetModify"] style:UIBarButtonItemStylePlain target:self action:@selector(modifyFileButtonPressed:)];
  242. if (![NCBrandOptions sharedInstance].disable_openin_file) {
  243. self.buttonAction = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"openFile"] style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)];
  244. }
  245. buttonShare = [[UIBarButtonItem alloc] initWithImage:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"share"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] style:UIBarButtonItemStylePlain target:self action:@selector(shareButtonPressed:)];
  246. buttonDelete = [[UIBarButtonItem alloc] initWithImage:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"trash"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] style:UIBarButtonItemStylePlain target:self action:@selector(deleteButtonPressed:)];
  247. if ([CCUtility isDocumentModifiableExtension:fileNameExtension]) {
  248. if ([CCUtility isFolderEncrypted:_metadataDetail.serverUrl account:appDelegate.activeAccount]) // E2EE
  249. [self.toolbar setItems:[NSArray arrayWithObjects: buttonModifyFile, flexible, buttonDelete, fixedSpaceMini, self.buttonAction, nil]];
  250. else
  251. [self.toolbar setItems:[NSArray arrayWithObjects: buttonModifyFile, flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, self.buttonAction, nil]];
  252. } else {
  253. if ([CCUtility isFolderEncrypted:_metadataDetail.serverUrl account:appDelegate.activeAccount]) // E2EE
  254. [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, self.buttonAction, nil]];
  255. else
  256. [self.toolbar setItems:[NSArray arrayWithObjects: flexible, buttonDelete, fixedSpaceMini, buttonShare, fixedSpaceMini, self.buttonAction, nil]];
  257. }
  258. [self.toolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];
  259. self.toolbar.barTintColor = NCBrandColor.sharedInstance.tabBar;
  260. self.toolbar.tintColor = NCBrandColor.sharedInstance.brandElement;
  261. [self.view addSubview:self.toolbar];
  262. }
  263. #pragma --------------------------------------------------------------------------------------------
  264. #pragma mark ===== View Image =====
  265. #pragma --------------------------------------------------------------------------------------------
  266. - (void)viewImage
  267. {
  268. self.photoBrowser = [[MWPhotoBrowser alloc] initWithDelegate:self];
  269. indexNowVisible = -1;
  270. ocIdNowVisible = nil;
  271. [self.photos removeAllObjects];
  272. // if not images, exit
  273. if ([self.photoDataSource count] == 0)
  274. return;
  275. NSUInteger index = 0;
  276. for (tableMetadata *metadata in self.photoDataSource) {
  277. // start from here ?
  278. if (self.metadataDetail.ocId && [metadata.ocId isEqualToString:self.metadataDetail.ocId])
  279. [self.photoBrowser setCurrentPhotoIndex:index];
  280. [self.photos addObject:[MWPhoto photoWithImage:nil]];
  281. // add directory
  282. index++;
  283. }
  284. // PhotoBrowser
  285. if ([NCBrandOptions sharedInstance].disable_openin_file) {
  286. self.photoBrowser.displayActionButton = NO;
  287. } else {
  288. self.photoBrowser.displayActionButton = YES;
  289. }
  290. self.photoBrowser.displayDeleteButton = YES;
  291. if ([CCUtility isFolderEncrypted:_metadataDetail.serverUrl account:appDelegate.activeAccount]) // E2EE
  292. self.photoBrowser.displayShareButton = NO;
  293. else
  294. self.photoBrowser.displayShareButton = YES;
  295. self.photoBrowser.displayNavArrows = YES;
  296. self.photoBrowser.displaySelectionButtons = NO;
  297. self.photoBrowser.alwaysShowControls = NO;
  298. self.photoBrowser.zoomPhotosToFill = NO;
  299. self.photoBrowser.autoPlayOnAppear = NO;
  300. self.photoBrowser.delayToHideElements = 15;
  301. if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
  302. self.photoBrowser.enableSwipeToDismiss = NO;
  303. if (self.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
  304. [self addChildViewController:self.photoBrowser];
  305. [self.view addSubview:self.photoBrowser.view];
  306. [self.photoBrowser didMoveToParentViewController:self];
  307. } else {
  308. [self.navigationController pushViewController:self.photoBrowser animated:NO];
  309. }
  310. self.navigationController.navigationBar.topItem.title = _metadataDetail.fileNameView;
  311. }
  312. - (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
  313. {
  314. return [self.photoDataSource count];
  315. }
  316. - (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
  317. {
  318. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  319. NSString *titleDir = metadata.fileNameView;
  320. self.title = titleDir;
  321. return titleDir;
  322. }
  323. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index
  324. {
  325. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  326. indexNowVisible = index;
  327. ocIdNowVisible = metadata.ocId;
  328. photoBrowser.toolbar.hidden = NO;
  329. // Download image ?
  330. if (metadata) {
  331. NSInteger status;
  332. tableMetadata *metadataDB = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", metadata.ocId]];
  333. if (metadataDB) {
  334. status = metadataDB.status;
  335. } else {
  336. status = k_metadataStatusNormal;
  337. }
  338. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView] == NO && status == k_metadataStatusNormal) {
  339. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView]] == NO && metadata.hasPreview) {
  340. [CCGraphics addImageToTitle:NSLocalizedString(@"_...loading..._", nil) colorTitle:NCBrandColor.sharedInstance.brandText imageTitle:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"load"] multiplier:2 color:NCBrandColor.sharedInstance.brandText] imageRight:NO navigationItem:self.navigationItem];
  341. CGFloat width = [[NCUtility sharedInstance] getScreenWidthForPreview];
  342. CGFloat height = [[NCUtility sharedInstance] getScreenHeightForPreview];
  343. [[OCNetworking sharedManager] downloadPreviewWithAccount:appDelegate.activeAccount metadata:metadata withWidth:width andHeight:height completion:^(NSString *account, UIImage *image, NSString *message, NSInteger errorCode) {
  344. self.navigationItem.titleView = nil;
  345. self.title = metadata.fileNameView;
  346. if (errorCode == 0 && [account isEqualToString:appDelegate.activeAccount]) {
  347. [self.photoBrowser reloadData];
  348. }
  349. }];
  350. } else {
  351. [self downloadPhotoBrowser:metadata];
  352. }
  353. }
  354. }
  355. // Title
  356. if (metadata)
  357. self.title = metadata.fileNameView;
  358. }
  359. - (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
  360. {
  361. UIImage *image;
  362. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  363. if (index < self.photos.count) {
  364. if (metadata.ocId) {
  365. UIImage *imagePreview = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView]];
  366. // if (!imagePreview) imagePreview = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"file_photo"] multiplier:3 color:[NCBrandColor.sharedInstance icon]];
  367. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_image]) {
  368. NSString *fileImage = [CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView];
  369. NSString *ext = [CCUtility getExtension:metadata.fileNameView];
  370. if ([ext isEqualToString:@"GIF"]) image = [UIImage animatedImageWithAnimatedGIFURL:[NSURL fileURLWithPath:fileImage]];
  371. else image = [UIImage imageWithContentsOfFile:fileImage];
  372. if (image) {
  373. MWPhoto *photo = [MWPhoto photoWithImage:image];
  374. // Location ??
  375. [self setLocationCaptionPhoto:photo ocId:metadata.ocId];
  376. [self.photos replaceObjectAtIndex:index withObject:photo];
  377. } else {
  378. if (metadata.status == k_metadataStatusDownloadError) {
  379. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  380. } else {
  381. if (imagePreview)
  382. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  383. }
  384. }
  385. }
  386. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_video]) {
  387. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  388. NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView]];
  389. MWPhoto *video = [MWPhoto photoWithImage:[CCGraphics thumbnailImageForVideo:url atTime:1.0]];
  390. video.videoURL = url;
  391. [self.photos replaceObjectAtIndex:index withObject:video];
  392. } else {
  393. if (metadata.status == k_metadataStatusDownloadError) {
  394. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  395. } else {
  396. if (imagePreview)
  397. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  398. }
  399. }
  400. }
  401. if ([metadata.typeFile isEqualToString: k_metadataTypeFile_audio]) {
  402. if ([CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView]) {
  403. MWPhoto *audio;
  404. UIImage *audioImage;
  405. NSURL *url = [NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView]];
  406. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView]]) {
  407. audioImage = [UIImage imageWithContentsOfFile:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView]];
  408. } else {
  409. audioImage = [UIImage imageNamed:@"notaMusic"]; //[CCGraphics scaleImage:[UIImage imageNamed:@"notaMusic"] toSize:CGSizeMake(200, 200) isAspectRation:YES];
  410. }
  411. audio = [MWPhoto photoWithImage:audioImage];
  412. audio.videoURL = url;
  413. [self.photos replaceObjectAtIndex:index withObject:audio];
  414. } else {
  415. if (metadata.status == k_metadataStatusDownloadError) {
  416. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:[UIImage imageNamed:@"filePreviewError"]]];
  417. } else {
  418. if (imagePreview)
  419. [self.photos replaceObjectAtIndex:index withObject:[MWPhoto photoWithImage:imagePreview]];
  420. }
  421. }
  422. }
  423. }
  424. // energy saving memory
  425. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  426. int iPrev = (int)index - 2;
  427. if (iPrev >= 0) {
  428. if ([self.photos objectAtIndex:iPrev] != nil)
  429. [self.photos replaceObjectAtIndex:iPrev withObject:[MWPhoto photoWithImage:nil]];
  430. }
  431. int iNext = (int)index + 2;
  432. if (iNext < _photos.count) {
  433. if ([self.photos objectAtIndex:iNext] != nil)
  434. [self.photos replaceObjectAtIndex:iNext withObject:[MWPhoto photoWithImage:nil]];
  435. }
  436. });
  437. return [self.photos objectAtIndex:index];
  438. }
  439. return nil;
  440. }
  441. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index
  442. {
  443. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  444. if (metadata == nil) return;
  445. docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:[CCUtility getDirectoryProviderStorageOcId:metadata.ocId fileNameView:metadata.fileNameView]]];
  446. docController.delegate = self;
  447. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  448. [docController presentOptionsMenuFromRect:photoBrowser.view.frame inView:photoBrowser.view animated:YES];
  449. [docController presentOptionsMenuFromBarButtonItem:photoBrowser.actionButton animated:YES];
  450. }
  451. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser shareButtonPressedForPhotoAtIndex:(NSUInteger)index
  452. {
  453. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  454. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:metadata indexPage:2];
  455. }
  456. - (void)photoBrowser:(MWPhotoBrowser *)photoBrowser deleteButtonPressedForPhotoAtIndex:(NSUInteger)index deleteButton:(UIBarButtonItem *)deleteButton
  457. {
  458. tableMetadata *metadata = [self.photoDataSource objectAtIndex:index];
  459. if (metadata == nil || [CCUtility fileProviderStorageExists:metadata.ocId fileNameView:metadata.fileNameView] == NO) {
  460. [[NCContentPresenter shared] messageNotification:@"_info_" description:@"_file_not_found_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:0];
  461. return;
  462. }
  463. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  464. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  465. style:UIAlertActionStyleDestructive
  466. handler:^(UIAlertAction *action) {
  467. [self deleteFile:metadata];
  468. }]];
  469. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  470. style:UIAlertActionStyleCancel
  471. handler:^(UIAlertAction *action) {
  472. }]];
  473. alertController.popoverPresentationController.barButtonItem = deleteButton;
  474. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  475. [alertController.view layoutIfNeeded];
  476. [self.parentViewController presentViewController:alertController animated:YES completion:NULL];
  477. }
  478. - (void)photoBrowserDidFinishPresentation:(MWPhotoBrowser *)photoBrowser
  479. {
  480. [self.navigationController popViewControllerAnimated:YES];
  481. }
  482. - (void)downloadPhotoBrowserSuccessFailure:(tableMetadata *)metadata selector:(NSString *)selector errorCode:(NSInteger)errorCode
  483. {
  484. // if a message for a directory of these
  485. if (![metadata.ocId isEqualToString:ocIdNowVisible])
  486. return;
  487. // Title
  488. self.navigationItem.titleView = nil;
  489. self.title = metadata.fileNameView;
  490. if (errorCode == 0) {
  491. // verifico se esiste l'icona e se la posso creare
  492. if ([[NSFileManager defaultManager] fileExistsAtPath:[CCUtility getDirectoryProviderStorageIconOcId:metadata.ocId fileNameView:metadata.fileNameView]] == NO) {
  493. [CCGraphics createNewImageFrom:metadata.fileNameView ocId:metadata.ocId extension:[metadata.fileNameView pathExtension] filterGrayScale:NO typeFile:metadata.typeFile writeImage:YES];
  494. }
  495. [self.photoBrowser reloadData];
  496. } else {
  497. [[NCContentPresenter shared] messageNotification:@"_download_selected_files_" description:@"_error_download_photobrowser_" delay:k_dismissAfterSecond type:messageTypeError errorCode:errorCode];
  498. [self.navigationController popViewControllerAnimated:YES];
  499. }
  500. }
  501. - (void)downloadPhotoBrowser:(tableMetadata *)metadata
  502. {
  503. tableMetadata *metadataForDownload = [[NCManageDatabase sharedInstance] initNewMetadata:metadata];
  504. metadataForDownload.session = k_download_session;
  505. metadataForDownload.sessionError = @"";
  506. metadataForDownload.sessionSelector = selectorLoadViewImage;
  507. metadataForDownload.status = k_metadataStatusWaitDownload;
  508. // Add Metadata for Download
  509. (void)[[NCManageDatabase sharedInstance] addMetadata:metadataForDownload];
  510. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:metadata.serverUrl ocId:metadataForDownload.ocId action:k_action_MOD];
  511. [appDelegate startLoadAutoDownloadUpload];
  512. [CCGraphics addImageToTitle:NSLocalizedString(@"_...loading..._", nil) colorTitle:NCBrandColor.sharedInstance.brandText imageTitle:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"load"] multiplier:2 color:NCBrandColor.sharedInstance.brandText] imageRight:NO navigationItem:self.navigationItem];
  513. }
  514. - (void)insertGeocoderLocation:(NSNotification *)notification
  515. {
  516. if (notification.userInfo.count == 0)
  517. return;
  518. NSString *ocId = [[notification.userInfo allKeys] objectAtIndex:0];
  519. //NSDate *date = [[notification.userInfo allValues] objectAtIndex:0];
  520. // test [Chrash V 1.14,15]
  521. if (indexNowVisible >= [self.photos count])
  522. return;
  523. if ([ocId isEqualToString:ocIdNowVisible]) {
  524. MWPhoto *photo = [self.photos objectAtIndex:indexNowVisible];
  525. [self setLocationCaptionPhoto:photo ocId:ocId];
  526. [self.photoBrowser reloadData];
  527. }
  528. }
  529. - (void)setLocationCaptionPhoto:(MWPhoto *)photo ocId:(NSString *)ocId
  530. {
  531. tableLocalFile *localFile;
  532. // read Geocoder
  533. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  534. if ([localFile.exifLatitude doubleValue] != 0 || [localFile.exifLongitude doubleValue] != 0) {
  535. // Fix BUG Geo latitude & longitude
  536. if ([localFile.exifLatitude doubleValue] == 9999 || [localFile.exifLongitude doubleValue] == 9999) {
  537. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  538. if (metadata) {
  539. [[CCExifGeo sharedInstance] setExifLocalTableEtag:metadata];
  540. }
  541. }
  542. [[CCExifGeo sharedInstance] setGeocoderEtag:ocId exifDate:localFile.exifDate latitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  543. localFile = [[NCManageDatabase sharedInstance] getTableLocalFileWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", ocId]];
  544. if ([localFile.exifLatitude floatValue] != 0 || [localFile.exifLongitude floatValue] != 0) {
  545. NSString *location = [[NCManageDatabase sharedInstance] getLocationFromGeoLatitude:localFile.exifLatitude longitude:localFile.exifLongitude];
  546. if ([localFile.exifDate isEqualToDate:[NSDate distantPast]] == NO && location) {
  547. NSString *localizedDateTime = [NSDateFormatter localizedStringFromDate:localFile.exifDate dateStyle:NSDateFormatterFullStyle timeStyle:NSDateFormatterMediumStyle];
  548. photo.caption = [NSString stringWithFormat:NSLocalizedString(@"%@\n%@", nil), localizedDateTime, location];
  549. }
  550. }
  551. }
  552. }
  553. #pragma --------------------------------------------------------------------------------------------
  554. #pragma mark ===== View PDF =====
  555. #pragma --------------------------------------------------------------------------------------------
  556. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
  557. {
  558. [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
  559. [[alertView textFieldAtIndex:0] resignFirstResponder];
  560. if (alertView.tag == alertRequestPasswordPDF) [self performSelector:@selector(viewPDF:) withObject:[alertView textFieldAtIndex:0].text afterDelay:0.3];
  561. }
  562. - (void)viewPDF:(NSString *)password
  563. {
  564. // remove cache PDF
  565. NSString *filePlistReader = [NSString stringWithFormat:@"%@/%@.plist", [CCUtility getDirectoryReaderMetadata], self.metadataDetail.fileNameView.stringByDeletingPathExtension];
  566. [CCUtility removeFileAtPath:filePlistReader];
  567. NSString *fileNamePath = [CCUtility getDirectoryProviderStorageOcId:self.metadataDetail.ocId fileNameView:self.metadataDetail.fileNameView];
  568. if ([CCUtility fileProviderStorageExists:self.metadataDetail.ocId fileNameView:self.metadataDetail.fileNameView] == NO) {
  569. // read file error
  570. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  571. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  572. [alertController addAction:okAction];
  573. [self presentViewController:alertController animated:YES completion:nil];
  574. }
  575. CGPDFDocumentRef pdf = CGPDFDocumentCreateWithURL((CFURLRef)[NSURL fileURLWithPath:fileNamePath]);
  576. if (pdf) {
  577. // Encrypted
  578. if (CGPDFDocumentIsEncrypted(pdf) == YES) {
  579. // Try a blank password first, per Apple's Quartz PDF example
  580. if (CGPDFDocumentUnlockWithPassword(pdf, "") == YES) {
  581. // blank password
  582. [self readerPDF:fileNamePath password:@""];
  583. } else {
  584. if ([password length] == 0) {
  585. // password request
  586. UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"_insert_password_pfd_",nil) message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"_ok_", nil), nil];
  587. [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
  588. alertView.tag = alertRequestPasswordPDF;
  589. [alertView show];
  590. } else {
  591. const char *key = [password UTF8String];
  592. // failure
  593. if (CGPDFDocumentUnlockWithPassword(pdf, key) == NO) {
  594. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_password_pdf_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  595. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  596. [alertController addAction:okAction];
  597. [self presentViewController:alertController animated:YES completion:nil];
  598. } else {
  599. // pdf with password
  600. [self readerPDF:fileNamePath password:password];
  601. }
  602. }
  603. }
  604. } else{
  605. // No password
  606. [self readerPDF:fileNamePath password:@""];
  607. }
  608. } else {
  609. // read file error
  610. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  611. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  612. [alertController addAction:okAction];
  613. [self presentViewController:alertController animated:YES completion:nil];
  614. }
  615. }
  616. - (void)readerPDF:(NSString *)fileName password:(NSString *)password
  617. {
  618. ReaderDocument *documentPDF = [ReaderDocument withDocumentFilePath:fileName password:password];
  619. CGFloat safeAreaBottom = 0;
  620. if (@available(iOS 11, *)) {
  621. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  622. }
  623. if (documentPDF != nil) {
  624. self.readerPDFViewController = [[ReaderViewController alloc] initWithReaderDocument:documentPDF];
  625. self.readerPDFViewController.delegate = self;
  626. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  627. [self.readerPDFViewController updateContentViews];
  628. [self addChildViewController:self.readerPDFViewController];
  629. [self.view addSubview:self.readerPDFViewController.view];
  630. [self.readerPDFViewController didMoveToParentViewController:self];
  631. } else {
  632. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"_error_", nil) message:NSLocalizedString(@"_read_file_error_", nil) preferredStyle:UIAlertControllerStyleAlert];
  633. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {}];
  634. [alertController addAction:okAction];
  635. [self presentViewController:alertController animated:YES completion:nil];
  636. }
  637. }
  638. - (void)handleSingleTapReader
  639. {
  640. UILayoutGuide *layoutGuide;
  641. CGFloat safeAreaTop = 0;
  642. CGFloat safeAreaBottom = 0;
  643. if (@available(iOS 11, *)) {
  644. layoutGuide = [UIApplication sharedApplication].delegate.window.safeAreaLayoutGuide;
  645. safeAreaTop = [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;
  646. safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
  647. }
  648. self.navigationController.navigationBarHidden = !self.navigationController.navigationBarHidden;
  649. self.toolbar.hidden = !self.toolbar.isHidden;
  650. if (self.toolbar.isHidden) {
  651. self.readerPDFViewController.view.frame = CGRectMake(0, safeAreaTop, self.view.bounds.size.width, self.view.bounds.size.height - safeAreaTop - safeAreaBottom);
  652. } else {
  653. self.readerPDFViewController.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height - TOOLBAR_HEIGHT - safeAreaBottom);
  654. }
  655. [self.readerPDFViewController updateContentViews];
  656. }
  657. - (void)handleSwipeUpDown
  658. {
  659. // REMOVE IT'S UNUSABLE
  660. /*
  661. self.navigationController.navigationBarHidden = false; // iOS App is unusable after swipe up or down with PDF in fullscreen #526
  662. [self removeAllView];
  663. [self.navigationController popViewControllerAnimated:YES];
  664. */
  665. }
  666. #pragma --------------------------------------------------------------------------------------------
  667. #pragma mark ===== Delete =====
  668. #pragma --------------------------------------------------------------------------------------------
  669. - (void)deleteFile:(tableMetadata *)metadata
  670. {
  671. tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND e2eEncrypted == 1 AND serverUrl == %@", appDelegate.activeAccount, metadata.serverUrl]];
  672. [[NCMainCommon sharedInstance ] deleteFileWithMetadatas:[[NSArray alloc] initWithObjects:metadata, nil] e2ee:tableDirectory.e2eEncrypted serverUrl:tableDirectory.serverUrl folderocId:tableDirectory.ocId completion:^(NSInteger errorCode, NSString *message) {
  673. if (errorCode == 0) {
  674. // reload data source
  675. [[NCMainCommon sharedInstance] reloadDatasourceWithServerUrl:tableDirectory.serverUrl ocId:metadata.ocId action:k_action_DEL];
  676. // Not image
  677. if ([self.metadataDetail.typeFile isEqualToString: k_metadataTypeFile_image] == NO) {
  678. // exit
  679. [self.navigationController popViewControllerAnimated:YES];
  680. } else {
  681. for (NSUInteger index=0; index < [self.photoDataSource count] && _photoBrowser; index++ ) {
  682. tableMetadata *metadataTemp = [self.photoDataSource objectAtIndex:index];
  683. if ([metadata isInvalidated] || [metadataTemp.ocId isEqualToString:metadata.ocId]) {
  684. [self.photoDataSource removeObjectAtIndex:index];
  685. [self.photos removeObjectAtIndex:index];
  686. [self.photoBrowser reloadData];
  687. // exit
  688. if ([self.photoDataSource count] == 0) {
  689. [self.navigationController popViewControllerAnimated:YES];
  690. }
  691. }
  692. }
  693. }
  694. } else {
  695. NSLog(@"[LOG] DeleteFileOrFolder failure error %d, %@", (int)errorCode, message);
  696. }
  697. }];
  698. }
  699. #pragma --------------------------------------------------------------------------------------------
  700. #pragma mark ===== ButtonPressed =====
  701. #pragma --------------------------------------------------------------------------------------------
  702. - (void)dismissTextView
  703. {
  704. if (self.webView) {
  705. NSString *fileNamePath = [NSTemporaryDirectory() stringByAppendingString:self.metadataDetail.fileNameView];
  706. [[NSFileManager defaultManager] removeItemAtPath:fileNamePath error:nil];
  707. [[NSFileManager defaultManager] linkItemAtPath:[CCUtility getDirectoryProviderStorageOcId:self.metadataDetail.ocId fileNameView:self.metadataDetail.fileNameView] toPath:fileNamePath error:nil];
  708. [self.webView reload];
  709. }
  710. }
  711. - (void)modifyFileButtonPressed:(UIBarButtonItem *)sender
  712. {
  713. tableMetadata *metadata = [[NCManageDatabase sharedInstance] getMetadataWithPredicate:[NSPredicate predicateWithFormat:@"ocId == %@", self.metadataDetail.ocId]];
  714. if (metadata && [self.selectorDetail isEqualToString:selectorLoadFileInternalView]) {
  715. UINavigationController* navigationController = [[UIStoryboard storyboardWithName:@"NCText" bundle:nil] instantiateViewControllerWithIdentifier:@"NCText"];
  716. NCText *viewController = (NCText *)navigationController.topViewController;
  717. viewController.metadata = metadata;
  718. viewController.delegate = self;
  719. navigationController.modalPresentationStyle = UIModalPresentationPageSheet;
  720. navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
  721. [self presentViewController:navigationController animated:YES completion:nil];
  722. }
  723. }
  724. - (void)actionButtonPressed:(UIBarButtonItem *)sender
  725. {
  726. if ([self.metadataDetail.fileNameView length] == 0) return;
  727. NSString *filePath = [CCUtility getDirectoryProviderStorageOcId:self.metadataDetail.ocId fileNameView:self.metadataDetail.fileNameView];
  728. docController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
  729. docController.delegate = self;
  730. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  731. [docController presentOptionsMenuFromRect:self.view.frame inView:self.view animated:YES];
  732. else
  733. [docController presentOptionsMenuFromBarButtonItem:sender animated:YES];
  734. }
  735. - (void)shareButtonPressed:(UIBarButtonItem *)sender
  736. {
  737. [[NCMainCommon sharedInstance] openShareWithViewController:self metadata:self.metadataDetail indexPage:2];
  738. }
  739. - (void)deleteButtonPressed:(UIBarButtonItem *)sender
  740. {
  741. if ([self.metadataDetail.fileNameView length] == 0) return;
  742. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  743. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_delete_", nil)
  744. style:UIAlertActionStyleDestructive
  745. handler:^(UIAlertAction *action) {
  746. [self deleteFile:self.metadataDetail];
  747. }]];
  748. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil)
  749. style:UIAlertActionStyleCancel
  750. handler:^(UIAlertAction *action) {
  751. [alertController dismissViewControllerAnimated:YES completion:nil];
  752. }]];
  753. alertController.popoverPresentationController.barButtonItem = buttonDelete;
  754. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
  755. [alertController.view layoutIfNeeded];
  756. [self presentViewController:alertController animated:YES completion:NULL];
  757. }
  758. @end