CCDetail.m 48 KB

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