CCDetail.m 47 KB

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