CCDetail.m 47 KB

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