CCDetail.m 47 KB

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