CCDetail.m 47 KB

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